crypto-api-tests-0.1: A test framework and KATs for cryptographic operations.





Basic tests for some common cryptographic algorithms Most user only need to run the {make,run}Tests functions:

        runTests (makeMD5Tests (undefined :: MD5Digest))


       runTests =<< makeAESTests (undefined :: AESKey)

TODO: More KATs are needed - particularly ones for non-AES, SHA, or MD5 algorithms.


Block Cipher KATs

makeBlockCipherPropTests :: BlockCipher k => k -> [Test]Source

Build test groups for encrypt/decrypt identity and equality of operations on strict and lazy ByteStrings.

Admittedly, these tests conflate testing the algorithm in question and testing the mode implementation in 'crypto-api', but more testing isn't exactly a bad thing.

Hash property tests

makeHashPropTests :: Hash c d => d -> TestSource

Construct a test group to check common hash properties. Properties include:

  • Operating on lazy bytestrings obtains the same result as on strict bytestrings.
  • The length of the digest (instance definition) matches the Serialize definition.
  • encode . decode == id
  • Hash block length is byte aligned (the 'crypto-api' operations require this!)
  • The digest (output) length is byte aligned (also needed by 'crypto-api')


hexStringToBS :: String -> ByteStringSource

Convert hex strings to bytestrings, for example:

 "3adf91c0" ==> B.pack [0x3a, 0xdf, 0x91, 0xc0]

Strings of odd length will cause an exception as will non-hex characters such as '0x'.


defaultMain :: [Test] -> IO ()