Skip to content

Learning about the bitcoin hashing and SHA-256 algorithms.

License

Notifications You must be signed in to change notification settings

barrettotte/BTC-Hash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BTC-Hash

Learning about the bitcoin hashing and SHA-256 algorithms.

SHA-256

Followed the SHA-256 specification - http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf

I saw a lot of implementations had multiple functions (init,process,final) and a sha256_context struct. For my purposes I thought it was kind of overkill to go that route, so I made a function to produce the SHA-256 digest in one call rather than 3.

Bitcoin Hashing Algorithm

I followed the logic laid out on the bitcoin wiki for the hashing algorithm. The hardest part was getting my double SHA-256 hash working correctly (it took me 2 hours to realize I was using the wrong endianness)

Sample

Calculating/outputting hash rate every 100,000 iterations.

Nonce  1500000 : 41b76de4a780eda162e312ef989501326a115ea879a1fa615a326d5cc88e10df    Hash Rate: 196.840578 kH/s
Nonce  1600000 : fd550eac652dde1d6d6b9525dacce686cf4f59aa237f98c93d508b485578a6d9    Hash Rate: 196.841893 kH/s
Nonce  1700000 : 659e8fc9b7c915d1591218036f569c09895703b91051591dd9ae1afe40a16833    Hash Rate: 197.170350 kH/s
Nonce  1800000 : bf243bd487a79ac57ad2eabcd1619d6b665cc9c11a75e1c5446a7bd165246409    Hash Rate: 197.335943 kH/s
Nonce  1900000 : e58bc951d6db6c19b03a191a6f57184ef0a66c77793ee2cbe0e5d85622e8ce1e    Hash Rate: 196.960608 kH/s
Nonce  2000000 : 33bd6d0f054d21a860044af4107480150546f80fd80f4247ec19e4bbb72c969e    Hash Rate: 197.241110 kH/s

References

About

Learning about the bitcoin hashing and SHA-256 algorithms.

Topics

Resources

License

Stars

Watchers

Forks