Created
October 2, 2018 16:56
-
-
Save larskuhtz/223d0d1ace42accfdec943fa7b32cba9 to your computer and use it in GitHub Desktop.
Demonstrate incompatibility of Haskell packages cryptonite and blake2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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