switch to using cryptohash for MAC
This commit is contained in:
parent
d3cff7a320
commit
c0497aa571
4 changed files with 16 additions and 15 deletions
|
@ -34,7 +34,7 @@ module Crypto (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import Data.ByteString.Lazy.UTF8 (fromString)
|
import Data.ByteString.UTF8 (fromString)
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{- git-annex crypto types
|
{- git-annex crypto types
|
||||||
-
|
-
|
||||||
- Copyright 2011-2012 Joey Hess <id@joeyh.name>
|
- Copyright 2011-2015 Joey Hess <id@joeyh.name>
|
||||||
-
|
-
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
@ -17,10 +17,11 @@ module Types.Crypto (
|
||||||
calcMac,
|
calcMac,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy as L
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as T
|
import qualified Data.Text.Encoding as T
|
||||||
import Data.Digest.Pure.SHA
|
import Data.Digest.Pure.SHA
|
||||||
|
import qualified Data.ByteString as B
|
||||||
|
import Crypto.Hash
|
||||||
|
|
||||||
import Utility.Gpg (KeyIds(..))
|
import Utility.Gpg (KeyIds(..))
|
||||||
|
|
||||||
|
@ -62,17 +63,17 @@ readMac _ = Nothing
|
||||||
|
|
||||||
calcMac
|
calcMac
|
||||||
:: Mac -- ^ MAC
|
:: Mac -- ^ MAC
|
||||||
-> L.ByteString -- ^ secret key
|
-> B.ByteString -- ^ secret key
|
||||||
-> L.ByteString -- ^ message
|
-> B.ByteString -- ^ message
|
||||||
-> String -- ^ MAC'ed message, in hexadecimal
|
-> String -- ^ MAC'ed message, in hexadecimal
|
||||||
calcMac mac = case mac of
|
calcMac mac = case mac of
|
||||||
HmacSha1 -> showDigest $* hmacSha1
|
HmacSha1 -> use SHA1
|
||||||
HmacSha224 -> showDigest $* hmacSha224
|
HmacSha224 -> use SHA224
|
||||||
HmacSha256 -> showDigest $* hmacSha256
|
HmacSha256 -> use SHA256
|
||||||
HmacSha384 -> showDigest $* hmacSha384
|
HmacSha384 -> use SHA384
|
||||||
HmacSha512 -> showDigest $* hmacSha512
|
HmacSha512 -> use SHA512
|
||||||
where
|
where
|
||||||
($*) g f x y = g $ f x y
|
use alg k m = show (hmacGetDigest (hmacAlg alg k m))
|
||||||
|
|
||||||
-- Check that all the MACs continue to produce the same.
|
-- Check that all the MACs continue to produce the same.
|
||||||
prop_mac_stable :: Bool
|
prop_mac_stable :: Bool
|
||||||
|
@ -84,5 +85,5 @@ prop_mac_stable = all (\(mac, result) -> calcMac mac key msg == result)
|
||||||
, (HmacSha512, "114682914c5d017dfe59fdc804118b56a3a652a0b8870759cf9e792ed7426b08197076bf7d01640b1b0684df79e4b67e37485669e8ce98dbab60445f0db94fce")
|
, (HmacSha512, "114682914c5d017dfe59fdc804118b56a3a652a0b8870759cf9e792ed7426b08197076bf7d01640b1b0684df79e4b67e37485669e8ce98dbab60445f0db94fce")
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
key = L.fromChunks [T.encodeUtf8 $ T.pack "foo"]
|
key = T.encodeUtf8 $ T.pack "foo"
|
||||||
msg = L.fromChunks [T.encodeUtf8 $ T.pack "bar"]
|
msg = T.encodeUtf8 $ T.pack "bar"
|
||||||
|
|
2
debian/control
vendored
2
debian/control
vendored
|
@ -11,7 +11,7 @@ Build-Depends:
|
||||||
libghc-hslogger-dev,
|
libghc-hslogger-dev,
|
||||||
libghc-pcre-light-dev,
|
libghc-pcre-light-dev,
|
||||||
libghc-sha-dev,
|
libghc-sha-dev,
|
||||||
libghc-cryptohash-dev,
|
libghc-cryptohash-dev (>= 0.11.0),
|
||||||
libghc-dataenc-dev,
|
libghc-dataenc-dev,
|
||||||
libghc-utf8-string-dev,
|
libghc-utf8-string-dev,
|
||||||
libghc-aws-dev (>= 0.9.2-2~),
|
libghc-aws-dev (>= 0.9.2-2~),
|
||||||
|
|
|
@ -110,7 +110,7 @@ Executable git-annex
|
||||||
IfElse, text, QuickCheck >= 2.1, bloomfilter, edit-distance,
|
IfElse, text, QuickCheck >= 2.1, bloomfilter, edit-distance,
|
||||||
SafeSemaphore, uuid, random, dlist, unix-compat, async, stm (>= 2.3),
|
SafeSemaphore, uuid, random, dlist, unix-compat, async, stm (>= 2.3),
|
||||||
data-default, case-insensitive, http-conduit, http-types,
|
data-default, case-insensitive, http-conduit, http-types,
|
||||||
cryptohash (>= 0.10.0),
|
cryptohash (>= 0.11.0),
|
||||||
esqueleto, persistent-sqlite, persistent, persistent-template,
|
esqueleto, persistent-sqlite, persistent, persistent-template,
|
||||||
monad-logger, resourcet
|
monad-logger, resourcet
|
||||||
CC-Options: -Wall
|
CC-Options: -Wall
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue