Skip to content

Commit

Permalink
Switch to MD5
Browse files Browse the repository at this point in the history
  • Loading branch information
ekarayel committed Nov 4, 2015
1 parent fb32614 commit fe66edc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
7 changes: 2 additions & 5 deletions src/Sync/MerkleTree/CommTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,11 @@ data QueryFileResponse

instance Serial QueryFileResponse

data ProtocolVersion
= Version1
| Version2
| Version3
data ProtocolVersion = ProtocolVersion !Int
deriving (Read, Show, Eq)

thisProtocolVersion :: ProtocolVersion
thisProtocolVersion = Version3
thisProtocolVersion = ProtocolVersion 4

data LaunchMessage
= LaunchMessage
Expand Down
2 changes: 1 addition & 1 deletion src/Sync/MerkleTree/Sync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ tests = H.TestList $
do inst <-
ST.fromByteString $ P.runPutS $ SE.serialize $ show $
LaunchMessage
{ lm_protocolVersion = Version1
{ lm_protocolVersion = ProtocolVersion 1
, lm_dir = dir
, lm_side = Client
, lm_clientServerOptions =
Expand Down
12 changes: 6 additions & 6 deletions src/Sync/MerkleTree/Trie.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ degree :: Int
degree = 64

class HasDigest a where
digest :: a -> Digest SHA256
digest :: a -> Digest MD5

-- | Fingerprint of a Merkle-Hash-Tree node
-- We asssume the Tree below a node is identical while synchronizing if its FingerPrint is
Expand Down Expand Up @@ -96,19 +96,19 @@ mkNode arr =
, t_node = Node arr
}

hashSHA256 :: BS.ByteString -> Digest SHA256
hashSHA256 = hash
hashMD5 :: BS.ByteString -> Digest MD5
hashMD5 = hash

combineHash :: [Hash] -> Hash
combineHash = Hash . toBytes . hashSHA256 . BS.concat . map unHash
combineHash = Hash . toBytes . hashMD5 . BS.concat . map unHash

-- | The function @groupOf x@ eeturns a value between 0 to degree-1 for a digest with the property
-- that @groupOf@ forms an approximate unviversal hash familiy.
groupOf :: (HasDigest a) => Int -> a -> Int
groupOf i x = fromInteger $ toInteger $ (h0 `mod` (fromInteger $ toInteger degree))
where
Just (h0, _t) = BS.uncons $ toBytes $ h
h :: Digest SHA256
h :: Digest MD5
h = hash $ BS.concat [BS.pack [fromInteger $ toInteger i], toBytes $ digest x]

mkLeave :: (HasDigest a, Ord a) => [a] -> Trie a
Expand Down Expand Up @@ -159,7 +159,7 @@ newtype TestDigest = TestDigest { unTestDigest :: T.Text }
deriving (Eq, Ord, Show)

instance HasDigest TestDigest where
digest = hashSHA256 . TE.encodeUtf8 . unTestDigest
digest = hashMD5 . TE.encodeUtf8 . unTestDigest

tests :: H.Test
tests = H.TestList $
Expand Down

0 comments on commit fe66edc

Please sign in to comment.