add AFIS tests
This commit is contained in:
parent
abb470f8b7
commit
ba565ce6f0
52
tests/KAT_AFIS.hs
Normal file
52
tests/KAT_AFIS.hs
Normal file
@ -0,0 +1,52 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE ExistentialQuantification #-}
|
||||
module KAT_AFIS (tests) where
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
|
||||
import Crypto.Hash
|
||||
import Crypto.Random
|
||||
import qualified Crypto.Data.AFIS as AFIS
|
||||
|
||||
import Data.ByteString (ByteString)
|
||||
import Data.ByteString.Char8 ()
|
||||
import qualified Data.ByteString as B
|
||||
|
||||
import Test.Tasty
|
||||
import Test.Tasty.QuickCheck
|
||||
import Test.Tasty.HUnit
|
||||
|
||||
mergeVec =
|
||||
[ (3
|
||||
, hash :: HashFunctionBS SHA1
|
||||
, "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"
|
||||
, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\xd4\x76\xc8\x58\xbd\xf0\x15\xbe\x9f\x40\xe3\x65\x20\x1c\x9c\xb8\xd8\x1c\x16\x64"
|
||||
)
|
||||
, (3
|
||||
, hash :: HashFunctionBS SHA1
|
||||
, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17"
|
||||
, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\xd6\x75\xc8\x59\xbb\xf7\x11\xbb\x95\x4b\xeb\x6c\x2e\x13\x90\xb5\xca\x0f\x06\x75\x17\x70\x39\x28"
|
||||
)
|
||||
]
|
||||
|
||||
mergeKATs = map toProp $ zip mergeVec [(0 :: Int)..]
|
||||
where toProp ((nbExpands, hashF, expected, dat), i) =
|
||||
testCase ("merge " ++ show i) (expected @=? AFIS.merge hashF nbExpands dat)
|
||||
|
||||
data AFISParams = forall a . HashAlgorithm a => AFISParams B.ByteString Int (HashFunctionBS a) ChaChaDRG
|
||||
|
||||
instance Show AFISParams where
|
||||
show (AFISParams dat expand _ _) = "data: " ++ show dat ++ " expanded: " ++ show expand
|
||||
|
||||
instance Arbitrary AFISParams where
|
||||
arbitrary = AFISParams <$> arbitraryBS <*> choose (2,2) <*> elements [hash :: HashFunctionBS SHA1] <*> arbitrary
|
||||
where arbitraryBS = choose (3,46) >>= \sz -> B.pack <$> replicateM sz arbitrary
|
||||
|
||||
instance Arbitrary ChaChaDRG where
|
||||
arbitrary = drgNewTest <$> arbitrary
|
||||
|
||||
tests = testGroup "AFIS"
|
||||
[ testGroup "KAT merge" mergeKATs
|
||||
, testProperty "merge.split == id" $ \(AFISParams bs e hf rng) -> bs == (AFIS.merge hf e $ fst (AFIS.split hf rng e bs))
|
||||
]
|
||||
@ -22,6 +22,7 @@ import qualified KAT_Curve25519
|
||||
import qualified KAT_Scrypt
|
||||
import qualified KAT_RC4
|
||||
import qualified KAT_Blowfish
|
||||
import qualified KAT_AFIS
|
||||
import qualified BlockCipher
|
||||
|
||||
b8_128_k0_i0 = "\xe2\x8a\x5f\xa4\xa6\x7f\x8c\x5d\xef\xed\x3e\x6f\xb7\x30\x34\x86\xaa\x84\x27\xd3\x14\x19\xa7\x29\x57\x2d\x77\x79\x53\x49\x11\x20\xb6\x4a\xb8\xe7\x2b\x8d\xeb\x85\xcd\x6a\xea\x7c\xb6\x08\x9a\x10\x18\x24\xbe\xeb\x08\x81\x4a\x42\x8a\xab\x1f\xa2\xc8\x16\x08\x1b\x8a\x26\xaf\x44\x8a\x1b\xa9\x06\x36\x8f\xd8\xc8\x38\x31\xc1\x8c\xec\x8c\xed\x81\x1a\x02\x8e\x67\x5b\x8d\x2b\xe8\xfc\xe0\x81\x16\x5c\xea\xe9\xf1\xd1\xb7\xa9\x75\x49\x77\x49\x48\x05\x69\xce\xb8\x3d\xe6\xa0\xa5\x87\xd4\x98\x4f\x19\x92\x5f\x5d\x33\x8e\x43\x0d"
|
||||
@ -81,6 +82,7 @@ tests = testGroup "cryptonite"
|
||||
, KAT_Scrypt.tests
|
||||
, KAT_RC4.tests
|
||||
, KAT_Blowfish.tests
|
||||
, KAT_AFIS.tests
|
||||
]
|
||||
where chachaRunSimple expected rounds klen nonceLen =
|
||||
let chacha = ChaCha.initialize rounds (B.replicate klen 0) (B.replicate nonceLen 0)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user