{"id":16189048,"url":"https://github.com/fogfish/hash","last_synced_at":"2025-10-29T10:24:50.793Z","repository":{"id":139268938,"uuid":"56179678","full_name":"fogfish/hash","owner":"fogfish","description":"collection of hash functions for Erlang applications","archived":false,"fork":false,"pushed_at":"2018-08-03T17:19:45.000Z","size":34,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-18T16:17:58.412Z","etag":null,"topics":["erlang","hash","hash-functions"],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fogfish.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-04-13T19:22:10.000Z","updated_at":"2021-10-05T06:58:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"1ac7e0aa-fa1e-47f5-b0d0-6b2ffc3886c8","html_url":"https://github.com/fogfish/hash","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":0.09999999999999998,"last_synced_commit":"a1b9101189e115b4eabbe941639f3c626614e986"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogfish%2Fhash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogfish%2Fhash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogfish%2Fhash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogfish%2Fhash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fogfish","download_url":"https://codeload.github.com/fogfish/hash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243965774,"owners_count":20375917,"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":["erlang","hash","hash-functions"],"created_at":"2024-10-10T07:33:35.633Z","updated_at":"2025-10-29T10:24:45.770Z","avatar_url":"https://github.com/fogfish.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hash\n\nThe library implements various non-crypto hash functions.\n\n[![Build Status](https://secure.travis-ci.org/fogfish/hash.svg?branch=master)](http://travis-ci.org/fogfish/hash)\n\n## Inspiration \n\nSoftware development project requires various function to map a data to fixed size values. This library aggregates these function to single project allowing easy re-use across Erlang projects, using unified interface `hash:function(...)` and allowing the function-per-module development practice.  \n\n\n\n\n## Getting started\n\nThe latest version of hash library is available at its master branch. All development, including new features and bug fixes, take place on the master branch using forking and pull requests as described in contribution guidelines.\n\n### Installation\n\nIf you use `rebar` you can include `hash` library in your project with\n```\n{hash, \".*\",\n   {git, \"https://github.com/fogfish/hash\", {branch, master}}\n}\n```\n\n### Usage\n\nThe library exposes _all_ hash function through exports of `hash` module. Just call required function with input data, e.g:\n```\nhash:fnv32(\"erlang\").\n```\n\n\n\n## Supported hash functions\n\n\n### `fnv` - Fowler–Noll–Vo \n\nThe FNV hash was designed for fast hash table and checksum use, not cryptography. The library implements both variants (FNV-1, FNV-1a) of original function and its improved version proposed by Bret Mulvey (FNV-1m) suitable for hashing in text processing applications. \n\n```\n-spec fnv32(_) -\u003e integer().\n-spec fnv32a(_) -\u003e integer().\n-spec fnv32m(_) -\u003e integer().\n-spec fnv64(_) -\u003e integer().\n-spec fnv64a(_) -\u003e integer().\n-spec fnv128(_) -\u003e integer().\n-spec fnv128a(_) -\u003e integer().\n```\n\n### `seq` -  Additive Congruential Random Number (ACORN)\n\nThe additive congruential random number generator, This is a special case of a multiple recursive generator. It is used to generate identical sequences on any machine.\n\n```\n-spec seq31(integer()) -\u003e integer().\n-spec seq32(integer()) -\u003e integer().\n```\n\n### `fold` - XOR folding\n\nThe function fold data structure to single integer using XOR.\n\n```\n-spec fold32(_) -\u003e integer().\n```\n\n### `buz` - Cyclic polynomial (BuzHash)\n\nThe hash function is based on cyclic polynomial belongs to class of rolling hash functions. It has the benefit of avoiding multiplications, using barrel shifts instead. The popular applications are finger-printing, content sync. \n\n\nThis hash function requires a state passing between calls. The usage request opaque state initialization.\n\n```\n-spec buz32(integer()) -\u003e _.\n```\n\nEvery consequent call request the previous state and element to hash, it returns hash value and new opaque state.\n```\n-spec buz32(_, _) -\u003e {integer(), _}.\n```\n\n### `pbkdf2` - Password-Based Key Derivation Function 2\n\nThe function applies recursively a HMAC to password along with salt to produce a derived key usable as a cryptographic key in subsequent operations.\n\n```\n-spec pbkdf2(prf(), pass(), salt(), c(), dklen()) -\u003e binary().\n```\n\n* `prf()` is a pseudo-random function (hash algorithm for [HMAC](http://erldocs.com/17.0/crypto/crypto.html?i=0\u0026search=crypto:hma#hmac/3))\n* `pass()` is the master password used for key derivation\n* `salt()` is sequence of bits\n* `c()` number of iterations to apply the function\n* `dklen()` the length of desired derive key in bits\n\n\n### `geo` - Geo Hash\n\nThe function subdivide the space into buckets using z-order curve. It allows to move geo-graphical coordinate domain to string domain, offering arbitrary precision (reducing the size by removing tail of string).\n\n```\n-spec geo(binary()) -\u003e {lat(), lng()}.\n-spec geo({lat(), lng()}) -\u003e binary().\n-spec geo(lat(), lng()) -\u003e binary().\n```  \n\n### AWS Signature Version 4\n\nThe function implements [Signature Version 4](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html). \n\n```\n-spec aws_v4(access(), secret(), token(), region(), service()) -\u003e hash().\n-spec aws_v4_sign(method(), host(), path(), query(), headers(), payload(), hash()) -\u003e [headers()]\n```\n\nYou need to seed a hash state with your AWS credentials\n```erlang\nHash = hash:aws_v4(\u003c\u003c\"YOURKEY\"\u003e\u003e, \u003c\u003c\"YOURSECRET\"\u003e\u003e, 'us-east-1', 'es'),\n```\n\nThe hash state is then used at each iteration to sign you HTTP request\n```erlang\nhash:aws_v4_sign(\n   'POST',                                   %% http method\n   \"search-foo.us-east-1.es.amazonaws.com\",  %% host \n   \"/mypath\",                                %% path\n   [{version, 1}, {foo, \u003c\u003c\"bar\"\u003e\u003e}],         %% query parameters  \n   [{'Content-Type', \u003c\u003c\"application/x-www-form-urlencoded\"\u003e\u003e}], %% list of http headers to sign\n   \u003c\u003c\"foo=bar\"\u003e\u003e,                            %% payload\n   Hash).                                    %% hash state\n```\n\n## How to Contribute\n\n`hash` is Apache 2.0 licensed and accepts contributions via GitHub pull requests.\n\n### getting started\n\n* Fork the repository on GitHub\n* Read the README.md for build instructions\n\n### commit message\n\nThe commit message helps us to write a good release note, speed-up review process. The message should address two question what changed and why. The project follows the template defined by chapter [Contributing to a Project](http://git-scm.com/book/ch5-2.html) of Git book.\n\n\u003e\n\u003e Short (50 chars or less) summary of changes\n\u003e\n\u003e More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together.\n\u003e \n\u003e Further paragraphs come after blank lines.\n\u003e \n\u003e Bullet points are okay, too\n\u003e \n\u003e Typically a hyphen or asterisk is used for the bullet, preceded by a single space, with blank lines in between, but conventions vary here\n\u003e\n\n## Bugs\nIf you detect a bug, please bring it to our attention via GitHub issues. Please make your report detailed and accurate so that we can identify and replicate the issues you experience:\n- specify the configuration of your environment, including which operating system you're using and the versions of your runtime environments\n- attach logs, screen shots and/or exceptions if possible\n- briefly summarize the steps you took to resolve or reproduce the problem\n\n\n## License\n\nCopyright 2012 Dmitry Kolesnikov\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffogfish%2Fhash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffogfish%2Fhash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffogfish%2Fhash/lists"}