ripemd160

Pure Haskell RIPEMD-160, HMAC-RIPEMD160 (docs.ppad.tech/ripemd160).
git clone git://git.ppad.tech/ripemd160.git
Log | Files | Refs | README | LICENSE

commit da68bffa72058742e5217d5c8d8b019909c784c2
Author: Jared Tobin <jared@jtobin.io>
Date:   Sun, 10 Nov 2024 07:07:57 +0400

lib: initial skeleton

Diffstat:
ACHANGELOG | 0
ALICENSE | 20++++++++++++++++++++
Abench/Main.hs | 5+++++
Aflake.lock | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aflake.nix | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Alib/Crypto/Hash/RIPEMD160.hs | 3+++
Appad-ripemd160.cabal | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atest/Main.hs | 5+++++
Atest/Wycheproof.hs | 2++
9 files changed, 217 insertions(+), 0 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG diff --git a/LICENSE b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2024 Jared Tobin + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/bench/Main.hs b/bench/Main.hs @@ -0,0 +1,5 @@ + +module Main where + +main :: IO () +main = pure () diff --git a/flake.lock b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1725910328, + "narHash": "sha256-n9pCtzGZ0httmTwMuEbi5E78UQ4ZbQMr1pzi5N0LAG8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5775c2583f1801df7b790bf7f7d710a19bac66f4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix @@ -0,0 +1,53 @@ +{ + description = "Pure Haskell RIPEMD-160 and HMAC-RIPEMD160"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + lib = "ppad-ripemd160"; + + pkgs = import nixpkgs { inherit system; }; + hlib = pkgs.haskell.lib; + + hpkgs = pkgs.haskell.packages.ghc981.extend (new: old: { + ${lib} = old.callCabal2nixWithOptions lib ./. "--enable-profiling" {}; + }); + + cc = pkgs.stdenv.cc; + ghc = hpkgs.ghc; + cabal = hpkgs.cabal-install; + in + { + packages.default = hpkgs.${lib}; + + devShells.default = hpkgs.shellFor { + packages = p: [ + (hlib.doBenchmark p.${lib}) + ]; + + buildInputs = [ + cabal + cc + ]; + + inputsFrom = builtins.attrValues self.packages.${system}; + + doBenchmark = true; + + shellHook = '' + PS1="[${lib}] \w$ " + echo "entering ${system} shell, using" + echo "cc: $(${cc}/bin/cc --version)" + echo "ghc: $(${ghc}/bin/ghc --version)" + echo "cabal: $(${cabal}/bin/cabal --version)" + ''; + }; + } + ); +} + diff --git a/lib/Crypto/Hash/RIPEMD160.hs b/lib/Crypto/Hash/RIPEMD160.hs @@ -0,0 +1,3 @@ + +module Crypto.Hash.RIPEMD160 where + diff --git a/ppad-ripemd160.cabal b/ppad-ripemd160.cabal @@ -0,0 +1,68 @@ +cabal-version: 3.0 +name: ppad-ripemd160 +version: 0.1.0 +synopsis: The RIPEMD-160 hashing algorithm. +license: MIT +license-file: LICENSE +author: Jared Tobin +maintainer: jared@ppad.tech +category: Cryptography +build-type: Simple +tested-with: GHC == 9.8.1 +extra-doc-files: CHANGELOG +description: + A pure implementation of RIPEMD-160 and HMAC-RIPEMD160 on strict and + lazy ByteStrings. + +source-repository head + type: git + location: git.ppad.tech/ripemd160.git + +library + default-language: Haskell2010 + hs-source-dirs: lib + ghc-options: + -Wall + exposed-modules: + Crypto.Hash.RIPEMD160 + build-depends: + base >= 4.9 && < 5 + , bytestring >= 0.9 && < 0.13 + +test-suite ripemd160-tests + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: test + main-is: Main.hs + other-modules: + Wycheproof + + ghc-options: + -rtsopts -Wall -O2 + + build-depends: + aeson + , base + , base16-bytestring + , bytestring + , ppad-ripemd160 + , tasty + , tasty-hunit + , text + +benchmark ripemd160-bench + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: bench + main-is: Main.hs + + ghc-options: + -rtsopts -O2 -Wall + + build-depends: + base + , bytestring + , criterion + , ppad-ripemd160 + , SHA + diff --git a/test/Main.hs b/test/Main.hs @@ -0,0 +1,5 @@ + +module Main where + +main :: IO () +main = pure () diff --git a/test/Wycheproof.hs b/test/Wycheproof.hs @@ -0,0 +1,2 @@ + +module Wycheproof where