packages feed

crypto-cipher-tests 0.0.7 → 0.0.8

raw patch · 4 files changed

+43/−4 lines, 4 filesdep ~crypto-cipher-typesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: crypto-cipher-types

API changes (from Hackage documentation)

+ Crypto.Cipher.Tests: KAT_CFB :: ByteString -> ByteString -> ByteString -> ByteString -> KAT_CFB
+ Crypto.Cipher.Tests: cfbCiphertext :: KAT_CFB -> ByteString
+ Crypto.Cipher.Tests: cfbIV :: KAT_CFB -> ByteString
+ Crypto.Cipher.Tests: cfbKey :: KAT_CFB -> ByteString
+ Crypto.Cipher.Tests: cfbPlaintext :: KAT_CFB -> ByteString
+ Crypto.Cipher.Tests: data KAT_CFB
+ Crypto.Cipher.Tests: kat_CFB :: KATs -> [KAT_CFB]
- Crypto.Cipher.Tests: KATs :: [KAT_ECB] -> [KAT_CBC] -> [KAT_CTR] -> [KAT_XTS] -> [KAT_AEAD] -> KATs
+ Crypto.Cipher.Tests: KATs :: [KAT_ECB] -> [KAT_CBC] -> [KAT_CFB] -> [KAT_CTR] -> [KAT_XTS] -> [KAT_AEAD] -> KATs

Files

