diff options
Diffstat (limited to 'cryptonite-backport/Crypto/Internal/Compat.hs')
-rw-r--r-- | cryptonite-backport/Crypto/Internal/Compat.hs | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/cryptonite-backport/Crypto/Internal/Compat.hs b/cryptonite-backport/Crypto/Internal/Compat.hs deleted file mode 100644 index a3712a7c..00000000 --- a/cryptonite-backport/Crypto/Internal/Compat.hs +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | -- | | ||
2 | -- Module : Crypto.Internal.Compat | ||
3 | -- License : BSD-style | ||
4 | -- Maintainer : Vincent Hanquez <vincent@snarc.org> | ||
5 | -- Stability : stable | ||
6 | -- Portability : Good | ||
7 | -- | ||
8 | -- This module try to keep all the difference between versions of base | ||
9 | -- or other needed packages, so that modules don't need to use CPP | ||
10 | -- | ||
11 | {-# LANGUAGE CPP #-} | ||
12 | module Crypto.Internal.Compat | ||
13 | ( unsafeDoIO | ||
14 | , popCount | ||
15 | , byteSwap64 | ||
16 | ) where | ||
17 | |||
18 | import System.IO.Unsafe | ||
19 | import Data.Word | ||
20 | import Data.Bits | ||
21 | |||
22 | -- | perform io for hashes that do allocation and ffi. | ||
23 | -- unsafeDupablePerformIO is used when possible as the | ||
24 | -- computation is pure and the output is directly linked | ||
25 | -- to the input. we also do not modify anything after it has | ||
26 | -- been returned to the user. | ||
27 | unsafeDoIO :: IO a -> a | ||
28 | #if __GLASGOW_HASKELL__ > 704 | ||
29 | unsafeDoIO = unsafeDupablePerformIO | ||
30 | #else | ||
31 | unsafeDoIO = unsafePerformIO | ||
32 | #endif | ||
33 | |||
34 | #if !(MIN_VERSION_base(4,5,0)) | ||
35 | popCount :: Word64 -> Int | ||
36 | popCount n = loop 0 n | ||
37 | where loop c 0 = c | ||
38 | loop c i = loop (c + if testBit c 0 then 1 else 0) (i `shiftR` 1) | ||
39 | #endif | ||
40 | |||
41 | #if !(MIN_VERSION_base(4,7,0)) | ||
42 | byteSwap64 :: Word64 -> Word64 | ||
43 | byteSwap64 w = | ||
44 | (w `shiftR` 56) .|. (w `shiftL` 56) | ||
45 | .|. ((w `shiftR` 40) .&. 0xff00) .|. ((w .&. 0xff00) `shiftL` 40) | ||
46 | .|. ((w `shiftR` 24) .&. 0xff0000) .|. ((w .&. 0xff0000) `shiftL` 24) | ||
47 | .|. ((w `shiftR` 8) .&. 0xff000000) .|. ((w .&. 0xff000000) `shiftL` 8) | ||
48 | #endif | ||