From 95b247e5eb1a9e98a330f81f5afa9c8be9d0d797 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Wed, 14 Apr 2021 17:16:15 +1200 Subject: [PATCH] Fix for 32 bit platforms The use of `(fromIntegral (maxBound :: Word32))` causes problems. It is used to make an `Int` and 32 bit systems it winds up being -1. --- Crypto/Hash.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Crypto/Hash.hs b/Crypto/Hash.hs index 9a53003..0568cb8 100644 --- a/Crypto/Hash.hs +++ b/Crypto/Hash.hs @@ -54,7 +54,8 @@ import Foreign.Ptr (Ptr, plusPtr) import Crypto.Internal.ByteArray (ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B import qualified Data.ByteString.Lazy as L -import Data.Word (Word8, Word32) +import Data.Word (Word8) +import Data.Int (Int32) -- | Hash a strict bytestring into a digest. hash :: (ByteArrayAccess ba, HashAlgorithm a) => ba -> Digest a @@ -91,14 +92,14 @@ hashUpdates c l mapM_ (\b -> B.withByteArray b (processBlocks ctx (B.length b))) ls where ls = filter (not . B.null) l - -- process the data in 4GB chunks to fit in uint32_t + -- process the data in 2GB chunks to fit in uint32_t and Int on 32 bit systems processBlocks ctx bytesLeft dataPtr | bytesLeft == 0 = return () | otherwise = do hashInternalUpdate ctx dataPtr (fromIntegral actuallyProcessed) processBlocks ctx (bytesLeft - actuallyProcessed) (dataPtr `plusPtr` actuallyProcessed) where - actuallyProcessed = min bytesLeft (fromIntegral (maxBound :: Word32)) + actuallyProcessed = min bytesLeft (fromIntegral (maxBound :: Int32)) -- | Finalize a context and return a digest. hashFinalize :: forall a . HashAlgorithm a