{"id":15011267,"url":"https://github.com/dosyago/discohash","last_synced_at":"2025-04-13T06:41:48.571Z","repository":{"id":56420006,"uuid":"239294957","full_name":"dosyago/DISCoHAsH","owner":"dosyago","description":":rocket: DISCoHAsH - Simple, fast, quality hash in 120 lines. 10GB/s serial (depending on hardware). Also in NodeJS","archived":false,"fork":false,"pushed_at":"2023-07-09T16:08:47.000Z","size":2536,"stargazers_count":219,"open_issues_count":0,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-10T19:19:10.953Z","etag":null,"topics":["256-bit","64-bit","arx","bebb4185","cpp","cryptanalysis","cryptography","cryptohash","discohash","ecrypt","encryption","hash","hashing","hashing-algorithm","node-js","nodejs","prime","smhasher","supercop","supercrypt"],"latest_commit_sha":null,"homepage":"https://dosyago.com","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dosyago.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":"2020-02-09T11:43:06.000Z","updated_at":"2024-12-19T15:30:05.000Z","dependencies_parsed_at":"2024-06-21T05:42:48.994Z","dependency_job_id":"657bb920-5abe-4d7b-a7c5-f20eb9f66463","html_url":"https://github.com/dosyago/DISCoHAsH","commit_stats":null,"previous_names":["crisdosyago/discohash","cris691/discohash"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dosyago%2FDISCoHAsH","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dosyago%2FDISCoHAsH/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dosyago%2FDISCoHAsH/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dosyago%2FDISCoHAsH/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dosyago","download_url":"https://codeload.github.com/dosyago/DISCoHAsH/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675434,"owners_count":21143763,"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":["256-bit","64-bit","arx","bebb4185","cpp","cryptanalysis","cryptography","cryptohash","discohash","ecrypt","encryption","hash","hashing","hashing-algorithm","node-js","nodejs","prime","smhasher","supercop","supercrypt"],"created_at":"2024-09-24T19:40:04.631Z","updated_at":"2025-04-13T06:41:48.549Z","avatar_url":"https://github.com/dosyago.png","language":"C++","readme":"# 🚀 [DISCoHAsH](https://github.com/dosyago/discohash) - A Blend of Simplicity and Performance in Hashing\n\n[![version](https://img.shields.io/npm/v/bebb4185.svg?label=\u0026color=0080FF)](https://github.com/cris691/discohash/releases/latest) ![npm downloads](https://img.shields.io/npm/dt/bebb4185)\n\n#### **Achieves 8-10GB/s, Successfully Passed [SMHasher Tests](https://github.com/rurban/smhasher/blob/master/doc/BEBB4185.txt)**\n\n---\n\n## Introduction\n\n**DISCoHAsH**, also known as **BEBB4185** or just **discohash**, is a straightforward and high-performance hash function that combines simplicity with impressive performance. While there are several great high-speed hash functions available, DISCoHAsH stands out for its elementary implementation, not relying on architecture-specific optimizations, and still delivering commendable speed and quality. It’s not the fastest nor the best in quality, but its simplicity and portability make it an excellent choice for various applications.\n\nDISCoHAsH has passed all the tests in SMHasher and clocks in at 8-10GB/s, depending on hardware. It's one of the fastest hash functions as per [SUPERCOP ECRYPT benchmark](https://bench.cr.yp.to/impl-hash/bebb4185.html).\n\nThis repository features a portable, serial implementation in C++. Moreover, an unofficial Go port is available [here](https://github.com/dgryski/go-disco), and there's also a JavaScript version.\n\n---\n\n## Quick Highlights\n\n- 🚀 High-speed 64-bit hash function.\n- 🎛 Flexible output sizes ranging from 64 to 256 bits.\n- 🛠 Remarkably simple and portable implementation.\n- 🧪 Successfully passes all SMHasher tests.\n- 🌐 Implemented in C++ with ports to JavaScript and Go.\n- 🔧 Includes a simple Command Line Interface (CLI) app for hashing files or standard input from the command line.\n- 🔄 Efficient mixing function utilizing multiplications by 64-bit primes, bit rotation, and XOR.\n\n---\n\n## Elementary Cryptanalysis\n\n[Doing elementary cryptanalysis on DISCoHAsH with ChatGPT assisting.](https://sharegpt.com/c/MYcTWEO)\n\n## In-depth Cryptanalysis\n\nWe extend an open invitation to the cryptographic community for cryptanalysis of DISCoHAsH, particularly focusing on the 128-bit variant. This is an excellent opportunity for cryptographers and security enthusiasts to evaluate the strength of Discohash.\n\nIf you are able to make a breakthrough or conduct significant analysis, please submit your results as Pull Requests, updating the README with a link to your analysis. Alternatively, you can [contact Cris (me, the author)](mailto:cris@dosyago.com) directly.\n\n*Important Note: To focus on the 128-bit variants, you must modify the source files in C/C++.*\n\n---\n\n## Implementation Details\n\n### Core Mixing Function\n\nThe 128-bit to 128-bit core mixing function is succinctly presented below:\n\n```c\n  mix(const int A) {\n      const int B = A + 1;\n\n      ds[A] *= P;\n      ds[A] = rot(ds[A], 23);\n      ds[A] *= Q;\n\n      ds[B] ^= ds[A];\n\n      ds[B] *= P;\n      ds[B] = rot(ds[B], 23);\n      ds[B] *= Q;\n  }\n```\n\nThis function makes use of two 64-bit primes, `P` and `Q`, bit rotation, and XOR operations. The primes `P` and `Q` are defined as:\n\n- P = 0xFFFFFFFFFFFFFFFF - 58 (largest 64-bit prime)\n- Q = 13166748625691186689 (random prime)\n\nInterestingly, P and Q have the interesting property that `P - Q = P ^ Q` (their difference equals their XOR).\n\n### Standard Version\n\nDiscohash's standard version employs an internal\n\n state of 256 bits, with the mixing function operating across it. The standard digest size is 64 bits, but you can modify it to produce 128 bits or higher for cryptographic security.\n\n---\n\n## How to Use\n\n#### C++ Implementation:\n\n*The output has the same format as `shasum -a 256 myfile.txt`*\n\n```console\ncd src\n./build.sh\n./bin/discosum myfile.txt\n\u003e ... 256-bit hash value as hex ... myfile.txt\n```\n\n#### JavaScript Implementation:\n\nInstall using npm:\n\n```console\nnpm i --save bebb4185\n```\n\nUse in Node.JS:\n\n```javascript\nimport {discohash} from 'bebb4185'\n```\n\nUsage:\n\n```javascript\nconst hash = discohash(string_or_typed_array_key, optional_seed);\n```\n\n*Note: The JavaScript implementation is ~500x slower than the C++ implementation due to the use of BigInts.*\n\n---\n\n## Golang Port\n\nFor Golang enthusiasts, an unofficial port to Go is available [here](https://github.com/dgryski/go-disco).\n\n---\n\n## Chain Zero Prefix Order\n\nThis hash when applied iteratively to its own hex output (a chain; with the initial link being a 32-byte input of all zeroes in binary not hex), generates a 2-byte zero prefix after 8,715 iterations, and a 3-byte zero prefix after 8,670,480 iterations:\n\n```\n8670467: 630f74d376ad3dc21aef6b2b6522ba385153fc9bad730e045153fc9bad730e04\n8670468: 8d3b99e94dd7b62e62b3958909d7802e0e9ddfdee75087a50e9ddfdee75087a5\n8670469: 6026eb0fce14e4835f14c0efa9e88363b9ab4053a1ee8b6bb9ab4053a1ee8b6b\n8670470: f83dd7560d0b6271e7bd174582ca5d718801aefeeebf46f48801aefeeebf46f4\n8670471: aef29abc0eda55952ee2183be8159551a7f4aca19bad85e2a7f4aca19bad85e2\n8670472: e6160e8f87accfb9d515ec6f7790ac397ba822756d23b8d07ba822756d23b8d0\n8670473: 99803a19074ebd91557fb596f820398d709bbb32784d3896709bbb32784d3896\n8670474: 199d695ee4f4ecce0459161c1ac2cc2e9482b241e7fb8ec29482b241e7fb8ec2\n8670475: 82b400dd268da3ee6233fcdd160d1bee5defcdb070c223cc5defcdb070c223cc\n8670476: 67c5760121db846b07c461fe99d87363d6ec497d53aee544d6ec497d53aee544\n8670477: 482ea819bb8b7996b7a91615bb40715092aa897234e15d2e92aa897234e15d2e\n8670478: 10b44e30f2eea61fccb431cef28e981f7dca7cc0b91748e57dca7cc0b91748e5\n8670479: 0421da4bddc42996e3d821231a33c16073ba1d3140a2b05973ba1d3140a2b059\n8670480: 0000009d947ee793ffffff5114791753e4f60afe9a96cf43e4f60afe9a96cf43\nFound hash with first three bytes 0x00 after 8670480 iterations.\n```\n\nThese values are inline with when on average you would expect to land on some particular criterion (~ 1/2 * 2**b) where b is the bit length of the criterion, from a random sequence. So for two bytes (b = 16) you'd expect it around 32768 (with 8,715 being roughly 0.27x) and for 3 bytes (b = 24) you'd expect it around 8388608 (with 8670480 being roughly 1.03x).\n\n---\n\nFor detailed information and updates, please visit the [Discohash GitHub repository](https://github.com/dosyago/discohash). Your contributions and feedback are always welcome!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdosyago%2Fdiscohash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdosyago%2Fdiscohash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdosyago%2Fdiscohash/lists"}