add test to ensure hmac remains stable
This commit is contained in:
parent
892593c5ef
commit
b72de39ba4
2 changed files with 15 additions and 3 deletions
16
Crypto.hs
16
Crypto.hs
|
@ -22,6 +22,8 @@ module Crypto (
|
||||||
withDecryptedHandle,
|
withDecryptedHandle,
|
||||||
withEncryptedContent,
|
withEncryptedContent,
|
||||||
withDecryptedContent,
|
withDecryptedContent,
|
||||||
|
|
||||||
|
prop_hmacWithCipher_sane
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy.Char8 as L
|
import qualified Data.ByteString.Lazy.Char8 as L
|
||||||
|
@ -144,9 +146,7 @@ decryptCipher _ (EncryptedCipher encipher _) =
|
||||||
encryptKey :: Cipher -> Key -> IO Key
|
encryptKey :: Cipher -> Key -> IO Key
|
||||||
encryptKey c k =
|
encryptKey c k =
|
||||||
return Key {
|
return Key {
|
||||||
keyName = showOctets $ hmac_sha1
|
keyName = hmacWithCipher c (show k),
|
||||||
(s2w8 $ cipherHmac c)
|
|
||||||
(s2w8 $ show k),
|
|
||||||
keyBackendName = "GPGHMACSHA1",
|
keyBackendName = "GPGHMACSHA1",
|
||||||
keySize = Nothing, -- size and mtime omitted
|
keySize = Nothing, -- size and mtime omitted
|
||||||
keyMtime = Nothing -- to avoid leaking data
|
keyMtime = Nothing -- to avoid leaking data
|
||||||
|
@ -260,3 +260,13 @@ showOctets = concat . map hexChars
|
||||||
hexChars c = [arr ! (c `div` 16), arr ! (c `mod` 16)]
|
hexChars c = [arr ! (c `div` 16), arr ! (c `mod` 16)]
|
||||||
arr = listArray (0, 15) "0123456789abcdef"
|
arr = listArray (0, 15) "0123456789abcdef"
|
||||||
|
|
||||||
|
hmacWithCipher :: Cipher -> String -> String
|
||||||
|
hmacWithCipher c = hmacWithCipher' (cipherHmac c)
|
||||||
|
hmacWithCipher' :: String -> String -> String
|
||||||
|
hmacWithCipher' c s = showOctets $ hmac_sha1 (s2w8 c) (s2w8 s)
|
||||||
|
|
||||||
|
{- Ensure that hmacWithCipher' returns the same thing forevermore. -}
|
||||||
|
prop_hmacWithCipher_sane :: Bool
|
||||||
|
prop_hmacWithCipher_sane = known_good == hmacWithCipher' "foo" "bar"
|
||||||
|
where
|
||||||
|
known_good = "46b4ec586117154dacd49d664e5d63fdc88efb51"
|
||||||
|
|
2
test.hs
2
test.hs
|
@ -40,6 +40,7 @@ import qualified Content
|
||||||
import qualified Command.DropUnused
|
import qualified Command.DropUnused
|
||||||
import qualified Key
|
import qualified Key
|
||||||
import qualified Config
|
import qualified Config
|
||||||
|
import qualified Crypto
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
@ -63,6 +64,7 @@ quickcheck = TestLabel "quickcheck" $ TestList
|
||||||
, qctest "prop_parentDir_basics" Utility.prop_parentDir_basics
|
, qctest "prop_parentDir_basics" Utility.prop_parentDir_basics
|
||||||
, qctest "prop_relPathDirToDir_basics" Utility.prop_relPathDirToDir_basics
|
, qctest "prop_relPathDirToDir_basics" Utility.prop_relPathDirToDir_basics
|
||||||
, qctest "prop_cost_sane" Config.prop_cost_sane
|
, qctest "prop_cost_sane" Config.prop_cost_sane
|
||||||
|
, qctest "prop_hmacWithCipher_sane" Crypto.prop_hmacWithCipher_sane
|
||||||
]
|
]
|
||||||
|
|
||||||
blackbox :: Test
|
blackbox :: Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue