Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mirage/digestif

Simple hash algorithms in OCaml
https://github.com/mirage/digestif

blake2b c hash md5 ocaml sha1 sha224 sha256 sha384 sha512

Last synced: 3 days ago
JSON representation

Simple hash algorithms in OCaml

Awesome Lists containing this project

README

        

Digestif - Hash algorithms in C and OCaml
=========================================

Digestif is a toolbox which implements hashes:

* MD5
* SHA1
* SHA2
* SHA3
* WHIRLPOOL
* BLAKE2B
* BLAKE2S
* RIPEMD160

Digestif uses a trick about linking and let the end-user to choose which
implementation he wants to use. We provide 2 implementations:

* C implementation with `digestif.c`
* OCaml implementation with `digestif.ocaml`

Both are well-tested. However, OCaml implementation is slower than the C
implementation.

**Note**: The linking trick requires `digestif.c` or `digestif.ocaml` to be the
first of your dependencies.

Documentation: https://mirage.github.io/digestif/

Contact: Romain Calascibetta ``

## Install & Usage

The library is available on [OPAM](https://opam.ocaml.org/packages/digestif/). You can install it via:
```sh
$ opam install digestif
```

This is a simple program which implements `sha1sum`:
```sh
$ cat >sha1sum.ml < Digestif.SHA1.get ctx
| len ->
let ctx = Digestif.SHA1.feed_bytes ctx ~off:0 ~len tmp in
go ctx
| exception End_of_file -> Digestif.SHA1.get ctx in
go Digestif.SHA1.empty

let () = match Sys.argv with
| [| _; filename; |] when Sys.file_exists filename ->
let ic = open_in filename in
let hash = sum ic in
close_in ic ; print_endline (Digestif.SHA1.to_hex hash)
| [| _ |] ->
let hash = sum stdin in
print_endline (Digestif.SHA1.to_hex hash)
| _ -> Format.eprintf "%s []\n%!" Sys.argv.(0)
EOF
$ cat >dune <= 4.03.0 (may be less but need test)
* `base-bytes` meta-package
* `base-bigarray` meta-package
* `dune` to build the project

If you want to compile the test program, you need:

* `alcotest`

## Credits

This work is from the [nocrypto](https://github.com/mirleft/nocrypto) library
and the Vincent hanquez's work in
[ocaml-sha](https://github.com/vincenthz/ocaml-sha).

All credits appear in the begin of files and this library is motivated by two
reasons:
* delete the dependancy with `nocrypto` if you don't use the encryption (and
common) part
* aggregate all hashes functions in one library