Crypto/Cipher/Tests.hs view
@@ -17,6 +17,7 @@     , KAT_Stream(..)     , KAT_ECB(..)     , KAT_CBC(..)+    , KAT_CFB(..)     , KAT_CTR(..)     , KAT_XTS(..)     , KAT_AEAD(..)
Crypto/Cipher/Tests/KATs.hs view
@@ -24,6 +24,14 @@     , cbcCiphertext :: ByteString -- ^ Ciphertext     } deriving (Show,Eq) +-- | CFB KAT+data KAT_CFB = KAT_CFB+    { cfbKey        :: ByteString -- ^ Key+    , cfbIV         :: ByteString -- ^ IV+    , cfbPlaintext  :: ByteString -- ^ Plaintext+    , cfbCiphertext :: ByteString -- ^ Ciphertext+    } deriving (Show,Eq)+ -- | CTR KAT data KAT_CTR = KAT_CTR     { ctrKey        :: ByteString -- ^ Key@@ -58,6 +66,7 @@ data KATs = KATs     { kat_ECB  :: [KAT_ECB]     , kat_CBC  :: [KAT_CBC]+    , kat_CFB  :: [KAT_CFB]     , kat_CTR  :: [KAT_CTR]     , kat_XTS  :: [KAT_XTS]     , kat_AEAD :: [KAT_AEAD]@@ -75,6 +84,7 @@ defaultKATs = KATs     { kat_ECB  = []     , kat_CBC  = []+    , kat_CFB  = []     , kat_CTR  = []     , kat_XTS  = []     , kat_AEAD = []@@ -89,6 +99,7 @@ testKATs kats cipher = testGroup "KAT"     (   maybeGroup makeECBTest "ECB" (kat_ECB kats)      ++ maybeGroup makeCBCTest "CBC" (kat_CBC kats)+     ++ maybeGroup makeCFBTest "CFB" (kat_CFB kats)      ++ maybeGroup makeCTRTest "CTR" (kat_CTR kats)      ++ maybeGroup makeXTSTest "XTS" (kat_XTS kats)      ++ maybeGroup makeAEADTest "AEAD" (kat_AEAD kats)@@ -104,6 +115,12 @@             ]           where ctx = cipherInit (cipherMakeKey cipher $ cbcKey d)                 iv  = cipherMakeIV cipher $ cbcIV d+        makeCFBTest i d =+            [ testCase ("E" ++ i) (cfbEncrypt ctx iv (cfbPlaintext d) @?= cfbCiphertext d)+            , testCase ("D" ++ i) (cfbDecrypt ctx iv (cfbCiphertext d) @?= cfbPlaintext d)+            ]+          where ctx = cipherInit (cipherMakeKey cipher $ cfbKey d)+                iv  = cipherMakeIV cipher $ cfbIV d         makeCTRTest i d =             [ testCase ("E" ++ i) (ctrCombine ctx iv (ctrPlaintext d) @?= ctrCiphertext d)             , testCase ("D" ++ i) (ctrCombine ctx iv (ctrCiphertext d) @?= ctrPlaintext d)
Crypto/Cipher/Tests/Properties.hs view
@@ -22,6 +22,10 @@ data CBCUnit a = CBCUnit (Key a) (IV a) B.ByteString     deriving (Eq) +-- | a CBC unit test+data CFBUnit a = CFBUnit (Key a) (IV a) B.ByteString+    deriving (Eq)+ -- | a CTR unit test data CTRUnit a = CTRUnit (Key a) (IV a) B.ByteString     deriving (Eq)@@ -41,6 +45,8 @@     show (ECBUnit key b) = "ECB(key=" ++ show (toBytes key) ++ ",input=" ++ show b ++ ")" instance Show (CBCUnit a) where     show (CBCUnit key iv b) = "CBC(key=" ++ show (toBytes key) ++ ",iv=" ++ show (toBytes iv) ++ ",input=" ++ show b ++ ")"+instance Show (CFBUnit a) where+    show (CFBUnit key iv b) = "CFB(key=" ++ show (toBytes key) ++ ",iv=" ++ show (toBytes iv) ++ ",input=" ++ show b ++ ")" instance Show (CTRUnit a) where     show (CTRUnit key iv b) = "CTR(key=" ++ show (toBytes key) ++ ",iv=" ++ show (toBytes iv) ++ ",input=" ++ show b ++ ")" instance Show (XTSUnit a) where@@ -88,6 +94,11 @@                         <*> generateIv                         <*> generatePlaintextMultiple16 +instance BlockCipher a => Arbitrary (CFBUnit a) where+    arbitrary = CFBUnit <$> generateKey+                        <*> generateIv+                        <*> generatePlaintextMultiple16+ instance BlockCipher a => Arbitrary (CTRUnit a) where     arbitrary = CTRUnit <$> generateKey                         <*> generateIv@@ -116,6 +127,7 @@     [ testGroup "decrypt.encrypt==id"         [ testProperty "ECB" ecbProp         , testProperty "CBC" cbcProp+        , testProperty "CFB" cfbProp         , testProperty "CTR" ctrProp         , testProperty "XTS" xtsProp         , testProperty "OCB" (aeadProp AEAD_OCB)@@ -125,12 +137,18 @@         , testProperty "GCM" (aeadProp AEAD_GCM)         ]     ]-  where (ecbProp,cbcProp,ctrProp,xtsProp,aeadProp) = toTests cipher+  where (ecbProp,cbcProp,cfbProp,ctrProp,xtsProp,aeadProp) = toTests cipher         toTests :: BlockCipher a                 => a-                -> ((ECBUnit a -> Bool), (CBCUnit a -> Bool), (CTRUnit a -> Bool), (XTSUnit a -> Bool), (AEADMode -> AEADUnit a -> Bool))+                -> ((ECBUnit a -> Bool),+                    (CBCUnit a -> Bool),+                    (CFBUnit a -> Bool),+                    (CTRUnit a -> Bool),+                    (XTSUnit a -> Bool),+                    (AEADMode -> AEADUnit a -> Bool))         toTests _ = (testProperty_ECB                     ,testProperty_CBC+                    ,testProperty_CFB                     ,testProperty_CTR                     ,testProperty_XTS                     ,testProperty_AEAD@@ -140,6 +158,9 @@          testProperty_CBC (CBCUnit (cipherInit -> ctx) testIV plaintext) =             plaintext `assertEq` cbcDecrypt ctx testIV (cbcEncrypt ctx testIV plaintext)++        testProperty_CFB (CFBUnit (cipherInit -> ctx) testIV plaintext) =+            plaintext `assertEq` cfbDecrypt ctx testIV (cfbEncrypt ctx testIV plaintext)          testProperty_CTR (CTRUnit (cipherInit -> ctx) testIV plaintext) =             plaintext `assertEq` ctrCombine ctx testIV (ctrCombine ctx testIV plaintext)
crypto-cipher-tests.cabal view
@@ -1,5 +1,5 @@ Name:                crypto-cipher-tests-Version:             0.0.7+Version:             0.0.8 Synopsis:            Generic cryptography cipher tests Description:         Generic cryptography cipher tests License:             BSD3@@ -27,7 +27,7 @@                    , bytestring                    , byteable >= 0.1.1                    , securemem >= 0.1.1-                   , crypto-cipher-types >= 0.0.5+                   , crypto-cipher-types >= 0.0.6   ghc-options:       -Wall -fwarn-tabs  Test-Suite test-crypto-cipher-dummy