commit 6752c4336c1b581ae7875b1c9a0eaed115e420a3
parent 6a6281342faa0e9adaa5fce1e85de84b058e49ae
Author: Jared Tobin <jared@jtobin.io>
Date: Sat, 27 Dec 2025 08:41:11 -0330
meta: llvm flag
Diffstat:
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
@@ -45,12 +45,14 @@ benchmark suite):
```
benchmarking ppad-chacha/cipher
- time 770.2 ns (769.9 ns .. 770.5 ns)
+ time 485.7 ns (485.2 ns .. 486.3 ns)
1.000 R² (1.000 R² .. 1.000 R²)
- mean 770.2 ns (770.0 ns .. 770.5 ns)
- std dev 794.7 ps (653.0 ps .. 999.5 ps)
+ mean 485.9 ns (485.1 ns .. 486.3 ns)
+ std dev 1.943 ns (1.389 ns .. 2.809 ns)
```
+You should compile with the 'llvm' flag for maximum performance.
+
## Security
This library aims at the maximum security achievable in a
@@ -62,7 +64,6 @@ and the downstream AEAD-ChaCha20-Poly1305 implementation in
[ppad-aead](https://github.com/ppad-tech/aead) passes all the [Project
Wycheproof vectors][wyche].
-
If you discover any vulnerabilities, please disclose them via
security@ppad.tech.
diff --git a/flake.nix b/flake.nix
@@ -26,10 +26,11 @@
pkgs = import nixpkgs { inherit system; };
hlib = pkgs.haskell.lib;
+ llvm = pkgs.llvmPackages_15.llvm;
hpkgs = pkgs.haskell.packages.ghc981.extend (new: old: {
- ${lib} = old.callCabal2nixWithOptions lib ./. "--enable-profiling" {};
ppad-base16 = ppad-base16.packages.${system}.default;
+ ${lib} = new.callCabal2nixWithOptions lib ./. "--enable-profiling" {};
});
cc = pkgs.stdenv.cc;
@@ -47,10 +48,9 @@
buildInputs = [
cabal
cc
+ llvm
];
- inputsFrom = builtins.attrValues self.packages.${system};
-
doBenchmark = true;
shellHook = ''
@@ -59,6 +59,7 @@
echo "cc: $(${cc}/bin/cc --version)"
echo "ghc: $(${ghc}/bin/ghc --version)"
echo "cabal: $(${cabal}/bin/cabal --version)"
+ echo "llc: $(${llvm}/bin/llc --version | head -2 | tail -1)"
'';
};
}
diff --git a/ppad-chacha.cabal b/ppad-chacha.cabal
@@ -13,6 +13,11 @@ extra-doc-files: CHANGELOG
description:
A pure ChaCha20 stream cipher and block function.
+flag llvm
+ description: Use GHC's LLVM backend.
+ default: False
+ manual: True
+
source-repository head
type: git
location: git.ppad.tech/chacha.git
@@ -22,6 +27,8 @@ library
hs-source-dirs: lib
ghc-options:
-Wall
+ if flag(llvm)
+ ghc-options: -fllvm -O2
exposed-modules:
Crypto.Cipher.ChaCha20
build-depends: