{"id":18994871,"url":"https://github.com/jweinst1/sha-256-tree","last_synced_at":"2025-10-28T08:49:59.554Z","repository":{"id":97724145,"uuid":"124008274","full_name":"jweinst1/SHA-256-Tree","owner":"jweinst1","description":"A C implementation of the SHA 256 tree hash algorithm","archived":false,"fork":false,"pushed_at":"2018-03-06T19:41:15.000Z","size":4608,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-01T15:43:29.182Z","etag":null,"topics":["hashing","hashing-algorithm","sha-256"],"latest_commit_sha":null,"homepage":null,"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/jweinst1.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":"2018-03-06T02:26:19.000Z","updated_at":"2020-04-14T07:04:35.000Z","dependencies_parsed_at":"2023-07-06T10:15:48.363Z","dependency_job_id":null,"html_url":"https://github.com/jweinst1/SHA-256-Tree","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/jweinst1%2FSHA-256-Tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jweinst1%2FSHA-256-Tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jweinst1%2FSHA-256-Tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jweinst1%2FSHA-256-Tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jweinst1","download_url":"https://codeload.github.com/jweinst1/SHA-256-Tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240010212,"owners_count":19733514,"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":["hashing","hashing-algorithm","sha-256"],"created_at":"2024-11-08T17:27:21.797Z","updated_at":"2025-10-28T08:49:54.518Z","avatar_url":"https://github.com/jweinst1.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SHA-256-Tree\nA C implementation of the SHA 256 tree hash algorithm\n\n## Intro\n\nThis repo contains an implementation of the SHA-256 tree hash algorithm. This algorithm takes a file of binary data (or treats it as binary data), and calculates a tree-ordered checksum of each one megabyte chunk of data present for the file. This implementation does not use any existing 3rd party libraries, just the C standard library. If a file is less than 1 MB in size, no tree hash reduction logic is involved.\n\n## Installation\n\nTo build the CLI tool, clone the repo then run in your terminal:\n\n```\n$ make cli\n```\n\nThis builds an executable in a `bin` dir named `shatree`.\n\n## Usage\n\nTo open the help guide, simply run the executable\n\n```\n$ ./bin/shatree\n----Usage Guide----\nThis executable perfroms as SHA-256 tree hash on documents and prints out detailed performance info.\nIt also prints out round of reduction info.\nshatree \u003cfilename\u003e\n-------------------\n```\n\nTo hash a file, supply the file name\n```\n$ ./bin/shatree testfiles/test1.JPG\n```\n\n## Mechanics\n\nThis implementation uses a data structure optimized for hashing larger files and deferring expensive calls to `free()` until after the entire checksum is calculated.\n\nThis is accomplished by usage a garbage stack, and not freeing any hold hash nodes until the final checksum is completed.\n\n### HashListing\n\nThe first process in this implementation is to turn a document into 1MB hashed chunks, which is essentially a linked list of hashes. Here is an example debug-representation of that.\n\n```\n____Document_Hash_List______\nHashNode:(1) @ 0x7f96b9402660\nHash = 185520110146192269015611140144228249224192322714914120324819582118249211941499127\n- - - - - - -\nHashNode:(2) @ 0x7f96b9402690\nHash = 312255676321378911615719087129204205887213745121385134163822271991722812221732\n- - - - - - -\n____________________________\n```\n\nSince only two chunks exist in this hash list, the file is just over 1 MB in size.\n\nAfter this, the hash nodes in the list are reduced, by concatenation and rehashing. This is done until only 1 node remains, which is the final hash.\n\n\n## Example\n\nBelow is a full print out of the hash result of a file.\n\n```\nHashing File at path: testfiles/test2.jpg\nChunk Hashing completed, elapsed time = 0.056209s\n---Reducing Hashed File Chunks---\nHash Reduction Round 1\n::::::::::::::::::::::::\n____Document_Hash_List______\nHashNode:(1) @ 0x7f8315c02660\nHash = 216127152166107254150130128181986886246133188142183438739732437915754250761552297156\n- - - - - - -\nHashNode:(2) @ 0x7f8315d00000\nHash = 2920412165171605013163177229967024934302508511725422221221761826398136223211127225\n- - - - - - -\nHashNode:(3) @ 0x7f8315e00000\nHash = 1292038313822021715171236282181071271682121472166024610220224378154395422318520521343230\n- - - - - - -\nHashNode:(4) @ 0x7f8315f00000\nHash = 3185189426117824857411021822712821212417920612915837981775911138982517125324521256\n- - - - - - -\n____________________________\nHash Reduction Round 2\n::::::::::::::::::::::::\n____Document_Hash_List______\nHashNode:(1) @ 0x7f8315c02660\nHash = 23918810059971541311206230941892917820837248200366720993180852209519814321923471253\n- - - - - - -\nHashNode:(2) @ 0x7f8315e00000\nHash = 58651729825324016796232334223895171337716544629143706711722417610112429253179148\n- - - - - - -\n____________________________\nHash Reduction Round 3\n::::::::::::::::::::::::\n____Document_Hash_List______\nHashNode:(1) @ 0x7f8315c02660\nHash = 11173143892071531461621732122251137125150193240123497616925521016990140207232423664175\n- - - - - - -\n____________________________\nHash Chunk Reducing Finished, elapsed time = 0.000062s\nFinal Checksum Hash = 11173143892071531461621732122251137125150193240123497616925521016990140207232423664175\n~~~~~~~~~\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjweinst1%2Fsha-256-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjweinst1%2Fsha-256-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjweinst1%2Fsha-256-tree/lists"}