/
Crypto.source
99 lines (87 loc) · 4.62 KB
/
Crypto.source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
Index: archhaskell-habs/haskell-crypto/src/Crypto-4.2.5/Data/Digest/SHA1.hs
===================================================================
--- archhaskell-habs.orig/haskell-crypto/src/Crypto-4.2.5/Data/Digest/SHA1.hs
+++ archhaskell-habs/haskell-crypto/src/Crypto-4.2.5/Data/Digest/SHA1.hs
@@ -93,7 +93,7 @@ blockWord8sIn512 =
g [] = Nothing
g xs = Just (splitAt 64 xs)
-fromBytes :: (Bits a) => [a] -> a
+fromBytes :: (Num a, Bits a) => [a] -> a
fromBytes input =
let dofb accum [] = accum
dofb accum (x:xs) = dofb ((shiftL accum 8) .|. x) xs
Index: archhaskell-habs/haskell-crypto/src/Crypto-4.2.5/Data/Digest/SHA2.hs
===================================================================
--- archhaskell-habs.orig/haskell-crypto/src/Crypto-4.2.5/Data/Digest/SHA2.hs
+++ archhaskell-habs/haskell-crypto/src/Crypto-4.2.5/Data/Digest/SHA2.hs
@@ -80,7 +80,7 @@ blockSize = 16
-- | 'padding' currently requires that the bitSize of @a@ divide the bitSize
-- of @w@
-----------------------------------------------------------------------------
-padding :: (ShaData w, Bits a, Integral a) => [a] -> [[w]]
+padding :: (ShaData w, Bits a, Num w, Integral a) => [a] -> [[w]]
padding x = unfoldr block $ paddingHelper x 0 (0::Int) (0::Integer)
where
block [] = Nothing
@@ -155,7 +155,7 @@ instance Hash Hash384 where
instance Hash Hash224 where
toOctets (Hash224 x0 x1 x2 x3 x4 x5 x6) = bitsToOctets =<< [x0, x1, x2, x3, x4, x5, x6]
-shaStep :: (ShaData w) => Hash8 w -> [w] -> Hash8 w
+shaStep :: (ShaData w, Num w) => Hash8 w -> [w] -> Hash8 w
shaStep h m = (foldl' (flip id) h (zipWith mkStep3 ks ws)) `plus` h
where
ws = m++zipWith4 smallSigma (drop (blockSize-2) ws) (drop (blockSize-7) ws)
@@ -173,7 +173,7 @@ shaStep h m = (foldl' (flip id) h (zipWi
-- | Due to the limitations of 'padding', 'sha' currently requires that the
-- bitSize of @a@ divide the bitSize of @w@
-----------------------------------------------------------------------------
-sha :: (ShaData w, Bits a, Integral a) => Hash8 w -> [a] -> Hash8 w
+sha :: (ShaData w, Num w, Bits a, Integral a) => Hash8 w -> [a] -> Hash8 w
sha h0 x = foldl' shaStep h0 $ padding x
stringToOctets :: String -> [Word8]
@@ -282,4 +282,4 @@ test_sha2 = "SHA-2" ~: test
-- Test with:
-- ghc -no-recomp -O --make Data/Digest/SHA2.hs -main-is Data.Digest.SHA2.moduleTest -o moduleTest && ./moduleTest && rm moduleTest
-moduleTest = runTestTT test_sha2
\ No newline at end of file
+moduleTest = runTestTT test_sha2
Index: archhaskell-habs/haskell-crypto/src/Crypto-4.2.5/Data/LargeWord.hs
===================================================================
--- archhaskell-habs.orig/haskell-crypto/src/Crypto-4.2.5/Data/LargeWord.hs
+++ archhaskell-habs/haskell-crypto/src/Crypto-4.2.5/Data/LargeWord.hs
@@ -62,7 +62,7 @@ instance LargeWord Word64 where
data LargeKey a b = LargeKey a b
deriving (Eq, Ord)
-instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) =>
+instance (Num a, Ord a, Bits a, LargeWord a, Num b, Bits b, LargeWord b) =>
LargeWord (LargeKey a b) where
largeWordToInteger (LargeKey lo hi) =
largeWordToInteger lo + (2^(bitSize lo)) * largeWordToInteger hi
@@ -96,17 +96,17 @@ instance (Ord a, Bits a, LargeWord a, Bi
where conv = integerToLargeWord . largeWordToInteger
largeBitSize ~(LargeKey lo hi) = largeBitSize lo + largeBitSize hi
-instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => Show (LargeKey a b) where
+instance (Num a, Ord a, Bits a, LargeWord a, Num b, Bits b, LargeWord b) => Show (LargeKey a b) where
showsPrec p = showInt . largeWordToInteger
-instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) =>
+instance (Num a, Ord a, Bits a, LargeWord a, Num b, Bits b, LargeWord b) =>
Num (LargeKey a b) where
(+) = largeWordPlus
fromInteger = integerToLargeWord
-- Larger keys are instances of Bits provided their constituents are keys.
-instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) =>
+instance (Num a, Ord a, Bits a, LargeWord a, Num b, Bits b, LargeWord b) =>
Bits (LargeKey a b) where
(.&.) = largeWordAnd
(.|.) = largeWordOr
@@ -130,11 +130,11 @@ aoflk = undefined
boflk :: (LargeKey a b) -> b
boflk = undefined
-instance (Ord a, Bits a, LargeWord a, Ord b, Bits b, LargeWord b) =>
+instance (Num a, Ord a, Bits a, LargeWord a, Num b, Ord b, Bits b, LargeWord b) =>
Integral (LargeKey a b) where
toInteger = largeWordToInteger
-instance (Ord a, Bits a, LargeWord a, Ord b, Bits b, LargeWord b) =>
+instance (Num a, Ord a, Bits a, LargeWord a, Num b, Ord b, Bits b, LargeWord b) =>
Real (LargeKey a b)
instance Enum (LargeKey a b)