{"id":13995152,"url":"https://github.com/jedisct1/rust-sthash","last_synced_at":"2025-04-04T14:04:26.535Z","repository":{"id":34303397,"uuid":"176266057","full_name":"jedisct1/rust-sthash","owner":"jedisct1","description":"Very fast cryptographic hashing for large messages.","archived":false,"fork":false,"pushed_at":"2025-03-11T20:44:32.000Z","size":78,"stargazers_count":70,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T13:05:05.919Z","etag":null,"topics":["crypto","cryptography","digest","fast","hash","nhpoly1305","rust","uhf"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jedisct1.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-03-18T11:09:12.000Z","updated_at":"2025-03-11T20:43:56.000Z","dependencies_parsed_at":"2025-01-16T00:09:55.434Z","dependency_job_id":"32d83812-90b6-456c-af54-13c2e538bd31","html_url":"https://github.com/jedisct1/rust-sthash","commit_stats":{"total_commits":99,"total_committers":3,"mean_commits":33.0,"dds":0.04040404040404044,"last_synced_commit":"40fcb7fdbde17a46d8e7d1b728a809304de25840"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedisct1%2Frust-sthash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedisct1%2Frust-sthash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedisct1%2Frust-sthash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedisct1%2Frust-sthash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jedisct1","download_url":"https://codeload.github.com/jedisct1/rust-sthash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247185999,"owners_count":20898077,"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":["crypto","cryptography","digest","fast","hash","nhpoly1305","rust","uhf"],"created_at":"2024-08-09T14:03:16.611Z","updated_at":"2025-04-04T14:04:26.494Z","avatar_url":"https://github.com/jedisct1.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# STHash\n\n[![docs.rs](https://docs.rs/sthash/badge.svg)](https://docs.rs/sthash)\n\nSTHash is a fast, keyed, cryptographic hash function designed to process large, possibly untrusted data.\n\nThe flipside is that using a secret key (or, in this implementation, a secret seed) is mandatory. This is not a general-purpose hash function.\n\nA typical use of STHash is to compute keys for locally cached objects.\n\nThe construction relies on:\n\n- A composition of two ϵ-almost-∆-universal functions, NH and Poly1305. See the [Adiantum](https://tosc.iacr.org/index.php/ToSC/article/view/7360/6530) paper for a justification of this composition.\n- The cSHAKE function as a XOF to derive the NH, Poly1305 and finalization keys, and KMAC to produce the final tag.\n\nThe current code is portable, written in safe Rust, and has a lot of room for optimization.\n\nHowever, it is already consistently faster than optimized BLAKE2bp and BLAKE3 implementations on all common platforms.\n\nYou can expect future versions to be even faster.\n\n## Usage\n\n```rust\nuse sthash::*;\nuse rand::{thread_rng, RngCore};\n\n// This must be a random, secret seed.\nlet mut seed = [0u8; SEED_BYTES];\nthread_rng().fill_bytes(\u0026mut seed);\n\n// The key constructor accepts an optional application name\n// Different personalization strings produce different keys\n// from the same `seed`.\nlet key = Key::from_seed(\u0026seed, Some(b\"Documentation example\"));\n\n// Another personalization string, such as the purpose of the\n// `Hasher`, can be provided here as well.\nlet hasher = Hasher::new(key, None);\n\n// Returns a 256-bit hash.\nlet h1 = hasher.hash(b\"data\");\n\n// `Hasher` structures can safely be reused to hash more data.\nlet h2 = hasher.hash(b\"data2\");\n```\n\n## Benchmarks\n\nMeasurements from the built-in benchmark, hashing 1 Mb data. \nGet your own data with the `cargo bench` command.\n\nComparison with BLAKE3 (from `blake3`)\n\n| Machine                                | BLAKE3 (μs) | STHash (μs) | Ratio |\n| -------------------------------------- | ----------- | ----------- | ----- |\n| Apple M1, MacOS                        | 646         | 119         | 5.4   |\n| AMD Zen2, Ubuntu                       | 212         | 71          | 3.0   |\n| AMD Zen4 (Ryzen 7700), Ubuntu          | 148         | 61          | 2.4   |\n| Core i9 2.9Ghz, MacOS                  | 226         | 86          | 2.6   |\n| ARMv8 (Freebox Delta), Debian Linux VM | 3729        | 646         | 5.8   |\n\nComparison with BLAKE2bp (from `blake2b-simd`)\n\n| Machine                                        | BLAKE2bp (μs) | STHash (μs) | Ratio |\n| ---------------------------------------------- | ------------- | ----------- | ----- |\n| Core i9 2.9Ghz, MacOS                          | 391           | 95          | 4.1   |\n| Core i7 2.8Ghz, MacOS                          | 607           | 134         | 4.5   |\n| Xeon CPU E5-1650 v4 3.60GHz, Ubuntu Linux      | 479           | 130         | 3.7   |\n| Xeon CPU E3-1245 V2 3.40GHz, OpenBSD VM        | 2681          | 493         | 5.4   |\n| ARMv8 (Freebox Delta), Debian Linux VM         | 2949          | 668         | 4.4   |\n| ARMv8 (Raspberry Pi 4b), Raspbian              | 10496         | 3127        | 3.4   |\n| ARMv7 (Scaleway C1), Ubuntu Linux              | 29402         | 7871        | 3.7   |\n| ARMv7 (Raspberry Pi 3b), Raspbian              | 19596         | 4944        | 4     |\n| Atom C3955 2.10GHz (Scaleway Start1-XS), Linux | 3709          | 886         | 4.2   |\n| AMD FX-6300, CentOS Linux                      | 1812          | 737         | 2.5   |\n| AMD Zen4 (Ryzen 7700), Ubuntu                  | 278           | 61          | 4.5   |\n\nComparison with HMAC-SHA2 (from `rust-crypto`)\n\n| Machine                                        | HMAC-SHA512 (μs) | STHash (μs) | Ratio |\n| ---------------------------------------------- | ---------------- | ----------- | ----- |\n| Core i9 2.9Ghz, MacOS                          | 2280             | 95          | 24    |\n| Core i7 2.8Ghz, MacOS                          | 3233             | 134         | 24.1  |\n| Xeon CPU E5-1650 v4 3.60GHz, Ubuntu Linux      | 2600             | 130         | 20    |\n| Xeon CPU E3-1245 V2 3.40GHz, OpenBSD VM        | 6423             | 493         | 13    |\n| ARMv8 (Freebox Delta), Debian Linux VM         | 4587             | 668         | 6.9   |\n| ARMv8 (Raspberry Pi 4b), Raspbian              | 19864            | 3127        | 6.4   |\n| ARMv7 (Scaleway C1), Ubuntu Linux              | 167670           | 7871        | 21.3  |\n| ARMv7 (Raspberry Pi 3b), Raspbian              | 49309            | 4944        | 9.9   |\n| Atom C3955 2.10GHz (Scaleway Start1-XS), Linux | 7052             | 886         | 8     |\n| AMD FX-6300, CentOS Linux                      | 3700             | 737         | 5     |\n\n## Algorithm\n\n```text\nKm || Kp || Kn ← cSHAKE128(seed, c1)\n\nHp ← Poly1305(Kp, NH*(Kn, pad128(M)))\n\nH ← KMAC(Km, c2, pad64(|M|) || Hp)\n```\n\n`NH` is instantiated with 4 passes and a stride of 2.\n\n`M` is processed as 1 KB chunks, and the resulting NH hashes are compressed using Poly1305 after 16 hashes have been accumulated (≡ 16 KB of `M` have been processed).\n\n`c1` and `c2` are personalization strings.\n\n`Kp` represents the Poly1305 random secret. In this context, we don't need to perform the final addition with an encrypted nonce.\n\nValues are encoded as little-endian.\n\n## References\n\n- [UMAC: Fast and Secure Message Authentication](https://fastcrypto.org/umac/umac_proc.pdf) (J. Black, S.Halevi, H.Krawczyk, T.Krovetz, and P. Rogaway)\n- [The Poly1305-AES message authentication code](https://cr.yp.to/mac/poly1305-20050329.pdf) (Daniel J. Bernstein)\n- [Adiantum: length-preserving encryption for entry-level processors](https://tosc.iacr.org/index.php/ToSC/article/view/7360/6530) (Paul Crowley and Eric Biggers)\n- [Short-output universal hash functions and their use in fast and secure data authentication](https://eprint.iacr.org/2011/116.pdf) (Yannick Seurin)\n\n## Thanks\n\nThis crate is based on work by Paul Crowley and Eric Biggers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedisct1%2Frust-sthash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjedisct1%2Frust-sthash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedisct1%2Frust-sthash/lists"}