summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Backend/Hash.hs10
-rw-r--r--BuildFlags.hs6
-rw-r--r--Utility/Hash.hs29
-rw-r--r--doc/install/fromscratch.mdwn2
-rw-r--r--git-annex.cabal9
5 files changed, 48 insertions, 8 deletions
diff --git a/Backend/Hash.hs b/Backend/Hash.hs
index 9cef3cae1..96a9bab3c 100644
--- a/Backend/Hash.hs
+++ b/Backend/Hash.hs
@@ -5,6 +5,8 @@
- Licensed under the GNU GPL version 3 or higher.
-}
+{-# LANGUAGE CPP #-}
+
module Backend.Hash (backends) where
import Common.Annex
@@ -27,7 +29,9 @@ type HashSize = Int
hashes :: [Hash]
hashes = concat
[ map SHAHash [256, 1, 512, 224, 384]
+#ifdef WITH_CRYPTOHASH
, map SkeinHash [256, 512]
+#endif
]
{- The SHA256E backend is the default, so genBackendE comes first. -}
@@ -143,7 +147,7 @@ shaHasher hashsize filesize
| hashsize == 224 = use SysConfig.sha224 sha224
| hashsize == 384 = use SysConfig.sha384 sha384
| hashsize == 512 = use SysConfig.sha512 sha512
- | otherwise = error $ "bad sha size " ++ show hashsize
+ | otherwise = error $ "unsupported sha size " ++ show hashsize
where
use Nothing hasher = Left $ show . hasher
use (Just c) hasher
@@ -157,6 +161,8 @@ shaHasher hashsize filesize
skeinHasher :: HashSize -> (L.ByteString -> String)
skeinHasher hashsize
+#ifdef WITH_CRYPTOHASH
| hashsize == 256 = show . skein256
| hashsize == 512 = show . skein512
- | otherwise = error $ "bad skein size " ++ show hashsize
+#endif
+ | otherwise = error $ "unsupported skein size " ++ show hashsize
diff --git a/BuildFlags.hs b/BuildFlags.hs
index e1e5c1b88..40d5bb29b 100644
--- a/BuildFlags.hs
+++ b/BuildFlags.hs
@@ -54,4 +54,10 @@ buildFlags = filter (not . null)
#ifdef WITH_QUVI
, "Quvi"
#endif
+#ifdef WITH_TDFA
+ , "TDFA"
+#endif
+#ifdef WITH_CRYPTOHASH
+ , "CryptoHash"
+#endif
]
diff --git a/Utility/Hash.hs b/Utility/Hash.hs
index 8b25998ae..cecc6af3e 100644
--- a/Utility/Hash.hs
+++ b/Utility/Hash.hs
@@ -1,13 +1,30 @@
{- Convenience wrapper around cryptohash.
- -
- - The resulting Digests can be shown to get a canonical hash encoding. -}
+ - Falls back to SHA if it's not available.
+ -}
-module Utility.Hash where
+{-# LANGUAGE CPP #-}
+
+module Utility.Hash (
+ sha1,
+ sha224,
+ sha256,
+ sha384,
+ sha512,
+#ifdef WITH_CRYPTOHASH
+ skein256,
+ skein512,
+#endif
+ prop_hashes_stable
+) where
-import Crypto.Hash
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Char8 as C8
+#ifndef WITH_CRYPTOHASH
+import Data.Digest.Pure.SHA
+#else
+import Crypto.Hash
+
sha1 :: L.ByteString -> Digest SHA1
sha1 = hashlazy
@@ -33,6 +50,8 @@ skein256 = hashlazy
skein512 :: L.ByteString -> Digest Skein512_512
skein512 = hashlazy
+#endif
+
{- Check that all the hashes continue to hash the same. -}
prop_hashes_stable :: Bool
prop_hashes_stable = all (\(hasher, result) -> hasher foo == result)
@@ -41,8 +60,10 @@ prop_hashes_stable = all (\(hasher, result) -> hasher foo == result)
, (show . sha256, "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae")
, (show . sha384, "98c11ffdfdd540676b1a137cb1a22b2a70350c9a44171d6b1180c6be5cbb2ee3f79d532c8a1dd9ef2e8e08e752a3babb")
, (show . sha512, "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7")
+#ifdef WITH_CRYPTOHASH
, (show . skein256, "a04efd9a0aeed6ede40fe5ce0d9361ae7b7d88b524aa19917b9315f1ecf00d33")
, (show . skein512, "fd8956898113510180aa4658e6c0ac85bd74fb47f4a4ba264a6b705d7a8e8526756e75aecda12cff4f1aca1a4c2830fbf57f458012a66b2b15a3dd7d251690a7")
+#endif
]
where
foo = L.fromChunks [C8.pack "foo"]
diff --git a/doc/install/fromscratch.mdwn b/doc/install/fromscratch.mdwn
index 7694733c7..c85de7ef0 100644
--- a/doc/install/fromscratch.mdwn
+++ b/doc/install/fromscratch.mdwn
@@ -7,7 +7,7 @@ quite a lot.
* [MissingH](http://github.com/jgoerzen/missingh/wiki)
* [utf8-string](http://hackage.haskell.org/package/utf8-string)
* [SHA](http://hackage.haskell.org/package/SHA)
- * [cryptohash](http://hackage.haskell.org/package/cryptohash)
+ * [cryptohash](http://hackage.haskell.org/package/cryptohash) (optional but recommended)
* [dataenc](http://hackage.haskell.org/package/dataenc)
* [monad-control](http://hackage.haskell.org/package/monad-control)
* [QuickCheck 2](http://hackage.haskell.org/package/QuickCheck)
diff --git a/git-annex.cabal b/git-annex.cabal
index fe7723d89..c501b29be 100644
--- a/git-annex.cabal
+++ b/git-annex.cabal
@@ -71,12 +71,15 @@ Flag Feed
Flag Quvi
Description: Enable use of quvi to download videos
+Flag CryptoHash
+ Description: Enable use of cryptohash for checksumming
+
Executable git-annex
Main-Is: git-annex.hs
Build-Depends: MissingH, hslogger, directory, filepath,
containers, utf8-string, network (>= 2.0), mtl (>= 2),
bytestring, old-locale, time, HTTP,
- extensible-exceptions, dataenc, SHA, cryptohash, process, json,
+ extensible-exceptions, dataenc, SHA, process, json,
base (>= 4.5 && < 4.8), monad-control, MonadCatchIO-transformers,
IfElse, text, QuickCheck >= 2.1, bloomfilter, edit-distance, process,
SafeSemaphore, uuid, random, dlist, unix-compat
@@ -106,6 +109,10 @@ Executable git-annex
if flag(TDFA)
Build-Depends: regex-tdfa
CPP-Options: -DWITH_TDFA
+
+ if flag(CryptoHash)
+ Build-Depends: cryptohash (>= 0.10.0)
+ CPP-Options: -DWITH_CRYPTOHASH
if flag(S3)
Build-Depends: hS3