package digestif

  1. Overview
  2. Docs
Hashes implementations (SHA*, RIPEMD160, BLAKE2* and MD5)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

digestif-1.3.1.tbz
sha256=3927949a56d435ac2106cdb8394400bff989d44567eba9038e47db266cc88466
sha512=436dcd82081aa03b6d3424629950dbc64212c6281e241dad5e39812d58f2e5ddd52e0138840ad92e172baffbae81d1d34df8f5d893b83c734ac53cd95cad2707

Description

Digestif is a toolbox to provide hashes implementations in C and OCaml.

It uses the linking trick and user can decide at the end to use the C implementation or the OCaml implementation.

We provides implementation of:

  • MD5
  • SHA1
  • SHA224
  • SHA256
  • SHA384
  • SHA512
  • SHA3
  • Keccak-256
  • WHIRLPOOL
  • BLAKE2B
  • BLAKE2S
  • RIPEMD160

Added to opam-repository:

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 <romain.calascibet ta@gmail.com>

Install & Usage

The library is available on OPAM. You can install it via:

$ opam install digestif

This is a simple program which implements sha1sum:

$ cat >sha1sum.ml <<EOF
let sum ic =
  let tmp = Bytes.create 0x1000 in
  let rec go ctx = match input ic tmp 0 0x1000 with
    | 0 -> 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 [<filename>]\n%!" Sys.argv.(0)
EOF
$ cat >dune <<EOF
(executable
 (name sha1sum)
 (libraries digestif))
EOF
$ dune exec ./sha1sum.exe -- sha1sum.ml
fe6e6639a817c23857b507e2d833ec776f23f327

API

For each hash, we implement the same API which is referentially transparent. Then, on the top of these, we reflect functions (like digesti or hmaci) with GADT - however, conversion from GADT to hash type is not possible (but you can destruct GADT with to_raw_string).

Equal/Compare function

We deciced to protect users to timing-attack. In this case, Digestif.equal (by eqaf package) compares hashes in constant-time.

However, we provide unsafe_compare function too which is not a constant time function. In some contexts, like ocaml-git, we don't care about timing attack and we use unsafe_compare - then, we need to make a wrap where we rename unsafe_compare to compare to be able to use it in some functors like Map.Make or Set.Make.

It's little annoying to do that but it forces the user to get the right question about security issues. So, please, don't ask to rename this function.

MirageOS

Of course, this package is available to be used on MirageOS (both implementations). User is able to compile digestif.ocaml with js_of_ocaml and this package is platform agnostic.

Build Requirements

  • OCaml >= 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 library and the Vincent hanquez's work in 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

Dependencies (3)

  1. eqaf
  2. dune >= "2.6.0"
  3. ocaml >= "4.08.0"

Dev Dependencies (8)

  1. crowbar with-test
  2. ocamlfind with-test
  3. rresult with-test
  4. fpath with-test
  5. astring with-test
  6. bos with-test
  7. alcotest with-test
  8. fmt with-test & >= "0.8.7"

Used by (98)

  1. albatross >= "2.3.0"
  2. archetype < "1.2.2"
  3. atproto
  4. aws >= "1.2"
  5. aws-eio
  6. aws-s3
  7. awskit
  8. awskit-s3
  9. awskit-s3-eio < "0.2.0"
  10. awskit-s3-sim
  11. builder-web >= "0.2.0"
  12. ca-certs >= "1.0.1"
  13. ca-certs-nss >= "3.104"
  14. caldav >= "0.2.3"
  15. carton < "1.0.0"
  16. carton-git-lwt
  17. carton-lwt
  18. carton-miou
  19. carton-miou-unix
  20. chamelon
  21. chatoyant
  22. cohttp-async >= "6.0.0"
  23. conex-mirage-crypto >= "1.0.0"
  24. dkim
  25. dkim-mirage
  26. dns-tsig >= "9.1.0"
  27. docfd >= "13.0.0"
  28. docteur
  29. docteur-solo5
  30. docteur-unix
  31. dream < "1.0.0~alpha3" | >= "1.0.0~alpha5"
  32. dream-httpaf < "1.0.0~alpha4"
  33. esperanto-cosmopolitan >= "0.0.5"
  34. fluxt
  35. git >= "3.2.0"
  36. git-kv >= "0.2.0"
  37. git-unix >= "3.2.0"
  38. graphql-cohttp >= "0.9.0"
  39. hpke
  40. httpcats
  41. httpun-ws-async
  42. httpun-ws-eio
  43. httpun-ws-lwt
  44. index-bench >= "1.5.0"
  45. irmin
  46. irmin-cli
  47. irmin-git
  48. irmin-http
  49. irmin-server
  50. irmin-tezos
  51. irmin-unix
  52. jose >= "0.10.0"
  53. jupyter-kernel
  54. jws >= "0.0.2"
  55. jwto >= "0.4.0"
  56. kdf
  57. learn-ocaml
  58. learn-ocaml-client
  59. letsencrypt >= "1.0.0" & < "2.0.0"
  60. MlFront_Cli < "2.3.1"
  61. MlFront_Core
  62. MlFront_Thunk
  63. MlFront_ZipFile >= "2.4.2.169"
  64. mcrunch >= "0.0.2"
  65. miaou-driver-web
  66. miou
  67. mirage-crypto-ec >= "1.1.0"
  68. mirage-crypto-pk >= "1.1.0"
  69. mirage-crypto-rng >= "1.1.0"
  70. mirage-crypto-rng-miou-unix
  71. mirage-crypto-rng-mkernel
  72. multihash-digestif
  73. naboris >= "0.1.3"
  74. nocoiner
  75. noise
  76. nomad
  77. ocluster
  78. ocluster-worker
  79. ometrics >= "0.1.2"
  80. openstellina
  81. otr >= "1.0.0"
  82. owi >= "0.2"
  83. polymarket
  84. simple_httpd
  85. smaws-lib
  86. sosie
  87. soupault >= "4.4.0"
  88. spoke
  89. swhid
  90. swhid_compute
  91. tezos-base58
  92. tezos-context-hash
  93. tls >= "1.0.4"
  94. unic
  95. valkey
  96. webauthn >= "0.2.0"
  97. yocaml_runtime
  98. zeit

Conflicts (2)

  1. ocaml-freestanding
  2. mirage-xen < "6.0.0"