README.md (3488B)
1 # ripemd160 2 3 [](https://hackage.haskell.org/package/ppad-ripemd160) 4  5 [](https://docs.ppad.tech/ripemd160) 6 7 A pure Haskell implementation of [RIPEMD-160][ripem] and HMAC-RIPEMD160 8 on strict and lazy ByteStrings. 9 10 ## Usage 11 12 A sample GHCi session: 13 14 ``` 15 > :set -XOverloadedStrings 16 > 17 > -- import qualified 18 > import qualified Crypto.Hash.RIPEMD160 as RIPEMD160 19 > 20 > -- 'hash' and 'hmac' operate on strict bytestrings 21 > 22 > let hash_s = RIPEMD160.hash "strict bytestring input" 23 > let hmac_s = RIPEMD160.hmac "strict secret" "strict bytestring input" 24 > 25 > -- 'hash_lazy' and 'hmac_lazy' operate on lazy bytestrings 26 > -- but note that the key for HMAC is always strict 27 > 28 > let hash_l = RIPEMD160.hash_lazy "lazy bytestring input" 29 > let hmac_l = RIPEMD160.hmac_lazy "strict secret" "lazy bytestring input" 30 > 31 > -- results are always unformatted 160-bit (20-byte) strict bytestrings 32 > 33 > import qualified Data.ByteString as BS 34 > 35 > BS.take 10 hash_s 36 "=\211\211\197]\NULJ\223n\223" 37 > BS.take 10 hmac_l 38 "\154\248\145[\196\ETX\f\ESC\NULs" 39 > 40 > -- you can use third-party libraries for rendering if needed 41 > -- e.g., using ppad-base16: 42 > 43 > import qualified Data.ByteString.Base16 as B16 44 > 45 > B16.encode hash_s 46 "3dd3d3c55d004adf6edf9e11cb01f9ac9c56441f" 47 > B16.encode hmac_l 48 "9af8915bc4030c1b007323c8531b3129d82f50bd" 49 ``` 50 51 ## Documentation 52 53 Haddocks (API documentation, etc.) are hosted at 54 [docs.ppad.tech/ripemd160][hadoc]. 55 56 ## Performance 57 58 The aim is best-in-class performance for pure, highly-auditable Haskell 59 code. 60 61 Current benchmark figures on my M4 Silicon MacBook Air look like (use 62 `cabal bench` to run the benchmark suite): 63 64 ``` 65 benchmarking ppad-ripemd160/RIPEMD160 (32B input)/hash 66 time 244.2 ns (244.0 ns .. 244.4 ns) 67 1.000 R² (1.000 R² .. 1.000 R²) 68 mean 244.5 ns (244.4 ns .. 244.7 ns) 69 std dev 522.8 ps (355.8 ps .. 868.0 ps) 70 71 benchmarking ppad-ripemd160/HMAC-RIPEMD160 (32B input)/hmac 72 time 836.1 ns (835.3 ns .. 837.0 ns) 73 1.000 R² (1.000 R² .. 1.000 R²) 74 mean 836.6 ns (835.6 ns .. 837.4 ns) 75 std dev 3.105 ns (2.474 ns .. 4.117 ns) 76 ``` 77 78 Compile with the 'llvm' flag for maximum performance. 79 80 ## Security 81 82 This library aims at the maximum security achievable in a 83 garbage-collected language under an optimizing compiler such as GHC, in 84 which strict constant-timeness can be challenging to achieve. 85 86 The RIPEMD-160 functions pass the vectors present in the [official 87 spec][ripem], and the HMAC-RIPEMD160 functions pass all vectors found 88 contained in [RFC2286][rfc22]. 89 90 If you discover any vulnerabilities, please disclose them via 91 security@ppad.tech. 92 93 ## Development 94 95 You'll require [Nix][nixos] with [flake][flake] support enabled. Enter a 96 development shell with: 97 98 ``` 99 $ nix develop 100 ``` 101 102 Then do e.g.: 103 104 ``` 105 $ cabal repl ppad-ripemd160 106 ``` 107 108 to get a REPL for the main library. 109 110 [nixos]: https://nixos.org/ 111 [flake]: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html 112 [hadoc]: https://docs.ppad.tech/ripemd160 113 [ripem]: https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf 114 [rfc22]: https://www.rfc-editor.org/rfc/rfc2286.html#section-2