diff options
author | joe <joe@jerkface.net> | 2017-06-07 05:56:55 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-06-07 05:56:55 -0400 |
commit | a4fe28f0cf95da88f5c2db4e3397c227625aa6ac (patch) | |
tree | a2d47a89dca5734be5216952c73a299f1587cfba | |
parent | cb1a1fb883527c1c6075c97d7262e41729a9b924 (diff) |
Switch to cryptonite-based hashing.
-rw-r--r-- | bittorrent.cabal | 3 | ||||
-rw-r--r-- | src/Data/Torrent.hs | 9 |
2 files changed, 7 insertions, 5 deletions
diff --git a/bittorrent.cabal b/bittorrent.cabal index b625176d..4b1199b4 100644 --- a/bittorrent.cabal +++ b/bittorrent.cabal | |||
@@ -178,7 +178,8 @@ library | |||
178 | , vector >= 0.10 | 178 | , vector >= 0.10 |
179 | 179 | ||
180 | -- Hashing | 180 | -- Hashing |
181 | , cryptohash >= 0.10 | 181 | , cryptonite |
182 | , memory | ||
182 | , hashable >= 1.2 | 183 | , hashable >= 1.2 |
183 | 184 | ||
184 | -- Codecs & Serialization | 185 | -- Codecs & Serialization |
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index 8746fff5..1f70aea2 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs | |||
@@ -153,7 +153,7 @@ import Control.DeepSeq | |||
153 | import Control.Exception | 153 | import Control.Exception |
154 | import Control.Lens | 154 | import Control.Lens |
155 | import Control.Monad | 155 | import Control.Monad |
156 | import Crypto.Hash.SHA1 as SHA1 | 156 | import Crypto.Hash |
157 | #ifdef VERSION_bencoding | 157 | #ifdef VERSION_bencoding |
158 | import Data.BEncode as BE | 158 | import Data.BEncode as BE |
159 | import Data.BEncode.Types as BE | 159 | import Data.BEncode.Types as BE |
@@ -162,6 +162,7 @@ import Data.Bits | |||
162 | #ifdef VERSION_bits_extras | 162 | #ifdef VERSION_bits_extras |
163 | import Data.Bits.Extras | 163 | import Data.Bits.Extras |
164 | #endif | 164 | #endif |
165 | import qualified Data.ByteArray as Bytes | ||
165 | import Data.ByteString as BS | 166 | import Data.ByteString as BS |
166 | import Data.ByteString.Base16 as Base16 | 167 | import Data.ByteString.Base16 as Base16 |
167 | import Data.ByteString.Base32 as Base32 | 168 | import Data.ByteString.Base32 as Base32 |
@@ -645,7 +646,7 @@ pieceSize Piece {..} = fromIntegral (BL.length pieceData) | |||
645 | 646 | ||
646 | -- | Get piece hash. | 647 | -- | Get piece hash. |
647 | hashPiece :: Piece BL.ByteString -> PieceHash | 648 | hashPiece :: Piece BL.ByteString -> PieceHash |
648 | hashPiece Piece {..} = SHA1.hashlazy pieceData | 649 | hashPiece Piece {..} = Bytes.convert (hashlazy pieceData :: Digest SHA1) |
649 | 650 | ||
650 | {----------------------------------------------------------------------- | 651 | {----------------------------------------------------------------------- |
651 | -- Piece control | 652 | -- Piece control |
@@ -728,7 +729,7 @@ checkPieceLazy :: PieceInfo -> Piece BL.ByteString -> Bool | |||
728 | checkPieceLazy pinfo @ PieceInfo {..} Piece {..} | 729 | checkPieceLazy pinfo @ PieceInfo {..} Piece {..} |
729 | = (fromIntegral (BL.length pieceData) == piPieceLength | 730 | = (fromIntegral (BL.length pieceData) == piPieceLength |
730 | || isLastPiece pinfo pieceIndex) | 731 | || isLastPiece pinfo pieceIndex) |
731 | && SHA1.hashlazy pieceData == pieceHash pinfo pieceIndex | 732 | && Bytes.convert (hashlazy pieceData :: Digest SHA1) == pieceHash pinfo pieceIndex |
732 | 733 | ||
733 | {----------------------------------------------------------------------- | 734 | {----------------------------------------------------------------------- |
734 | -- Info dictionary | 735 | -- Info dictionary |
@@ -774,7 +775,7 @@ instance Hashable InfoDict where | |||
774 | 775 | ||
775 | -- | Hash lazy bytestring using SHA1 algorithm. | 776 | -- | Hash lazy bytestring using SHA1 algorithm. |
776 | hashLazyIH :: BL.ByteString -> InfoHash | 777 | hashLazyIH :: BL.ByteString -> InfoHash |
777 | hashLazyIH = either (const (error msg)) id . safeConvert . SHA1.hashlazy | 778 | hashLazyIH = either (const (error msg)) id . safeConvert . (Bytes.convert :: Digest SHA1 -> BS.ByteString) . hashlazy |
778 | where | 779 | where |
779 | msg = "Infohash.hash: impossible: SHA1 is always 20 bytes long" | 780 | msg = "Infohash.hash: impossible: SHA1 is always 20 bytes long" |
780 | 781 | ||