{"id":22624673,"url":"https://github.com/barrettotte/btc-hash","last_synced_at":"2025-04-16T00:57:01.908Z","repository":{"id":114089671,"uuid":"202933171","full_name":"barrettotte/BTC-Hash","owner":"barrettotte","description":"Learning about the bitcoin hashing and SHA-256 algorithms.","archived":false,"fork":false,"pushed_at":"2020-08-31T17:41:45.000Z","size":91,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-16T00:56:57.084Z","etag":null,"topics":["bitcoin","btc","c","sha-256"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/barrettotte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-17T21:33:31.000Z","updated_at":"2025-01-20T11:39:12.000Z","dependencies_parsed_at":"2023-06-12T13:45:29.025Z","dependency_job_id":null,"html_url":"https://github.com/barrettotte/BTC-Hash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrettotte%2FBTC-Hash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrettotte%2FBTC-Hash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrettotte%2FBTC-Hash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrettotte%2FBTC-Hash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barrettotte","download_url":"https://codeload.github.com/barrettotte/BTC-Hash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249178215,"owners_count":21225349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","btc","c","sha-256"],"created_at":"2024-12-09T00:17:20.087Z","updated_at":"2025-04-16T00:57:01.887Z","avatar_url":"https://github.com/barrettotte.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BTC-Hash\n\nLearning about the bitcoin hashing and SHA-256 algorithms.\n\n\n## SHA-256\nFollowed the SHA-256 specification - http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf\n\n\nI saw a lot of implementations had multiple functions (init,process,final) and a sha256_context struct. \nFor my purposes I thought it was kind of overkill to go that route, so I made a function\nto produce the SHA-256 digest in one call rather than 3.\n\n\n## Bitcoin Hashing Algorithm\nI followed the logic laid out on the [bitcoin wiki](https://en.bitcoin.it/wiki/Block_hashing_algorithm) for the\nhashing algorithm. The hardest part was getting my double SHA-256 hash working correctly \n(it took me 2 hours to realize I was using the wrong endianness)\n\n\n## Sample\nCalculating/outputting hash rate every 100,000 iterations.\n\n```\nNonce  1500000 : 41b76de4a780eda162e312ef989501326a115ea879a1fa615a326d5cc88e10df    Hash Rate: 196.840578 kH/s\nNonce  1600000 : fd550eac652dde1d6d6b9525dacce686cf4f59aa237f98c93d508b485578a6d9    Hash Rate: 196.841893 kH/s\nNonce  1700000 : 659e8fc9b7c915d1591218036f569c09895703b91051591dd9ae1afe40a16833    Hash Rate: 197.170350 kH/s\nNonce  1800000 : bf243bd487a79ac57ad2eabcd1619d6b665cc9c11a75e1c5446a7bd165246409    Hash Rate: 197.335943 kH/s\nNonce  1900000 : e58bc951d6db6c19b03a191a6f57184ef0a66c77793ee2cbe0e5d85622e8ce1e    Hash Rate: 196.960608 kH/s\nNonce  2000000 : 33bd6d0f054d21a860044af4107480150546f80fd80f4247ec19e4bbb72c969e    Hash Rate: 197.241110 kH/s\n```\n\n\n## References\n* Inspiration for the project [Mining BTC on the Apollo Guidance Computer](http://www.righto.com/2019/07/bitcoin-mining-on-apollo-guidance.html)\n* BTC\n  * Mined block used in implementation https://www.blockchain.com/btc/block-height/250000\n  * BTC hashing algorithm https://en.bitcoin.it/wiki/Block_hashing_algorithm\n  * BTC Protocol https://en.bitcoin.it/wiki/Protocol_documentation\n  * BTC mining the hard way http://www.righto.com/2014/02/bitcoin-mining-hard-way-algorithms.html\n* SHA-256 calculator\n * https://emn178.github.io/online-tools/sha256.html\n * https://www.fileformat.info/tool/hash.htm\n* SHA-256\n  * Test vectors for SHA https://www.di-mgt.com.au/sha_testvectors.html\n  * SHA-256 pseudocode https://en.wikipedia.org/wiki/SHA-2#pseudocode\n  * SHA-256 spec http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarrettotte%2Fbtc-hash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarrettotte%2Fbtc-hash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarrettotte%2Fbtc-hash/lists"}