cryptohash 0.9.0 → 0.9.1
raw patch · 3 files changed
+32/−19 lines, 3 filesdep +byteablePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: byteable
API changes (from Hackage documentation)
- Crypto.Hash: hmacToByteString :: HMAC a -> ByteString
+ Crypto.Hash: instance Byteable (HMAC a)
+ Crypto.Hash.Types: instance Byteable (Context a)
+ Crypto.Hash.Types: instance Byteable (Digest a)
Files
- Crypto/Hash.hs +10/−14
- Crypto/Hash/Types.hs +20/−3
- cryptohash.cabal +2/−2
Crypto/Hash.hs view
@@ -54,8 +54,8 @@ import Crypto.Hash.Types import Crypto.Hash.Utils import Data.ByteString (ByteString)+import Data.Byteable import Data.Bits (xor)-import Data.List (foldl') import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as L @@ -94,7 +94,7 @@ -- | Return the hexadecimal (base16) bytestring of the digest digestToHexByteString :: Digest a -> ByteString-digestToHexByteString = toHex . digestToByteString+digestToHexByteString = toHex . toBytes #define DEFINE_INSTANCE(NAME, MODULENAME) \ data NAME; \@@ -140,20 +140,16 @@ DEFINE_INSTANCE_LEN(Skein512_384, Skein512, 384) DEFINE_INSTANCE_LEN(Skein512_512, Skein512, 512) --- | Represent an HMAC that is phantom types with the hash used to produce the mac.+-- | Represent an HMAC that is a phantom type with the hash used to produce the mac. -- -- The Eq instance is constant time.-data HMAC a = HMAC { hmacToByteString :: ByteString -- ^ return the binary HMAC- }+data HMAC a = HMAC ByteString +instance Byteable (HMAC a) where+ toBytes (HMAC b) = b+ instance Eq (HMAC a) where- (HMAC b1) == (HMAC b2)- | B.length b1 /= B.length b2 = False- | otherwise = foldl' (&&!) True $ B.zipWith (==) b1 b2- where True &&! True = True- True &&! False = False- False &&! True = False- False &&! False = False+ (HMAC b1) == (HMAC b2) = constEqBytes b1 b2 -- | compute a MAC using the supplied hashing function hmac :: HashFunctionBS a -- ^ Hash function to use@@ -161,10 +157,10 @@ -> ByteString -- ^ Secret key -> ByteString -- ^ Message to MAC -> HMAC a-hmac hashF blockSize secret msg = HMAC $ digestToByteString $ hashF $ B.append opad (digestToByteString $ hashF $ B.append ipad msg)+hmac hashF blockSize secret msg = HMAC $ toBytes $ hashF $ B.append opad (toBytes $ hashF $ B.append ipad msg) where opad = B.map (xor 0x5c) k' ipad = B.map (xor 0x36) k' k' = B.append kt pad- kt = if B.length secret > fromIntegral blockSize then digestToByteString (hashF secret) else secret+ kt = if B.length secret > fromIntegral blockSize then toBytes (hashF secret) else secret pad = B.replicate (fromIntegral blockSize - B.length kt) 0
Crypto/Hash/Types.hs view
@@ -11,10 +11,14 @@ ( HashAlgorithm(..) , Context(..) , Digest(..)+ -- * deprecated+ , contextToByteString+ , digestToByteString ) where import Data.ByteString (ByteString)+import Data.Byteable import qualified Data.ByteString.Char8 as BC import Crypto.Hash.Utils (toHex) @@ -41,12 +45,25 @@ digestFromByteString :: ByteString -> Maybe (Digest a) -- | Represent a context for a given hash algorithm.-newtype Context a = Context { contextToByteString :: ByteString }+newtype Context a = Context ByteString +instance Byteable (Context a) where+ toBytes (Context bs) = bs++-- | return the binary bytestring. deprecated use toBytes.+contextToByteString :: Context a -> ByteString+contextToByteString = toBytes+ -- | Represent a digest for a given hash algorithm.-newtype Digest a = Digest { digestToByteString :: ByteString -- ^ Return the binary digest- }+newtype Digest a = Digest ByteString deriving (Eq,Ord)++instance Byteable (Digest a) where+ toBytes (Digest bs) = bs++-- | return the binary bytestring. deprecated use toBytes.+digestToByteString :: Digest a -> ByteString+digestToByteString = toBytes instance Show (Digest a) where show (Digest bs) = BC.unpack $ toHex bs
cryptohash.cabal view
@@ -1,5 +1,5 @@ Name: cryptohash-Version: 0.9.0+Version: 0.9.1 Description: A collection of crypto hashes, with a practical incremental and one-pass, pure APIs, with performance close to the fastest implementations available in others languages.@@ -51,7 +51,7 @@ Default: True Library- Build-Depends: base >= 4 && < 6, bytestring, ghc-prim+ Build-Depends: base >= 4 && < 6, bytestring, byteable, ghc-prim if flag(cryptoapi) Build-depends: crypto-api >= 0.5, tagged >= 0.1, cereal >= 0.2 cpp-options: -DHAVE_CRYPTOAPI