{"id":13507709,"url":"https://github.com/whitfin/siphash-elixir","last_synced_at":"2025-04-19T14:08:53.520Z","repository":{"id":47232947,"uuid":"48388884","full_name":"whitfin/siphash-elixir","owner":"whitfin","description":"An Elixir implementation of the SipHash cryptographic hash family","archived":false,"fork":false,"pushed_at":"2021-09-07T18:29:25.000Z","size":61,"stargazers_count":18,"open_issues_count":2,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-14T04:08:52.723Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/whitfin.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}},"created_at":"2015-12-21T19:00:59.000Z","updated_at":"2023-08-22T16:46:40.000Z","dependencies_parsed_at":"2022-08-28T11:22:14.935Z","dependency_job_id":null,"html_url":"https://github.com/whitfin/siphash-elixir","commit_stats":null,"previous_names":["zackehh/siphash-elixir"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fsiphash-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fsiphash-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fsiphash-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fsiphash-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whitfin","download_url":"https://codeload.github.com/whitfin/siphash-elixir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246157604,"owners_count":20732644,"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":[],"created_at":"2024-08-01T02:00:38.017Z","updated_at":"2025-03-30T09:33:00.405Z","avatar_url":"https://github.com/whitfin.png","language":"Elixir","funding_links":[],"categories":["Cryptography"],"sub_categories":[],"readme":"# SipHash\n[![Build Status](https://travis-ci.org/whitfin/siphash-elixir.svg?branch=master)](https://travis-ci.org/whitfin/siphash-elixir) [![Coverage Status](https://coveralls.io/repos/whitfin/siphash-elixir/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/whitfin/siphash-elixir?branch=master)\n\nAn Elixir implementation of the SipHash cryptographic hash family using native components for faster execution. Supports any variation, although defaults to the widely used SipHash-2-4. Previous versions focused on correctness, now there is a larger emphasis on performance optimizations as I intend to use it in a production environment (so naturally correctness will be upheld).\n\n## Installation\n\nThis package can be installed via Hex:\n\n1. Add siphash to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:siphash, \"~\u003e 3.2\"}]\nend\n```\n\n2. Ensure siphash is started before your application:\n\n```elixir\ndef application do\n  [applications: [:siphash]]\nend\n```\n\n## Quick Usage\n\nIt's straightforward to get going, you just supply your key and input to `SipHash.hash/3`.\n\n```elixir\niex(1)\u003e SipHash.hash(\"0123456789ABCDEF\", \"Hello, World!\")\n{ :ok, 16916637876837948234 }\niex(2)\u003e SipHash.hash!(\"0123456789ABCDEF\", \"Hello, World!\") # default in v2.x\n16916637876837948234\niex(2)\u003e SipHash.hash!(\"0123456789ABCDEF\", \"Hello, World!\", hex: true) # default in v1.x\n\"EAC3F88552D81B4A\"\n```\n\nFor further examples, as well as different flags to customize output, please see the [documentation](http://hexdocs.pm/siphash/SipHash.html).\n\n## Migration to v3.1.x\n\nThe only change with v3.1.x is a deprecation label on using the `SIPHASH_IMPL` environment variable to control whether a NIF is loaded or not. In future, you should control it via the application configuration as follows:\n\n```elixir\nconfig :siphash,\n  disable_nifs: true\n```\n\nThis is just generally a better way to control this, rather than tainting the execution environment. In order to preserve backwards compatibility for the time being, the default value for `disable_nifs` will just be `System.get_env(\"SIPHASH_IMPL\") == \"embedded\"`. In future this will be removed and modified to simply be `false`; this will likely happen if/when a v3.2.x comes alone.\n\n## Migration to v3.x\n\nWith v3.x come huge performance gains over all prior versions, roughly 200x the speed of the initial implementations. This is due to a smarter NIF binding, so it's recommended to use the NIF whenever possible.\n\nIt was previously possible to disable different types of NIF using both the `HASH_IMPL` and `STATE_IMPL` environment variables. The new implementation uses a single NIF, and can only be disabled by setting `SIPHASH_IMPL` to `embedded`. This will fall back to using an Elixir implementation. This version is somewhat slower, but it comes with less risk attached (although the NIF is pretty bulletproof when used correctly).\n\nIn addition, the typical Elixir standard of `{ :ok, result }` and `{ :error, message }` has been adopted as of v3.0.0. As such, all hashes are returned in a tuple signifying whether the hash was a success or not. Below is an example of both cases:\n\n```elixir\niex(1)\u003e SipHash.hash(\"0123456789ABCDEF\", \"Hello, World!\")\n{ :ok, 16916637876837948234 }\niex(2)\u003e SipHash.hash(\"invalid_bytes\", \"Hello, World!\")\n{ :error, \"Key must be exactly 16 bytes!\" }\n```\n\nBecause all potential errors are pretty much down to programmer error, you should be safe to use the alternate `SipHash.hash!/3` implementation which returns the straight result (or raises the appropriate error). This is the same behavior as that of `\u003c v3.0.0`.\n\n```elixir\niex(1)\u003e SipHash.hash!(\"0123456789ABCDEF\", \"Hello, World!\")\n16916637876837948234\niex(2)\u003e SipHash.hash!(\"invalid_bytes\", \"Hello, World!\")\n** (ArgumentError) Key must be exactly 16 bytes!\n```\n\n## Issues/Contributions\n\nIf you spot any issues with the implementation, please file an [issue](http://github.com/whitfin/siphash-elixir/issues) or even a PR. The faster we can make it, the better!\n\nMake sure to test your changes though!\n\n```bash\n$ SIPHASH_IMPL=native mix test --trace    # test NIF  successes/failures\n$ SIPHASH_IMPL=embedded mix test --trace  # test Elixir successes/failures\n$ SIPHASH_IMPL=embedded mix coveralls     # code coverage, try keep 100% please!\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitfin%2Fsiphash-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhitfin%2Fsiphash-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitfin%2Fsiphash-elixir/lists"}