{"id":18974546,"url":"https://github.com/m7a/bo-blake3-ada","last_synced_at":"2026-04-08T15:30:20.955Z","repository":{"id":164554563,"uuid":"538218264","full_name":"m7a/bo-blake3-ada","owner":"m7a","description":"BLAKE3 Implementation in Ada","archived":false,"fork":false,"pushed_at":"2024-04-28T19:29:12.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-01T09:08:17.653Z","etag":null,"topics":["ada","blake3"],"latest_commit_sha":null,"homepage":"https://masysma.net/32/blake3_ada.xhtml","language":"Ada","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/m7a.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2022-09-18T19:27:42.000Z","updated_at":"2024-04-28T19:29:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"e9210a52-6eca-4a70-957f-cb4fe48a8a96","html_url":"https://github.com/m7a/bo-blake3-ada","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m7a%2Fbo-blake3-ada","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m7a%2Fbo-blake3-ada/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m7a%2Fbo-blake3-ada/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m7a%2Fbo-blake3-ada/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m7a","download_url":"https://codeload.github.com/m7a/bo-blake3-ada/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239972108,"owners_count":19727307,"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":["ada","blake3"],"created_at":"2024-11-08T15:15:23.493Z","updated_at":"2026-04-08T15:30:20.903Z","avatar_url":"https://github.com/m7a.png","language":"Ada","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\nsection: 32\nx-masysma-name: blake3_ada\ntitle: BLAKE3 Hash Function for Ada\ndate: 2022/09/13 21:12:43\nlang: en-US\nauthor: [\"Linux-Fan, Ma_Sys.ma (info@masysma.net)\"]\nkeywords: [\"blake3\", \"hash\", \"ada\", \"library\"]\nx-masysma-version: 1.0.0\nx-masysma-website: https://masysma.net/32/blake3_ada.xhtml\nx-masysma-repository: https://www.github.com/m7a/bo-blake3-ada\nx-masysma-copyright: \"2022 Ma_Sys.ma \u003cinfo@masysma.net\u003e\"\n---\nAbstract\n========\n\nThis repository provides an Ada implementation of the BLAKE3 Hash Function\nreference implementation (cf.\n\u003chttps://github.com/BLAKE3-team/BLAKE3/blob/master/reference_impl/reference_impl.rs\u003e).\n\nThis implementation supports hashes and keyed hashes.\nIt does not currently implement key derivation.\n\nLicense\n=======\n\nLike the reference implementation, this library is available under CC0 and can\nhence be freely integrated. See `LICENSE.txt` for details.\n\nCompiling\n=========\n\nThe following dependencies are required for building:\n\n * Ada compiler (`gcc`, `gnatmake`)\n * Ant build tool (`ant`)\n\n## Compile\n\n\tant\n\n## Run Tests\n\n\tcd test_suite\n\tant run\n\n## Install\n\n\tinstall -DsT lib/libblake3.so /usr/local/lib/x86_64-linux-gnu\n\tinstall -m 644 -DT lib/blake3.ali /usr/local/lib/x86_64-linux-gnu/ada/adalib/blake3\n\tinstall -m 644 -DT lib/blake3.ads /usr/local/share/ada/adainclude/blake3\n\nRepository Structure\n====================\n\nThis repository contains multiple subdirectories for the various components of\nthe library.\n\n~~~\n/bo-blake3-ada\n   |\n   +-- lib/\n   |    |\n   |    +-- blake3.adb                *** This is the implementation. ***\n   |    |\n   |    +-- blake3.ads                *** Implementation header file. ***\n   |    |\n   |    +-- build.xml                 Build instructions\n   |\n   +-- sample/\n   |    |\n   |    +-- blake3hello.adb           Minimal example program.\n   |\n   +-- test_suite/                    Test program to process test vectors.\n   |\n   +-- test_vectors/                  Test vector data and scripts.\n   |\n   +-- util/\n   |    |\n   |    +-- blake3ada.adb             Commandline sample application.\n   |    |\n   |    +-- build.xml                 Build instructions for Linux.\n   |\n   +-- README.md                      This file.\n   |\n   +-- LICENSE.txt                    CC0 license.\n   |\n   +-- build.xml                      Recursive antfile build instructions.\n~~~\n\nThe important subdirectory regarding the library is `lib`. If you do not\nneed tests or example programs, it is sufficient to compile and use only the\nfiles from that directory.\n\nSample Program\n==============\n\nThis sample program computes the hash over `Hello world.` (hex\n`48656c6c6f20776f726c642e0a`). You can find it in directory `sample` under\n`blake3hello.adb`.\n\n~~~{.ada}\nwith Blake3;\nwith Ada.Text_IO;\n\nprocedure Blake3Hello is\n\tpackage Output_Formatter is new Ada.Text_IO.Integer_IO(Integer);\n \tCtx: Blake3.Hasher := Blake3.Init;\nbegin\n \tCtx.Update(\"Hello world.\");\n\tdeclare\n\t\tResult: constant String := Ctx.Final;\n\t\tHex:    String          := \"16#00#\";\n\tbegin\n\t\tfor I in Result'Range loop\n\t\t\tOutput_Formatter.Put(Hex, Character'Pos(Result(I)), 16);\n\t\t\tAda.Text_IO.Put(if Hex(1) = ' ' then (\"0\" \u0026 Hex(5 .. 5))\n\t\t\t\t\t\t\telse Hex(4 .. 5));\n\t\tend loop;\n\tend;\nend Blake3Hello;\n~~~\n\nThe main complexity of this program arises from the necessity to write the\noutput. Neither a direct binary output to stdout, nor an easy means to convert\nto hexadecimal are available in Ada. As a comparatively short alternative to\nusing a lookup table, this sample program uses the formatting provided by\nAda.Text_IO.Integer_IO and then postprocesses the output to cut-off any\n`16#` leading markers and account for the output right-alignment.\n\nUsing the installed Library\n===========================\n\nAssuming the library is already installed on your system, you can compile\nand run the sample program as follows:\n\n\tgnatmake -o blake3hello blake3hello.adb \\\n\t\t-aO/usr/lib/x86_64-linux-gnu/ada/adalib/blake3 \\\n\t\t-aI/usr/share/ada/adainclude/blake3 \\\n\t\t-largs -lblake3\n\t./blake3hello\n\nOutput: `C7A4B65F79934D742EA07A9E85B3BBB1AB9AD9F42033D8A0698495D0F564C804`\n\nUsing the Library without Installation\n======================================\n\nIf the library is not installed on your system, it can be integrated using\nmultiple different approaches.\n\n## Easy Vendoring\n\nThe quickest way to get started is to just include the `blake3.ads` and\n`blake3.adb` files into the source tree. Here is what the directory structure\nmay look like then:\n\n~~~\n  ...\n   |\n   +-- sample/\n   |    +-- blake3.adb\n   |    +-- blake3.ads\n   |    +-- blake3hello.adb\n   |    +-- build.xml\n  ...\n~~~\n\nCompilation and invocation then become trivial:\n\n\tcp ../lib/blake3.ad? .\n\tgnatmake -o blake3hello blake3.adb\n\t./blake3hello\n\nOutput: `C7A4B65F79934D742EA07A9E85B3BBB1AB9AD9F42033D8A0698495D0F564C804`\n\n## Inclusion from different directory\n\nIt may not be suitable to just copy-over the files. In this case, it is also\npossible to import the compiled library from a different directory. Assume\nthat the library is compiled but not installed, then the file structure may\nlook as follows:\n\n~~~\n  ...\n   +-- lib/\n   |    +-- blake3.adb\n   |    +-- blake3.ads\n   |    +-- blake3.ali\n   |    +-- build.xml\n   |    +-- libblake3.so\n   |\n   +-- sample/\n   |    +-- blake3hello.adb\n   |    +-- build.xml\n  ...\n~~~\n\nCompilation and invocation then have to account for the library not being\ninstalled as follows:\n\n\tgnatmake -o blake3hello blake3hello.adb -aO../lib -aI../lib -largs -lblake3\n\tLD_LIBRARY_PATH=$PWD/../lib ./blake3hello\n\nOutput: `C7A4B65F79934D742EA07A9E85B3BBB1AB9AD9F42033D8A0698495D0F564C804`\n\nAPI Description\n===============\n\n## Types\n\n~~~{.ada}\ntype    U8     is mod 2**8;\ntype    U32    is new Interfaces.Unsigned_32;\ntype    Octets is array (U32 range \u003c\u003e) of U8;\nsubtype U8x32  is Octets(0..31);\ntype    Hasher is tagged limited private;\n~~~\n\n * `U8`:     This type is used to represent a single byte.\n * `U32`:    This type is used to represent a 32 bit word.\n * `Octets`: This type is used to represent a byte string.\n * `U8x32`:  This type is used to represent a 32 bytes byte string.\n * `Hasher`: This type is used to represent an opaque context of operation.\n * `String`: Strings are used as an alternative representation of byte strings.\n   This allows interfacing with other code without forcing it to use the\n   types supplied by this library. Conversion between Octets and Strings can\n   be performed by using the `for Octet_Var'Address use String_Var'Address;`\n   syntax if necessary.\n\n## Context Re-Use\n\nThe `Hasher` contexts provided by this API represent the state of hashing.\nSince `Final` does not update the state in any way, it is possible to\ncall `Final` multiple times without expecting a change in output.\n\nAdditionally, it is possible to call `Final`, then perform multiple `Update`\ninvocations and then call `Final` again. The output of the last `Final`\ncorresponds to the concatenation of all data supplied through preceding uses\nof `Update` on the same context.\n\nIt is currently not possible to reset the context to discard the old computation\nstate. If entirely new data is to be processed, it is suggested to create an\nentirely new context for this purpose.\n\n## Functions and Procedures\n\nA detailed description of the API functions follows after the overview excerpt\nfrom `blake3.ads`.\n\n~~~{.ada}\n-- Initialize as hash function\nfunction  Init return Hasher;\n\n-- Initialize as keyed hash function\nfunction  Init(Key: in U8x32) return Hasher;\nfunction  Init(Key: in String) return Hasher\n\t\t\t\twith Pre =\u003e Key'Length = Key_Len;\n\n-- Add data to process. Do not call with \"empty\" Strings\nprocedure Update(Self: in out Hasher; Input: in String)\n\t\t\t\twith Pre =\u003e Input'Length \u003e 0;\nprocedure Update(Self: in out Hasher; Input: in Octets);\n\n-- Compute hash, Octets-based API allows variable-length output\nfunction  Final(Self: in Hasher) return String;\nprocedure Final(Self: in Hasher; Out_Slice: out Octets);\n~~~\n\n### `function Init return Hasher`\n\nThis function creates a BLAKE3 context to be used as a _hash function_. It has\nto be called before using any of the other API functions.\n\n### `function Init(Key: in) return Hasher`\n\nThis variant of `Init` creates a BLAKE3 context to be used as a\n_keyed hash function_. The user is free to either supply an `U32x8` input\nor a 32-byte `String` which the library then interprets as `U32x8` internally\nwithout incurring a notable performance overhead.\n\n### `procedure Update(Self: in out Hasher; Input: in)`\n\nUse this function to supply the data that is considered input into the\n(optionally keyed) BLAKE3 hashing function. The user is free to supply the\ninternal type `Octets` or a regular `String` which the library then interprets\nas `Octets` internally.\n\nThis API expects the minimum number of bytes supplied to `Update` to be 1.\nDo not call it with empty arrays or strings.\n\n### `procedure Final(Self: in Hasher) return String`\n\nThis function outputs the 32-byte hash corresponding to the concatenation of all\ndata supplied with `Update` to the provided `Hasher` context and returns it as\na string with binary data. If this String is to be written to a text format,\na conversion to hexadecimal representation is recommended. See\n`util/blake3ada.adb` for an easy means to achieve such a conversion.\n\n### `procedure Final(Self: in Hasher; Out_Slice: out Octets)`\n\nThis alternative `Final` implementation uses the internal `Octets` datatype\nfor output. Additionally, by providing an `Out_Slice` of different length,\ndifferent lengths of hashes can be output. Note that BLAKE3 supports arbitrarily\nlong outputs as needed.\n\nRationale and Usage Recommendation\n==================================\n\nThis library was created out of the need to process data from a Rust program\nthat relies on BLAKE3 for all of its hashing operations. This should not deter\nyou from using it for creating new hashes in new programs with this library,\ntoo. However, you are advised to also consider chosing a more widely supported\nhash function in order to avoid being dependent on a single implementation.\n\nChanges\n=======\n\nFeel free to send patches with bugfixes or missing functionality directly to\n\u003cinfo@masysma.net\u003e. Include a note to confirm that you are OK with these\npatches being included under CC0. Please note that API breaks are only accepted\nif _very strong reasons_ exist to motivate them.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm7a%2Fbo-blake3-ada","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm7a%2Fbo-blake3-ada","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm7a%2Fbo-blake3-ada/lists"}