1

Probably a simple question, but I believe it is important to state it clearly for the beginners like me out there.

What is the hash function used for the Bitcoin proof-of-work? What implementations are available? Any Java implementation?

Peter Mel
  • 625
  • 1
  • 7
  • 14
  • 1
    Related: http://bitcoin.stackexchange.com/questions/6037/why-are-hashes-in-the-bitcoin-protocol-typically-computed-twice-double-computed – morsecoder Sep 03 '15 at 14:25
  • 1
    Related: http://bitcoin.stackexchange.com/questions/4317/why-does-bitcoin-use-two-rounds-of-sha256 – morsecoder Sep 03 '15 at 14:27

2 Answers2

2

Bitcoin uses SHA256d to hash block headers, which is sha256(sha256(x)).

In anticipation of your next question, it uses a double hash to protect against length extension attacks (source).

morsecoder
  • 14,168
  • 2
  • 42
  • 94
  • 1
    In reality extension attacks aren't really applicable to proof of work anyway, but convention is probably as good of a reason as any I suppose. – Claris Sep 03 '15 at 21:47
1

From Bitcoin Wiki PoW and tangentially, HashCash:

SHA256(SHA256(Block_Header)) but you have to be careful about byte-order.

Specifically, it is SHA256d

Implementations are often standard libraries, like Python's hashlib.

Wizard Of Ozzie
  • 5,298
  • 4
  • 31
  • 63