diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/Setup.lhs b/Setup.lhs
new file mode 100644
--- /dev/null
+++ b/Setup.lhs
@@ -0,0 +1,4 @@
+#!/usr/bin/env runhaskell
+
+> import Distribution.Simple
+> main = defaultMain
diff --git a/digest-pure.cabal b/digest-pure.cabal
new file mode 100644
--- /dev/null
+++ b/digest-pure.cabal
@@ -0,0 +1,51 @@
+Name:               digest-pure
+Version:            0.0.1
+License:            OtherLicense
+License-file:       LICENSE
+Copyright:          Copyright 2011 Daniël de Kok
+Maintainer:         Daniël de Kok <me@danieldk.eu>
+Author:             Daniël de Kok <me@danieldk.eu>
+Homepage:           http://github.com/danieldk/digest-pure
+Category:           Cryptography
+Synopsis:           Pure hash functions for bytestrings
+Description:        This package provides pure hash functions for pure and lazy
+                    bytestrings, implementing the same interface as the /digest/
+                    package.
+                    .
+                    For efficiency, use the /digest/ package, which provides
+                    FFI bindings to efficient code from zlib, instead.
+                    .
+                    Performance compared to 'Data.Digest' on a Mac Mini 2010,
+                    2.4GHz Core 2 Duo, using 'Data.ByteString.Lazy.ByteString':
+                    .
+                    * Data.Digest.Pure.Adler32: 380 MB/s
+                    .
+                    * Data.Digest.Adler32: 4906 MB/s
+                    .
+                    * Data.Digest.Pure.CRC32: 232 MB/s
+                    .
+                    * Data.Digest.CRC32: 774 MB/s
+Build-Type:         Simple
+Cabal-Version:      >= 1.8
+Extra-Source-Files: test/TestSuiteDigestPure.hs
+
+Source-Repository head
+  type:                 git
+  location:             git@github.com:danieldk/digest-pure.git
+
+
+Library
+  Build-Depends:        base >= 4 && < 5, bytestring >= 0.9.1.10 && < 0.9.2,
+                        array >= 0.3.0.2 && < 0.4
+  Exposed-modules:      Data.Digest.Pure.Adler32, Data.Digest.Pure.CRC32
+  Ghc-Options:          -Wall -O2
+  HS-Source-Dirs:       src
+
+Test-Suite TestSuiteDigestPure
+  Type:                 exitcode-stdio-1.0
+  Main-Is:              TestSuiteDigestPure.hs
+  Build-Depends:        base >= 4 && < 5, bytestring >= 0.9.1.10 && < 0.9.2,
+                        array >= 0.3.0.2 && < 0.4, QuickCheck >= 2.4.0.1,
+                        digest >= 0.0.0.9
+  Ghc-Options:          -O2
+  HS-Source-Dirs:       src, test
diff --git a/src/Data/Digest/Pure/Adler32.hs b/src/Data/Digest/Pure/Adler32.hs
new file mode 100644
--- /dev/null
+++ b/src/Data/Digest/Pure/Adler32.hs
@@ -0,0 +1,93 @@
+{-# LANGUAGE BangPatterns #-}
+
+-- |
+-- Module      : Data.Digest.Pure.Adler32
+-- Copyright   : (c) 2011 Daniël de Kok
+-- License     : OtherLicense
+--
+-- Maintainer  : Daniël de Kok <me@danieldk.eu>
+-- Stability   : experimental
+--
+-- This module provides functions to calculate Adler32 checksums.
+
+module Data.Digest.Pure.Adler32 (
+  Adler32(..)
+) where
+
+import Data.Bits ((.&.), (.|.), shiftL, shiftR)
+import qualified Data.ByteString as BS
+import qualified Data.ByteString.Lazy as BL
+import Data.Int (Int64)
+import Data.Word (Word8, Word32)
+
+-- |
+-- The class of values for which Adler32 checksums can be computed.
+class Adler32 a where
+  -- |
+  -- Compute the Adler32 checksum.
+  adler32       :: a -> Word32
+  -- |
+  -- Incrementally update an Adler32 checksum. The Adler32 checksum of one
+  -- /A/ updated with /B/, equals the checksum of the concatenation of /A/ and
+  -- /B/.
+  adler32Update :: Word32 -> a -> Word32
+
+data AdlerState = AdlerState {-# UNPACK #-} !Word32  {-# UNPACK #-} !Word32
+
+instance Adler32 BL.ByteString where
+  adler32       = adler32Update adler32Initial
+  adler32Update = adler32Update'
+
+instance Adler32 BS.ByteString where
+  adler32             = adler32Update adler32Initial
+  adler32Update state = adler32Update state . BL.fromChunks . return
+
+adler32Initial :: Word32
+adler32Initial = 1
+
+adler32Base :: Word32
+adler32Base = 65521
+
+adler32Nmax :: Int64
+adler32Nmax = 5552
+
+adler32Update' :: Word32 -> BL.ByteString -> Word32
+adler32Update' adlerState =
+  combineAdler . loop (breakAdler adlerState)
+  where
+    loop adlerState' str
+      | BL.null xs = adlerState'
+      | otherwise  = loop (adler32Chunk adlerState' xs) ys
+        where
+          (xs, ys) = BL.splitAt adler32Nmax str
+
+adler32Chunk :: AdlerState -> BL.ByteString -> AdlerState
+adler32Chunk adler =
+  modAdler . BL.foldl' sumAdler adler
+
+breakAdler :: Word32 -> AdlerState
+breakAdler adler =
+  AdlerState (adler .&. 0xffff) ((adler `shiftR` 16) .&. 0xffff)
+
+combineAdler :: AdlerState -> Word32
+combineAdler (AdlerState a b) =
+  a .|. (b `shiftL` 16)
+
+sumAdler :: AdlerState -> Word8 -> AdlerState
+{-# INLINE sumAdler #-}
+sumAdler (AdlerState a b) !byte = AdlerState newA (sumB b newA)
+  where
+    newA = sumA a byte
+
+sumA :: Word32 -> Word8 -> Word32
+{-# INLINE sumA #-}
+sumA !adlerA !byte = (adlerA + (fromIntegral byte))
+
+sumB :: Word32 -> Word32 -> Word32
+{-# INLINE sumB #-}
+sumB !adlerB !adlerA = adlerB + adlerA
+
+modAdler :: AdlerState -> AdlerState
+modAdler (AdlerState adlerA adlerB) =
+  AdlerState (adlerA `mod` adler32Base) (adlerB `mod` adler32Base)
+
diff --git a/src/Data/Digest/Pure/CRC32.hs b/src/Data/Digest/Pure/CRC32.hs
new file mode 100644
--- /dev/null
+++ b/src/Data/Digest/Pure/CRC32.hs
@@ -0,0 +1,121 @@
+{-# LANGUAGE BangPatterns #-}
+
+-- |
+-- Module      : Data.Digest.Pure.CRC32
+-- Copyright   : (c) 2011 Daniël de Kok
+-- License     : OtherLicense
+--
+-- Maintainer  : Daniël de Kok <me@danieldk.eu>
+-- Stability   : experimental
+--
+-- This module provides functions to calculate CRC32 checksums.
+
+module Data.Digest.Pure.CRC32 (
+  CRC32(..)
+) where
+
+import Data.Bits ((.&.), shiftR, xor)
+import qualified Data.ByteString as BS
+import qualified Data.ByteString.Lazy as BL
+import Data.Array.Base (unsafeAt)
+import Data.Array.Unboxed
+import Data.Word (Word8, Word32)
+
+-- |
+-- The class of values for which CRC-32 checksums can be computed.
+class CRC32 a where
+  -- |
+  -- Compute the CRC-32 checksum.
+  crc32       :: a -> Word32
+  -- |
+  -- Incrementally update an CRC-32 checksum. The CRC-32 checksum of one
+  -- /A/ updated with /B/, equals the checksum of the concatenation of /A/ and
+  -- /B/.
+  crc32Update :: Word32 -> a -> Word32
+
+instance CRC32 BL.ByteString where
+  crc32       = crc32Update crc32Initial
+  crc32Update = crc32Update'
+
+instance CRC32 BS.ByteString where
+  crc32             = crc32Update crc32Initial
+  crc32Update state = crc32Update state . BL.fromChunks . return
+
+crc32Initial :: Word32
+crc32Initial = 0
+
+crc32Update' :: Word32 -> BL.ByteString -> Word32
+crc32Update' crc = BL.foldl' crc32Step crc
+
+crc32Step :: Word32 -> Word8 -> Word32
+{-# INLINE crc32Step #-}
+crc32Step prevCRC c =
+  flipAll (tblEntry `xor` (crc `shiftR` 8))
+  where
+    -- Note: unsafe access is ok here, we guarantee that the value is within
+    -- (0..255), crc32Table covers that range.
+    tblEntry = crc32Table !!! ((crc `xor` (fromIntegral c)) .&. 0xff)
+    crc = flipAll prevCRC 
+    flipAll = xor 0xffffffff
+
+-- | Unsafe array access.
+(!!!) :: (IArray a e, Ix i, Integral i) => a i e -> i -> e
+arr !!! i = unsafeAt arr $ fromIntegral i
+
+-- CRC table, generated using make_crc_table from zlib
+crc32Table :: UArray Word32 Word32 
+crc32Table = listArray (0, 255) $ 
+  [ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
+    0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
+    0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
+    0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
+    0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
+    0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+    0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
+    0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
+    0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
+    0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
+    0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
+    0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+    0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
+    0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
+    0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
+    0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
+    0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
+    0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+    0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
+    0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
+    0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
+    0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
+    0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
+    0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+    0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
+    0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
+    0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
+    0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
+    0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
+    0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+    0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
+    0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
+    0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
+    0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
+    0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
+    0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+    0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
+    0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
+    0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
+    0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
+    0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
+    0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+    0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
+    0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
+    0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
+    0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
+    0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
+    0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+    0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
+    0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
+    0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
+    0x2d02ef8d
+  ]
+
diff --git a/test/TestSuiteDigestPure.hs b/test/TestSuiteDigestPure.hs
new file mode 100644
--- /dev/null
+++ b/test/TestSuiteDigestPure.hs
@@ -0,0 +1,56 @@
+{-# LANGUAGE DoAndIfThenElse #-}
+
+module Main where
+
+import qualified Data.ByteString.Lazy as B
+import qualified Data.Digest.Adler32 as A
+import qualified Data.Digest.CRC32 as C
+import qualified Data.Digest.Pure.Adler32 as AP
+import qualified Data.Digest.Pure.CRC32 as CP
+import System.Exit
+import Test.QuickCheck
+import Text.Printf
+
+instance Arbitrary B.ByteString where
+  arbitrary = do
+    n <- choose (1, 1000000)
+    l <- vector n
+    return $ B.pack l
+
+main = do
+  results <- mapM (\(s, a) -> printf "%-25s: " s >> a) tests
+  if all succesful results then
+    exitSuccess
+  else
+    exitFailure
+
+succesful :: Result -> Bool
+succesful (Success _ _ _) = True
+succesful _               = False
+
+tests = [
+  ("adler32CompareZlib", quickCheckResult adler32CompareZlib),
+  ("adler32Update",      quickCheckResult adler32Update),
+  ("crc32CompareZlib",   quickCheckResult crc32CompareZlib),
+  ("crc32Update",        quickCheckResult crc32Update) ]
+
+adler32CompareZlib :: B.ByteString -> Bool
+adler32CompareZlib str =
+  AP.adler32 str == A.adler32 str
+
+adler32Update :: B.ByteString -> B.ByteString -> Bool
+adler32Update str1 str2 =
+  AP.adler32 strConcat == AP.adler32Update (AP.adler32 str1) str2
+  where
+    strConcat = B.append str1 str2
+
+crc32CompareZlib :: B.ByteString -> Bool
+crc32CompareZlib str =
+  CP.crc32 str == C.crc32 str
+
+crc32Update :: B.ByteString -> B.ByteString -> Bool
+crc32Update str1 str2 =
+  CP.crc32 strConcat == CP.crc32Update (CP.crc32 str1) str2
+  where
+    strConcat = B.append str1 str2
+
