<div dir="ltr">Thanks, Ethan, that&#39;s helpful and I&#39;ll stop thinking that collision attacks require 2^(n/2) memory...<div><br></div><div>So can we quantify the incremental increase in security of SHA256(SHA256) over RIPEMD160(SHA256) versus the incremental increase in security of having a simpler implementation of segwitness?</div><div><br></div><div>I&#39;m going to claim that the difference in the first case is very, very, very small-- the risk of an implementation error caused by having multiple ways of interpreting the segwitness hash in the scriptPubKey is much, much greater.</div><div><br></div><div>And even if there IS some risk of collision attack now or at some point in the future, I claim that it is easy for wallets to mitigate that risk. In fact, the principle of security in depth means wallets that don&#39;t completely control the scriptPubKeys they&#39;re creating on behalf of users SHOULD be coded to mitigate that risk (e.g. not allowing arbitrary data around a user&#39;s public key in a Script so targeted substring attacks are eliminated entirely).</div><div><br></div><div>Purely from a security point of view, I think a single 20-byte segwitness in the scriptPubKey is the best design.</div>&quot;Keep the design as simple and small as possible&quot; <a href="https://www.securecoding.cert.org/confluence/plugins/servlet/mobile#content/view/2426">https://www.securecoding.cert.org/confluence/plugins/servlet/mobile#content/view/2426</a><div><br><div>Add in the implied capacity increase of smaller scriptPubKeys and I still think it is a no-brainer.</div><div><br></div><div><br></div><div class="gmail_extra"><div class="gmail_quote">On Thu, Jan 7, 2016 at 5:56 PM, Ethan Heilman <span dir="ltr">&lt;<a href="mailto:eth3rs@gmail.com" target="_blank">eth3rs@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">&gt;Ethan:  your algorithm will find two arbitrary values that collide. That isn&#39;t useful as an attack in the context we&#39;re talking about here (both of those values will be useless as coin destinations with overwhelming probability).<br>
<br>
</span>I&#39;m not sure exactly the properties you want here and determining<br>
these properties is not an easy task, but the case is far worse than<br>
just two random values. For instance: (a). with a small modification<br>
my algorithm can also find collisions containing targeted substrings,<br>
(b). length extension attacks are possible with RIPEMD160.<br>
<br>
(a). targeted cycles:<br>
<br>
target1 = &quot;str to prepend&quot;<br>
target2 = &quot;str to end with&quot;<br>
<span class=""><br>
seed = {0,1}^160<br>
x = hash(seed)<br>
<br>
for i in 2^80:<br>
</span>....x = hash(target1||x||target2)<br>
x_final = x<br>
<br>
y = hash(tartget1||x_final||target2)<br>
<span class=""><br>
for j in 2^80:<br>
....if y == x_final:<br>
........print &quot;cycle len: &quot;+j<br>
........break<br>
</span>....y = hash(target1||y||target2)<br>
<br>
If a collision is found, the two colliding inputs must both start with<br>
&quot;str to prepend&quot; and end with the phrase &quot;str to end with&quot;. As before<br>
this only requires 2^81.5 computations and no real memory. For an<br>
additional 2**80 an adversary has an good change of finding two<br>
different targeted substrings which collide. Consider the case where<br>
the attacker mixes the targeted strings with the hash output:<br>
<br>
hash(&quot;my name is=0x329482039483204324423&quot;+x[1]+&quot;, my favorite number<br>
is=&quot;+x) where x[1] is the first bit of x.<br>
<br>
(b). length extension attacks<br>
<br>
Even if all the adversary can do is create two random values that<br>
collide, you can append substrings to the input and get collisions.<br>
Once you find two random values hash(x) = hash(y), you could use a<br>
length extension attack on RIPEMD-160 to find hash(x||z) = hash(y||z).<br>
<br>
Now the bitcoin wiki says:<br>
&quot;The padding scheme is identical to MD4 using Merkle–Damgård<br>
strengthening to prevent length extension attacks.&quot;[1]<br>
<br>
Which is confusing to me because:<br>
<br>
1. MD4 is vulnerable to length extension attacks<br>
2. Merkle–Damgård strengthening does not protect against length<br>
extension: &quot;Indeed, we already pointed out that none of the 64<br>
variants above can withstand the &#39;extension&#39; attack on the MAC<br>
application, even with the Merkle-Damgard strengthening&quot; [2]<br>
3. RIPEMD-160 is vulnerable to length extension attacks, is Bitcoin<br>
using a non-standard version of RIPEMD-160.<br>
<br>
RIPEMD160(SHA256()) does not protect against length extension attacks<br>
on SHA256, but should protect RIPEMD-160 against length extension<br>
attacks as RIPEMD-160 uses 512-bit message blocks. That being said we<br>
should be very careful here. Research has been done that shows that<br>
cascading the same hash function twice is weaker than using HMAC[3]. I<br>
can&#39;t find results on cascading RIPEMD160(SHA256()).<br>
<br>
RIPEMD160(SHA256()) seems better than RIPEMD160() though, but security<br>
should not rest on the notion that an attacker requires 2**80 memory,<br>
many targeted collision attacks can work without much memory.<br>
<br>
[1]: <a href="https://en.bitcoin.it/wiki/RIPEMD-160" rel="noreferrer" target="_blank">https://en.bitcoin.it/wiki/RIPEMD-160</a><br>
[2]: &quot;Merkle-Damgard Revisited: How to Construct a Hash Function&quot;<br>
<a href="https://www.cs.nyu.edu/~puniya/papers/merkle.pdf" rel="noreferrer" target="_blank">https://www.cs.nyu.edu/~puniya/papers/merkle.pdf</a><br>
[3]: <a href="https://www.cs.nyu.edu/~dodis/ps/h-of-h.pdf" rel="noreferrer" target="_blank">https://www.cs.nyu.edu/~dodis/ps/h-of-h.pdf</a><br>
<div class=""><div class="h5"><br>
On Thu, Jan 7, 2016 at 4:06 PM, Gavin Andresen via bitcoin-dev<br>
&lt;<a href="mailto:bitcoin-dev@lists.linuxfoundation.org">bitcoin-dev@lists.linuxfoundation.org</a>&gt; wrote:<br>
&gt; Maybe I&#39;m asking this question on the wrong mailing list:<br>
&gt;<br>
&gt; Matt/Adam: do you have some reason to think that RIPEMD160 will be broken<br>
&gt; before SHA256?<br>
&gt; And do you have some reason to think that they will be so broken that the<br>
&gt; nested hash construction RIPEMD160(SHA256()) will be vulnerable?<br>
&gt;<br>
&gt; Adam: re: &quot;where to stop&quot;  :  I&#39;m suggesting we stop exactly at the current<br>
&gt; status quo, where we use RIPEMD160 for P2SH and P2PKH.<br>
&gt;<br>
&gt; Ethan:  your algorithm will find two arbitrary values that collide. That<br>
&gt; isn&#39;t useful as an attack in the context we&#39;re talking about here (both of<br>
&gt; those values will be useless as coin destinations with overwhelming<br>
&gt; probability).<br>
&gt;<br>
&gt; Dave: you described a first preimage attack, which is 2**160 cpu time and no<br>
&gt; storage.<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; --<br>
&gt; Gavin Andresen<br>
&gt;<br>
</div></div><div class=""><div class="h5">&gt; _______________________________________________<br>
&gt; bitcoin-dev mailing list<br>
&gt; <a href="mailto:bitcoin-dev@lists.linuxfoundation.org">bitcoin-dev@lists.linuxfoundation.org</a><br>
&gt; <a href="https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev" rel="noreferrer" target="_blank">https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev</a><br>
&gt;<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">--<br>Gavin Andresen<br></div>
</div></div></div>