Added MD5 and MD5E backends.

This commit is contained in:
Joey Hess 2015-02-04 13:47:54 -04:00
parent 95c1593098
commit 8eb01bc894
4 changed files with 15 additions and 5 deletions

View file

@ -5,8 +5,6 @@
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
{-# LANGUAGE CPP #-}
module Backend.Hash ( module Backend.Hash (
backends, backends,
testKeyBackend, testKeyBackend,
@ -24,7 +22,7 @@ import qualified Build.SysConfig as SysConfig
import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy as L
import Data.Char import Data.Char
data Hash = SHAHash HashSize | SkeinHash HashSize data Hash = SHAHash HashSize | SkeinHash HashSize | MD5Hash
type HashSize = Int type HashSize = Int
{- Order is slightly significant; want SHA256 first, and more general {- Order is slightly significant; want SHA256 first, and more general
@ -33,6 +31,7 @@ hashes :: [Hash]
hashes = concat hashes = concat
[ map SHAHash [256, 1, 512, 224, 384] [ map SHAHash [256, 1, 512, 224, 384]
, map SkeinHash [256, 512] , map SkeinHash [256, 512]
, [MD5Hash]
] ]
{- The SHA256E backend is the default, so genBackendE comes first. -} {- The SHA256E backend is the default, so genBackendE comes first. -}
@ -58,6 +57,7 @@ genBackendE hash = (genBackend hash)
hashName :: Hash -> String hashName :: Hash -> String
hashName (SHAHash size) = "SHA" ++ show size hashName (SHAHash size) = "SHA" ++ show size
hashName (SkeinHash size) = "SKEIN" ++ show size hashName (SkeinHash size) = "SKEIN" ++ show size
hashName MD5Hash = "MD5"
hashNameE :: Hash -> String hashNameE :: Hash -> String
hashNameE hash = hashName hash ++ "E" hashNameE hash = hashName hash ++ "E"
@ -154,6 +154,7 @@ hashFile hash file filesize = liftIO $ go hash
either error return either error return
=<< externalSHA command hashsize file =<< externalSHA command hashsize file
go (SkeinHash hashsize) = skeinHasher hashsize <$> L.readFile file go (SkeinHash hashsize) = skeinHasher hashsize <$> L.readFile file
go MD5Hash = md5Hasher <$> L.readFile file
shaHasher :: HashSize -> Integer -> Either (L.ByteString -> String) String shaHasher :: HashSize -> Integer -> Either (L.ByteString -> String) String
shaHasher hashsize filesize shaHasher hashsize filesize
@ -180,6 +181,9 @@ skeinHasher hashsize
| hashsize == 512 = show . skein512 | hashsize == 512 = show . skein512
| otherwise = error $ "unsupported skein size " ++ show hashsize | otherwise = error $ "unsupported skein size " ++ show hashsize
md5Hasher :: L.ByteString -> String
md5Hasher = show . md5
{- A varient of the SHA256E backend, for testing that needs special keys {- A varient of the SHA256E backend, for testing that needs special keys
- that cannot collide with legitimate keys in the repository. - that cannot collide with legitimate keys in the repository.
- -

View file

@ -8,6 +8,7 @@ module Utility.Hash (
sha512, sha512,
skein256, skein256,
skein512, skein512,
md5,
prop_hashes_stable prop_hashes_stable
) where ) where
@ -42,6 +43,9 @@ skein256 = hashlazy
skein512 :: L.ByteString -> Digest Skein512_512 skein512 :: L.ByteString -> Digest Skein512_512
skein512 = hashlazy skein512 = hashlazy
md5 :: L.ByteString -> Digest MD5
md5 = hashlazy
{- Check that all the hashes continue to hash the same. -} {- Check that all the hashes continue to hash the same. -}
prop_hashes_stable :: Bool prop_hashes_stable :: Bool
prop_hashes_stable = all (\(hasher, result) -> hasher foo == result) prop_hashes_stable = all (\(hasher, result) -> hasher foo == result)
@ -52,6 +56,7 @@ prop_hashes_stable = all (\(hasher, result) -> hasher foo == result)
, (show . sha512, "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7") , (show . sha512, "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7")
, (show . skein256, "a04efd9a0aeed6ede40fe5ce0d9361ae7b7d88b524aa19917b9315f1ecf00d33") , (show . skein256, "a04efd9a0aeed6ede40fe5ce0d9361ae7b7d88b524aa19917b9315f1ecf00d33")
, (show . skein512, "fd8956898113510180aa4658e6c0ac85bd74fb47f4a4ba264a6b705d7a8e8526756e75aecda12cff4f1aca1a4c2830fbf57f458012a66b2b15a3dd7d251690a7") , (show . skein512, "fd8956898113510180aa4658e6c0ac85bd74fb47f4a4ba264a6b705d7a8e8526756e75aecda12cff4f1aca1a4c2830fbf57f458012a66b2b15a3dd7d251690a7")
, (show . md5, "acbd18db4cc2f85cedef654fccc4a4d8")
] ]
where where
foo = L.fromChunks [T.encodeUtf8 $ T.pack "foo"] foo = L.fromChunks [T.encodeUtf8 $ T.pack "foo"]

1
debian/changelog vendored
View file

@ -29,6 +29,7 @@ git-annex (5.20150114) UNRELEASED; urgency=medium
* Support annex.tune.objecthash1, annex.tune.objecthashlower, and * Support annex.tune.objecthash1, annex.tune.objecthashlower, and
annex.tune.branchhash1. annex.tune.branchhash1.
* Remove support for building without cryptohash. * Remove support for building without cryptohash.
* Added MD5 and MD5E backends.
-- Joey Hess <id@joeyh.name> Tue, 13 Jan 2015 17:03:39 -0400 -- Joey Hess <id@joeyh.name> Tue, 13 Jan 2015 17:03:39 -0400

View file

@ -17,8 +17,8 @@ can use different ones for different files.
This is the least expensive backend, recommended for really large This is the least expensive backend, recommended for really large
files or slow systems. files or slow systems.
* `SHA512`, `SHA512E` -- Best SHA-2 hash, for the very paranoid. * `SHA512`, `SHA512E` -- Best SHA-2 hash, for the very paranoid.
* `SHA1`, `SHA1E` -- Smaller hash than `SHA256` for those who want a checksum * `SHA1`, `SHA1E`, `MD5`, `MD5E` -- Smaller hashes than `SHA256`
but are not concerned about security. for those who want a checksum but are not concerned about security.
* `SHA384`, `SHA384E`, `SHA224`, `SHA224E` -- Hashes for people who like * `SHA384`, `SHA384E`, `SHA224`, `SHA224E` -- Hashes for people who like
unusual sizes. unusual sizes.
* `SKEIN512`, `SKEIN512E`, `SKEIN256`, `SKEIN256E` * `SKEIN512`, `SKEIN512E`, `SKEIN256`, `SKEIN256E`