diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-04-19 10:52:49 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-04-19 10:52:49 -0400 |
commit | 42c4cf332ce09d11b66d48ed3d39df7990882ecb (patch) | |
tree | fe895787941ac4fcbb5a45d4ae6aebd062aba7f0 | |
parent | f617b96226e6afe6fe16668e63ae6442438e3cda (diff) |
add test for stable macs
-rw-r--r-- | Test.hs | 1 | ||||
-rw-r--r-- | Types/Crypto.hs | 15 |
2 files changed, 16 insertions, 0 deletions
@@ -156,6 +156,7 @@ properties = localOption (QuickCheckTests 1000) $ testGroup "QuickCheck" , testProperty "prop_read_show_TrustLevel" Types.TrustLevel.prop_read_show_TrustLevel , testProperty "prop_parse_show_TrustLog" Logs.Trust.prop_parse_show_TrustLog , testProperty "prop_hashes_stable" Utility.Hash.prop_hashes_stable + , testProperty "prop_mac_stable" Utility.Hash.prop_mac_stable , testProperty "prop_schedule_roundtrips" Utility.Scheduled.prop_schedule_roundtrips , testProperty "prop_past_sane" Utility.Scheduled.prop_past_sane , testProperty "prop_duration_roundtrips" Utility.HumanTime.prop_duration_roundtrips 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"] |