From 67dd8ed7fc9dc780fe3b6179a9ddcbcc23646c65 Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Tue, 25 Apr 2017 14:23:13 +0100 Subject: [PATCH] [Hash] change Digest to use a foundation UArray that have configurable pinnable memory setting --- Crypto/Hash/Types.hs | 9 +++++++-- cryptonite.cabal | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Crypto/Hash/Types.hs b/Crypto/Hash/Types.hs index ccf8bfc..ec9d392 100644 --- a/Crypto/Hash/Types.hs +++ b/Crypto/Hash/Types.hs @@ -18,6 +18,8 @@ import Crypto.Internal.Imports import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes) import qualified Crypto.Internal.ByteArray as B import Foreign.Ptr (Ptr) +import qualified Foundation.Array as F +import qualified Foundation as F -- | Class representing hashing algorithms. -- @@ -50,8 +52,11 @@ newtype Context a = Context Bytes deriving (ByteArrayAccess,NFData) -- | Represent a digest for a given hash algorithm. -newtype Digest a = Digest Bytes - deriving (Eq,Ord,ByteArrayAccess,NFData) +newtype Digest a = Digest (F.UArray Word8) + deriving (Eq,Ord,ByteArrayAccess) + +instance NFData (Digest a) where + rnf (Digest u) = u `F.deepseq` () instance Show (Digest a) where show (Digest bs) = map (toEnum . fromIntegral) diff --git a/cryptonite.cabal b/cryptonite.cabal index 4ebac8d..9298857 100644 --- a/cryptonite.cabal +++ b/cryptonite.cabal @@ -220,7 +220,8 @@ Library Crypto.Internal.Nat Build-depends: base >= 4.3 && < 5 , bytestring - , memory >= 0.12 + , memory >= 0.14.4 + , foundation >= 0.0.8 , ghc-prim ghc-options: -Wall -fwarn-tabs -optc-O3 -fno-warn-unused-imports default-language: Haskell2010