From d2df760e34e83a9f2217b87086366acccdee10a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Ch=C3=A9ron?= Date: Sat, 8 Feb 2020 16:32:35 +0100 Subject: [PATCH] Use zipWith --- tests/ECC.hs | 8 ++++---- tests/KAT_AFIS.hs | 4 ++-- tests/KAT_Argon2.hs | 4 ++-- tests/KAT_Ed25519.hs | 12 +++++------ tests/KAT_Ed448.hs | 12 +++++------ tests/KAT_PBKDF2.hs | 16 +++++++-------- tests/KAT_PubKey.hs | 4 ++-- tests/KAT_PubKey/DSA.hs | 24 +++++++++++----------- tests/KAT_PubKey/ECC.hs | 4 ++-- tests/KAT_PubKey/ECDSA.hs | 24 +++++++++++----------- tests/KAT_PubKey/OAEP.hs | 14 ++++++------- tests/KAT_PubKey/PSS.hs | 24 +++++++++++----------- tests/KAT_PubKey/RSA.hs | 8 ++++---- tests/KAT_PubKey/Rabin.hs | 42 +++++++++++++++++++-------------------- tests/KAT_RC4.hs | 4 ++-- tests/KAT_Scrypt.hs | 4 ++-- tests/Number.hs | 8 ++++---- tests/Padding.hs | 4 ++-- tests/Salsa.hs | 2 +- tests/XSalsa.hs | 4 ++-- 20 files changed, 113 insertions(+), 113 deletions(-) diff --git a/tests/ECC.hs b/tests/ECC.hs index 5faaf81..32b4a15 100644 --- a/tests/ECC.hs +++ b/tests/ECC.hs @@ -275,13 +275,13 @@ vpEncodedPoint vector = let Right bs = convertFromBase Base16 (vpHex vector) in cryptoError :: CryptoFailable a -> Maybe CryptoError cryptoError = onCryptoFailure Just (const Nothing) -doPointDecodeTest (i, vector) = +doPointDecodeTest i vector = case vpCurve vector of Curve curve -> let prx = Just curve -- using Maybe as Proxy in testCase (show i) (vpError vector @=? cryptoError (ECC.decodePoint prx $ vpEncodedPoint vector)) -doWeakPointECDHTest (i, vector) = +doWeakPointECDHTest i vector = case vpCurve vector of Curve curve -> testCase (show i) $ do let prx = Just curve -- using Maybe as Proxy @@ -290,8 +290,8 @@ doWeakPointECDHTest (i, vector) = vpError vector @=? cryptoError (ECC.ecdh prx (ECC.keypairGetPrivate keyPair) public) tests = testGroup "ECC" - [ testGroup "decodePoint" $ map doPointDecodeTest (zip [katZero..] vectorsPoint) - , testGroup "ECDH weak points" $ map doWeakPointECDHTest (zip [katZero..] vectorsWeakPoint) + [ testGroup "decodePoint" $ zipWith doPointDecodeTest [katZero..] vectorsPoint + , testGroup "ECDH weak points" $ zipWith doWeakPointECDHTest [katZero..] vectorsWeakPoint , testGroup "property" [ testProperty "decodePoint.encodePoint==id" $ \testDRG (Curve curve) -> let prx = Just curve -- using Maybe as Proxy diff --git a/tests/KAT_AFIS.hs b/tests/KAT_AFIS.hs index f4cb9b5..b808423 100644 --- a/tests/KAT_AFIS.hs +++ b/tests/KAT_AFIS.hs @@ -23,8 +23,8 @@ mergeVec = ) ] -mergeKATs = map toProp $ zip mergeVec [(0 :: Int)..] - where toProp ((nbExpands, hashAlg, expected, dat), i) = +mergeKATs = zipWith toProp mergeVec [(0 :: Int)..] + where toProp (nbExpands, hashAlg, expected, dat) i = testCase ("merge " ++ show i) (expected @=? AFIS.merge hashAlg nbExpands dat) data AFISParams = AFISParams B.ByteString Int SHA1 ChaChaDRG diff --git a/tests/KAT_Argon2.hs b/tests/KAT_Argon2.hs index aa73555..a347fc5 100644 --- a/tests/KAT_Argon2.hs +++ b/tests/KAT_Argon2.hs @@ -28,9 +28,9 @@ vectors = ] kdfTests :: [TestTree] -kdfTests = map toKDFTest $ zip is vectors +kdfTests = zipWith toKDFTest is vectors where - toKDFTest (i, v) = + toKDFTest i v = testCase (show i) (CryptoPassed (kdfResult v) @=? Argon2.hash (kdfOptions v) (kdfPass v) (kdfSalt v) (B.length $ kdfResult v)) diff --git a/tests/KAT_Ed25519.hs b/tests/KAT_Ed25519.hs index 44dee95..80d08b5 100644 --- a/tests/KAT_Ed25519.hs +++ b/tests/KAT_Ed25519.hs @@ -47,18 +47,18 @@ vectors = ] -doPublicKeyTest (i, vec) = testCase (show i) (pub @=? Ed25519.toPublic sec) +doPublicKeyTest i vec = testCase (show i) (pub @=? Ed25519.toPublic sec) where !pub = throwCryptoError $ Ed25519.publicKey (vecPub vec) !sec = throwCryptoError $ Ed25519.secretKey (vecSec vec) -doSignatureTest (i, vec) = testCase (show i) (sig @=? Ed25519.sign sec pub (vecMsg vec)) +doSignatureTest i vec = testCase (show i) (sig @=? Ed25519.sign sec pub (vecMsg vec)) where !sig = throwCryptoError $ Ed25519.signature (vecSig vec) !pub = throwCryptoError $ Ed25519.publicKey (vecPub vec) !sec = throwCryptoError $ Ed25519.secretKey (vecSec vec) -doVerifyTest (i, vec) = testCase (show i) (True @=? Ed25519.verify pub (vecMsg vec) sig) +doVerifyTest i vec = testCase (show i) (True @=? Ed25519.verify pub (vecMsg vec) sig) where !sig = throwCryptoError $ Ed25519.signature (vecSig vec) !pub = throwCryptoError $ Ed25519.publicKey (vecPub vec) @@ -66,7 +66,7 @@ doVerifyTest (i, vec) = testCase (show i) (True @=? Ed25519.verify pub (vecMsg v tests = testGroup "Ed25519" [ testCase "gen secretkey" (Ed25519.generateSecretKey *> pure ()) - , testGroup "gen publickey" $ map doPublicKeyTest (zip [katZero..] vectors) - , testGroup "gen signature" $ map doSignatureTest (zip [katZero..] vectors) - , testGroup "verify sig" $ map doVerifyTest (zip [katZero..] vectors) + , testGroup "gen publickey" $ zipWith doPublicKeyTest [katZero..] vectors + , testGroup "gen signature" $ zipWith doSignatureTest [katZero..] vectors + , testGroup "verify sig" $ zipWith doVerifyTest [katZero..] vectors ] diff --git a/tests/KAT_Ed448.hs b/tests/KAT_Ed448.hs index 1c66cd6..5c4d5cc 100644 --- a/tests/KAT_Ed448.hs +++ b/tests/KAT_Ed448.hs @@ -65,18 +65,18 @@ vectors = ] -doPublicKeyTest (i, vec) = testCase (show i) (pub @=? Ed448.toPublic sec) +doPublicKeyTest i vec = testCase (show i) (pub @=? Ed448.toPublic sec) where !pub = throwCryptoError $ Ed448.publicKey (vecPub vec) !sec = throwCryptoError $ Ed448.secretKey (vecSec vec) -doSignatureTest (i, vec) = testCase (show i) (sig @=? Ed448.sign sec pub (vecMsg vec)) +doSignatureTest i vec = testCase (show i) (sig @=? Ed448.sign sec pub (vecMsg vec)) where !sig = throwCryptoError $ Ed448.signature (vecSig vec) !pub = throwCryptoError $ Ed448.publicKey (vecPub vec) !sec = throwCryptoError $ Ed448.secretKey (vecSec vec) -doVerifyTest (i, vec) = testCase (show i) (True @=? Ed448.verify pub (vecMsg vec) sig) +doVerifyTest i vec = testCase (show i) (True @=? Ed448.verify pub (vecMsg vec) sig) where !sig = throwCryptoError $ Ed448.signature (vecSig vec) !pub = throwCryptoError $ Ed448.publicKey (vecPub vec) @@ -84,7 +84,7 @@ doVerifyTest (i, vec) = testCase (show i) (True @=? Ed448.verify pub (vecMsg vec tests = testGroup "Ed448" [ testCase "gen secretkey" (Ed448.generateSecretKey *> pure ()) - , testGroup "gen publickey" $ map doPublicKeyTest (zip [katZero..] vectors) - , testGroup "gen signature" $ map doSignatureTest (zip [katZero..] vectors) - , testGroup "verify sig" $ map doVerifyTest (zip [katZero..] vectors) + , testGroup "gen publickey" $ zipWith doPublicKeyTest [katZero..] vectors + , testGroup "gen signature" $ zipWith doSignatureTest [katZero..] vectors + , testGroup "verify sig" $ zipWith doVerifyTest [katZero..] vectors ] diff --git a/tests/KAT_PBKDF2.hs b/tests/KAT_PBKDF2.hs index 39373cc..de877a6 100644 --- a/tests/KAT_PBKDF2.hs +++ b/tests/KAT_PBKDF2.hs @@ -67,21 +67,21 @@ tests = testGroup "PBKDF2" , testGroup "KATs-HMAC-SHA512" (katTests (PBKDF2.prfHMAC SHA512) vectors_hmac_sha512) , testGroup "KATs-HMAC-SHA512 (fast)" (katTestFastPBKDF2_SHA512 vectors_hmac_sha512) ] - where katTests prf vects = map (toKatTest prf) $ zip is vects + where katTests prf = zipWith (toKatTest prf) is - toKatTest prf (i, ((pass, salt, iter, dkLen), output)) = + toKatTest prf i ((pass, salt, iter, dkLen), output) = testCase (show i) (output @=? PBKDF2.generate prf (PBKDF2.Parameters iter dkLen) pass salt) - katTestFastPBKDF2_SHA1 = map toKatTestFastPBKDF2_SHA1 . zip is - toKatTestFastPBKDF2_SHA1 (i, ((pass, salt, iter, dkLen), output)) = + katTestFastPBKDF2_SHA1 = zipWith toKatTestFastPBKDF2_SHA1 is + toKatTestFastPBKDF2_SHA1 i ((pass, salt, iter, dkLen), output) = testCase (show i) (output @=? PBKDF2.fastPBKDF2_SHA1 (PBKDF2.Parameters iter dkLen) pass salt) - katTestFastPBKDF2_SHA256 = map toKatTestFastPBKDF2_SHA256 . zip is - toKatTestFastPBKDF2_SHA256 (i, ((pass, salt, iter, dkLen), output)) = + katTestFastPBKDF2_SHA256 = zipWith toKatTestFastPBKDF2_SHA256 is + toKatTestFastPBKDF2_SHA256 i ((pass, salt, iter, dkLen), output) = testCase (show i) (output @=? PBKDF2.fastPBKDF2_SHA256 (PBKDF2.Parameters iter dkLen) pass salt) - katTestFastPBKDF2_SHA512 = map toKatTestFastPBKDF2_SHA512 . zip is - toKatTestFastPBKDF2_SHA512 (i, ((pass, salt, iter, dkLen), output)) = + katTestFastPBKDF2_SHA512 = zipWith toKatTestFastPBKDF2_SHA512 is + toKatTestFastPBKDF2_SHA512 i ((pass, salt, iter, dkLen), output) = testCase (show i) (output @=? PBKDF2.fastPBKDF2_SHA512 (PBKDF2.Parameters iter dkLen) pass salt) diff --git a/tests/KAT_PubKey.hs b/tests/KAT_PubKey.hs index ba619e8..c3da494 100644 --- a/tests/KAT_PubKey.hs +++ b/tests/KAT_PubKey.hs @@ -25,7 +25,7 @@ data VectorMgf = VectorMgf { seed :: ByteString , dbMask :: ByteString } -doMGFTest (i, vmgf) = testCase (show i) (dbMask vmgf @=? actual) +doMGFTest i vmgf = testCase (show i) (dbMask vmgf @=? actual) where actual = mgf1 SHA1 (seed vmgf) (B.length $ dbMask vmgf) vectorsMGF = @@ -36,7 +36,7 @@ vectorsMGF = ] tests = testGroup "PubKey" - [ testGroup "MGF1" $ map doMGFTest (zip [katZero..] vectorsMGF) + [ testGroup "MGF1" $ zipWith doMGFTest [katZero..] vectorsMGF , rsaTests , pssTests , oaepTests diff --git a/tests/KAT_PubKey/DSA.hs b/tests/KAT_PubKey/DSA.hs index 9bb8ff7..7fd7eb9 100644 --- a/tests/KAT_PubKey/DSA.hs +++ b/tests/KAT_PubKey/DSA.hs @@ -331,32 +331,32 @@ vectorToPublic vector = DSA.PublicKey , DSA.public_params = pgq vector } -doSignatureTest hashAlg (i, vector) = testCase (show i) (expected @=? actual) +doSignatureTest hashAlg i vector = testCase (show i) (expected @=? actual) where expected = Just $ DSA.Signature (r vector) (s vector) actual = DSA.signWith (k vector) (vectorToPrivate vector) hashAlg (msg vector) -doVerifyTest hashAlg (i, vector) = testCase (show i) (True @=? actual) +doVerifyTest hashAlg i vector = testCase (show i) (True @=? actual) where actual = DSA.verify hashAlg (vectorToPublic vector) (DSA.Signature (r vector) (s vector)) (msg vector) dsaTests = testGroup "DSA" [ testGroup "SHA1" - [ testGroup "signature" $ map (doSignatureTest SHA1) (zip [katZero..] vectorsSHA1) - , testGroup "verify" $ map (doVerifyTest SHA1) (zip [katZero..] vectorsSHA1) + [ testGroup "signature" $ zipWith (doSignatureTest SHA1) [katZero..] vectorsSHA1 + , testGroup "verify" $ zipWith (doVerifyTest SHA1) [katZero..] vectorsSHA1 ] , testGroup "SHA224" - [ testGroup "signature" $ map (doSignatureTest SHA224) (zip [katZero..] vectorsSHA224) - , testGroup "verify" $ map (doVerifyTest SHA224) (zip [katZero..] vectorsSHA224) + [ testGroup "signature" $ zipWith (doSignatureTest SHA224) [katZero..] vectorsSHA224 + , testGroup "verify" $ zipWith (doVerifyTest SHA224) [katZero..] vectorsSHA224 ] , testGroup "SHA256" - [ testGroup "signature" $ map (doSignatureTest SHA256) (zip [katZero..] vectorsSHA256) - , testGroup "verify" $ map (doVerifyTest SHA256) (zip [katZero..] vectorsSHA256) + [ testGroup "signature" $ zipWith (doSignatureTest SHA256) [katZero..] vectorsSHA256 + , testGroup "verify" $ zipWith (doVerifyTest SHA256) [katZero..] vectorsSHA256 ] , testGroup "SHA384" - [ testGroup "signature" $ map (doSignatureTest SHA384) (zip [katZero..] vectorsSHA384) - , testGroup "verify" $ map (doVerifyTest SHA384) (zip [katZero..] vectorsSHA384) + [ testGroup "signature" $ zipWith (doSignatureTest SHA384) [katZero..] vectorsSHA384 + , testGroup "verify" $ zipWith (doVerifyTest SHA384) [katZero..] vectorsSHA384 ] , testGroup "SHA512" - [ testGroup "signature" $ map (doSignatureTest SHA512) (zip [katZero..] vectorsSHA512) - , testGroup "verify" $ map (doVerifyTest SHA512) (zip [katZero..] vectorsSHA512) + [ testGroup "signature" $ zipWith (doSignatureTest SHA512) [katZero..] vectorsSHA512 + , testGroup "verify" $ zipWith (doVerifyTest SHA512) [katZero..] vectorsSHA512 ] ] diff --git a/tests/KAT_PubKey/ECC.hs b/tests/KAT_PubKey/ECC.hs index 7a97428..2267851 100644 --- a/tests/KAT_PubKey/ECC.hs +++ b/tests/KAT_PubKey/ECC.hs @@ -136,7 +136,7 @@ vectorsPoint = } ] -doPointValidTest (i, vector) = testCase (show i) (valid vector @=? ECC.isPointValid (curve vector) (ECC.Point (x vector) (y vector))) +doPointValidTest i vector = testCase (show i) (valid vector @=? ECC.isPointValid (curve vector) (ECC.Point (x vector) (y vector))) arbitraryPoint :: ECC.Curve -> Gen ECC.Point arbitraryPoint aCurve = @@ -146,7 +146,7 @@ arbitraryPoint aCurve = pointGen = ECC.pointBaseMul aCurve <$> choose (1, n - 1) eccTests = testGroup "ECC" - [ testGroup "valid-point" $ map doPointValidTest (zip [katZero..] vectorsPoint) + [ testGroup "valid-point" $ zipWith doPointValidTest [katZero..] vectorsPoint , localOption (QuickCheckTests 20) $ testGroup "property" [ testProperty "point-add" $ \aCurve (QAInteger r1) (QAInteger r2) -> let curveN = ECC.ecc_n . ECC.common_curve $ aCurve diff --git a/tests/KAT_PubKey/ECDSA.hs b/tests/KAT_PubKey/ECDSA.hs index c4de4ba..d1bac13 100644 --- a/tests/KAT_PubKey/ECDSA.hs +++ b/tests/KAT_PubKey/ECDSA.hs @@ -490,32 +490,32 @@ vectorToPrivate vector = ECDSA.PrivateKey (curve vector) (d vector) vectorToPublic :: VectorECDSA -> ECDSA.PublicKey vectorToPublic vector = ECDSA.PublicKey (curve vector) (q vector) -doSignatureTest hashAlg (i, vector) = testCase (show i) (expected @=? actual) +doSignatureTest hashAlg i vector = testCase (show i) (expected @=? actual) where expected = Just $ ECDSA.Signature (r vector) (s vector) actual = ECDSA.signWith (k vector) (vectorToPrivate vector) hashAlg (msg vector) -doVerifyTest hashAlg (i, vector) = testCase (show i) (True @=? actual) +doVerifyTest hashAlg i vector = testCase (show i) (True @=? actual) where actual = ECDSA.verify hashAlg (vectorToPublic vector) (ECDSA.Signature (r vector) (s vector)) (msg vector) ecdsaTests = testGroup "ECDSA" [ testGroup "SHA1" - [ testGroup "signature" $ map (doSignatureTest SHA1) (zip [katZero..] vectorsSHA1) - , testGroup "verify" $ map (doVerifyTest SHA1) (zip [katZero..] vectorsSHA1) + [ testGroup "signature" $ zipWith (doSignatureTest SHA1) [katZero..] vectorsSHA1 + , testGroup "verify" $ zipWith (doVerifyTest SHA1) [katZero..] vectorsSHA1 ] , testGroup "SHA224" - [ testGroup "signature" $ map (doSignatureTest SHA224) (zip [katZero..] rfc6979_vectorsSHA224) - , testGroup "verify" $ map (doVerifyTest SHA224) (zip [katZero..] rfc6979_vectorsSHA224) + [ testGroup "signature" $ zipWith (doSignatureTest SHA224) [katZero..] rfc6979_vectorsSHA224 + , testGroup "verify" $ zipWith (doVerifyTest SHA224) [katZero..] rfc6979_vectorsSHA224 ] , testGroup "SHA256" - [ testGroup "signature" $ map (doSignatureTest SHA256) (zip [katZero..] rfc6979_vectorsSHA256) - , testGroup "verify" $ map (doVerifyTest SHA256) (zip [katZero..] rfc6979_vectorsSHA256) + [ testGroup "signature" $ zipWith (doSignatureTest SHA256) [katZero..] rfc6979_vectorsSHA256 + , testGroup "verify" $ zipWith (doVerifyTest SHA256) [katZero..] rfc6979_vectorsSHA256 ] , testGroup "SHA384" - [ testGroup "signature" $ map (doSignatureTest SHA384) (zip [katZero..] rfc6979_vectorsSHA384) - , testGroup "verify" $ map (doVerifyTest SHA384) (zip [katZero..] rfc6979_vectorsSHA384) + [ testGroup "signature" $ zipWith (doSignatureTest SHA384) [katZero..] rfc6979_vectorsSHA384 + , testGroup "verify" $ zipWith (doVerifyTest SHA384) [katZero..] rfc6979_vectorsSHA384 ] , testGroup "SHA512" - [ testGroup "signature" $ map (doSignatureTest SHA512) (zip [katZero..] rfc6979_vectorsSHA512) - , testGroup "verify" $ map (doVerifyTest SHA512) (zip [katZero..] rfc6979_vectorsSHA512) + [ testGroup "signature" $ zipWith (doSignatureTest SHA512) [katZero..] rfc6979_vectorsSHA512 + , testGroup "verify" $ zipWith (doVerifyTest SHA512) [katZero..] rfc6979_vectorsSHA512 ] ] diff --git a/tests/KAT_PubKey/OAEP.hs b/tests/KAT_PubKey/OAEP.hs index c0aff87..a37197e 100644 --- a/tests/KAT_PubKey/OAEP.hs +++ b/tests/KAT_PubKey/OAEP.hs @@ -81,17 +81,17 @@ vectorsKey1 = } ] -doEncryptionTest key (i, vec) = testCase (show i) (Right (cipherText vec) @=? actual) - where actual = OAEP.encryptWithSeed (seed vec) (OAEP.defaultOAEPParams SHA1) key (message vec) +doEncryptionTest key i vec = testCase (show i) (Right (cipherText vec) @=? actual) + where actual = OAEP.encryptWithSeed (seed vec) (OAEP.defaultOAEPParams SHA1) key (message vec) -doDecryptionTest key (i, vec) = testCase (show i) (Right (message vec) @=? actual) +doDecryptionTest key i vec = testCase (show i) (Right (message vec) @=? actual) where actual = OAEP.decrypt Nothing (OAEP.defaultOAEPParams SHA1) key (cipherText vec) oaepTests = testGroup "RSA-OAEP" [ testGroup "internal" - [ doEncryptionTest (private_pub rsaKeyInt) (0 :: Int, vectorInt) - , doDecryptionTest rsaKeyInt (0 :: Int, vectorInt) + [ doEncryptionTest (private_pub rsaKeyInt) (0 :: Int) vectorInt + , doDecryptionTest rsaKeyInt (0 :: Int) vectorInt ] - , testGroup "encryption key 1024 bits" $ map (doEncryptionTest $ private_pub rsaKey1) (zip [katZero..] vectorsKey1) - , testGroup "decryption key 1024 bits" $ map (doDecryptionTest rsaKey1) (zip [katZero..] vectorsKey1) + , testGroup "encryption key 1024 bits" $ zipWith (doEncryptionTest $ private_pub rsaKey1) [katZero..] vectorsKey1 + , testGroup "decryption key 1024 bits" $ zipWith (doDecryptionTest rsaKey1) [katZero..] vectorsKey1 ] diff --git a/tests/KAT_PubKey/PSS.hs b/tests/KAT_PubKey/PSS.hs index 551ac61..4ced84d 100644 --- a/tests/KAT_PubKey/PSS.hs +++ b/tests/KAT_PubKey/PSS.hs @@ -326,23 +326,23 @@ vectorsKey8 = } ] -doSignTest key (i, vector) = testCase (show i) (Right (signature vector) @=? actual) +doSignTest key i vector = testCase (show i) (Right (signature vector) @=? actual) where actual = PSS.signWithSalt (salt vector) Nothing PSS.defaultPSSParamsSHA1 key (message vector) -doVerifyTest key (i, vector) = testCase (show i) (True @=? actual) +doVerifyTest key i vector = testCase (show i) (True @=? actual) where actual = PSS.verify PSS.defaultPSSParamsSHA1 (private_pub key) (message vector) (signature vector) pssTests = testGroup "RSA-PSS" [ testGroup "signature internal" - [ doSignTest rsaKeyInt (katZero, vectorInt) ] + [ doSignTest rsaKeyInt katZero vectorInt ] , testGroup "verify internal" - [ doVerifyTest rsaKeyInt (katZero, vectorInt) ] - , testGroup "signature key 1024" $ map (doSignTest rsaKey1) (zip [katZero..] vectorsKey1) - , testGroup "verify key 1024" $ map (doVerifyTest rsaKey1) (zip [katZero..] vectorsKey1) - , testGroup "signature key 1025" $ map (doSignTest rsaKey2) (zip [katZero..] vectorsKey2) - , testGroup "verify key 1025" $ map (doVerifyTest rsaKey2) (zip [katZero..] vectorsKey2) - , testGroup "signature key 1026" $ map (doSignTest rsaKey3) (zip [katZero..] vectorsKey3) - , testGroup "verify key 1026" $ map (doVerifyTest rsaKey3) (zip [katZero..] vectorsKey3) - , testGroup "signature key 1031" $ map (doSignTest rsaKey8) (zip [katZero..] vectorsKey8) - , testGroup "verify key 1031" $ map (doVerifyTest rsaKey8) (zip [katZero..] vectorsKey8) + [ doVerifyTest rsaKeyInt katZero vectorInt ] + , testGroup "signature key 1024" $ zipWith (doSignTest rsaKey1) [katZero..] vectorsKey1 + , testGroup "verify key 1024" $ zipWith (doVerifyTest rsaKey1) [katZero..] vectorsKey1 + , testGroup "signature key 1025" $ zipWith (doSignTest rsaKey2) [katZero..] vectorsKey2 + , testGroup "verify key 1025" $ zipWith (doVerifyTest rsaKey2) [katZero..] vectorsKey2 + , testGroup "signature key 1026" $ zipWith (doSignTest rsaKey3) [katZero..] vectorsKey3 + , testGroup "verify key 1026" $ zipWith (doVerifyTest rsaKey3) [katZero..] vectorsKey3 + , testGroup "signature key 1031" $ zipWith (doSignTest rsaKey8) [katZero..] vectorsKey8 + , testGroup "verify key 1031" $ zipWith (doVerifyTest rsaKey8) [katZero..] vectorsKey8 ] diff --git a/tests/KAT_PubKey/RSA.hs b/tests/KAT_PubKey/RSA.hs index 068043c..87fd106 100644 --- a/tests/KAT_PubKey/RSA.hs +++ b/tests/KAT_PubKey/RSA.hs @@ -86,17 +86,17 @@ vectorToPublic vector = RSA.PublicKey vectorHasSignature :: VectorRSA -> Bool vectorHasSignature = isRight . sig -doSignatureTest (i, vector) = testCase (show i) (expected @=? actual) +doSignatureTest i vector = testCase (show i) (expected @=? actual) where expected = sig vector actual = RSA.sign Nothing (Just SHA1) (vectorToPrivate vector) (msg vector) -doVerifyTest (i, vector) = testCase (show i) (True @=? actual) +doVerifyTest i vector = testCase (show i) (True @=? actual) where actual = RSA.verify (Just SHA1) (vectorToPublic vector) (msg vector) bs Right bs = sig vector rsaTests = testGroup "RSA" [ testGroup "SHA1" - [ testGroup "signature" $ map doSignatureTest (zip [katZero..] vectorsSHA1) - , testGroup "verify" $ map doVerifyTest $ filter (vectorHasSignature . snd) (zip [katZero..] vectorsSHA1) + [ testGroup "signature" $ zipWith doSignatureTest [katZero..] vectorsSHA1 + , testGroup "verify" $ zipWith doVerifyTest [katZero..] $ filter vectorHasSignature vectorsSHA1 ] ] diff --git a/tests/KAT_PubKey/Rabin.hs b/tests/KAT_PubKey/Rabin.hs index 2f44260..89a92b3 100644 --- a/tests/KAT_PubKey/Rabin.hs +++ b/tests/KAT_PubKey/Rabin.hs @@ -95,51 +95,51 @@ rwSignatureVectors = } ] -doBasicRabinEncryptTest key (i, vector) = testCase (show i) (Right (cipherText vector) @=? actual) +doBasicRabinEncryptTest key i vector = testCase (show i) (Right (cipherText vector) @=? actual) where actual = BRabin.encryptWithSeed (seed vector) (OAEP.defaultOAEPParams SHA1) key (plainText vector) -doBasicRabinDecryptTest key (i, vector) = testCase (show i) (Just (plainText vector) @=? actual) +doBasicRabinDecryptTest key i vector = testCase (show i) (Just (plainText vector) @=? actual) where actual = BRabin.decrypt (OAEP.defaultOAEPParams SHA1) key (cipherText vector) -doBasicRabinSignTest key (i, vector) = testCase (show i) (Right (BRabin.Signature ((os2ip $ padding vector), (signature vector))) @=? actual) +doBasicRabinSignTest key i vector = testCase (show i) (Right (BRabin.Signature ((os2ip $ padding vector), (signature vector))) @=? actual) where actual = BRabin.signWith (padding vector) key SHA1 (message vector) -doBasicRabinVerifyTest key (i, vector) = testCase (show i) (True @=? actual) +doBasicRabinVerifyTest key i vector = testCase (show i) (True @=? actual) where actual = BRabin.verify key SHA1 (message vector) (BRabin.Signature ((os2ip $ padding vector), (signature vector))) -doModifiedRabinSignTest key (i, vector) = testCase (show i) (Right (signature vector) @=? actual) +doModifiedRabinSignTest key i vector = testCase (show i) (Right (signature vector) @=? actual) where actual = MRabin.sign key SHA1 (message vector) -doModifiedRabinVerifyTest key (i, vector) = testCase (show i) (True @=? actual) +doModifiedRabinVerifyTest key i vector = testCase (show i) (True @=? actual) where actual = MRabin.verify key SHA1 (message vector) (signature vector) -doRwEncryptTest key (i, vector) = testCase (show i) (Right (cipherText vector) @=? actual) - where actual = RW.encryptWithSeed (seed vector) (OAEP.defaultOAEPParams SHA1) key (plainText vector) +doRwEncryptTest key i vector = testCase (show i) (Right (cipherText vector) @=? actual) + where actual = RW.encryptWithSeed (seed vector) (OAEP.defaultOAEPParams SHA1) key (plainText vector) -doRwDecryptTest key (i, vector) = testCase (show i) (Just (plainText vector) @=? actual) +doRwDecryptTest key i vector = testCase (show i) (Just (plainText vector) @=? actual) where actual = RW.decrypt (OAEP.defaultOAEPParams SHA1) key (cipherText vector) -doRwSignTest key (i, vector) = testCase (show i) (Right (signature vector) @=? actual) +doRwSignTest key i vector = testCase (show i) (Right (signature vector) @=? actual) where actual = RW.sign key SHA1 (message vector) -doRwVerifyTest key (i, vector) = testCase (show i) (True @=? actual) +doRwVerifyTest key i vector = testCase (show i) (True @=? actual) where actual = RW.verify key SHA1 (message vector) (signature vector) rabinTests = testGroup "Rabin" [ testGroup "Basic" - [ testGroup "encrypt" $ map (doBasicRabinEncryptTest $ BRabin.private_pub basicRabinKey) (zip [katZero..] basicRabinEncryptionVectors) - , testGroup "decrypt" $ map (doBasicRabinDecryptTest $ basicRabinKey) (zip [katZero..] basicRabinEncryptionVectors) - , testGroup "sign" $ map (doBasicRabinSignTest $ basicRabinKey) (zip [katZero..] basicRabinSignatureVectors) - , testGroup "verify" $ map (doBasicRabinVerifyTest $ BRabin.private_pub basicRabinKey) (zip [katZero..] basicRabinSignatureVectors) + [ testGroup "encrypt" $ zipWith (doBasicRabinEncryptTest $ BRabin.private_pub basicRabinKey) [katZero..] basicRabinEncryptionVectors + , testGroup "decrypt" $ zipWith (doBasicRabinDecryptTest basicRabinKey) [katZero..] basicRabinEncryptionVectors + , testGroup "sign" $ zipWith (doBasicRabinSignTest basicRabinKey) [katZero..] basicRabinSignatureVectors + , testGroup "verify" $ zipWith (doBasicRabinVerifyTest $ BRabin.private_pub basicRabinKey) [katZero..] basicRabinSignatureVectors ] , testGroup "Modified" - [ testGroup "sign" $ map (doModifiedRabinSignTest $ modifiedRabinKey) (zip [katZero..] modifiedRabinSignatureVectors) - , testGroup "verify" $ map (doModifiedRabinVerifyTest $ MRabin.private_pub modifiedRabinKey) (zip [katZero..] modifiedRabinSignatureVectors) + [ testGroup "sign" $ zipWith (doModifiedRabinSignTest modifiedRabinKey) [katZero..] modifiedRabinSignatureVectors + , testGroup "verify" $ zipWith (doModifiedRabinVerifyTest $ MRabin.private_pub modifiedRabinKey) [katZero..] modifiedRabinSignatureVectors ] , testGroup "RW" - [ testGroup "encrypt" $ map (doRwEncryptTest $ RW.private_pub rwKey) (zip [katZero..] rwEncryptionVectors) - , testGroup "decrypt" $ map (doRwDecryptTest $ rwKey) (zip [katZero..] rwEncryptionVectors) - , testGroup "sign" $ map (doRwSignTest $ rwKey) (zip [katZero..] rwSignatureVectors) - , testGroup "verify" $ map (doRwVerifyTest $ RW.private_pub rwKey) (zip [katZero..] rwSignatureVectors) + [ testGroup "encrypt" $ zipWith (doRwEncryptTest $ RW.private_pub rwKey) [katZero..] rwEncryptionVectors + , testGroup "decrypt" $ zipWith (doRwDecryptTest rwKey) [katZero..] rwEncryptionVectors + , testGroup "sign" $ zipWith (doRwSignTest rwKey) [katZero..] rwSignatureVectors + , testGroup "verify" $ zipWith (doRwVerifyTest $ RW.private_pub rwKey) [katZero..] rwSignatureVectors ] ] diff --git a/tests/KAT_RC4.hs b/tests/KAT_RC4.hs index 0c113c3..b5d4db0 100644 --- a/tests/KAT_RC4.hs +++ b/tests/KAT_RC4.hs @@ -27,8 +27,8 @@ vectors = ] tests = testGroup "RC4" - $ map toKatTest $ zip is vectors - where toKatTest (i, (key, plainText, cipherText)) = + $ zipWith toKatTest is vectors + where toKatTest i (key, plainText, cipherText) = testCase (show i) (cipherText @=? snd (RC4.combine (RC4.initialize key) plainText)) is :: [Int] is = [1..] diff --git a/tests/KAT_Scrypt.hs b/tests/KAT_Scrypt.hs index eee5a76..4d5e5bd 100644 --- a/tests/KAT_Scrypt.hs +++ b/tests/KAT_Scrypt.hs @@ -28,6 +28,6 @@ vectors = ] tests = testGroup "Scrypt" - $ map toCase $ zip [(1::Int)..] vectors - where toCase (i, ((pass,salt,n,r,p,dklen), output)) = + $ zipWith toCase [(1::Int)..] vectors + where toCase i ((pass,salt,n,r,p,dklen), output) = testCase (show i) (output @=? Scrypt.generate (Scrypt.Parameters n r p dklen) pass salt) diff --git a/tests/Number.hs b/tests/Number.hs index 7aa6acf..85b5a3d 100644 --- a/tests/Number.hs +++ b/tests/Number.hs @@ -79,9 +79,9 @@ tests = testGroup "number" getQAInteger qaInt == BE.os2ip (B.reverse (LE.i2osp (getQAInteger qaInt) :: Bytes)) , testProperty "le-rev-be-40" $ \qaInt -> getQAInteger qaInt == BE.os2ip (B.reverse (LE.i2ospOf_ 40 (getQAInteger qaInt) :: Bytes)) - , testGroup "marshalling-kat-to-bytearray" $ map toSerializationKat $ zip [katZero..] serializationVectors - , testGroup "marshalling-kat-to-integer" $ map toSerializationKatInteger $ zip [katZero..] serializationVectors + , testGroup "marshalling-kat-to-bytearray" $ zipWith toSerializationKat [katZero..] serializationVectors + , testGroup "marshalling-kat-to-integer" $ zipWith toSerializationKatInteger [katZero..] serializationVectors ] where - toSerializationKat (i, (sz, n, ba)) = testCase (show i) (ba @=? BE.i2ospOf_ sz n) - toSerializationKatInteger (i, (_, n, ba)) = testCase (show i) (n @=? BE.os2ip ba) + toSerializationKat i (sz, n, ba) = testCase (show i) (ba @=? BE.i2ospOf_ sz n) + toSerializationKatInteger i (_, n, ba) = testCase (show i) (n @=? BE.os2ip ba) diff --git a/tests/Padding.hs b/tests/Padding.hs index cc4dcf6..53bb29c 100644 --- a/tests/Padding.hs +++ b/tests/Padding.hs @@ -33,6 +33,6 @@ testZeroPad n (inp, sz, padded, unpadded) = ] tests = testGroup "Padding" - [ testGroup "Cases" $ map (uncurry testPad) (zip [1..] cases) - , testGroup "ZeroCases" $ map (uncurry testZeroPad) (zip [1..] zeroCases) + [ testGroup "Cases" $ zipWith testPad [1..] cases + , testGroup "ZeroCases" $ zipWith testZeroPad [1..] zeroCases ] diff --git a/tests/Salsa.hs b/tests/Salsa.hs index 1ecda19..7fceb86 100644 --- a/tests/Salsa.hs +++ b/tests/Salsa.hs @@ -37,7 +37,7 @@ instance Arbitrary RandomVector where tests = testGroup "Salsa" [ testGroup "KAT" $ - map (\(i,f) -> testCase (show (i :: Int)) f) $ zip [1..] $ map (\(r, k,i,e) -> salsaRunSimple e r k i) vectors + zipWith (\i (r,k,n,e) -> testCase (show (i :: Int)) $ salsaRunSimple e r k n) [1..] vectors , testProperty "generate-combine" salsaGenerateCombine , testProperty "chunking-generate" salsaGenerateChunks , testProperty "chunking-combine" salsaCombineChunks diff --git a/tests/XSalsa.hs b/tests/XSalsa.hs index 0bc4d5c..87eec2a 100644 --- a/tests/XSalsa.hs +++ b/tests/XSalsa.hs @@ -110,9 +110,9 @@ vectorsCB = tests = testGroup "XSalsa" [ testGroup "KAT" $ - map (\(i,f) -> testCase (show (i :: Int)) f) $ zip [1..] $ map (\(r, k, i, p, e) -> salsaRunSimple r k i p e) vectors + zipWith (\i (r, k, n, p, e) -> testCase (show (i :: Int)) $ salsaRunSimple r k n p e) [1..] vectors , testGroup "crypto_box encryption" $ - map (\(i,f) -> testCase (show (i :: Int)) f) $ zip [1..] $ map (\(r, k, i, p, e) -> cryptoBoxEnc r k i p e) vectorsCB + zipWith (\i (r, k, n, p, e) -> testCase (show (i :: Int)) $ cryptoBoxEnc r k n p e) [1..] vectorsCB ] where salsaRunSimple rounds key nonce plain expected =