{"id":16701485,"url":"https://github.com/starbelly/hydro","last_synced_at":"2025-12-12T00:11:30.813Z","repository":{"id":57504796,"uuid":"138561006","full_name":"starbelly/hydro","owner":"starbelly","description":"Libhydrogen bindings for Erlang","archived":false,"fork":false,"pushed_at":"2019-02-10T02:23:45.000Z","size":83,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T17:18:18.824Z","etag":null,"topics":["crypto","erlang","libhydrogen"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","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/starbelly.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":"2018-06-25T07:49:29.000Z","updated_at":"2024-05-26T09:07:46.000Z","dependencies_parsed_at":"2022-09-19T05:40:19.644Z","dependency_job_id":null,"html_url":"https://github.com/starbelly/hydro","commit_stats":null,"previous_names":["starbelly/helium"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starbelly%2Fhydro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starbelly%2Fhydro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starbelly%2Fhydro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starbelly%2Fhydro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/starbelly","download_url":"https://codeload.github.com/starbelly/hydro/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154990,"owners_count":21056543,"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","erlang","libhydrogen"],"created_at":"2024-10-12T18:44:15.829Z","updated_at":"2025-12-12T00:11:30.753Z","avatar_url":"https://github.com/starbelly.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"![H](assets/logo-xsmall.png) Hydro [![Hex Version](https://img.shields.io/hexpm/v/hydro.svg)](https://hex.pm/packages/hydro) [![Gitlab-CI](https://gitlab.com/starbelly/hydro/badges/master/pipeline.svg)](https://gitlab.com/starbelly/hydro/commits/master) [![Travis-CI](https://travis-ci.com/starbelly/hydro.svg?branch=master)](https://travis-ci.com/starbelly/hydro) [![License](https://img.shields.io/badge/License-MIT-blue.svg)]()\n============\n\nLibhydrogen bindings for Erlang\n\n* [Installation](#installation)\n    * [Rebar3](#rebar3)\n    * [Mix](#mix)\n* [Usage](#usage)\n    * [Hydro](#hydro)\n        * [dice/0](#dice0)\n        * [generic hashing](#generic_hashing)\n        * [rand/1](#rand1)\n        * [rand_uniform/1](#rand_uniform1)\n    * [Hydro API](#hydro-api-1)\n        * [hash_keygen/0](#hash_keygen)\n        * [random_u32/0](#random_u320)\n        * [random_buf/1](#random_buf1)\n        * [random_uniform/1](#random_uniform1)\n* [Reference](#reference)\n\n## About\n\nhydro provides Erlang bindings to the Hydrogen Crypto Library ([libhydrogen](https://www.libhydrogen.org/doc/)).\n\nWorking with hydro is simple in both Erlang and Elixr.\n\n- ***Erlang***\n```erlang\n1\u003e N = hydro:rand(42).\n\u003c\u003c115,97,120,157,28,208,118,165,137,95,122,152,195,49,52,\n  188,73,136,216,201,77,183,29,144\u003e\u003e\n1\u003e hydro:rand(42).\n\u003c\u003c196,216,103,100,59,248,220,7,212,176,11,59,76,54,33,27,\n  87,166,157,249,120,120,106,253,233,234,148,136,133,...\u003e\u003e\n```\n\n- ***Elixir***\n```elixir\niex(1)\u003e n = :hydro.rand(42)\n\u003c\u003c115,97,120,157,28,208,118,165,137,95,122,152,195,49,52,\n  188,73,136,216,201,77,183,29,144,110,108,111,101,180...\u003e\u003e\n```\n\n## Installation\n\n### Rebar3\n\n```erlang\n{deps, [{hydro, \"0.1.0\"}]}\n```\n\n### Mix\n\n```elixir\ndef deps do\n  [{:hydro, \"~\u003e 0.1.0\"}]\nend\n```\n\n## Usage\n\n### Hydro\n\n#### dice/0\n\nGenerates and returns a random value between 0 and 0xffffffff (inclusive).\n\n```erlang\n1\u003e hydro:dice().\n3397059606\n2\u003e hydro:dice().\n2426160804\n3\u003e hydro:dice().\n2140249458\n```\n\n#### shuffle/1 \n Takes and randomly sorts a list. \n\n```erlang\n1\u003e hydro:shuffle(lists:seq(1,100)).\n[7,84,18,10,50,65,94,82,97,92,28,9,86,49,37,20,63,46,66,23,\n 64,26,39,16,90,33,15,40,57|...]\n2\u003e hydro:shuffle(lists:seq(1,100)).\n[46,3,5,17,52,38,4,50,55,21,71,80,51,54,88,30,96,18,44,42,\n 87,29,68,79,65,14,34,53,99|...]\n3\u003e hydro:shuffle(lists:seq(1,100)).\n[81,77,38,63,89,43,79,46,31,28,41,8,68,93,92,76,5,24,29,17,\n 23,13,26,27,60,71,34,9,40|...]\n```\n\n#### rand_pick/1\n  Takes a list, randomly sorts it, and randomly picks an element from the list.\n\n```erlang\n1\u003e hydro:rand_pick(lists:seq(1,100)).\n23\n2\u003e hydro:rand_pick(lists:seq(1,100)).\n27\n3\u003e hydro:rand_pick(lists:seq(1,100)).\n93\n4\u003e hydro:rand_pick(lists:seq(1,100)).\n82\n5\u003e hydro:rand_pick(lists:seq(1,100)).\n98\n6\u003e hydro:rand_pick(lists:seq(1,100)).\n13\n```\n\n#### Generic Hashing\n\nNote that a context is an 8 byte binary. \n\n##### Single part\n\nWithout a key\n\n```erlang\n1\u003e hydro:hash(\u003c\u003c\"context0\"\u003e\u003e, \u003c\u003c\"msg\"\u003e\u003e, 64).\n{ok,\u003c\u003c231,51,76,246,39,178,123,195,254,34,172,216,53,135,\n      95,160,94,6,97,118,224,8,66,187,247,150,58,...\u003e\u003e}\n```\n\nWith a key\n\n```erlang\n1\u003e hydro:hash(\u003c\u003c\"context1\"\u003e\u003e, \u003c\u003c\"msg\"\u003e\u003e, 32, hydro:hash_keygen()).\n{ok,\u003c\u003c55,230,42,62,224,198,89,79,68,155,73,29,38,82,114,\n      199,66,128,43,180,27,92,152,135,252,224,145,...\u003e\u003e}\n```\n\n##### Multi-part \n\nWithout a key\n\n```erlang\n1\u003e {ok, State} = hydro:hash_init(\u003c\u003c\"context0\"\u003e\u003e, 42).\n{ok,#Ref\u003c0.4176683979.2420768776.167622\u003e}\n2\u003e {ok, true} = hydro:hash_update(State, \u003c\u003c\"MyMsg1\"\u003e\u003e).\n{ok,true}\n3\u003e {ok, true} = hydro:hash_update(State, \u003c\u003c\"MyMsg2\"\u003e\u003e).\n{ok,true}\n4\u003e {ok, Hash} = hydro:hash_final(State, 88).\n{ok,\u003c\u003c44,201,1,123,196,16,201,224,112,217,21,86,149,189,\n      159,139,179,108,69,30,129,180,76,56,95,166,17,...\u003e\u003e}\n```\n\nWith key\n\n```erlang\n1\u003e {ok, State} = hydro:hash_init(\u003c\u003c\"context0\"\u003e\u003e, 64, hydro:hash_keygen()).\n{ok,#Ref\u003c0.1264487252.3744858120.160049\u003e}\n2\u003e {ok, true} = hydro:hash_update(State, \u003c\u003c\"MyMsg1\"\u003e\u003e).\n{ok,true}\n3\u003e {ok, true} = hydro:hash_update(State, \u003c\u003c\"MyMsg2\"\u003e\u003e).\n{ok,true}\n4\u003e {ok, Hash} = hydro:hash_final(State, 128).\n{ok,\u003c\u003c41,55,10,38,139,118,239,161,123,224,141,247,74,77,\n      123,91,119,28,2,34,69,137,146,203,160,122,81,...\u003e\u003e}\n```\n\n#### rand/1\n\nGenerates and returns a random sequence of bytes up to the specified size. \n\n```erlang\n1\u003e N = hydro:rand(42).\n\u003c\u003c115,97,120,157,28,208,118,165,137,95,122,152,195,49,52,\n  188,73,136,216,201,77,183,29,144\u003e\u003e\n1\u003e hydro:rand(42).\n\u003c\u003c196,216,103,100,59,248,220,7,212,176,11,59,76,54,33,27,\n  87,166,157,249,120,120,106,253,233,234,148,136,133,...\u003e\u003e\n```\n\n#### rand_uniform/1\n\nGenerates and returns a uniform distributed random value between 0 and the supplied upper\nbound (exlusive).\n\n```erlang\n1\u003e hydro:rand_uniform(100*100).\n1243\n2\u003e hydro:rand_uniform(100*100).\n901\n3\u003e hydro:rand_uniform(100*100).\n7966\n```\n\n### Hydro API\n\n For advanced usage there is the hydro api.\n\n#### hash_keygen/0\nCreate a secret key suitable for use with hash*\n\n```erlang\n1\u003e hydro_api:hash_keygen().\n\u003c\u003c196,216,103,100,59,248,220,7,212,176,11,59,76,54,33,27,\n  87,166,157,249,120,120,106,253,233,234,148,136,133,...\u003e\u003e\n```\n\n#### random_u32/0\n\nGenerates and returns a random value between 0 and 0xffffffff (inclusive).\n\n```erlang\n1\u003e hydro_api:random_u32().\n537265334\n2\u003e hydro_api:random_u32().\n623392245\n3\u003e hydro_api:random_u32().\n533755626\n4\u003e\n```\n\n#### random_buf/1\n\n```erlang\n1\u003e hydro_api:random_buf(42).\n\u003c\u003c196,216,103,100,59,248,220,7,212,176,11,59,76,54,33,27,\n  87,166,157,249,120,120,106,253,233,234,148,136,133,...\u003e\u003e\n2\u003e hydro_api:random_buf(42).\n\u003c\u003c161,240,252,190,45,94,112,230,59,93,7,151,230,50,244,\n  105,208,28,6,148,116,101,117,107,226,0,43,9,89,...\u003e\u003e\n3\u003e hydro_api:random_buf(42).\n\u003c\u003c208,189,65,169,124,15,251,118,0,61,33,12,188,100,91,129,\n  95,166,210,85,9,196,247,251,70,74,61,27,19,...\u003e\u003e\n```\n\nGenerates and returns a random sequence of bytes up to the specified size. \n\n#### random_uniform/1\n\nGenerates and returns a uniform distributed random value between 0 and the supplied upper\nbound (exlusive).\n\n```erlang\n5\u003e hydro_api:random_uniform(100*100).\n5260\n6\u003e hydro_api:random_uniform(100*100).\n6564\n7\u003e hydro_api:random_uniform(100*100).\n9529\n```\n\n## Reference\n\n - [libhydrogen](https://www.libhydrogen.org/doc/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarbelly%2Fhydro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarbelly%2Fhydro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarbelly%2Fhydro/lists"}