add test for stable macs

This commit is contained in:
Joey Hess 2015-04-19 10:52:49 -04:00
parent ca2cf63e34
commit d3cff7a320
2 changed files with 16 additions and 0 deletions

View file

@ -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

View file

@ -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"]