Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Frodek on November 21, 2015, 08:13:57 PM



Title: Why sha256(sha256()) ?
Post by: Frodek on November 21, 2015, 08:13:57 PM
In Bitcoin Developer Reference https://bitcoin.org/en/developer-reference (https://bitcoin.org/en/developer-reference) is in many places sha256(sha256()) instead sha256(), it has any meaning?


Title: Re: Why sha256(sha256()) ?
Post by: virtualx on November 21, 2015, 08:27:25 PM
In Bitcoin Developer Reference https://bitcoin.org/en/developer-reference (https://bitcoin.org/en/developer-reference) is in many places sha256(sha256()) instead sha256(), it has any meaning?

Yes sha256 is a hashing function used in the protocol. A hashing function is 'easy' to compute one way but difficult to compute the other way. Other hashing functions are SHA1 and MD5. MD5 is partly broken, lots of collisions.

From satoshi:
Quote
SHA-256 is very strong.  It's not like the incremental step from MD5 to SHA1.  It can last several decades unless there's some massive breakthrough attack.

If SHA-256 became completely broken, I think we could come to some agreement about what the honest block chain was before the trouble started, lock that in and continue from there with a new hash function.

If the hash breakdown came gradually, we could transition to a new hash in an orderly way.  The software would be programmed to start using a new hash after a certain block number.  Everyone would have to upgrade by that time.  The software could save the new hash of all the old blocks to make sure a different block with the same old hash can't be used.



Title: Re: Why sha256(sha256()) ?
Post by: cr1776 on November 21, 2015, 09:06:56 PM
I think he was asking why double hashing vs just a single sha256.

If so, it was to help prevent length-extension attacks:

see e.g.
http://crypto.stackexchange.com/a/884


Title: Re: Why sha256(sha256()) ?
Post by: DiamondCardz on November 21, 2015, 09:12:57 PM
In Bitcoin Developer Reference https://bitcoin.org/en/developer-reference (https://bitcoin.org/en/developer-reference) is in many places sha256(sha256()) instead sha256(), it has any meaning?

Yes sha256 is a hashing function used in the protocol. A hashing function is 'easy' to compute one way but difficult to compute the other way. Other hashing functions are SHA1 and MD5. MD5 is partly broken, lots of collisions.

I don't think you actually read the OP properly. Unsure if that's due to your signature or just due to inattentiveness. His question does not ask why hashing is used, I'm fairly sure he knows why it is used and he did refer to "instead of sha256()". He's referring to double hashing.


Title: Re: Why sha256(sha256()) ?
Post by: Frodek on November 22, 2015, 07:27:52 AM
Twice Sha256 is to prevent length-extension attacks. If in theory, instead SHA-2 would be SHA-3, not need twice SHA?


Title: Re: Why sha256(sha256()) ?
Post by: moneyart on November 22, 2015, 04:15:56 PM
1. priv/pub key
2. SHA-256
3. RIPEMD-160
4. Add version byte 0
5. SHA-256
6. SHA-256
7. Take 4 bytes
8. Add 4 bytes to result of 4
9. Convert to base 58

The double SHA-256 is only for the 4 check bytes. Why is this important for security reasons?


Title: Re: Why sha256(sha256()) ?
Post by: achow101 on November 22, 2015, 04:25:05 PM
1. priv/pub key
2. SHA-256
3. RIPEMD-160
4. Add version byte 0
5. SHA-256
6. SHA-256
7. Take 4 bytes
8. Add 4 bytes to result of 4
9. Convert to base 58

The double SHA-256 is only for the 4 check bytes. Why is this important for security reasons?
It is used for mining. The mining algorithm is sha256d


Title: Re: Why sha256(sha256()) ?
Post by: moneyart on November 22, 2015, 04:30:50 PM
You also double SHA 256 when you build up the merkle tree.