digest-0.0.1.0/0000755000000000000000000000000011631107345011314 5ustar0000000000000000digest-0.0.1.0/Setup.hs0000644000000000000000000000005611631107345012751 0ustar0000000000000000import Distribution.Simple main = defaultMain digest-0.0.1.0/LICENSE0000644000000000000000000000243311631107345012323 0ustar0000000000000000Copyright (c) 2008-2009, Eugene Kirpichov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. digest-0.0.1.0/digest.cabal0000644000000000000000000000261611631107345013564 0ustar0000000000000000name: digest version: 0.0.1.0 copyright: (c) 2009 Eugene Kirpichov license: BSD3 license-file: LICENSE author: Eugene Kirpichov maintainer: Eugene Kirpichov category: Cryptography synopsis: Various cryptographic hashes for bytestrings; CRC32 and Adler32 for now. description: This package provides efficient cryptographic hash implementations for strict and lazy bytestrings. For now, CRC32 and Adler32 are supported; they are implemented as FFI bindings to efficient code from zlib. stability: provisional build-type: Simple cabal-version: >= 1.6 flag bytestring-in-base description: In the ghc-6.6 era the bytestring modules were included in the base package. source-repository head type: git location: git://github.com/jkff/digest library exposed-modules: Data.Digest.CRC32, Data.Digest.Adler32 extensions: CPP, ForeignFunctionInterface build-depends: base < 5 if flag(bytestring-in-base) -- bytestring was in base-2.0 and 2.1.1 build-depends: base >= 2.0 && < 2.2 cpp-options: -DBYTESTRING_IN_BASE else build-depends: base < 2.0 || >= 2.2, bytestring >= 0.9 includes: zlib.h ghc-options: -Wall if !os(windows) extra-libraries: z else build-depends: zlib digest-0.0.1.0/Data/0000755000000000000000000000000011631107345012165 5ustar0000000000000000digest-0.0.1.0/Data/Digest/0000755000000000000000000000000011631107345013404 5ustar0000000000000000digest-0.0.1.0/Data/Digest/CRC32.hsc0000644000000000000000000000365011631107345014663 0ustar0000000000000000{-# LANGUAGE ForeignFunctionInterface, FlexibleInstances #-} ------------------------------------------------------------ -- | -- Copyright : (c) 2008 Eugene Kirpichov -- License : BSD-style -- -- Maintainer : ekirpichov@gmail.com -- Stability : experimental -- Portability : portable (H98 + FFI) -- -- CRC32 wrapper -- ------------------------------------------------------------ module Data.Digest.CRC32 ( CRC32, crc32, crc32Update ) where import Foreign import Foreign.C.Types import Foreign.ForeignPtr () import GHC.Ptr () import qualified Data.ByteString as S import qualified Data.ByteString.Internal as BI import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy.Internal as LI #include "zlib.h" -- | The class of values for which CRC32 may be computed class CRC32 a where -- | Compute CRC32 checksum crc32 :: a -> Word32 crc32 = crc32Update 0 -- | Given the CRC32 checksum of a string, compute CRC32 of its -- concatenation with another string (t.i., incrementally update -- the CRC32 hash value) crc32Update :: Word32 -> a -> Word32 instance CRC32 S.ByteString where crc32Update = crc32_s_update instance CRC32 L.ByteString where crc32Update = crc32_l_update instance CRC32 [Word8] where crc32Update n = (crc32Update n) . L.pack crc32_s_update :: Word32 -> S.ByteString -> Word32 crc32_s_update n s = crc32_l_update n (LI.Chunk s LI.Empty) crc32_l_update :: Word32 -> L.ByteString -> Word32 crc32_l_update n = LI.foldlChunks updateCRC n where updateCRC crc bs = fromIntegral $ crc32_c (fromIntegral crc) buf (fromIntegral len) where (ptr, offset, len) = BI.toForeignPtr bs buf = (unsafeForeignPtrToPtr ptr) `plusPtr` offset foreign import ccall unsafe "zlib.h crc32" crc32_c :: CInt -> Ptr Word8 -> CInt -> CInt -- crc, buf, len -> crc' digest-0.0.1.0/Data/Digest/Adler32.hsc0000644000000000000000000000376511631107345015312 0ustar0000000000000000{-# LANGUAGE ForeignFunctionInterface, FlexibleInstances #-} ------------------------------------------------------------ -- | -- Copyright : (c) 2008 Eugene Kirpichov -- License : BSD-style -- -- Maintainer : ekirpichov@gmail.com -- Stability : experimental -- Portability : portable (H98 + FFI) -- -- Adler32 wrapper -- ------------------------------------------------------------ module Data.Digest.Adler32 ( Adler32, adler32, adler32Update ) where import Foreign import Foreign.C.Types import Foreign.ForeignPtr () import GHC.Ptr () import qualified Data.ByteString as S import qualified Data.ByteString.Internal as BI import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy.Internal as LI #include "zlib.h" -- | The class of values for which Adler32 may be computed class Adler32 a where -- | Compute Adler32 checksum adler32 :: a -> Word32 adler32 = adler32Update 1 -- | Given the Adler32 checksum of a string, compute Adler32 of its -- concatenation with another string (t.i., incrementally update the -- Adler32 hash value). adler32Update :: Word32 -> a -> Word32 instance Adler32 S.ByteString where adler32Update = adler32_s_update instance Adler32 L.ByteString where adler32Update = adler32_l_update instance Adler32 [Word8] where adler32Update n = (adler32Update n) . L.pack adler32_s_update :: Word32 -> S.ByteString -> Word32 adler32_s_update n s = adler32_l_update n (LI.Chunk s LI.Empty) adler32_l_update :: Word32 -> L.ByteString -> Word32 adler32_l_update n = LI.foldlChunks updateAdler n where updateAdler adler bs = fromIntegral $ adler32_c (fromIntegral adler) buf (fromIntegral len) where (ptr, offset, len) = BI.toForeignPtr bs buf = (unsafeForeignPtrToPtr ptr) `plusPtr` offset foreign import ccall unsafe "zlib.h adler32" adler32_c :: CInt -> Ptr Word8 -> CInt -> CInt -- adler, buf, len -> adler'