Skip to content

Instantly share code, notes, and snippets.

@larskuhtz
Created October 2, 2018 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larskuhtz/223d0d1ace42accfdec943fa7b32cba9 to your computer and use it in GitHub Desktop.
Save larskuhtz/223d0d1ace42accfdec943fa7b32cba9 to your computer and use it in GitHub Desktop.
Demonstrate incompatibility of Haskell packages cryptonite and blake2
#!/bin/bash
# The Haskell packages cryptonite and blake2 both include a version
# of the C sources of the blake2 reference implementation. Linking
# both packages into the same Haskell binary can result in a broken
# binary that produces unsound results.
TDIR=$(mktemp -d "${TMPDIR:-/tmp/}$(basename $0).XXXXXXXXXXXX")
trap "{ rm -rf "$TDIR"; }" EXIT
HSFILE="$TDIR/Main.hs"
MAIN="$TDIR/main"
cat > "$HSFILE" << EOF
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Crypto.Hash.BLAKE2.BLAKE2b
main = print $ hash 64 mempty "abc"
EOF
# compile Main.hs
ghc "$HSFILE" -o "$MAIN"
rm -f "$MAIN"
# from here on only linking happens
function get-id { ghc-pkg field $1 id | cut -d ' ' -f 2 ; }
echo
ghc "$HSFILE" -o "$MAIN"
echo ghc ./Tmp.hs -o "$MAIN"
"$MAIN"
rm -f "$MAIN"
echo
ghc -package-id `get-id blake2` "$HSFILE" -o "$MAIN"
echo ghc -package-id `get-id blake2` "$HSFILE" -o "$MAIN"
"$MAIN"
rm -f "$MAIN"
echo
ghc -package-id `get-id cryptonite` "$HSFILE" -o "$MAIN"
echo ghc -package-id `get-id cryptonite` "$HSFILE" -o "$MAIN"
"$MAIN"
rm -f "$MAIN"
echo
ghc -package-id `get-id blake2` -package-id `get-id cryptonite` "$HSFILE" -o "$MAIN"
echo ghc -package-id `get-id blake2` -package-id `get-id cryptonite` "$HSFILE" -o "$MAIN"
"$MAIN"
rm -f "$MAIN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment