summaryrefslogtreecommitdiff
path: root/Types/Crypto.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-04-19 10:52:49 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-04-19 10:52:49 -0400
commit42c4cf332ce09d11b66d48ed3d39df7990882ecb (patch)
treefe895787941ac4fcbb5a45d4ae6aebd062aba7f0 /Types/Crypto.hs
parentf617b96226e6afe6fe16668e63ae6442438e3cda (diff)
add test for stable macs
Diffstat (limited to 'Types/Crypto.hs')
-rw-r--r--Types/Crypto.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/Types/Crypto.hs b/Types/Crypto.hs
index 682629d6a..005be4531 100644
--- a/Types/Crypto.hs
+++ b/Types/Crypto.hs
@@ -18,6 +18,8 @@ module Types.Crypto (
) where
import qualified Data.ByteString.Lazy as L
+import qualified Data.Text as T
+import qualified Data.Text.Encoding as T
import Data.Digest.Pure.SHA
import Utility.Gpg (KeyIds(..))
@@ -71,3 +73,16 @@ calcMac mac = case mac of
HmacSha512 -> showDigest $* hmacSha512
where
($*) g f x y = g $ f x y
+
+-- Check that all the MACs continue to produce the same.
+prop_mac_stable :: Bool
+prop_mac_stable = all (\(mac, result) -> calcMac mac key msg == result)
+ [ (HmacSha1, "46b4ec586117154dacd49d664e5d63fdc88efb51")
+ , (HmacSha224, "4c1f774863acb63b7f6e9daa9b5c543fa0d5eccf61e3ffc3698eacdd")
+ , (HmacSha256, "f9320baf0249169e73850cd6156ded0106e2bb6ad8cab01b7bbbebe6d1065317")
+ , (HmacSha384, "3d10d391bee2364df2c55cf605759373e1b5a4ca9355d8f3fe42970471eca2e422a79271a0e857a69923839015877fc6")
+ , (HmacSha512, "114682914c5d017dfe59fdc804118b56a3a652a0b8870759cf9e792ed7426b08197076bf7d01640b1b0684df79e4b67e37485669e8ce98dbab60445f0db94fce")
+ ]
+ where
+ key = L.fromChunks [T.encodeUtf8 $ T.pack "foo"]
+ msg = L.fromChunks [T.encodeUtf8 $ T.pack "bar"]