crypton 1.0.1 → 1.0.2
raw patch · 200 files changed
+20248/−11758 lines, 200 filesdep ~basesetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Crypto.Cipher.ChaChaPoly1305: aeadChacha20poly1305Init :: (ByteArrayAccess k, ByteArrayAccess n) => k -> n -> CryptoFailable (AEAD ChaCha20Poly1305)
+ Crypto.Cipher.ChaChaPoly1305: type ChaCha20Poly1305 = State
+ Crypto.ECC: instance GHC.Base.Monoid Crypto.ECC.SharedSecret
+ Crypto.ECC: instance GHC.Base.Semigroup Crypto.ECC.SharedSecret
+ Crypto.ECC: scalarToPoint :: EllipticCurve curve => proxy curve -> Scalar curve -> Point curve
+ Crypto.KDF.HKDF: toPRK :: (HashAlgorithm a, ByteArrayAccess ba) => ba -> Maybe (PRK a)
+ Crypto.Number.F2m: quadraticF2m :: BinaryPolynomial -> Integer -> Maybe Integer
+ Crypto.Number.Generate: generatePrefix :: MonadRandom m => Int -> m Integer
+ Crypto.PubKey.ECC.ECDSA: ExtendedSignature :: Integer -> Bool -> Signature -> ExtendedSignature
+ Crypto.PubKey.ECC.ECDSA: [index] :: ExtendedSignature -> Integer
+ Crypto.PubKey.ECC.ECDSA: [parity] :: ExtendedSignature -> Bool
+ Crypto.PubKey.ECC.ECDSA: [signature] :: ExtendedSignature -> Signature
+ Crypto.PubKey.ECC.ECDSA: data ExtendedSignature
+ Crypto.PubKey.ECC.ECDSA: deterministicNonce :: (HashAlgorithm hashDRG, HashAlgorithm hashDigest) => hashDRG -> PrivateKey -> Digest hashDigest -> (Integer -> Maybe a) -> a
+ Crypto.PubKey.ECC.ECDSA: instance Data.Data.Data Crypto.PubKey.ECC.ECDSA.ExtendedSignature
+ Crypto.PubKey.ECC.ECDSA: instance GHC.Classes.Eq Crypto.PubKey.ECC.ECDSA.ExtendedSignature
+ Crypto.PubKey.ECC.ECDSA: instance GHC.Read.Read Crypto.PubKey.ECC.ECDSA.ExtendedSignature
+ Crypto.PubKey.ECC.ECDSA: instance GHC.Show.Show Crypto.PubKey.ECC.ECDSA.ExtendedSignature
+ Crypto.PubKey.ECC.ECDSA: recover :: (ByteArrayAccess msg, HashAlgorithm hash) => hash -> Curve -> ExtendedSignature -> msg -> Maybe PublicKey
+ Crypto.PubKey.ECC.ECDSA: recoverDigest :: HashAlgorithm hash => Curve -> ExtendedSignature -> Digest hash -> Maybe PublicKey
+ Crypto.PubKey.ECC.ECDSA: signExtendedDigest :: (HashAlgorithm hash, MonadRandom m) => PrivateKey -> Digest hash -> m ExtendedSignature
+ Crypto.PubKey.ECC.ECDSA: signExtendedDigestWith :: HashAlgorithm hash => Integer -> PrivateKey -> Digest hash -> Maybe ExtendedSignature
+ Crypto.PubKey.ECC.Prim: pointCompose :: Curve -> Integer -> Integer -> Bool -> Maybe Point
+ Crypto.PubKey.ECC.Prim: pointDecompose :: Curve -> Point -> Maybe (Integer, Integer, Bool)
- Crypto.ECC: decodeScalar :: (EllipticCurveBasepointArith curve, ByteArray bs) => proxy curve -> bs -> CryptoFailable (Scalar curve)
+ Crypto.ECC: decodeScalar :: (EllipticCurve curve, ByteArray bs) => proxy curve -> bs -> CryptoFailable (Scalar curve)
- Crypto.ECC: encodeScalar :: (EllipticCurveBasepointArith curve, ByteArray bs) => proxy curve -> Scalar curve -> bs
+ Crypto.ECC: encodeScalar :: (EllipticCurve curve, ByteArray bs) => proxy curve -> Scalar curve -> bs
Files
- CHANGELOG.md +13/−0
- Crypto/Cipher/AES.hs +17/−17
- Crypto/Cipher/AES/Primitive.hs +349/−237
- Crypto/Cipher/AESGCMSIV.hs +48/−42
- Crypto/Cipher/Blowfish.hs +14/−14
- Crypto/Cipher/Blowfish/Box.hs +282/−275
- Crypto/Cipher/Blowfish/Primitive.hs +150/−124
- Crypto/Cipher/CAST5.hs +12/−13
- Crypto/Cipher/CAST5/Primitive.hs +81/−64
- Crypto/Cipher/Camellia.hs +5/−6
- Crypto/Cipher/Camellia/Primitive.hs +177/−149
- Crypto/Cipher/ChaCha.hs +103/−71
- Crypto/Cipher/ChaChaPoly1305.hs +121/−82
- Crypto/Cipher/DES.hs +15/−15
- Crypto/Cipher/DES/Primitive.hs +450/−103
- Crypto/Cipher/RC4.hs +58/−37
- Crypto/Cipher/Salsa.hs +59/−40
- Crypto/Cipher/TripleDES.hs +32/−28
- Crypto/Cipher/Twofish.hs +17/−14
- Crypto/Cipher/Twofish/Primitive.hs +398/−185
- Crypto/Cipher/Types.hs +23/−21
- Crypto/Cipher/Types/AEAD.hs +45/−32
- Crypto/Cipher/Types/Base.hs +34/−28
- Crypto/Cipher/Types/Block.hs +148/−108
- Crypto/Cipher/Types/GF.hs +23/−22
- Crypto/Cipher/Types/Stream.hs +3/−4
- Crypto/Cipher/Types/Utils.hs +7/−6
- Crypto/Cipher/Utils.hs +16/−13
- Crypto/Cipher/XSalsa.hs +48/−34
- Crypto/ConstructHash/MiyaguchiPreneel.hs +38/−30
- Crypto/Data/AFIS.hs +107/−86
- Crypto/Data/Padding.hs +33/−31
- Crypto/ECC.hs +165/−104
- Crypto/ECC/Edwards25519.hs +133/−113
- Crypto/ECC/Simple/Prim.hs +68/−60
- Crypto/ECC/Simple/Types.hs +559/−382
- Crypto/Error.hs +3/−4
- Crypto/Error/Types.hs +34/−35
- Crypto/Hash.hs +89/−67
- Crypto/Hash/Algorithms.hs +72/−70
- Crypto/Hash/Blake2.hs +124/−83
- Crypto/Hash/Blake2b.hs +56/−54
- Crypto/Hash/Blake2bp.hs +20/−22
- Crypto/Hash/Blake2s.hs +38/−38
- Crypto/Hash/Blake2sp.hs +29/−30
- Crypto/Hash/IO.hs +32/−23
- Crypto/Hash/Keccak.hs +47/−46
- Crypto/Hash/MD2.hs +19/−19
- Crypto/Hash/MD4.hs +19/−19
- Crypto/Hash/MD5.hs +21/−20
- Crypto/Hash/RIPEMD160.hs +19/−19
- Crypto/Hash/SHA1.hs +21/−20
- Crypto/Hash/SHA224.hs +21/−20
- Crypto/Hash/SHA256.hs +21/−20
- Crypto/Hash/SHA3.hs +47/−46
- Crypto/Hash/SHA384.hs +21/−20
- Crypto/Hash/SHA512.hs +21/−20
- Crypto/Hash/SHA512t.hs +29/−30
- Crypto/Hash/SHAKE.hs +50/−45
- Crypto/Hash/Skein256.hs +29/−30
- Crypto/Hash/Skein512.hs +47/−46
- Crypto/Hash/Tiger.hs +19/−19
- Crypto/Hash/Types.hs +56/−45
- Crypto/Hash/Whirlpool.hs +19/−19
- Crypto/Internal/Builder.hs +18/−17
- Crypto/Internal/ByteArray.hs +12/−12
- Crypto/Internal/Compat.hs +9/−9
- Crypto/Internal/CompatPrim.hs +18/−14
- Crypto/Internal/DeepSeq.hs +5/−5
- Crypto/Internal/Imports.hs +9/−9
- Crypto/Internal/WordArray.hs +46/−46
- Crypto/Internal/Words.hs +6/−7
- Crypto/KDF/Argon2.hs +85/−72
- Crypto/KDF/BCrypt.hs +112/−65
- Crypto/KDF/BCryptPBKDF.hs +133/−123
- Crypto/KDF/HKDF.hs +60/−39
- Crypto/KDF/PBKDF2.hs +133/−102
- Crypto/KDF/Scrypt.hs +49/−33
- Crypto/MAC/CMAC.hs +83/−56
- Crypto/MAC/HMAC.hs +95/−73
- Crypto/MAC/KMAC.hs +56/−44
- Crypto/MAC/KeyedBlake2.hs +39/−35
- Crypto/MAC/Poly1305.hs +48/−38
- Crypto/Number/Basic.hs +86/−65
- Crypto/Number/Compat.hs +29/−27
- Crypto/Number/F2m.hs +142/−81
- Crypto/Number/Generate.hs +102/−68
- Crypto/Number/ModArithmetic.hs +90/−70
- Crypto/Number/Nat.hs +24/−20
- Crypto/Number/Prime.hs +506/−117
- Crypto/Number/Serialize.hs +19/−17
- Crypto/Number/Serialize/Internal.hs +27/−26
- Crypto/Number/Serialize/Internal/LE.hs +27/−25
- Crypto/Number/Serialize/LE.hs +19/−17
- Crypto/OTP.hs +43/−39
- Crypto/PubKey/Curve25519.hs +71/−54
- Crypto/PubKey/Curve448.hs +64/−46
- Crypto/PubKey/DH.hs +28/−23
- Crypto/PubKey/DSA.hs +90/−62
- Crypto/PubKey/ECC/DH.hs +24/−16
- Crypto/PubKey/ECC/ECDSA.hs +163/−63
- Crypto/PubKey/ECC/Generate.hs +15/−11
- Crypto/PubKey/ECC/P256.hs +122/−91
- Crypto/PubKey/ECC/Prim.hs +95/−57
- Crypto/PubKey/ECC/Types.hs +536/−335
- Crypto/PubKey/ECDSA.hs +155/−112
- Crypto/PubKey/ECIES.hs +23/−17
- Crypto/PubKey/Ed25519.hs +76/−64
- Crypto/PubKey/Ed448.hs +82/−70
- Crypto/PubKey/EdDSA.hs +276/−199
- Crypto/PubKey/ElGamal.hs +99/−73
- Crypto/PubKey/Internal.hs +14/−13
- Crypto/PubKey/MaskGenFunction.hs +25/−20
- Crypto/PubKey/RSA.hs +58/−44
- Crypto/PubKey/RSA/OAEP.hs +132/−100
- Crypto/PubKey/RSA/PKCS15.hs +313/−86
- Crypto/PubKey/RSA/PSS.hs +182/−133
- Crypto/PubKey/RSA/Prim.hs +26/−23
- Crypto/PubKey/RSA/Types.hs +64/−41
- Crypto/PubKey/Rabin/Basic.hs +183/−126
- Crypto/PubKey/Rabin/Modified.hs +84/−59
- Crypto/PubKey/Rabin/OAEP.hs +88/−71
- Crypto/PubKey/Rabin/RW.hs +131/−95
- Crypto/PubKey/Rabin/Types.hs +34/−25
- Crypto/Random.hs +33/−28
- Crypto/Random/ChaChaDRG.hs +27/−17
- Crypto/Random/Entropy.hs +6/−7
- Crypto/Random/Entropy/RDRand.hs +15/−14
- Crypto/Random/Entropy/Source.hs +5/−4
- Crypto/Random/Entropy/Unix.hs +30/−27
- Crypto/Random/Entropy/Unsafe.hs +15/−14
- Crypto/Random/EntropyPool.hs +26/−26
- Crypto/Random/HmacDRG.hs +51/−0
- Crypto/Random/Probabilistic.hs +7/−8
- Crypto/Random/SystemDRG.hs +29/−28
- Crypto/Random/Types.hs +9/−11
- Crypto/System/CPU.hs +19/−16
- Crypto/Tutorial.hs +10/−10
- Setup.hs +1/−0
- benchs/Bench.hs +224/−170
- benchs/Number/F2m.hs +10/−10
- crypton.cabal +5/−9
- tests/BCrypt.hs +67/−38
- tests/BCryptPBKDF.hs +192/−55
- tests/BlockCipher.hs +330/−228
- tests/ChaCha.hs +77/−68
- tests/ChaChaPoly1305.hs +113/−69
- tests/ECC.hs +173/−117
- tests/ECC/Edwards25519.hs +160/−112
- tests/ECDSA.hs +104/−33
- tests/Hash.hs +434/−218
- tests/Imports.hs +10/−8
- tests/KAT_AES.hs +102/−71
- tests/KAT_AES/KATCBC.hs +434/−81
- tests/KAT_AES/KATCCM.hs +196/−146
- tests/KAT_AES/KATECB.hs +696/−124
- tests/KAT_AES/KATGCM.hs +84/−58
- tests/KAT_AES/KATOCB3.hs +56/−33
- tests/KAT_AES/KATXTS.hs +14/−5
- tests/KAT_AESGCMSIV.hs +486/−307
- tests/KAT_AFIS.hs +32/−21
- tests/KAT_Argon2.hs +30/−20
- tests/KAT_Blake2.hs +96/−59
- tests/KAT_Blowfish.hs +141/−37
- tests/KAT_CAST5.hs +16/−5
- tests/KAT_CMAC.hs +114/−107
- tests/KAT_Camellia.hs +226/−13
- tests/KAT_Curve25519.hs +39/−14
- tests/KAT_Curve448.hs +39/−14
- tests/KAT_DES.hs +144/−39
- tests/KAT_Ed25519.hs +56/−37
- tests/KAT_Ed448.hs +76/−47
- tests/KAT_EdDSA.hs +81/−48
- tests/KAT_HKDF.hs +359/−23
- tests/KAT_HMAC.hs +95/−44
- tests/KAT_KMAC.hs +73/−46
- tests/KAT_MiyaguchiPreneel.hs +31/−25
- tests/KAT_OTP.hs +58/−29
- tests/KAT_PBKDF2.hs +66/−41
- tests/KAT_PubKey.hs +29/−22
- tests/KAT_PubKey/DSA.hs +163/−91
- tests/KAT_PubKey/ECC.hs +154/−131
- tests/KAT_PubKey/ECDSA.hs +1636/−521
- tests/KAT_PubKey/OAEP.hs +107/−62
- tests/KAT_PubKey/P256.hs +139/−126
- tests/KAT_PubKey/PSS.hs +384/−241
- tests/KAT_PubKey/RSA.hs +93/−65
- tests/KAT_PubKey/Rabin.hs +172/−75
- tests/KAT_RC4.hs +25/−17
- tests/KAT_Scrypt.hs +17/−9
- tests/KAT_TripleDES.hs +5/−3
- tests/KAT_Twofish.hs +374/−31
- tests/Number.hs +100/−70
- tests/Number/F2m.hs +115/−99
- tests/Padding.hs +20/−12
- tests/Poly1305.hs +29/−17
- tests/Salsa.hs +110/−76
- tests/Tests.hs +78/−67
- tests/Utils.hs +69/−60
- tests/XSalsa.hs +150/−105
CHANGELOG.md view
@@ -1,3 +1,16 @@+## 1.0.2++* Deterministic Nonce Generation for ECDSA+ [#46](https://github.com/kazu-yamamoto/crypton/pull/46)+* ECDSA Signature Normalization.+ [#45](https://github.com/kazu-yamamoto/crypton/pull/45)+* Add Full Test Suite from RFC 6979.+ [#44](https://github.com/kazu-yamamoto/crypton/pull/44)+* ECDSA with Public Key Recovery.+ [#43](https://github.com/kazu-yamamoto/crypton/pull/43)+* Providing necessary features for HPKE.+ [#42](https://github.com/kazu-yamamoto/crypton/pull/42)+ ## 1.0.1 * Update decaf library.
Crypto/Cipher/AES.hs view
@@ -1,22 +1,23 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.Cipher.AES -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : stable -- Portability : good-{-# LANGUAGE CPP #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.Cipher.AES- ( AES128- , AES192- , AES256- ) where+module Crypto.Cipher.AES (+ AES128,+ AES192,+ AES256,+) where -import Crypto.Error+import Crypto.Cipher.AES.Primitive import Crypto.Cipher.Types-import Crypto.Cipher.Utils import Crypto.Cipher.Types.Block-import Crypto.Cipher.AES.Primitive+import Crypto.Cipher.Utils+import Crypto.Error import Crypto.Internal.Imports -- | AES with 128 bit key@@ -32,20 +33,19 @@ deriving (NFData) instance Cipher AES128 where- cipherName _ = "AES128"+ cipherName _ = "AES128" cipherKeySize _ = KeySizeFixed 16- cipherInit k = AES128 <$> (initAES =<< validateKeySize (undefined :: AES128) k)+ cipherInit k = AES128 <$> (initAES =<< validateKeySize (undefined :: AES128) k) instance Cipher AES192 where- cipherName _ = "AES192"+ cipherName _ = "AES192" cipherKeySize _ = KeySizeFixed 24- cipherInit k = AES192 <$> (initAES =<< validateKeySize (undefined :: AES192) k)+ cipherInit k = AES192 <$> (initAES =<< validateKeySize (undefined :: AES192) k) instance Cipher AES256 where- cipherName _ = "AES256"+ cipherName _ = "AES256" cipherKeySize _ = KeySizeFixed 32- cipherInit k = AES256 <$> (initAES =<< validateKeySize (undefined :: AES256) k)-+ cipherInit k = AES256 <$> (initAES =<< validateKeySize (undefined :: AES256) k) #define INSTANCE_BLOCKCIPHER(CSTR) \ instance BlockCipher CSTR where \
Crypto/Cipher/AES/Primitive.hs view
@@ -1,75 +1,79 @@-{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE ViewPatterns #-}+ -- | -- Module : Crypto.Cipher.AES.Primitive -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : stable -- Portability : good----module Crypto.Cipher.AES.Primitive- (+module Crypto.Cipher.AES.Primitive ( -- * Block cipher data types- AES+ AES, -- * Authenticated encryption block cipher types- , AESGCM- , AESOCB+ AESGCM,+ AESOCB, -- * Creation- , initAES+ initAES, -- * Miscellanea- , genCTR- , genCounter+ genCTR,+ genCounter, -- * Encryption- , encryptECB- , encryptCBC- , encryptCTR- , encryptXTS+ encryptECB,+ encryptCBC,+ encryptCTR,+ encryptXTS, -- * Decryption- , decryptECB- , decryptCBC- , decryptCTR- , decryptXTS+ decryptECB,+ decryptCBC,+ decryptCTR,+ decryptXTS, -- * CTR with 32-bit wrapping- , combineC32+ combineC32, -- * Incremental GCM- , gcmMode- , gcmInit+ gcmMode,+ gcmInit, -- * Incremental OCB- , ocbMode- , ocbInit+ ocbMode,+ ocbInit, -- * CCM- , ccmMode- , ccmInit- ) where+ ccmMode,+ ccmInit,+) where -import Data.Word-import Foreign.Ptr-import Foreign.C.Types-import Foreign.C.String+import Data.Word+import Foreign.C.String+import Foreign.C.Types+import Foreign.Ptr -import Crypto.Error-import Crypto.Cipher.Types-import Crypto.Cipher.Types.Block (IV(..))-import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess, ScrubbedBytes, withByteArray)+import Crypto.Cipher.Types+import Crypto.Cipher.Types.Block (IV (..))+import Crypto.Error+import Crypto.Internal.ByteArray (+ ByteArray,+ ByteArrayAccess,+ ScrubbedBytes,+ withByteArray,+ ) import qualified Crypto.Internal.ByteArray as B+import Crypto.Internal.Compat+import Crypto.Internal.Imports instance Cipher AES where- cipherName _ = "AES"- cipherKeySize _ = KeySizeEnum [16,24,32]- cipherInit k = initAES k+ cipherName _ = "AES"+ cipherKeySize _ = KeySizeEnum [16, 24, 32]+ cipherInit k = initAES k instance BlockCipher AES where blockSize _ = 16@@ -81,38 +85,40 @@ aeadInit AEAD_GCM aes iv = CryptoPassed $ AEAD (gcmMode aes) (gcmInit aes iv) aeadInit AEAD_OCB aes iv = CryptoPassed $ AEAD (ocbMode aes) (ocbInit aes iv) aeadInit (AEAD_CCM n m l) aes iv = AEAD (ccmMode aes) <$> ccmInit aes iv n m l- aeadInit _ _ _ = CryptoFailed CryptoError_AEADModeNotSupported+ aeadInit _ _ _ = CryptoFailed CryptoError_AEADModeNotSupported instance BlockCipher128 AES where xtsEncrypt = encryptXTS xtsDecrypt = decryptXTS -- | Create an AES AEAD implementation for GCM gcmMode :: AES -> AEADModeImpl AESGCM-gcmMode aes = AEADModeImpl- { aeadImplAppendHeader = gcmAppendAAD- , aeadImplEncrypt = gcmAppendEncrypt aes- , aeadImplDecrypt = gcmAppendDecrypt aes- , aeadImplFinalize = gcmFinish aes- }+gcmMode aes =+ AEADModeImpl+ { aeadImplAppendHeader = gcmAppendAAD+ , aeadImplEncrypt = gcmAppendEncrypt aes+ , aeadImplDecrypt = gcmAppendDecrypt aes+ , aeadImplFinalize = gcmFinish aes+ } -- | Create an AES AEAD implementation for OCB ocbMode :: AES -> AEADModeImpl AESOCB-ocbMode aes = AEADModeImpl- { aeadImplAppendHeader = ocbAppendAAD aes- , aeadImplEncrypt = ocbAppendEncrypt aes- , aeadImplDecrypt = ocbAppendDecrypt aes- , aeadImplFinalize = ocbFinish aes- }+ocbMode aes =+ AEADModeImpl+ { aeadImplAppendHeader = ocbAppendAAD aes+ , aeadImplEncrypt = ocbAppendEncrypt aes+ , aeadImplDecrypt = ocbAppendDecrypt aes+ , aeadImplFinalize = ocbFinish aes+ } -- | Create an AES AEAD implementation for CCM ccmMode :: AES -> AEADModeImpl AESCCM-ccmMode aes = AEADModeImpl- { aeadImplAppendHeader = ccmAppendAAD aes- , aeadImplEncrypt = ccmEncrypt aes- , aeadImplDecrypt = ccmDecrypt aes- , aeadImplFinalize = ccmFinish aes- }-+ccmMode aes =+ AEADModeImpl+ { aeadImplAppendHeader = ccmAppendAAD aes+ , aeadImplEncrypt = ccmEncrypt aes+ , aeadImplDecrypt = ccmDecrypt aes+ , aeadImplFinalize = ccmFinish aes+ } -- | AES Context (pre-processed key) newtype AES = AES ScrubbedBytes@@ -145,42 +151,47 @@ ivToPtr :: ByteArrayAccess iv => iv -> (Ptr Word8 -> IO a) -> IO a ivToPtr iv f = withByteArray iv (f . castPtr) - ivCopyPtr :: IV AES -> (Ptr Word8 -> IO a) -> IO (a, IV AES)-ivCopyPtr (IV iv) f = (\(x,y) -> (x, IV y)) `fmap` copyAndModify iv f+ivCopyPtr (IV iv) f = (\(x, y) -> (x, IV y)) `fmap` copyAndModify iv f where copyAndModify :: ByteArray ba => ba -> (Ptr Word8 -> IO a) -> IO (a, ba) copyAndModify ba f' = B.copyRet ba f' -withKeyAndIV :: ByteArrayAccess iv => AES -> iv -> (Ptr AES -> Ptr Word8 -> IO a) -> IO a+withKeyAndIV+ :: ByteArrayAccess iv => AES -> iv -> (Ptr AES -> Ptr Word8 -> IO a) -> IO a withKeyAndIV ctx iv f = keyToPtr ctx $ \kptr -> ivToPtr iv $ \ivp -> f kptr ivp -withKey2AndIV :: ByteArrayAccess iv => AES -> AES -> iv -> (Ptr AES -> Ptr AES -> Ptr Word8 -> IO a) -> IO a+withKey2AndIV+ :: ByteArrayAccess iv+ => AES -> AES -> iv -> (Ptr AES -> Ptr AES -> Ptr Word8 -> IO a) -> IO a withKey2AndIV key1 key2 iv f = keyToPtr key1 $ \kptr1 -> keyToPtr key2 $ \kptr2 -> ivToPtr iv $ \ivp -> f kptr1 kptr2 ivp -withGCMKeyAndCopySt :: AES -> AESGCM -> (Ptr AESGCM -> Ptr AES -> IO a) -> IO (a, AESGCM)+withGCMKeyAndCopySt+ :: AES -> AESGCM -> (Ptr AESGCM -> Ptr AES -> IO a) -> IO (a, AESGCM) withGCMKeyAndCopySt aes (AESGCM gcmSt) f = keyToPtr aes $ \aesPtr -> do newSt <- B.copy gcmSt (\_ -> return ())- a <- withByteArray newSt $ \gcmStPtr -> f (castPtr gcmStPtr) aesPtr+ a <- withByteArray newSt $ \gcmStPtr -> f (castPtr gcmStPtr) aesPtr return (a, AESGCM newSt) withNewGCMSt :: AESGCM -> (Ptr AESGCM -> IO ()) -> IO AESGCM withNewGCMSt (AESGCM gcmSt) f = B.copy gcmSt (f . castPtr) >>= \sm2 -> return (AESGCM sm2) -withOCBKeyAndCopySt :: AES -> AESOCB -> (Ptr AESOCB -> Ptr AES -> IO a) -> IO (a, AESOCB)+withOCBKeyAndCopySt+ :: AES -> AESOCB -> (Ptr AESOCB -> Ptr AES -> IO a) -> IO (a, AESOCB) withOCBKeyAndCopySt aes (AESOCB gcmSt) f = keyToPtr aes $ \aesPtr -> do newSt <- B.copy gcmSt (\_ -> return ())- a <- withByteArray newSt $ \gcmStPtr -> f (castPtr gcmStPtr) aesPtr+ a <- withByteArray newSt $ \gcmStPtr -> f (castPtr gcmStPtr) aesPtr return (a, AESOCB newSt) -withCCMKeyAndCopySt :: AES -> AESCCM -> (Ptr AESCCM -> Ptr AES -> IO a) -> IO (a, AESCCM)+withCCMKeyAndCopySt+ :: AES -> AESCCM -> (Ptr AESCCM -> Ptr AES -> IO a) -> IO (a, AESCCM) withCCMKeyAndCopySt aes (AESCCM ccmSt) f = keyToPtr aes $ \aesPtr -> do newSt <- B.copy ccmSt (\_ -> return ())- a <- withByteArray newSt $ \ccmStPtr -> f (castPtr ccmStPtr) aesPtr+ a <- withByteArray newSt $ \ccmStPtr -> f (castPtr ccmStPtr) aesPtr return (a, AESCCM newSt) -- | Initialize a new context with a key@@ -192,10 +203,11 @@ | len == 24 = CryptoPassed $ initWithRounds 12 | len == 32 = CryptoPassed $ initWithRounds 14 | otherwise = CryptoFailed CryptoError_KeySizeInvalid- where len = B.length k- initWithRounds nbR = AES $ B.allocAndFreeze (16+2*2*16*nbR) aesInit- aesInit ptr = withByteArray k $ \ikey ->- c_aes_init (castPtr ptr) (castPtr ikey) (fromIntegral len)+ where+ len = B.length k+ initWithRounds nbR = AES $ B.allocAndFreeze (16 + 2 * 2 * 16 * nbR) aesInit+ aesInit ptr = withByteArray k $ \ikey ->+ c_aes_init (castPtr ptr) (castPtr ikey) (fromIntegral len) -- | encrypt using Electronic Code Book (ECB) {-# NOINLINE encryptECB #-}@@ -204,11 +216,16 @@ -- | encrypt using Cipher Block Chaining (CBC) {-# NOINLINE encryptCBC #-}-encryptCBC :: ByteArray ba- => AES -- ^ AES Context- -> IV AES -- ^ Initial vector of AES block size- -> ba -- ^ plaintext- -> ba -- ^ ciphertext+encryptCBC+ :: ByteArray ba+ => AES+ -- ^ AES Context+ -> IV AES+ -- ^ Initial vector of AES block size+ -> ba+ -- ^ plaintext+ -> ba+ -- ^ ciphertext encryptCBC = doCBC c_aes_encrypt_cbc -- | generate a counter mode pad. this is generally xor-ed to an input@@ -218,17 +235,22 @@ -- more data will be returned, so that the returned bytearray is -- a multiple of the block cipher size. {-# NOINLINE genCTR #-}-genCTR :: ByteArray ba- => AES -- ^ Cipher Key.- -> IV AES -- ^ usually a 128 bit integer.- -> Int -- ^ length of bytes required.- -> ba+genCTR+ :: ByteArray ba+ => AES+ -- ^ Cipher Key.+ -> IV AES+ -- ^ usually a 128 bit integer.+ -> Int+ -- ^ length of bytes required.+ -> ba genCTR ctx (IV iv) len- | len <= 0 = B.empty+ | len <= 0 = B.empty | otherwise = B.allocAndFreeze (nbBlocks * 16) generate- where generate o = withKeyAndIV ctx iv $ \k i -> c_aes_gen_ctr (castPtr o) k i (fromIntegral nbBlocks)- (nbBlocks',r) = len `quotRem` 16- nbBlocks = if r == 0 then nbBlocks' else nbBlocks' + 1+ where+ generate o = withKeyAndIV ctx iv $ \k i -> c_aes_gen_ctr (castPtr o) k i (fromIntegral nbBlocks)+ (nbBlocks', r) = len `quotRem` 16+ nbBlocks = if r == 0 then nbBlocks' else nbBlocks' + 1 -- | generate a counter mode pad. this is generally xor-ed to an input -- to make the standard counter mode block operations.@@ -239,22 +261,23 @@ -- -- Similiar to 'genCTR' but also return the next IV for continuation {-# NOINLINE genCounter #-}-genCounter :: ByteArray ba- => AES- -> IV AES- -> Int- -> (ba, IV AES)+genCounter+ :: ByteArray ba+ => AES+ -> IV AES+ -> Int+ -> (ba, IV AES) genCounter ctx iv len- | len <= 0 = (B.empty, iv)+ | len <= 0 = (B.empty, iv) | otherwise = unsafeDoIO $ keyToPtr ctx $ \k ->- ivCopyPtr iv $ \i ->- B.alloc outputLength $ \o -> do- c_aes_gen_ctr_cont (castPtr o) k i (fromIntegral nbBlocks)+ ivCopyPtr iv $ \i ->+ B.alloc outputLength $ \o -> do+ c_aes_gen_ctr_cont (castPtr o) k i (fromIntegral nbBlocks) where- (nbBlocks',r) = len `quotRem` 16- nbBlocks = if r == 0 then nbBlocks' else nbBlocks' + 1- outputLength = nbBlocks * 16+ (nbBlocks', r) = len `quotRem` 16+ nbBlocks = if r == 0 then nbBlocks' else nbBlocks' + 1+ outputLength = nbBlocks * 16 {- TODO: when genCTR has same AESIV requirements for IV, add the following rules: - RULES "snd . genCounter" forall ctx iv len . snd (genCounter ctx iv len) = genCTR ctx iv len@@ -264,30 +287,45 @@ -- -- in CTR mode encryption and decryption is the same operation. {-# NOINLINE encryptCTR #-}-encryptCTR :: ByteArray ba- => AES -- ^ AES Context- -> IV AES -- ^ initial vector of AES block size (usually representing a 128 bit integer)- -> ba -- ^ plaintext input- -> ba -- ^ ciphertext output+encryptCTR+ :: ByteArray ba+ => AES+ -- ^ AES Context+ -> IV AES+ -- ^ initial vector of AES block size (usually representing a 128 bit integer)+ -> ba+ -- ^ plaintext input+ -> ba+ -- ^ ciphertext output encryptCTR ctx iv input- | len <= 0 = B.empty- | B.length iv /= 16 = error $ "AES error: IV length must be block size (16). Its length is: " ++ (show $ B.length iv)+ | len <= 0 = B.empty+ | B.length iv /= 16 =+ error $+ "AES error: IV length must be block size (16). Its length is: "+ ++ (show $ B.length iv) | otherwise = B.allocAndFreeze len doEncrypt- where doEncrypt o = withKeyAndIV ctx iv $ \k v -> withByteArray input $ \i ->- c_aes_encrypt_ctr (castPtr o) k v i (fromIntegral len)- len = B.length input+ where+ doEncrypt o = withKeyAndIV ctx iv $ \k v -> withByteArray input $ \i ->+ c_aes_encrypt_ctr (castPtr o) k v i (fromIntegral len)+ len = B.length input -- | encrypt using XTS -- -- the first key is the normal block encryption key -- the second key is used for the initial block tweak {-# NOINLINE encryptXTS #-}-encryptXTS :: ByteArray ba- => (AES,AES) -- ^ AES cipher and tweak context- -> IV AES -- ^ a 128 bits IV, typically a sector or a block offset in XTS- -> Word32 -- ^ number of rounds to skip, also seen a 16 byte offset in the sector or block.- -> ba -- ^ input to encrypt- -> ba -- ^ output encrypted+encryptXTS+ :: ByteArray ba+ => (AES, AES)+ -- ^ AES cipher and tweak context+ -> IV AES+ -- ^ a 128 bits IV, typically a sector or a block offset in XTS+ -> Word32+ -- ^ number of rounds to skip, also seen a 16 byte offset in the sector or block.+ -> ba+ -- ^ input to encrypt+ -> ba+ -- ^ output encrypted encryptXTS = doXTS c_aes_encrypt_xts -- | decrypt using Electronic Code Book (ECB)@@ -303,82 +341,122 @@ -- | decrypt using Counter mode (CTR). -- -- in CTR mode encryption and decryption is the same operation.-decryptCTR :: ByteArray ba- => AES -- ^ AES Context- -> IV AES -- ^ initial vector, usually representing a 128 bit integer- -> ba -- ^ ciphertext input- -> ba -- ^ plaintext output+decryptCTR+ :: ByteArray ba+ => AES+ -- ^ AES Context+ -> IV AES+ -- ^ initial vector, usually representing a 128 bit integer+ -> ba+ -- ^ ciphertext input+ -> ba+ -- ^ plaintext output decryptCTR = encryptCTR -- | decrypt using XTS {-# NOINLINE decryptXTS #-}-decryptXTS :: ByteArray ba- => (AES,AES) -- ^ AES cipher and tweak context- -> IV AES -- ^ a 128 bits IV, typically a sector or a block offset in XTS- -> Word32 -- ^ number of rounds to skip, also seen a 16 byte offset in the sector or block.- -> ba -- ^ input to decrypt- -> ba -- ^ output decrypted+decryptXTS+ :: ByteArray ba+ => (AES, AES)+ -- ^ AES cipher and tweak context+ -> IV AES+ -- ^ a 128 bits IV, typically a sector or a block offset in XTS+ -> Word32+ -- ^ number of rounds to skip, also seen a 16 byte offset in the sector or block.+ -> ba+ -- ^ input to decrypt+ -> ba+ -- ^ output decrypted decryptXTS = doXTS c_aes_decrypt_xts -- | encrypt/decrypt using Counter mode (32-bit wrapping used in AES-GCM-SIV) {-# NOINLINE combineC32 #-}-combineC32 :: ByteArray ba- => AES -- ^ AES Context- -> IV AES -- ^ initial vector of AES block size (usually representing a 128 bit integer)- -> ba -- ^ plaintext input- -> ba -- ^ ciphertext output+combineC32+ :: ByteArray ba+ => AES+ -- ^ AES Context+ -> IV AES+ -- ^ initial vector of AES block size (usually representing a 128 bit integer)+ -> ba+ -- ^ plaintext input+ -> ba+ -- ^ ciphertext output combineC32 ctx iv input- | len <= 0 = B.empty- | B.length iv /= 16 = error $ "AES error: IV length must be block size (16). Its length is: " ++ show (B.length iv)+ | len <= 0 = B.empty+ | B.length iv /= 16 =+ error $+ "AES error: IV length must be block size (16). Its length is: "+ ++ show (B.length iv) | otherwise = B.allocAndFreeze len doEncrypt- where doEncrypt o = withKeyAndIV ctx iv $ \k v -> withByteArray input $ \i ->- c_aes_encrypt_c32 (castPtr o) k v i (fromIntegral len)- len = B.length input+ where+ doEncrypt o = withKeyAndIV ctx iv $ \k v -> withByteArray input $ \i ->+ c_aes_encrypt_c32 (castPtr o) k v i (fromIntegral len)+ len = B.length input {-# INLINE doECB #-}-doECB :: ByteArray ba- => (Ptr b -> Ptr AES -> CString -> CUInt -> IO ())- -> AES -> ba -> ba+doECB+ :: ByteArray ba+ => (Ptr b -> Ptr AES -> CString -> CUInt -> IO ())+ -> AES+ -> ba+ -> ba doECB f ctx input- | len == 0 = B.empty- | r /= 0 = error $ "Encryption error: input length must be a multiple of block size (16). Its length is: " ++ (show len)- | otherwise =+ | len == 0 = B.empty+ | r /= 0 =+ error $+ "Encryption error: input length must be a multiple of block size (16). Its length is: "+ ++ (show len)+ | otherwise = B.allocAndFreeze len $ \o ->- keyToPtr ctx $ \k ->- withByteArray input $ \i ->- f (castPtr o) k i (fromIntegral nbBlocks)- where (nbBlocks, r) = len `quotRem` 16- len = B.length input+ keyToPtr ctx $ \k ->+ withByteArray input $ \i ->+ f (castPtr o) k i (fromIntegral nbBlocks)+ where+ (nbBlocks, r) = len `quotRem` 16+ len = B.length input {-# INLINE doCBC #-}-doCBC :: ByteArray ba- => (Ptr b -> Ptr AES -> Ptr Word8 -> CString -> CUInt -> IO ())- -> AES -> IV AES -> ba -> ba+doCBC+ :: ByteArray ba+ => (Ptr b -> Ptr AES -> Ptr Word8 -> CString -> CUInt -> IO ())+ -> AES+ -> IV AES+ -> ba+ -> ba doCBC f ctx (IV iv) input- | len == 0 = B.empty- | r /= 0 = error $ "Encryption error: input length must be a multiple of block size (16). Its length is: " ++ (show len)+ | len == 0 = B.empty+ | r /= 0 =+ error $+ "Encryption error: input length must be a multiple of block size (16). Its length is: "+ ++ (show len) | otherwise = B.allocAndFreeze len $ \o ->- withKeyAndIV ctx iv $ \k v ->- withByteArray input $ \i ->- f (castPtr o) k v i (fromIntegral nbBlocks)- where (nbBlocks, r) = len `quotRem` 16- len = B.length input+ withKeyAndIV ctx iv $ \k v ->+ withByteArray input $ \i ->+ f (castPtr o) k v i (fromIntegral nbBlocks)+ where+ (nbBlocks, r) = len `quotRem` 16+ len = B.length input {-# INLINE doXTS #-}-doXTS :: ByteArray ba- => (Ptr b -> Ptr AES -> Ptr AES -> Ptr Word8 -> CUInt -> CString -> CUInt -> IO ())- -> (AES, AES)- -> IV AES- -> Word32- -> ba- -> ba-doXTS f (key1,key2) iv spoint input- | len == 0 = B.empty- | r /= 0 = error $ "Encryption error: input length must be a multiple of block size (16) for now. Its length is: " ++ (show len)+doXTS+ :: ByteArray ba+ => (Ptr b -> Ptr AES -> Ptr AES -> Ptr Word8 -> CUInt -> CString -> CUInt -> IO ())+ -> (AES, AES)+ -> IV AES+ -> Word32+ -> ba+ -> ba+doXTS f (key1, key2) iv spoint input+ | len == 0 = B.empty+ | r /= 0 =+ error $+ "Encryption error: input length must be a multiple of block size (16) for now. Its length is: "+ ++ (show len) | otherwise = B.allocAndFreeze len $ \o -> withKey2AndIV key1 key2 iv $ \k1 k2 v -> withByteArray input $ \i ->- f (castPtr o) k1 k2 v (fromIntegral spoint) i (fromIntegral nbBlocks)- where (nbBlocks, r) = len `quotRem` 16- len = B.length input+ f (castPtr o) k1 k2 v (fromIntegral spoint) i (fromIntegral nbBlocks)+ where+ (nbBlocks, r) = len `quotRem` 16+ len = B.length input ------------------------------------------------------------------------ -- GCM@@ -389,7 +467,7 @@ gcmInit :: ByteArrayAccess iv => AES -> iv -> AESGCM gcmInit ctx iv = unsafeDoIO $ do sm <- B.alloc sizeGCM $ \gcmStPtr ->- withKeyAndIV ctx iv $ \k v ->+ withKeyAndIV ctx iv $ \k v -> c_aes_gcm_init (castPtr gcmStPtr) k v (fromIntegral $ B.length iv) return $ AESGCM sm @@ -399,10 +477,11 @@ {-# NOINLINE gcmAppendAAD #-} gcmAppendAAD :: ByteArrayAccess aad => AESGCM -> aad -> AESGCM gcmAppendAAD gcmSt input = unsafeDoIO doAppend- where doAppend =- withNewGCMSt gcmSt $ \gcmStPtr ->+ where+ doAppend =+ withNewGCMSt gcmSt $ \gcmStPtr -> withByteArray input $ \i ->- c_aes_gcm_aad gcmStPtr i (fromIntegral $ B.length input)+ c_aes_gcm_aad gcmStPtr i (fromIntegral $ B.length input) -- | append data to encrypt and append to the GCM context --@@ -411,11 +490,12 @@ {-# NOINLINE gcmAppendEncrypt #-} gcmAppendEncrypt :: ByteArray ba => AES -> AESGCM -> ba -> (ba, AESGCM) gcmAppendEncrypt ctx gcm input = unsafeDoIO $ withGCMKeyAndCopySt ctx gcm doEnc- where len = B.length input- doEnc gcmStPtr aesPtr =- B.alloc len $ \o ->+ where+ len = B.length input+ doEnc gcmStPtr aesPtr =+ B.alloc len $ \o -> withByteArray input $ \i ->- c_aes_gcm_encrypt (castPtr o) gcmStPtr aesPtr i (fromIntegral len)+ c_aes_gcm_encrypt (castPtr o) gcmStPtr aesPtr i (fromIntegral len) -- | append data to decrypt and append to the GCM context --@@ -424,18 +504,20 @@ {-# NOINLINE gcmAppendDecrypt #-} gcmAppendDecrypt :: ByteArray ba => AES -> AESGCM -> ba -> (ba, AESGCM) gcmAppendDecrypt ctx gcm input = unsafeDoIO $ withGCMKeyAndCopySt ctx gcm doDec- where len = B.length input- doDec gcmStPtr aesPtr =- B.alloc len $ \o ->+ where+ len = B.length input+ doDec gcmStPtr aesPtr =+ B.alloc len $ \o -> withByteArray input $ \i ->- c_aes_gcm_decrypt (castPtr o) gcmStPtr aesPtr i (fromIntegral len)+ c_aes_gcm_decrypt (castPtr o) gcmStPtr aesPtr i (fromIntegral len) -- | Generate the Tag from GCM context {-# NOINLINE gcmFinish #-} gcmFinish :: AES -> AESGCM -> Int -> AuthTag gcmFinish ctx gcm taglen = AuthTag $ B.take taglen computeTag- where computeTag = B.allocAndFreeze 16 $ \t ->- withGCMKeyAndCopySt ctx gcm (c_aes_gcm_finish (castPtr t)) >> return ()+ where+ computeTag = B.allocAndFreeze 16 $ \t ->+ withGCMKeyAndCopySt ctx gcm (c_aes_gcm_finish (castPtr t)) >> return () ------------------------------------------------------------------------ -- OCB v3@@ -446,7 +528,7 @@ ocbInit :: ByteArrayAccess iv => AES -> iv -> AESOCB ocbInit ctx iv = unsafeDoIO $ do sm <- B.alloc sizeOCB $ \ocbStPtr ->- withKeyAndIV ctx iv $ \k v ->+ withKeyAndIV ctx iv $ \k v -> c_aes_ocb_init (castPtr ocbStPtr) k v (fromIntegral $ B.length iv) return $ AESOCB sm @@ -456,8 +538,9 @@ {-# NOINLINE ocbAppendAAD #-} ocbAppendAAD :: ByteArrayAccess aad => AES -> AESOCB -> aad -> AESOCB ocbAppendAAD ctx ocb input = unsafeDoIO (snd `fmap` withOCBKeyAndCopySt ctx ocb doAppend)- where doAppend ocbStPtr aesPtr =- withByteArray input $ \i ->+ where+ doAppend ocbStPtr aesPtr =+ withByteArray input $ \i -> c_aes_ocb_aad ocbStPtr aesPtr i (fromIntegral $ B.length input) -- | append data to encrypt and append to the OCB context@@ -467,11 +550,12 @@ {-# NOINLINE ocbAppendEncrypt #-} ocbAppendEncrypt :: ByteArray ba => AES -> AESOCB -> ba -> (ba, AESOCB) ocbAppendEncrypt ctx ocb input = unsafeDoIO $ withOCBKeyAndCopySt ctx ocb doEnc- where len = B.length input- doEnc ocbStPtr aesPtr =- B.alloc len $ \o ->+ where+ len = B.length input+ doEnc ocbStPtr aesPtr =+ B.alloc len $ \o -> withByteArray input $ \i ->- c_aes_ocb_encrypt (castPtr o) ocbStPtr aesPtr i (fromIntegral len)+ c_aes_ocb_encrypt (castPtr o) ocbStPtr aesPtr i (fromIntegral len) -- | append data to decrypt and append to the OCB context --@@ -480,45 +564,56 @@ {-# NOINLINE ocbAppendDecrypt #-} ocbAppendDecrypt :: ByteArray ba => AES -> AESOCB -> ba -> (ba, AESOCB) ocbAppendDecrypt ctx ocb input = unsafeDoIO $ withOCBKeyAndCopySt ctx ocb doDec- where len = B.length input- doDec ocbStPtr aesPtr =- B.alloc len $ \o ->+ where+ len = B.length input+ doDec ocbStPtr aesPtr =+ B.alloc len $ \o -> withByteArray input $ \i ->- c_aes_ocb_decrypt (castPtr o) ocbStPtr aesPtr i (fromIntegral len)+ c_aes_ocb_decrypt (castPtr o) ocbStPtr aesPtr i (fromIntegral len) -- | Generate the Tag from OCB context {-# NOINLINE ocbFinish #-} ocbFinish :: AES -> AESOCB -> Int -> AuthTag ocbFinish ctx ocb taglen = AuthTag $ B.take taglen computeTag- where computeTag = B.allocAndFreeze 16 $ \t ->- withOCBKeyAndCopySt ctx ocb (c_aes_ocb_finish (castPtr t)) >> return ()+ where+ computeTag = B.allocAndFreeze 16 $ \t ->+ withOCBKeyAndCopySt ctx ocb (c_aes_ocb_finish (castPtr t)) >> return () ccmGetM :: CCM_M -> Int ccmGetL :: CCM_L -> Int ccmGetM m = case m of- CCM_M4 -> 4- CCM_M6 -> 6- CCM_M8 -> 8- CCM_M10 -> 10- CCM_M12 -> 12- CCM_M14 -> 14- CCM_M16 -> 16+ CCM_M4 -> 4+ CCM_M6 -> 6+ CCM_M8 -> 8+ CCM_M10 -> 10+ CCM_M12 -> 12+ CCM_M14 -> 14+ CCM_M16 -> 16 ccmGetL l = case l of- CCM_L2 -> 2- CCM_L3 -> 3- CCM_L4 -> 4+ CCM_L2 -> 2+ CCM_L3 -> 3+ CCM_L4 -> 4 -- | initialize a ccm context {-# NOINLINE ccmInit #-}-ccmInit :: ByteArrayAccess iv => AES -> iv -> Int -> CCM_M -> CCM_L -> CryptoFailable AESCCM+ccmInit+ :: ByteArrayAccess iv+ => AES -> iv -> Int -> CCM_M -> CCM_L -> CryptoFailable AESCCM ccmInit ctx iv n m l | 15 - li /= B.length iv = CryptoFailed CryptoError_IvSizeInvalid | otherwise = unsafeDoIO $ do- sm <- B.alloc sizeCCM $ \ccmStPtr ->+ sm <- B.alloc sizeCCM $ \ccmStPtr -> withKeyAndIV ctx iv $ \k v ->- c_aes_ccm_init (castPtr ccmStPtr) k v (fromIntegral $ B.length iv) (fromIntegral n) (fromIntegral mi) (fromIntegral li)- return $ CryptoPassed (AESCCM sm)+ c_aes_ccm_init+ (castPtr ccmStPtr)+ k+ v+ (fromIntegral $ B.length iv)+ (fromIntegral n)+ (fromIntegral mi)+ (fromIntegral li)+ return $ CryptoPassed (AESCCM sm) where mi = ccmGetM m li = ccmGetL l@@ -529,8 +624,9 @@ {-# NOINLINE ccmAppendAAD #-} ccmAppendAAD :: ByteArrayAccess aad => AES -> AESCCM -> aad -> AESCCM ccmAppendAAD ctx ccm input = unsafeDoIO $ snd <$> withCCMKeyAndCopySt ctx ccm doAppend- where doAppend ccmStPtr aesPtr =- withByteArray input $ \i -> c_aes_ccm_aad ccmStPtr aesPtr i (fromIntegral $ B.length input)+ where+ doAppend ccmStPtr aesPtr =+ withByteArray input $ \i -> c_aes_ccm_aad ccmStPtr aesPtr i (fromIntegral $ B.length input) -- | append data to encrypt and append to the CCM context --@@ -539,11 +635,12 @@ {-# NOINLINE ccmEncrypt #-} ccmEncrypt :: ByteArray ba => AES -> AESCCM -> ba -> (ba, AESCCM) ccmEncrypt ctx ccm input = unsafeDoIO $ withCCMKeyAndCopySt ctx ccm cbcmacAndIv- where len = B.length input- cbcmacAndIv ccmStPtr aesPtr =- B.alloc len $ \o ->+ where+ len = B.length input+ cbcmacAndIv ccmStPtr aesPtr =+ B.alloc len $ \o -> withByteArray input $ \i ->- c_aes_ccm_encrypt (castPtr o) ccmStPtr aesPtr i (fromIntegral len)+ c_aes_ccm_encrypt (castPtr o) ccmStPtr aesPtr i (fromIntegral len) -- | append data to decrypt and append to the CCM context --@@ -552,18 +649,20 @@ {-# NOINLINE ccmDecrypt #-} ccmDecrypt :: ByteArray ba => AES -> AESCCM -> ba -> (ba, AESCCM) ccmDecrypt ctx ccm input = unsafeDoIO $ withCCMKeyAndCopySt ctx ccm cbcmacAndIv- where len = B.length input- cbcmacAndIv ccmStPtr aesPtr =- B.alloc len $ \o ->+ where+ len = B.length input+ cbcmacAndIv ccmStPtr aesPtr =+ B.alloc len $ \o -> withByteArray input $ \i ->- c_aes_ccm_decrypt (castPtr o) ccmStPtr aesPtr i (fromIntegral len)+ c_aes_ccm_decrypt (castPtr o) ccmStPtr aesPtr i (fromIntegral len) -- | Generate the Tag from CCM context {-# NOINLINE ccmFinish #-} ccmFinish :: AES -> AESCCM -> Int -> AuthTag ccmFinish ctx ccm taglen = AuthTag $ B.take taglen computeTag- where computeTag = B.allocAndFreeze 16 $ \t ->- withCCMKeyAndCopySt ctx ccm (c_aes_ccm_finish (castPtr t)) >> return ()+ where+ computeTag = B.allocAndFreeze 16 $ \t ->+ withCCMKeyAndCopySt ctx ccm (c_aes_ccm_finish (castPtr t)) >> return () ------------------------------------------------------------------------ foreign import ccall "crypton_aes.h crypton_aes_initkey"@@ -576,16 +675,20 @@ c_aes_decrypt_ecb :: CString -> Ptr AES -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_encrypt_cbc"- c_aes_encrypt_cbc :: CString -> Ptr AES -> Ptr Word8 -> CString -> CUInt -> IO ()+ c_aes_encrypt_cbc+ :: CString -> Ptr AES -> Ptr Word8 -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_decrypt_cbc"- c_aes_decrypt_cbc :: CString -> Ptr AES -> Ptr Word8 -> CString -> CUInt -> IO ()+ c_aes_decrypt_cbc+ :: CString -> Ptr AES -> Ptr Word8 -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_encrypt_xts"- c_aes_encrypt_xts :: CString -> Ptr AES -> Ptr AES -> Ptr Word8 -> CUInt -> CString -> CUInt -> IO ()+ c_aes_encrypt_xts+ :: CString -> Ptr AES -> Ptr AES -> Ptr Word8 -> CUInt -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_decrypt_xts"- c_aes_decrypt_xts :: CString -> Ptr AES -> Ptr AES -> Ptr Word8 -> CUInt -> CString -> CUInt -> IO ()+ c_aes_decrypt_xts+ :: CString -> Ptr AES -> Ptr AES -> Ptr Word8 -> CUInt -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_gen_ctr" c_aes_gen_ctr :: CString -> Ptr AES -> Ptr Word8 -> CUInt -> IO ()@@ -594,10 +697,12 @@ c_aes_gen_ctr_cont :: CString -> Ptr AES -> Ptr Word8 -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_encrypt_ctr"- c_aes_encrypt_ctr :: CString -> Ptr AES -> Ptr Word8 -> CString -> CUInt -> IO ()+ c_aes_encrypt_ctr+ :: CString -> Ptr AES -> Ptr Word8 -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_encrypt_c32"- c_aes_encrypt_c32 :: CString -> Ptr AES -> Ptr Word8 -> CString -> CUInt -> IO ()+ c_aes_encrypt_c32+ :: CString -> Ptr AES -> Ptr Word8 -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_gcm_init" c_aes_gcm_init :: Ptr AESGCM -> Ptr AES -> Ptr Word8 -> CUInt -> IO ()@@ -606,10 +711,12 @@ c_aes_gcm_aad :: Ptr AESGCM -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_gcm_encrypt"- c_aes_gcm_encrypt :: CString -> Ptr AESGCM -> Ptr AES -> CString -> CUInt -> IO ()+ c_aes_gcm_encrypt+ :: CString -> Ptr AESGCM -> Ptr AES -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_gcm_decrypt"- c_aes_gcm_decrypt :: CString -> Ptr AESGCM -> Ptr AES -> CString -> CUInt -> IO ()+ c_aes_gcm_decrypt+ :: CString -> Ptr AESGCM -> Ptr AES -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_gcm_finish" c_aes_gcm_finish :: CString -> Ptr AESGCM -> Ptr AES -> IO ()@@ -621,25 +728,30 @@ c_aes_ocb_aad :: Ptr AESOCB -> Ptr AES -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_ocb_encrypt"- c_aes_ocb_encrypt :: CString -> Ptr AESOCB -> Ptr AES -> CString -> CUInt -> IO ()+ c_aes_ocb_encrypt+ :: CString -> Ptr AESOCB -> Ptr AES -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_ocb_decrypt"- c_aes_ocb_decrypt :: CString -> Ptr AESOCB -> Ptr AES -> CString -> CUInt -> IO ()+ c_aes_ocb_decrypt+ :: CString -> Ptr AESOCB -> Ptr AES -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_ocb_finish" c_aes_ocb_finish :: CString -> Ptr AESOCB -> Ptr AES -> IO () foreign import ccall "crypton_aes.h crypton_aes_ccm_init"- c_aes_ccm_init :: Ptr AESCCM -> Ptr AES -> Ptr Word8 -> CUInt -> CUInt -> CInt -> CInt -> IO ()+ c_aes_ccm_init+ :: Ptr AESCCM -> Ptr AES -> Ptr Word8 -> CUInt -> CUInt -> CInt -> CInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_ccm_aad" c_aes_ccm_aad :: Ptr AESCCM -> Ptr AES -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_ccm_encrypt"- c_aes_ccm_encrypt :: CString -> Ptr AESCCM -> Ptr AES -> CString -> CUInt -> IO ()+ c_aes_ccm_encrypt+ :: CString -> Ptr AESCCM -> Ptr AES -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_ccm_decrypt"- c_aes_ccm_decrypt :: CString -> Ptr AESCCM -> Ptr AES -> CString -> CUInt -> IO ()+ c_aes_ccm_decrypt+ :: CString -> Ptr AESCCM -> Ptr AES -> CString -> CUInt -> IO () foreign import ccall "crypton_aes.h crypton_aes_ccm_finish" c_aes_ccm_finish :: CString -> Ptr AESCCM -> Ptr AES -> IO ()
Crypto/Cipher/AESGCMSIV.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.Cipher.AESGCMSIV -- License : BSD-style@@ -16,28 +19,27 @@ -- -- The specification allows inputs up to 2^36 bytes but this implementation -- requires AAD and plaintext/ciphertext to be both smaller than 2^32 bytes.-{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.Cipher.AESGCMSIV- ( Nonce- , nonce- , generateNonce- , encrypt- , decrypt- ) where+module Crypto.Cipher.AESGCMSIV (+ Nonce,+ nonce,+ generateNonce,+ encrypt,+ decrypt,+) where import Data.Bits+import Data.Maybe import Data.Word -import Foreign.C.Types import Foreign.C.String+import Foreign.C.Types import Foreign.Ptr (Ptr, plusPtr) import Foreign.Storable (peekElemOff, poke, pokeElemOff) -import Data.ByteArray+import Data.ByteArray import qualified Data.ByteArray as B-import Data.Memory.Endian (toLE)-import Data.Memory.PtrMethods (memXor)+import Data.Memory.Endian (toLE)+import Data.Memory.PtrMethods (memXor) import Crypto.Cipher.AES.Primitive import Crypto.Cipher.Types@@ -45,7 +47,6 @@ import Crypto.Internal.Compat (unsafeDoIO) import Crypto.Random - -- 12-byte nonces -- | Nonce value for AES-GCM-SIV, always 12 bytes.@@ -55,26 +56,27 @@ nonce :: ByteArrayAccess iv => iv -> CryptoFailable Nonce nonce iv | B.length iv == 12 = CryptoPassed (Nonce $ B.convert iv)- | otherwise = CryptoFailed CryptoError_IvSizeInvalid+ | otherwise = CryptoFailed CryptoError_IvSizeInvalid -- | Generate a random nonce for use with AES-GCM-SIV. generateNonce :: MonadRandom m => m Nonce generateNonce = Nonce <$> getRandomBytes 12 - -- POLYVAL (mutable context) newtype Polyval = Polyval Bytes polyvalInit :: ScrubbedBytes -> IO Polyval polyvalInit h = Polyval <$> doInit- where doInit = B.alloc 272 $ \pctx -> B.withByteArray h $ \ph ->- c_aes_polyval_init pctx ph+ where+ doInit = B.alloc 272 $ \pctx -> B.withByteArray h $ \ph ->+ c_aes_polyval_init pctx ph polyvalUpdate :: ByteArrayAccess ba => Polyval -> ba -> IO () polyvalUpdate (Polyval ctx) bs = B.withByteArray ctx $ \pctx -> B.withByteArray bs $ \pbs -> c_aes_polyval_update pctx pbs sz- where sz = fromIntegral (B.length bs)+ where+ sz = fromIntegral (B.length bs) polyvalFinalize :: Polyval -> IO ScrubbedBytes polyvalFinalize (Polyval ctx) = B.alloc 16 $ \dst ->@@ -89,7 +91,6 @@ foreign import ccall unsafe "crypton_aes.h crypton_aes_polyval_finalize" c_aes_polyval_finalize :: Ptr Polyval -> CString -> IO () - -- Key Generation le32iv :: Word32 -> Nonce -> Bytes@@ -100,24 +101,25 @@ deriveKeys :: BlockCipher128 aes => aes -> Nonce -> (ScrubbedBytes, AES) deriveKeys aes iv = case cipherKeySize aes of- KeySizeFixed sz | sz `mod` 8 == 0 ->- let mak = buildKey [0 .. 1]- key = buildKey [2 .. fromIntegral (sz `div` 8) + 1]- mek = throwCryptoError (cipherInit key)- in (mak, mek)+ KeySizeFixed sz+ | sz `mod` 8 == 0 ->+ let mak = buildKey [0 .. 1]+ key = buildKey [2 .. fromIntegral (sz `div` 8) + 1]+ mek = throwCryptoError (cipherInit key)+ in (mak, mek) _ -> error "AESGCMSIV: invalid cipher" where idx n = ecbEncrypt aes (le32iv n iv) `takeView` 8 buildKey = B.concat . map idx - -- Encryption and decryption lengthInvalid :: ByteArrayAccess ba => ba -> Bool lengthInvalid bs | finiteBitSize len > 32 = len >= 1 `unsafeShiftL` 32- | otherwise = False- where len = B.length bs+ | otherwise = False+ where+ len = B.length bs -- | AEAD encryption with the specified key and nonce. The key must be given -- as an initialized 'Crypto.Cipher.AES.AES128' or 'Crypto.Cipher.AES.AES256'@@ -125,8 +127,9 @@ -- -- Lengths of additional data and plaintext must be less than 2^32 bytes, -- otherwise an exception is thrown.-encrypt :: (BlockCipher128 aes, ByteArrayAccess aad, ByteArray ba)- => aes -> Nonce -> aad -> ba -> (AuthTag, ba)+encrypt+ :: (BlockCipher128 aes, ByteArrayAccess aad, ByteArray ba)+ => aes -> Nonce -> aad -> ba -> (AuthTag, ba) encrypt aes iv aad plaintext | lengthInvalid aad = error "AESGCMSIV: aad is too large" | lengthInvalid plaintext = error "AESGCMSIV: plaintext is too large"@@ -143,8 +146,9 @@ -- -- Lengths of additional data and ciphertext must be less than 2^32 bytes, -- otherwise an exception is thrown.-decrypt :: (BlockCipher128 aes, ByteArrayAccess aad, ByteArray ba)- => aes -> Nonce -> aad -> ba -> AuthTag -> Maybe ba+decrypt+ :: (BlockCipher128 aes, ByteArrayAccess aad, ByteArray ba)+ => aes -> Nonce -> aad -> ba -> AuthTag -> Maybe ba decrypt aes iv aad ciphertext (AuthTag tag) | lengthInvalid aad = error "AESGCMSIV: aad is too large" | lengthInvalid ciphertext = error "AESGCMSIV: ciphertext is too large"@@ -156,18 +160,19 @@ plaintext = combineC32 mek (transformTag tag) ciphertext -- Calculate S_s = POLYVAL(mak, X_1, X_2, ...).-getSs :: (ByteArrayAccess aad, ByteArrayAccess ba)- => ScrubbedBytes -> aad -> ba -> ScrubbedBytes+getSs+ :: (ByteArrayAccess aad, ByteArrayAccess ba)+ => ScrubbedBytes -> aad -> ba -> ScrubbedBytes getSs mak aad plaintext = unsafeDoIO $ do ctx <- polyvalInit mak polyvalUpdate ctx aad polyvalUpdate ctx plaintext- polyvalUpdate ctx (lb :: Bytes) -- the "length block"+ polyvalUpdate ctx (lb :: Bytes) -- the "length block" polyvalFinalize ctx where lb = B.allocAndFreeze 16 $ \ptr -> do- pokeElemOff ptr 0 (toLE64 $ B.length aad)- pokeElemOff ptr 1 (toLE64 $ B.length plaintext)+ pokeElemOff ptr 0 (toLE64 $ B.length aad)+ pokeElemOff ptr 1 (toLE64 $ B.length plaintext) toLE64 x = toLE (fromIntegral x * 8 :: Word64) -- XOR the first 12 bytes of S_s with the nonce and clear the most significant@@ -175,10 +180,10 @@ tagInput :: ScrubbedBytes -> Nonce -> Bytes tagInput ss (Nonce iv) = B.copyAndFreeze ss $ \ptr ->- B.withByteArray iv $ \ivPtr -> do- memXor ptr ptr ivPtr 12- b <- peekElemOff ptr 15- pokeElemOff ptr 15 (b .&. (0x7f :: Word8))+ B.withByteArray iv $ \ivPtr -> do+ memXor ptr ptr ivPtr 12+ b <- peekElemOff ptr 15+ pokeElemOff ptr 15 (b .&. (0x7f :: Word8)) -- Encrypt the result with AES using the message-encryption key to produce the -- tag.@@ -190,4 +195,5 @@ transformTag :: Bytes -> IV AES transformTag tag = toIV $ B.copyAndFreeze tag $ \ptr -> peekElemOff ptr 15 >>= pokeElemOff ptr 15 . (.|. (0x80 :: Word8))- where toIV bs = let Just iv = makeIV (bs :: Bytes) in iv+ where+ toIV bs = fromJust $ makeIV (bs :: Bytes)
Crypto/Cipher/Blowfish.hs view
@@ -1,23 +1,23 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.Cipher.Blowfish -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : stable -- Portability : good----{-# LANGUAGE CPP #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.Cipher.Blowfish- ( Blowfish- , Blowfish64- , Blowfish128- , Blowfish256- , Blowfish448- ) where+module Crypto.Cipher.Blowfish (+ Blowfish,+ Blowfish64,+ Blowfish128,+ Blowfish256,+ Blowfish448,+) where -import Crypto.Internal.Imports-import Crypto.Cipher.Types import Crypto.Cipher.Blowfish.Primitive+import Crypto.Cipher.Types+import Crypto.Internal.Imports -- | variable keyed blowfish state newtype Blowfish = Blowfish Context@@ -40,9 +40,9 @@ deriving (NFData) instance Cipher Blowfish where- cipherName _ = "blowfish"+ cipherName _ = "blowfish" cipherKeySize _ = KeySizeRange 6 56- cipherInit k = Blowfish `fmap` initBlowfish k+ cipherInit k = Blowfish `fmap` initBlowfish k instance BlockCipher Blowfish where blockSize _ = 8
Crypto/Cipher/Blowfish/Box.hs view
@@ -1,19 +1,22 @@+{-# LANGUAGE MagicHash #-}+ -- | -- Module : Crypto.Cipher.Blowfish.Box -- License : BSD-style -- Stability : experimental -- Portability : Good-{-# LANGUAGE MagicHash #-}-module Crypto.Cipher.Blowfish.Box- ( KeySchedule(..)- , createKeySchedule- , copyKeySchedule- ) where+module Crypto.Cipher.Blowfish.Box (+ KeySchedule (..),+ createKeySchedule,+ copyKeySchedule,+) where -import Crypto.Internal.WordArray (MutableArray32,- mutableArray32FromAddrBE,- mutableArrayRead32,- mutableArrayWrite32)+import Crypto.Internal.WordArray (+ MutableArray32,+ mutableArray32FromAddrBE,+ mutableArrayRead32,+ mutableArrayWrite32,+ ) newtype KeySchedule = KeySchedule MutableArray32 @@ -23,274 +26,278 @@ copyKeySchedule (KeySchedule dst) (KeySchedule src) = loop 0 where loop 1042 = return ()- loop i = do- w32 <-mutableArrayRead32 src i+ loop i = do+ w32 <- mutableArrayRead32 src i mutableArrayWrite32 dst i w32 loop (i + 1) -- | Create a key schedule mutable array of the pbox followed by -- all the sboxes. createKeySchedule :: IO KeySchedule-createKeySchedule = KeySchedule `fmap` mutableArray32FromAddrBE 1042 "\- \\x24\x3f\x6a\x88\x85\xa3\x08\xd3\x13\x19\x8a\x2e\x03\x70\x73\x44\- \\xa4\x09\x38\x22\x29\x9f\x31\xd0\x08\x2e\xfa\x98\xec\x4e\x6c\x89\- \\x45\x28\x21\xe6\x38\xd0\x13\x77\xbe\x54\x66\xcf\x34\xe9\x0c\x6c\- \\xc0\xac\x29\xb7\xc9\x7c\x50\xdd\x3f\x84\xd5\xb5\xb5\x47\x09\x17\- \\x92\x16\xd5\xd9\x89\x79\xfb\x1b\- \\xd1\x31\x0b\xa6\x98\xdf\xb5\xac\x2f\xfd\x72\xdb\xd0\x1a\xdf\xb7\- \\xb8\xe1\xaf\xed\x6a\x26\x7e\x96\xba\x7c\x90\x45\xf1\x2c\x7f\x99\- \\x24\xa1\x99\x47\xb3\x91\x6c\xf7\x08\x01\xf2\xe2\x85\x8e\xfc\x16\- \\x63\x69\x20\xd8\x71\x57\x4e\x69\xa4\x58\xfe\xa3\xf4\x93\x3d\x7e\- \\x0d\x95\x74\x8f\x72\x8e\xb6\x58\x71\x8b\xcd\x58\x82\x15\x4a\xee\- \\x7b\x54\xa4\x1d\xc2\x5a\x59\xb5\x9c\x30\xd5\x39\x2a\xf2\x60\x13\- \\xc5\xd1\xb0\x23\x28\x60\x85\xf0\xca\x41\x79\x18\xb8\xdb\x38\xef\- \\x8e\x79\xdc\xb0\x60\x3a\x18\x0e\x6c\x9e\x0e\x8b\xb0\x1e\x8a\x3e\- \\xd7\x15\x77\xc1\xbd\x31\x4b\x27\x78\xaf\x2f\xda\x55\x60\x5c\x60\- \\xe6\x55\x25\xf3\xaa\x55\xab\x94\x57\x48\x98\x62\x63\xe8\x14\x40\- \\x55\xca\x39\x6a\x2a\xab\x10\xb6\xb4\xcc\x5c\x34\x11\x41\xe8\xce\- \\xa1\x54\x86\xaf\x7c\x72\xe9\x93\xb3\xee\x14\x11\x63\x6f\xbc\x2a\- \\x2b\xa9\xc5\x5d\x74\x18\x31\xf6\xce\x5c\x3e\x16\x9b\x87\x93\x1e\- \\xaf\xd6\xba\x33\x6c\x24\xcf\x5c\x7a\x32\x53\x81\x28\x95\x86\x77\- \\x3b\x8f\x48\x98\x6b\x4b\xb9\xaf\xc4\xbf\xe8\x1b\x66\x28\x21\x93\- \\x61\xd8\x09\xcc\xfb\x21\xa9\x91\x48\x7c\xac\x60\x5d\xec\x80\x32\- \\xef\x84\x5d\x5d\xe9\x85\x75\xb1\xdc\x26\x23\x02\xeb\x65\x1b\x88\- \\x23\x89\x3e\x81\xd3\x96\xac\xc5\x0f\x6d\x6f\xf3\x83\xf4\x42\x39\- \\x2e\x0b\x44\x82\xa4\x84\x20\x04\x69\xc8\xf0\x4a\x9e\x1f\x9b\x5e\- \\x21\xc6\x68\x42\xf6\xe9\x6c\x9a\x67\x0c\x9c\x61\xab\xd3\x88\xf0\- \\x6a\x51\xa0\xd2\xd8\x54\x2f\x68\x96\x0f\xa7\x28\xab\x51\x33\xa3\- \\x6e\xef\x0b\x6c\x13\x7a\x3b\xe4\xba\x3b\xf0\x50\x7e\xfb\x2a\x98\- \\xa1\xf1\x65\x1d\x39\xaf\x01\x76\x66\xca\x59\x3e\x82\x43\x0e\x88\- \\x8c\xee\x86\x19\x45\x6f\x9f\xb4\x7d\x84\xa5\xc3\x3b\x8b\x5e\xbe\- \\xe0\x6f\x75\xd8\x85\xc1\x20\x73\x40\x1a\x44\x9f\x56\xc1\x6a\xa6\- \\x4e\xd3\xaa\x62\x36\x3f\x77\x06\x1b\xfe\xdf\x72\x42\x9b\x02\x3d\- \\x37\xd0\xd7\x24\xd0\x0a\x12\x48\xdb\x0f\xea\xd3\x49\xf1\xc0\x9b\- \\x07\x53\x72\xc9\x80\x99\x1b\x7b\x25\xd4\x79\xd8\xf6\xe8\xde\xf7\- \\xe3\xfe\x50\x1a\xb6\x79\x4c\x3b\x97\x6c\xe0\xbd\x04\xc0\x06\xba\- \\xc1\xa9\x4f\xb6\x40\x9f\x60\xc4\x5e\x5c\x9e\xc2\x19\x6a\x24\x63\- \\x68\xfb\x6f\xaf\x3e\x6c\x53\xb5\x13\x39\xb2\xeb\x3b\x52\xec\x6f\- \\x6d\xfc\x51\x1f\x9b\x30\x95\x2c\xcc\x81\x45\x44\xaf\x5e\xbd\x09\- \\xbe\xe3\xd0\x04\xde\x33\x4a\xfd\x66\x0f\x28\x07\x19\x2e\x4b\xb3\- \\xc0\xcb\xa8\x57\x45\xc8\x74\x0f\xd2\x0b\x5f\x39\xb9\xd3\xfb\xdb\- \\x55\x79\xc0\xbd\x1a\x60\x32\x0a\xd6\xa1\x00\xc6\x40\x2c\x72\x79\- \\x67\x9f\x25\xfe\xfb\x1f\xa3\xcc\x8e\xa5\xe9\xf8\xdb\x32\x22\xf8\- \\x3c\x75\x16\xdf\xfd\x61\x6b\x15\x2f\x50\x1e\xc8\xad\x05\x52\xab\- \\x32\x3d\xb5\xfa\xfd\x23\x87\x60\x53\x31\x7b\x48\x3e\x00\xdf\x82\- \\x9e\x5c\x57\xbb\xca\x6f\x8c\xa0\x1a\x87\x56\x2e\xdf\x17\x69\xdb\- \\xd5\x42\xa8\xf6\x28\x7e\xff\xc3\xac\x67\x32\xc6\x8c\x4f\x55\x73\- \\x69\x5b\x27\xb0\xbb\xca\x58\xc8\xe1\xff\xa3\x5d\xb8\xf0\x11\xa0\- \\x10\xfa\x3d\x98\xfd\x21\x83\xb8\x4a\xfc\xb5\x6c\x2d\xd1\xd3\x5b\- \\x9a\x53\xe4\x79\xb6\xf8\x45\x65\xd2\x8e\x49\xbc\x4b\xfb\x97\x90\- \\xe1\xdd\xf2\xda\xa4\xcb\x7e\x33\x62\xfb\x13\x41\xce\xe4\xc6\xe8\- \\xef\x20\xca\xda\x36\x77\x4c\x01\xd0\x7e\x9e\xfe\x2b\xf1\x1f\xb4\- \\x95\xdb\xda\x4d\xae\x90\x91\x98\xea\xad\x8e\x71\x6b\x93\xd5\xa0\- \\xd0\x8e\xd1\xd0\xaf\xc7\x25\xe0\x8e\x3c\x5b\x2f\x8e\x75\x94\xb7\- \\x8f\xf6\xe2\xfb\xf2\x12\x2b\x64\x88\x88\xb8\x12\x90\x0d\xf0\x1c\- \\x4f\xad\x5e\xa0\x68\x8f\xc3\x1c\xd1\xcf\xf1\x91\xb3\xa8\xc1\xad\- \\x2f\x2f\x22\x18\xbe\x0e\x17\x77\xea\x75\x2d\xfe\x8b\x02\x1f\xa1\- \\xe5\xa0\xcc\x0f\xb5\x6f\x74\xe8\x18\xac\xf3\xd6\xce\x89\xe2\x99\- \\xb4\xa8\x4f\xe0\xfd\x13\xe0\xb7\x7c\xc4\x3b\x81\xd2\xad\xa8\xd9\- \\x16\x5f\xa2\x66\x80\x95\x77\x05\x93\xcc\x73\x14\x21\x1a\x14\x77\- \\xe6\xad\x20\x65\x77\xb5\xfa\x86\xc7\x54\x42\xf5\xfb\x9d\x35\xcf\- \\xeb\xcd\xaf\x0c\x7b\x3e\x89\xa0\xd6\x41\x1b\xd3\xae\x1e\x7e\x49\- \\x00\x25\x0e\x2d\x20\x71\xb3\x5e\x22\x68\x00\xbb\x57\xb8\xe0\xaf\- \\x24\x64\x36\x9b\xf0\x09\xb9\x1e\x55\x63\x91\x1d\x59\xdf\xa6\xaa\- \\x78\xc1\x43\x89\xd9\x5a\x53\x7f\x20\x7d\x5b\xa2\x02\xe5\xb9\xc5\- \\x83\x26\x03\x76\x62\x95\xcf\xa9\x11\xc8\x19\x68\x4e\x73\x4a\x41\- \\xb3\x47\x2d\xca\x7b\x14\xa9\x4a\x1b\x51\x00\x52\x9a\x53\x29\x15\- \\xd6\x0f\x57\x3f\xbc\x9b\xc6\xe4\x2b\x60\xa4\x76\x81\xe6\x74\x00\- \\x08\xba\x6f\xb5\x57\x1b\xe9\x1f\xf2\x96\xec\x6b\x2a\x0d\xd9\x15\- \\xb6\x63\x65\x21\xe7\xb9\xf9\xb6\xff\x34\x05\x2e\xc5\x85\x56\x64\- \\x53\xb0\x2d\x5d\xa9\x9f\x8f\xa1\x08\xba\x47\x99\x6e\x85\x07\x6a\- \\x4b\x7a\x70\xe9\xb5\xb3\x29\x44\xdb\x75\x09\x2e\xc4\x19\x26\x23\- \\xad\x6e\xa6\xb0\x49\xa7\xdf\x7d\x9c\xee\x60\xb8\x8f\xed\xb2\x66\- \\xec\xaa\x8c\x71\x69\x9a\x17\xff\x56\x64\x52\x6c\xc2\xb1\x9e\xe1\- \\x19\x36\x02\xa5\x75\x09\x4c\x29\xa0\x59\x13\x40\xe4\x18\x3a\x3e\- \\x3f\x54\x98\x9a\x5b\x42\x9d\x65\x6b\x8f\xe4\xd6\x99\xf7\x3f\xd6\- \\xa1\xd2\x9c\x07\xef\xe8\x30\xf5\x4d\x2d\x38\xe6\xf0\x25\x5d\xc1\- \\x4c\xdd\x20\x86\x84\x70\xeb\x26\x63\x82\xe9\xc6\x02\x1e\xcc\x5e\- \\x09\x68\x6b\x3f\x3e\xba\xef\xc9\x3c\x97\x18\x14\x6b\x6a\x70\xa1\- \\x68\x7f\x35\x84\x52\xa0\xe2\x86\xb7\x9c\x53\x05\xaa\x50\x07\x37\- \\x3e\x07\x84\x1c\x7f\xde\xae\x5c\x8e\x7d\x44\xec\x57\x16\xf2\xb8\- \\xb0\x3a\xda\x37\xf0\x50\x0c\x0d\xf0\x1c\x1f\x04\x02\x00\xb3\xff\- \\xae\x0c\xf5\x1a\x3c\xb5\x74\xb2\x25\x83\x7a\x58\xdc\x09\x21\xbd\- \\xd1\x91\x13\xf9\x7c\xa9\x2f\xf6\x94\x32\x47\x73\x22\xf5\x47\x01\- \\x3a\xe5\xe5\x81\x37\xc2\xda\xdc\xc8\xb5\x76\x34\x9a\xf3\xdd\xa7\- \\xa9\x44\x61\x46\x0f\xd0\x03\x0e\xec\xc8\xc7\x3e\xa4\x75\x1e\x41\- \\xe2\x38\xcd\x99\x3b\xea\x0e\x2f\x32\x80\xbb\xa1\x18\x3e\xb3\x31\- \\x4e\x54\x8b\x38\x4f\x6d\xb9\x08\x6f\x42\x0d\x03\xf6\x0a\x04\xbf\- \\x2c\xb8\x12\x90\x24\x97\x7c\x79\x56\x79\xb0\x72\xbc\xaf\x89\xaf\- \\xde\x9a\x77\x1f\xd9\x93\x08\x10\xb3\x8b\xae\x12\xdc\xcf\x3f\x2e\- \\x55\x12\x72\x1f\x2e\x6b\x71\x24\x50\x1a\xdd\xe6\x9f\x84\xcd\x87\- \\x7a\x58\x47\x18\x74\x08\xda\x17\xbc\x9f\x9a\xbc\xe9\x4b\x7d\x8c\- \\xec\x7a\xec\x3a\xdb\x85\x1d\xfa\x63\x09\x43\x66\xc4\x64\xc3\xd2\- \\xef\x1c\x18\x47\x32\x15\xd9\x08\xdd\x43\x3b\x37\x24\xc2\xba\x16\- \\x12\xa1\x4d\x43\x2a\x65\xc4\x51\x50\x94\x00\x02\x13\x3a\xe4\xdd\- \\x71\xdf\xf8\x9e\x10\x31\x4e\x55\x81\xac\x77\xd6\x5f\x11\x19\x9b\- \\x04\x35\x56\xf1\xd7\xa3\xc7\x6b\x3c\x11\x18\x3b\x59\x24\xa5\x09\- \\xf2\x8f\xe6\xed\x97\xf1\xfb\xfa\x9e\xba\xbf\x2c\x1e\x15\x3c\x6e\- \\x86\xe3\x45\x70\xea\xe9\x6f\xb1\x86\x0e\x5e\x0a\x5a\x3e\x2a\xb3\- \\x77\x1f\xe7\x1c\x4e\x3d\x06\xfa\x29\x65\xdc\xb9\x99\xe7\x1d\x0f\- \\x80\x3e\x89\xd6\x52\x66\xc8\x25\x2e\x4c\xc9\x78\x9c\x10\xb3\x6a\- \\xc6\x15\x0e\xba\x94\xe2\xea\x78\xa5\xfc\x3c\x53\x1e\x0a\x2d\xf4\- \\xf2\xf7\x4e\xa7\x36\x1d\x2b\x3d\x19\x39\x26\x0f\x19\xc2\x79\x60\- \\x52\x23\xa7\x08\xf7\x13\x12\xb6\xeb\xad\xfe\x6e\xea\xc3\x1f\x66\- \\xe3\xbc\x45\x95\xa6\x7b\xc8\x83\xb1\x7f\x37\xd1\x01\x8c\xff\x28\- \\xc3\x32\xdd\xef\xbe\x6c\x5a\xa5\x65\x58\x21\x85\x68\xab\x98\x02\- \\xee\xce\xa5\x0f\xdb\x2f\x95\x3b\x2a\xef\x7d\xad\x5b\x6e\x2f\x84\- \\x15\x21\xb6\x28\x29\x07\x61\x70\xec\xdd\x47\x75\x61\x9f\x15\x10\- \\x13\xcc\xa8\x30\xeb\x61\xbd\x96\x03\x34\xfe\x1e\xaa\x03\x63\xcf\- \\xb5\x73\x5c\x90\x4c\x70\xa2\x39\xd5\x9e\x9e\x0b\xcb\xaa\xde\x14\- \\xee\xcc\x86\xbc\x60\x62\x2c\xa7\x9c\xab\x5c\xab\xb2\xf3\x84\x6e\- \\x64\x8b\x1e\xaf\x19\xbd\xf0\xca\xa0\x23\x69\xb9\x65\x5a\xbb\x50\- \\x40\x68\x5a\x32\x3c\x2a\xb4\xb3\x31\x9e\xe9\xd5\xc0\x21\xb8\xf7\- \\x9b\x54\x0b\x19\x87\x5f\xa0\x99\x95\xf7\x99\x7e\x62\x3d\x7d\xa8\- \\xf8\x37\x88\x9a\x97\xe3\x2d\x77\x11\xed\x93\x5f\x16\x68\x12\x81\- \\x0e\x35\x88\x29\xc7\xe6\x1f\xd6\x96\xde\xdf\xa1\x78\x58\xba\x99\- \\x57\xf5\x84\xa5\x1b\x22\x72\x63\x9b\x83\xc3\xff\x1a\xc2\x46\x96\- \\xcd\xb3\x0a\xeb\x53\x2e\x30\x54\x8f\xd9\x48\xe4\x6d\xbc\x31\x28\- \\x58\xeb\xf2\xef\x34\xc6\xff\xea\xfe\x28\xed\x61\xee\x7c\x3c\x73\- \\x5d\x4a\x14\xd9\xe8\x64\xb7\xe3\x42\x10\x5d\x14\x20\x3e\x13\xe0\- \\x45\xee\xe2\xb6\xa3\xaa\xab\xea\xdb\x6c\x4f\x15\xfa\xcb\x4f\xd0\- \\xc7\x42\xf4\x42\xef\x6a\xbb\xb5\x65\x4f\x3b\x1d\x41\xcd\x21\x05\- \\xd8\x1e\x79\x9e\x86\x85\x4d\xc7\xe4\x4b\x47\x6a\x3d\x81\x62\x50\- \\xcf\x62\xa1\xf2\x5b\x8d\x26\x46\xfc\x88\x83\xa0\xc1\xc7\xb6\xa3\- \\x7f\x15\x24\xc3\x69\xcb\x74\x92\x47\x84\x8a\x0b\x56\x92\xb2\x85\- \\x09\x5b\xbf\x00\xad\x19\x48\x9d\x14\x62\xb1\x74\x23\x82\x0e\x00\- \\x58\x42\x8d\x2a\x0c\x55\xf5\xea\x1d\xad\xf4\x3e\x23\x3f\x70\x61\- \\x33\x72\xf0\x92\x8d\x93\x7e\x41\xd6\x5f\xec\xf1\x6c\x22\x3b\xdb\- \\x7c\xde\x37\x59\xcb\xee\x74\x60\x40\x85\xf2\xa7\xce\x77\x32\x6e\- \\xa6\x07\x80\x84\x19\xf8\x50\x9e\xe8\xef\xd8\x55\x61\xd9\x97\x35\- \\xa9\x69\xa7\xaa\xc5\x0c\x06\xc2\x5a\x04\xab\xfc\x80\x0b\xca\xdc\- \\x9e\x44\x7a\x2e\xc3\x45\x34\x84\xfd\xd5\x67\x05\x0e\x1e\x9e\xc9\- \\xdb\x73\xdb\xd3\x10\x55\x88\xcd\x67\x5f\xda\x79\xe3\x67\x43\x40\- \\xc5\xc4\x34\x65\x71\x3e\x38\xd8\x3d\x28\xf8\x9e\xf1\x6d\xff\x20\- \\x15\x3e\x21\xe7\x8f\xb0\x3d\x4a\xe6\xe3\x9f\x2b\xdb\x83\xad\xf7\- \\xe9\x3d\x5a\x68\x94\x81\x40\xf7\xf6\x4c\x26\x1c\x94\x69\x29\x34\- \\x41\x15\x20\xf7\x76\x02\xd4\xf7\xbc\xf4\x6b\x2e\xd4\xa2\x00\x68\- \\xd4\x08\x24\x71\x33\x20\xf4\x6a\x43\xb7\xd4\xb7\x50\x00\x61\xaf\- \\x1e\x39\xf6\x2e\x97\x24\x45\x46\x14\x21\x4f\x74\xbf\x8b\x88\x40\- \\x4d\x95\xfc\x1d\x96\xb5\x91\xaf\x70\xf4\xdd\xd3\x66\xa0\x2f\x45\- \\xbf\xbc\x09\xec\x03\xbd\x97\x85\x7f\xac\x6d\xd0\x31\xcb\x85\x04\- \\x96\xeb\x27\xb3\x55\xfd\x39\x41\xda\x25\x47\xe6\xab\xca\x0a\x9a\- \\x28\x50\x78\x25\x53\x04\x29\xf4\x0a\x2c\x86\xda\xe9\xb6\x6d\xfb\- \\x68\xdc\x14\x62\xd7\x48\x69\x00\x68\x0e\xc0\xa4\x27\xa1\x8d\xee\- \\x4f\x3f\xfe\xa2\xe8\x87\xad\x8c\xb5\x8c\xe0\x06\x7a\xf4\xd6\xb6\- \\xaa\xce\x1e\x7c\xd3\x37\x5f\xec\xce\x78\xa3\x99\x40\x6b\x2a\x42\- \\x20\xfe\x9e\x35\xd9\xf3\x85\xb9\xee\x39\xd7\xab\x3b\x12\x4e\x8b\- \\x1d\xc9\xfa\xf7\x4b\x6d\x18\x56\x26\xa3\x66\x31\xea\xe3\x97\xb2\- \\x3a\x6e\xfa\x74\xdd\x5b\x43\x32\x68\x41\xe7\xf7\xca\x78\x20\xfb\- \\xfb\x0a\xf5\x4e\xd8\xfe\xb3\x97\x45\x40\x56\xac\xba\x48\x95\x27\- \\x55\x53\x3a\x3a\x20\x83\x8d\x87\xfe\x6b\xa9\xb7\xd0\x96\x95\x4b\- \\x55\xa8\x67\xbc\xa1\x15\x9a\x58\xcc\xa9\x29\x63\x99\xe1\xdb\x33\- \\xa6\x2a\x4a\x56\x3f\x31\x25\xf9\x5e\xf4\x7e\x1c\x90\x29\x31\x7c\- \\xfd\xf8\xe8\x02\x04\x27\x2f\x70\x80\xbb\x15\x5c\x05\x28\x2c\xe3\- \\x95\xc1\x15\x48\xe4\xc6\x6d\x22\x48\xc1\x13\x3f\xc7\x0f\x86\xdc\- \\x07\xf9\xc9\xee\x41\x04\x1f\x0f\x40\x47\x79\xa4\x5d\x88\x6e\x17\- \\x32\x5f\x51\xeb\xd5\x9b\xc0\xd1\xf2\xbc\xc1\x8f\x41\x11\x35\x64\- \\x25\x7b\x78\x34\x60\x2a\x9c\x60\xdf\xf8\xe8\xa3\x1f\x63\x6c\x1b\- \\x0e\x12\xb4\xc2\x02\xe1\x32\x9e\xaf\x66\x4f\xd1\xca\xd1\x81\x15\- \\x6b\x23\x95\xe0\x33\x3e\x92\xe1\x3b\x24\x0b\x62\xee\xbe\xb9\x22\- \\x85\xb2\xa2\x0e\xe6\xba\x0d\x99\xde\x72\x0c\x8c\x2d\xa2\xf7\x28\- \\xd0\x12\x78\x45\x95\xb7\x94\xfd\x64\x7d\x08\x62\xe7\xcc\xf5\xf0\- \\x54\x49\xa3\x6f\x87\x7d\x48\xfa\xc3\x9d\xfd\x27\xf3\x3e\x8d\x1e\- \\x0a\x47\x63\x41\x99\x2e\xff\x74\x3a\x6f\x6e\xab\xf4\xf8\xfd\x37\- \\xa8\x12\xdc\x60\xa1\xeb\xdd\xf8\x99\x1b\xe1\x4c\xdb\x6e\x6b\x0d\- \\xc6\x7b\x55\x10\x6d\x67\x2c\x37\x27\x65\xd4\x3b\xdc\xd0\xe8\x04\- \\xf1\x29\x0d\xc7\xcc\x00\xff\xa3\xb5\x39\x0f\x92\x69\x0f\xed\x0b\- \\x66\x7b\x9f\xfb\xce\xdb\x7d\x9c\xa0\x91\xcf\x0b\xd9\x15\x5e\xa3\- \\xbb\x13\x2f\x88\x51\x5b\xad\x24\x7b\x94\x79\xbf\x76\x3b\xd6\xeb\- \\x37\x39\x2e\xb3\xcc\x11\x59\x79\x80\x26\xe2\x97\xf4\x2e\x31\x2d\- \\x68\x42\xad\xa7\xc6\x6a\x2b\x3b\x12\x75\x4c\xcc\x78\x2e\xf1\x1c\- \\x6a\x12\x42\x37\xb7\x92\x51\xe7\x06\xa1\xbb\xe6\x4b\xfb\x63\x50\- \\x1a\x6b\x10\x18\x11\xca\xed\xfa\x3d\x25\xbd\xd8\xe2\xe1\xc3\xc9\- \\x44\x42\x16\x59\x0a\x12\x13\x86\xd9\x0c\xec\x6e\xd5\xab\xea\x2a\- \\x64\xaf\x67\x4e\xda\x86\xa8\x5f\xbe\xbf\xe9\x88\x64\xe4\xc3\xfe\- \\x9d\xbc\x80\x57\xf0\xf7\xc0\x86\x60\x78\x7b\xf8\x60\x03\x60\x4d\- \\xd1\xfd\x83\x46\xf6\x38\x1f\xb0\x77\x45\xae\x04\xd7\x36\xfc\xcc\- \\x83\x42\x6b\x33\xf0\x1e\xab\x71\xb0\x80\x41\x87\x3c\x00\x5e\x5f\- \\x77\xa0\x57\xbe\xbd\xe8\xae\x24\x55\x46\x42\x99\xbf\x58\x2e\x61\- \\x4e\x58\xf4\x8f\xf2\xdd\xfd\xa2\xf4\x74\xef\x38\x87\x89\xbd\xc2\- \\x53\x66\xf9\xc3\xc8\xb3\x8e\x74\xb4\x75\xf2\x55\x46\xfc\xd9\xb9\- \\x7a\xeb\x26\x61\x8b\x1d\xdf\x84\x84\x6a\x0e\x79\x91\x5f\x95\xe2\- \\x46\x6e\x59\x8e\x20\xb4\x57\x70\x8c\xd5\x55\x91\xc9\x02\xde\x4c\- \\xb9\x0b\xac\xe1\xbb\x82\x05\xd0\x11\xa8\x62\x48\x75\x74\xa9\x9e\- \\xb7\x7f\x19\xb6\xe0\xa9\xdc\x09\x66\x2d\x09\xa1\xc4\x32\x46\x33\- \\xe8\x5a\x1f\x02\x09\xf0\xbe\x8c\x4a\x99\xa0\x25\x1d\x6e\xfe\x10\- \\x1a\xb9\x3d\x1d\x0b\xa5\xa4\xdf\xa1\x86\xf2\x0f\x28\x68\xf1\x69\- \\xdc\xb7\xda\x83\x57\x39\x06\xfe\xa1\xe2\xce\x9b\x4f\xcd\x7f\x52\- \\x50\x11\x5e\x01\xa7\x06\x83\xfa\xa0\x02\xb5\xc4\x0d\xe6\xd0\x27\- \\x9a\xf8\x8c\x27\x77\x3f\x86\x41\xc3\x60\x4c\x06\x61\xa8\x06\xb5\- \\xf0\x17\x7a\x28\xc0\xf5\x86\xe0\x00\x60\x58\xaa\x30\xdc\x7d\x62\- \\x11\xe6\x9e\xd7\x23\x38\xea\x63\x53\xc2\xdd\x94\xc2\xc2\x16\x34\- \\xbb\xcb\xee\x56\x90\xbc\xb6\xde\xeb\xfc\x7d\xa1\xce\x59\x1d\x76\- \\x6f\x05\xe4\x09\x4b\x7c\x01\x88\x39\x72\x0a\x3d\x7c\x92\x7c\x24\- \\x86\xe3\x72\x5f\x72\x4d\x9d\xb9\x1a\xc1\x5b\xb4\xd3\x9e\xb8\xfc\- \\xed\x54\x55\x78\x08\xfc\xa5\xb5\xd8\x3d\x7c\xd3\x4d\xad\x0f\xc4\- \\x1e\x50\xef\x5e\xb1\x61\xe6\xf8\xa2\x85\x14\xd9\x6c\x51\x13\x3c\- \\x6f\xd5\xc7\xe7\x56\xe1\x4e\xc4\x36\x2a\xbf\xce\xdd\xc6\xc8\x37\- \\xd7\x9a\x32\x34\x92\x63\x82\x12\x67\x0e\xfa\x8e\x40\x60\x00\xe0\- \\x3a\x39\xce\x37\xd3\xfa\xf5\xcf\xab\xc2\x77\x37\x5a\xc5\x2d\x1b\- \\x5c\xb0\x67\x9e\x4f\xa3\x37\x42\xd3\x82\x27\x40\x99\xbc\x9b\xbe\- \\xd5\x11\x8e\x9d\xbf\x0f\x73\x15\xd6\x2d\x1c\x7e\xc7\x00\xc4\x7b\- \\xb7\x8c\x1b\x6b\x21\xa1\x90\x45\xb2\x6e\xb1\xbe\x6a\x36\x6e\xb4\- \\x57\x48\xab\x2f\xbc\x94\x6e\x79\xc6\xa3\x76\xd2\x65\x49\xc2\xc8\- \\x53\x0f\xf8\xee\x46\x8d\xde\x7d\xd5\x73\x0a\x1d\x4c\xd0\x4d\xc6\- \\x29\x39\xbb\xdb\xa9\xba\x46\x50\xac\x95\x26\xe8\xbe\x5e\xe3\x04\- \\xa1\xfa\xd5\xf0\x6a\x2d\x51\x9a\x63\xef\x8c\xe2\x9a\x86\xee\x22\- \\xc0\x89\xc2\xb8\x43\x24\x2e\xf6\xa5\x1e\x03\xaa\x9c\xf2\xd0\xa4\- \\x83\xc0\x61\xba\x9b\xe9\x6a\x4d\x8f\xe5\x15\x50\xba\x64\x5b\xd6\- \\x28\x26\xa2\xf9\xa7\x3a\x3a\xe1\x4b\xa9\x95\x86\xef\x55\x62\xe9\- \\xc7\x2f\xef\xd3\xf7\x52\xf7\xda\x3f\x04\x6f\x69\x77\xfa\x0a\x59\- \\x80\xe4\xa9\x15\x87\xb0\x86\x01\x9b\x09\xe6\xad\x3b\x3e\xe5\x93\- \\xe9\x90\xfd\x5a\x9e\x34\xd7\x97\x2c\xf0\xb7\xd9\x02\x2b\x8b\x51\- \\x96\xd5\xac\x3a\x01\x7d\xa6\x7d\xd1\xcf\x3e\xd6\x7c\x7d\x2d\x28\- \\x1f\x9f\x25\xcf\xad\xf2\xb8\x9b\x5a\xd6\xb4\x72\x5a\x88\xf5\x4c\- \\xe0\x29\xac\x71\xe0\x19\xa5\xe6\x47\xb0\xac\xfd\xed\x93\xfa\x9b\- \\xe8\xd3\xc4\x8d\x28\x3b\x57\xcc\xf8\xd5\x66\x29\x79\x13\x2e\x28\- \\x78\x5f\x01\x91\xed\x75\x60\x55\xf7\x96\x0e\x44\xe3\xd3\x5e\x8c\- \\x15\x05\x6d\xd4\x88\xf4\x6d\xba\x03\xa1\x61\x25\x05\x64\xf0\xbd\- \\xc3\xeb\x9e\x15\x3c\x90\x57\xa2\x97\x27\x1a\xec\xa9\x3a\x07\x2a\- \\x1b\x3f\x6d\x9b\x1e\x63\x21\xf5\xf5\x9c\x66\xfb\x26\xdc\xf3\x19\- \\x75\x33\xd9\x28\xb1\x55\xfd\xf5\x03\x56\x34\x82\x8a\xba\x3c\xbb\- \\x28\x51\x77\x11\xc2\x0a\xd9\xf8\xab\xcc\x51\x67\xcc\xad\x92\x5f\- \\x4d\xe8\x17\x51\x38\x30\xdc\x8e\x37\x9d\x58\x62\x93\x20\xf9\x91\- \\xea\x7a\x90\xc2\xfb\x3e\x7b\xce\x51\x21\xce\x64\x77\x4f\xbe\x32\- \\xa8\xb6\xe3\x7e\xc3\x29\x3d\x46\x48\xde\x53\x69\x64\x13\xe6\x80\- \\xa2\xae\x08\x10\xdd\x6d\xb2\x24\x69\x85\x2d\xfd\x09\x07\x21\x66\- \\xb3\x9a\x46\x0a\x64\x45\xc0\xdd\x58\x6c\xde\xcf\x1c\x20\xc8\xae\- \\x5b\xbe\xf7\xdd\x1b\x58\x8d\x40\xcc\xd2\x01\x7f\x6b\xb4\xe3\xbb\- \\xdd\xa2\x6a\x7e\x3a\x59\xff\x45\x3e\x35\x0a\x44\xbc\xb4\xcd\xd5\- \\x72\xea\xce\xa8\xfa\x64\x84\xbb\x8d\x66\x12\xae\xbf\x3c\x6f\x47\- \\xd2\x9b\xe4\x63\x54\x2f\x5d\x9e\xae\xc2\x77\x1b\xf6\x4e\x63\x70\- \\x74\x0e\x0d\x8d\xe7\x5b\x13\x57\xf8\x72\x16\x71\xaf\x53\x7d\x5d\- \\x40\x40\xcb\x08\x4e\xb4\xe2\xcc\x34\xd2\x46\x6a\x01\x15\xaf\x84\- \\xe1\xb0\x04\x28\x95\x98\x3a\x1d\x06\xb8\x9f\xb4\xce\x6e\xa0\x48\- \\x6f\x3f\x3b\x82\x35\x20\xab\x82\x01\x1a\x1d\x4b\x27\x72\x27\xf8\- \\x61\x15\x60\xb1\xe7\x93\x3f\xdc\xbb\x3a\x79\x2b\x34\x45\x25\xbd\- \\xa0\x88\x39\xe1\x51\xce\x79\x4b\x2f\x32\xc9\xb7\xa0\x1f\xba\xc9\- \\xe0\x1c\xc8\x7e\xbc\xc7\xd1\xf6\xcf\x01\x11\xc3\xa1\xe8\xaa\xc7\- \\x1a\x90\x87\x49\xd4\x4f\xbd\x9a\xd0\xda\xde\xcb\xd5\x0a\xda\x38\- \\x03\x39\xc3\x2a\xc6\x91\x36\x67\x8d\xf9\x31\x7c\xe0\xb1\x2b\x4f\- \\xf7\x9e\x59\xb7\x43\xf5\xbb\x3a\xf2\xd5\x19\xff\x27\xd9\x45\x9c\- \\xbf\x97\x22\x2c\x15\xe6\xfc\x2a\x0f\x91\xfc\x71\x9b\x94\x15\x25\- \\xfa\xe5\x93\x61\xce\xb6\x9c\xeb\xc2\xa8\x64\x59\x12\xba\xa8\xd1\- \\xb6\xc1\x07\x5e\xe3\x05\x6a\x0c\x10\xd2\x50\x65\xcb\x03\xa4\x42\- \\xe0\xec\x6e\x0e\x16\x98\xdb\x3b\x4c\x98\xa0\xbe\x32\x78\xe9\x64\- \\x9f\x1f\x95\x32\xe0\xd3\x92\xdf\xd3\xa0\x34\x2b\x89\x71\xf2\x1e\- \\x1b\x0a\x74\x41\x4b\xa3\x34\x8c\xc5\xbe\x71\x20\xc3\x76\x32\xd8\- \\xdf\x35\x9f\x8d\x9b\x99\x2f\x2e\xe6\x0b\x6f\x47\x0f\xe3\xf1\x1d\- \\xe5\x4c\xda\x54\x1e\xda\xd8\x91\xce\x62\x79\xcf\xcd\x3e\x7e\x6f\- \\x16\x18\xb1\x66\xfd\x2c\x1d\x05\x84\x8f\xd2\xc5\xf6\xfb\x22\x99\- \\xf5\x23\xf3\x57\xa6\x32\x76\x23\x93\xa8\x35\x31\x56\xcc\xcd\x02\- \\xac\xf0\x81\x62\x5a\x75\xeb\xb5\x6e\x16\x36\x97\x88\xd2\x73\xcc\- \\xde\x96\x62\x92\x81\xb9\x49\xd0\x4c\x50\x90\x1b\x71\xc6\x56\x14\- \\xe6\xc6\xc7\xbd\x32\x7a\x14\x0a\x45\xe1\xd0\x06\xc3\xf2\x7b\x9a\- \\xc9\xaa\x53\xfd\x62\xa8\x0f\x00\xbb\x25\xbf\xe2\x35\xbd\xd2\xf6\- \\x71\x12\x69\x05\xb2\x04\x02\x22\xb6\xcb\xcf\x7c\xcd\x76\x9c\x2b\- \\x53\x11\x3e\xc0\x16\x40\xe3\xd3\x38\xab\xbd\x60\x25\x47\xad\xf0\- \\xba\x38\x20\x9c\xf7\x46\xce\x76\x77\xaf\xa1\xc5\x20\x75\x60\x60\- \\x85\xcb\xfe\x4e\x8a\xe8\x8d\xd8\x7a\xaa\xf9\xb0\x4c\xf9\xaa\x7e\- \\x19\x48\xc2\x5c\x02\xfb\x8a\x8c\x01\xc3\x6a\xe4\xd6\xeb\xe1\xf9\- \\x90\xd4\xf8\x69\xa6\x5c\xde\xa0\x3f\x09\x25\x2d\xc2\x08\xe6\x9f\- \\xb7\x4e\x61\x32\xce\x77\xe2\x5b\x57\x8f\xdf\xe3\x3a\xc3\x72\xe6\- \"#+createKeySchedule =+ KeySchedule+ `fmap` mutableArray32FromAddrBE+ 1042+ "\+ \\x24\x3f\x6a\x88\x85\xa3\x08\xd3\x13\x19\x8a\x2e\x03\x70\x73\x44\+ \\xa4\x09\x38\x22\x29\x9f\x31\xd0\x08\x2e\xfa\x98\xec\x4e\x6c\x89\+ \\x45\x28\x21\xe6\x38\xd0\x13\x77\xbe\x54\x66\xcf\x34\xe9\x0c\x6c\+ \\xc0\xac\x29\xb7\xc9\x7c\x50\xdd\x3f\x84\xd5\xb5\xb5\x47\x09\x17\+ \\x92\x16\xd5\xd9\x89\x79\xfb\x1b\+ \\xd1\x31\x0b\xa6\x98\xdf\xb5\xac\x2f\xfd\x72\xdb\xd0\x1a\xdf\xb7\+ \\xb8\xe1\xaf\xed\x6a\x26\x7e\x96\xba\x7c\x90\x45\xf1\x2c\x7f\x99\+ \\x24\xa1\x99\x47\xb3\x91\x6c\xf7\x08\x01\xf2\xe2\x85\x8e\xfc\x16\+ \\x63\x69\x20\xd8\x71\x57\x4e\x69\xa4\x58\xfe\xa3\xf4\x93\x3d\x7e\+ \\x0d\x95\x74\x8f\x72\x8e\xb6\x58\x71\x8b\xcd\x58\x82\x15\x4a\xee\+ \\x7b\x54\xa4\x1d\xc2\x5a\x59\xb5\x9c\x30\xd5\x39\x2a\xf2\x60\x13\+ \\xc5\xd1\xb0\x23\x28\x60\x85\xf0\xca\x41\x79\x18\xb8\xdb\x38\xef\+ \\x8e\x79\xdc\xb0\x60\x3a\x18\x0e\x6c\x9e\x0e\x8b\xb0\x1e\x8a\x3e\+ \\xd7\x15\x77\xc1\xbd\x31\x4b\x27\x78\xaf\x2f\xda\x55\x60\x5c\x60\+ \\xe6\x55\x25\xf3\xaa\x55\xab\x94\x57\x48\x98\x62\x63\xe8\x14\x40\+ \\x55\xca\x39\x6a\x2a\xab\x10\xb6\xb4\xcc\x5c\x34\x11\x41\xe8\xce\+ \\xa1\x54\x86\xaf\x7c\x72\xe9\x93\xb3\xee\x14\x11\x63\x6f\xbc\x2a\+ \\x2b\xa9\xc5\x5d\x74\x18\x31\xf6\xce\x5c\x3e\x16\x9b\x87\x93\x1e\+ \\xaf\xd6\xba\x33\x6c\x24\xcf\x5c\x7a\x32\x53\x81\x28\x95\x86\x77\+ \\x3b\x8f\x48\x98\x6b\x4b\xb9\xaf\xc4\xbf\xe8\x1b\x66\x28\x21\x93\+ \\x61\xd8\x09\xcc\xfb\x21\xa9\x91\x48\x7c\xac\x60\x5d\xec\x80\x32\+ \\xef\x84\x5d\x5d\xe9\x85\x75\xb1\xdc\x26\x23\x02\xeb\x65\x1b\x88\+ \\x23\x89\x3e\x81\xd3\x96\xac\xc5\x0f\x6d\x6f\xf3\x83\xf4\x42\x39\+ \\x2e\x0b\x44\x82\xa4\x84\x20\x04\x69\xc8\xf0\x4a\x9e\x1f\x9b\x5e\+ \\x21\xc6\x68\x42\xf6\xe9\x6c\x9a\x67\x0c\x9c\x61\xab\xd3\x88\xf0\+ \\x6a\x51\xa0\xd2\xd8\x54\x2f\x68\x96\x0f\xa7\x28\xab\x51\x33\xa3\+ \\x6e\xef\x0b\x6c\x13\x7a\x3b\xe4\xba\x3b\xf0\x50\x7e\xfb\x2a\x98\+ \\xa1\xf1\x65\x1d\x39\xaf\x01\x76\x66\xca\x59\x3e\x82\x43\x0e\x88\+ \\x8c\xee\x86\x19\x45\x6f\x9f\xb4\x7d\x84\xa5\xc3\x3b\x8b\x5e\xbe\+ \\xe0\x6f\x75\xd8\x85\xc1\x20\x73\x40\x1a\x44\x9f\x56\xc1\x6a\xa6\+ \\x4e\xd3\xaa\x62\x36\x3f\x77\x06\x1b\xfe\xdf\x72\x42\x9b\x02\x3d\+ \\x37\xd0\xd7\x24\xd0\x0a\x12\x48\xdb\x0f\xea\xd3\x49\xf1\xc0\x9b\+ \\x07\x53\x72\xc9\x80\x99\x1b\x7b\x25\xd4\x79\xd8\xf6\xe8\xde\xf7\+ \\xe3\xfe\x50\x1a\xb6\x79\x4c\x3b\x97\x6c\xe0\xbd\x04\xc0\x06\xba\+ \\xc1\xa9\x4f\xb6\x40\x9f\x60\xc4\x5e\x5c\x9e\xc2\x19\x6a\x24\x63\+ \\x68\xfb\x6f\xaf\x3e\x6c\x53\xb5\x13\x39\xb2\xeb\x3b\x52\xec\x6f\+ \\x6d\xfc\x51\x1f\x9b\x30\x95\x2c\xcc\x81\x45\x44\xaf\x5e\xbd\x09\+ \\xbe\xe3\xd0\x04\xde\x33\x4a\xfd\x66\x0f\x28\x07\x19\x2e\x4b\xb3\+ \\xc0\xcb\xa8\x57\x45\xc8\x74\x0f\xd2\x0b\x5f\x39\xb9\xd3\xfb\xdb\+ \\x55\x79\xc0\xbd\x1a\x60\x32\x0a\xd6\xa1\x00\xc6\x40\x2c\x72\x79\+ \\x67\x9f\x25\xfe\xfb\x1f\xa3\xcc\x8e\xa5\xe9\xf8\xdb\x32\x22\xf8\+ \\x3c\x75\x16\xdf\xfd\x61\x6b\x15\x2f\x50\x1e\xc8\xad\x05\x52\xab\+ \\x32\x3d\xb5\xfa\xfd\x23\x87\x60\x53\x31\x7b\x48\x3e\x00\xdf\x82\+ \\x9e\x5c\x57\xbb\xca\x6f\x8c\xa0\x1a\x87\x56\x2e\xdf\x17\x69\xdb\+ \\xd5\x42\xa8\xf6\x28\x7e\xff\xc3\xac\x67\x32\xc6\x8c\x4f\x55\x73\+ \\x69\x5b\x27\xb0\xbb\xca\x58\xc8\xe1\xff\xa3\x5d\xb8\xf0\x11\xa0\+ \\x10\xfa\x3d\x98\xfd\x21\x83\xb8\x4a\xfc\xb5\x6c\x2d\xd1\xd3\x5b\+ \\x9a\x53\xe4\x79\xb6\xf8\x45\x65\xd2\x8e\x49\xbc\x4b\xfb\x97\x90\+ \\xe1\xdd\xf2\xda\xa4\xcb\x7e\x33\x62\xfb\x13\x41\xce\xe4\xc6\xe8\+ \\xef\x20\xca\xda\x36\x77\x4c\x01\xd0\x7e\x9e\xfe\x2b\xf1\x1f\xb4\+ \\x95\xdb\xda\x4d\xae\x90\x91\x98\xea\xad\x8e\x71\x6b\x93\xd5\xa0\+ \\xd0\x8e\xd1\xd0\xaf\xc7\x25\xe0\x8e\x3c\x5b\x2f\x8e\x75\x94\xb7\+ \\x8f\xf6\xe2\xfb\xf2\x12\x2b\x64\x88\x88\xb8\x12\x90\x0d\xf0\x1c\+ \\x4f\xad\x5e\xa0\x68\x8f\xc3\x1c\xd1\xcf\xf1\x91\xb3\xa8\xc1\xad\+ \\x2f\x2f\x22\x18\xbe\x0e\x17\x77\xea\x75\x2d\xfe\x8b\x02\x1f\xa1\+ \\xe5\xa0\xcc\x0f\xb5\x6f\x74\xe8\x18\xac\xf3\xd6\xce\x89\xe2\x99\+ \\xb4\xa8\x4f\xe0\xfd\x13\xe0\xb7\x7c\xc4\x3b\x81\xd2\xad\xa8\xd9\+ \\x16\x5f\xa2\x66\x80\x95\x77\x05\x93\xcc\x73\x14\x21\x1a\x14\x77\+ \\xe6\xad\x20\x65\x77\xb5\xfa\x86\xc7\x54\x42\xf5\xfb\x9d\x35\xcf\+ \\xeb\xcd\xaf\x0c\x7b\x3e\x89\xa0\xd6\x41\x1b\xd3\xae\x1e\x7e\x49\+ \\x00\x25\x0e\x2d\x20\x71\xb3\x5e\x22\x68\x00\xbb\x57\xb8\xe0\xaf\+ \\x24\x64\x36\x9b\xf0\x09\xb9\x1e\x55\x63\x91\x1d\x59\xdf\xa6\xaa\+ \\x78\xc1\x43\x89\xd9\x5a\x53\x7f\x20\x7d\x5b\xa2\x02\xe5\xb9\xc5\+ \\x83\x26\x03\x76\x62\x95\xcf\xa9\x11\xc8\x19\x68\x4e\x73\x4a\x41\+ \\xb3\x47\x2d\xca\x7b\x14\xa9\x4a\x1b\x51\x00\x52\x9a\x53\x29\x15\+ \\xd6\x0f\x57\x3f\xbc\x9b\xc6\xe4\x2b\x60\xa4\x76\x81\xe6\x74\x00\+ \\x08\xba\x6f\xb5\x57\x1b\xe9\x1f\xf2\x96\xec\x6b\x2a\x0d\xd9\x15\+ \\xb6\x63\x65\x21\xe7\xb9\xf9\xb6\xff\x34\x05\x2e\xc5\x85\x56\x64\+ \\x53\xb0\x2d\x5d\xa9\x9f\x8f\xa1\x08\xba\x47\x99\x6e\x85\x07\x6a\+ \\x4b\x7a\x70\xe9\xb5\xb3\x29\x44\xdb\x75\x09\x2e\xc4\x19\x26\x23\+ \\xad\x6e\xa6\xb0\x49\xa7\xdf\x7d\x9c\xee\x60\xb8\x8f\xed\xb2\x66\+ \\xec\xaa\x8c\x71\x69\x9a\x17\xff\x56\x64\x52\x6c\xc2\xb1\x9e\xe1\+ \\x19\x36\x02\xa5\x75\x09\x4c\x29\xa0\x59\x13\x40\xe4\x18\x3a\x3e\+ \\x3f\x54\x98\x9a\x5b\x42\x9d\x65\x6b\x8f\xe4\xd6\x99\xf7\x3f\xd6\+ \\xa1\xd2\x9c\x07\xef\xe8\x30\xf5\x4d\x2d\x38\xe6\xf0\x25\x5d\xc1\+ \\x4c\xdd\x20\x86\x84\x70\xeb\x26\x63\x82\xe9\xc6\x02\x1e\xcc\x5e\+ \\x09\x68\x6b\x3f\x3e\xba\xef\xc9\x3c\x97\x18\x14\x6b\x6a\x70\xa1\+ \\x68\x7f\x35\x84\x52\xa0\xe2\x86\xb7\x9c\x53\x05\xaa\x50\x07\x37\+ \\x3e\x07\x84\x1c\x7f\xde\xae\x5c\x8e\x7d\x44\xec\x57\x16\xf2\xb8\+ \\xb0\x3a\xda\x37\xf0\x50\x0c\x0d\xf0\x1c\x1f\x04\x02\x00\xb3\xff\+ \\xae\x0c\xf5\x1a\x3c\xb5\x74\xb2\x25\x83\x7a\x58\xdc\x09\x21\xbd\+ \\xd1\x91\x13\xf9\x7c\xa9\x2f\xf6\x94\x32\x47\x73\x22\xf5\x47\x01\+ \\x3a\xe5\xe5\x81\x37\xc2\xda\xdc\xc8\xb5\x76\x34\x9a\xf3\xdd\xa7\+ \\xa9\x44\x61\x46\x0f\xd0\x03\x0e\xec\xc8\xc7\x3e\xa4\x75\x1e\x41\+ \\xe2\x38\xcd\x99\x3b\xea\x0e\x2f\x32\x80\xbb\xa1\x18\x3e\xb3\x31\+ \\x4e\x54\x8b\x38\x4f\x6d\xb9\x08\x6f\x42\x0d\x03\xf6\x0a\x04\xbf\+ \\x2c\xb8\x12\x90\x24\x97\x7c\x79\x56\x79\xb0\x72\xbc\xaf\x89\xaf\+ \\xde\x9a\x77\x1f\xd9\x93\x08\x10\xb3\x8b\xae\x12\xdc\xcf\x3f\x2e\+ \\x55\x12\x72\x1f\x2e\x6b\x71\x24\x50\x1a\xdd\xe6\x9f\x84\xcd\x87\+ \\x7a\x58\x47\x18\x74\x08\xda\x17\xbc\x9f\x9a\xbc\xe9\x4b\x7d\x8c\+ \\xec\x7a\xec\x3a\xdb\x85\x1d\xfa\x63\x09\x43\x66\xc4\x64\xc3\xd2\+ \\xef\x1c\x18\x47\x32\x15\xd9\x08\xdd\x43\x3b\x37\x24\xc2\xba\x16\+ \\x12\xa1\x4d\x43\x2a\x65\xc4\x51\x50\x94\x00\x02\x13\x3a\xe4\xdd\+ \\x71\xdf\xf8\x9e\x10\x31\x4e\x55\x81\xac\x77\xd6\x5f\x11\x19\x9b\+ \\x04\x35\x56\xf1\xd7\xa3\xc7\x6b\x3c\x11\x18\x3b\x59\x24\xa5\x09\+ \\xf2\x8f\xe6\xed\x97\xf1\xfb\xfa\x9e\xba\xbf\x2c\x1e\x15\x3c\x6e\+ \\x86\xe3\x45\x70\xea\xe9\x6f\xb1\x86\x0e\x5e\x0a\x5a\x3e\x2a\xb3\+ \\x77\x1f\xe7\x1c\x4e\x3d\x06\xfa\x29\x65\xdc\xb9\x99\xe7\x1d\x0f\+ \\x80\x3e\x89\xd6\x52\x66\xc8\x25\x2e\x4c\xc9\x78\x9c\x10\xb3\x6a\+ \\xc6\x15\x0e\xba\x94\xe2\xea\x78\xa5\xfc\x3c\x53\x1e\x0a\x2d\xf4\+ \\xf2\xf7\x4e\xa7\x36\x1d\x2b\x3d\x19\x39\x26\x0f\x19\xc2\x79\x60\+ \\x52\x23\xa7\x08\xf7\x13\x12\xb6\xeb\xad\xfe\x6e\xea\xc3\x1f\x66\+ \\xe3\xbc\x45\x95\xa6\x7b\xc8\x83\xb1\x7f\x37\xd1\x01\x8c\xff\x28\+ \\xc3\x32\xdd\xef\xbe\x6c\x5a\xa5\x65\x58\x21\x85\x68\xab\x98\x02\+ \\xee\xce\xa5\x0f\xdb\x2f\x95\x3b\x2a\xef\x7d\xad\x5b\x6e\x2f\x84\+ \\x15\x21\xb6\x28\x29\x07\x61\x70\xec\xdd\x47\x75\x61\x9f\x15\x10\+ \\x13\xcc\xa8\x30\xeb\x61\xbd\x96\x03\x34\xfe\x1e\xaa\x03\x63\xcf\+ \\xb5\x73\x5c\x90\x4c\x70\xa2\x39\xd5\x9e\x9e\x0b\xcb\xaa\xde\x14\+ \\xee\xcc\x86\xbc\x60\x62\x2c\xa7\x9c\xab\x5c\xab\xb2\xf3\x84\x6e\+ \\x64\x8b\x1e\xaf\x19\xbd\xf0\xca\xa0\x23\x69\xb9\x65\x5a\xbb\x50\+ \\x40\x68\x5a\x32\x3c\x2a\xb4\xb3\x31\x9e\xe9\xd5\xc0\x21\xb8\xf7\+ \\x9b\x54\x0b\x19\x87\x5f\xa0\x99\x95\xf7\x99\x7e\x62\x3d\x7d\xa8\+ \\xf8\x37\x88\x9a\x97\xe3\x2d\x77\x11\xed\x93\x5f\x16\x68\x12\x81\+ \\x0e\x35\x88\x29\xc7\xe6\x1f\xd6\x96\xde\xdf\xa1\x78\x58\xba\x99\+ \\x57\xf5\x84\xa5\x1b\x22\x72\x63\x9b\x83\xc3\xff\x1a\xc2\x46\x96\+ \\xcd\xb3\x0a\xeb\x53\x2e\x30\x54\x8f\xd9\x48\xe4\x6d\xbc\x31\x28\+ \\x58\xeb\xf2\xef\x34\xc6\xff\xea\xfe\x28\xed\x61\xee\x7c\x3c\x73\+ \\x5d\x4a\x14\xd9\xe8\x64\xb7\xe3\x42\x10\x5d\x14\x20\x3e\x13\xe0\+ \\x45\xee\xe2\xb6\xa3\xaa\xab\xea\xdb\x6c\x4f\x15\xfa\xcb\x4f\xd0\+ \\xc7\x42\xf4\x42\xef\x6a\xbb\xb5\x65\x4f\x3b\x1d\x41\xcd\x21\x05\+ \\xd8\x1e\x79\x9e\x86\x85\x4d\xc7\xe4\x4b\x47\x6a\x3d\x81\x62\x50\+ \\xcf\x62\xa1\xf2\x5b\x8d\x26\x46\xfc\x88\x83\xa0\xc1\xc7\xb6\xa3\+ \\x7f\x15\x24\xc3\x69\xcb\x74\x92\x47\x84\x8a\x0b\x56\x92\xb2\x85\+ \\x09\x5b\xbf\x00\xad\x19\x48\x9d\x14\x62\xb1\x74\x23\x82\x0e\x00\+ \\x58\x42\x8d\x2a\x0c\x55\xf5\xea\x1d\xad\xf4\x3e\x23\x3f\x70\x61\+ \\x33\x72\xf0\x92\x8d\x93\x7e\x41\xd6\x5f\xec\xf1\x6c\x22\x3b\xdb\+ \\x7c\xde\x37\x59\xcb\xee\x74\x60\x40\x85\xf2\xa7\xce\x77\x32\x6e\+ \\xa6\x07\x80\x84\x19\xf8\x50\x9e\xe8\xef\xd8\x55\x61\xd9\x97\x35\+ \\xa9\x69\xa7\xaa\xc5\x0c\x06\xc2\x5a\x04\xab\xfc\x80\x0b\xca\xdc\+ \\x9e\x44\x7a\x2e\xc3\x45\x34\x84\xfd\xd5\x67\x05\x0e\x1e\x9e\xc9\+ \\xdb\x73\xdb\xd3\x10\x55\x88\xcd\x67\x5f\xda\x79\xe3\x67\x43\x40\+ \\xc5\xc4\x34\x65\x71\x3e\x38\xd8\x3d\x28\xf8\x9e\xf1\x6d\xff\x20\+ \\x15\x3e\x21\xe7\x8f\xb0\x3d\x4a\xe6\xe3\x9f\x2b\xdb\x83\xad\xf7\+ \\xe9\x3d\x5a\x68\x94\x81\x40\xf7\xf6\x4c\x26\x1c\x94\x69\x29\x34\+ \\x41\x15\x20\xf7\x76\x02\xd4\xf7\xbc\xf4\x6b\x2e\xd4\xa2\x00\x68\+ \\xd4\x08\x24\x71\x33\x20\xf4\x6a\x43\xb7\xd4\xb7\x50\x00\x61\xaf\+ \\x1e\x39\xf6\x2e\x97\x24\x45\x46\x14\x21\x4f\x74\xbf\x8b\x88\x40\+ \\x4d\x95\xfc\x1d\x96\xb5\x91\xaf\x70\xf4\xdd\xd3\x66\xa0\x2f\x45\+ \\xbf\xbc\x09\xec\x03\xbd\x97\x85\x7f\xac\x6d\xd0\x31\xcb\x85\x04\+ \\x96\xeb\x27\xb3\x55\xfd\x39\x41\xda\x25\x47\xe6\xab\xca\x0a\x9a\+ \\x28\x50\x78\x25\x53\x04\x29\xf4\x0a\x2c\x86\xda\xe9\xb6\x6d\xfb\+ \\x68\xdc\x14\x62\xd7\x48\x69\x00\x68\x0e\xc0\xa4\x27\xa1\x8d\xee\+ \\x4f\x3f\xfe\xa2\xe8\x87\xad\x8c\xb5\x8c\xe0\x06\x7a\xf4\xd6\xb6\+ \\xaa\xce\x1e\x7c\xd3\x37\x5f\xec\xce\x78\xa3\x99\x40\x6b\x2a\x42\+ \\x20\xfe\x9e\x35\xd9\xf3\x85\xb9\xee\x39\xd7\xab\x3b\x12\x4e\x8b\+ \\x1d\xc9\xfa\xf7\x4b\x6d\x18\x56\x26\xa3\x66\x31\xea\xe3\x97\xb2\+ \\x3a\x6e\xfa\x74\xdd\x5b\x43\x32\x68\x41\xe7\xf7\xca\x78\x20\xfb\+ \\xfb\x0a\xf5\x4e\xd8\xfe\xb3\x97\x45\x40\x56\xac\xba\x48\x95\x27\+ \\x55\x53\x3a\x3a\x20\x83\x8d\x87\xfe\x6b\xa9\xb7\xd0\x96\x95\x4b\+ \\x55\xa8\x67\xbc\xa1\x15\x9a\x58\xcc\xa9\x29\x63\x99\xe1\xdb\x33\+ \\xa6\x2a\x4a\x56\x3f\x31\x25\xf9\x5e\xf4\x7e\x1c\x90\x29\x31\x7c\+ \\xfd\xf8\xe8\x02\x04\x27\x2f\x70\x80\xbb\x15\x5c\x05\x28\x2c\xe3\+ \\x95\xc1\x15\x48\xe4\xc6\x6d\x22\x48\xc1\x13\x3f\xc7\x0f\x86\xdc\+ \\x07\xf9\xc9\xee\x41\x04\x1f\x0f\x40\x47\x79\xa4\x5d\x88\x6e\x17\+ \\x32\x5f\x51\xeb\xd5\x9b\xc0\xd1\xf2\xbc\xc1\x8f\x41\x11\x35\x64\+ \\x25\x7b\x78\x34\x60\x2a\x9c\x60\xdf\xf8\xe8\xa3\x1f\x63\x6c\x1b\+ \\x0e\x12\xb4\xc2\x02\xe1\x32\x9e\xaf\x66\x4f\xd1\xca\xd1\x81\x15\+ \\x6b\x23\x95\xe0\x33\x3e\x92\xe1\x3b\x24\x0b\x62\xee\xbe\xb9\x22\+ \\x85\xb2\xa2\x0e\xe6\xba\x0d\x99\xde\x72\x0c\x8c\x2d\xa2\xf7\x28\+ \\xd0\x12\x78\x45\x95\xb7\x94\xfd\x64\x7d\x08\x62\xe7\xcc\xf5\xf0\+ \\x54\x49\xa3\x6f\x87\x7d\x48\xfa\xc3\x9d\xfd\x27\xf3\x3e\x8d\x1e\+ \\x0a\x47\x63\x41\x99\x2e\xff\x74\x3a\x6f\x6e\xab\xf4\xf8\xfd\x37\+ \\xa8\x12\xdc\x60\xa1\xeb\xdd\xf8\x99\x1b\xe1\x4c\xdb\x6e\x6b\x0d\+ \\xc6\x7b\x55\x10\x6d\x67\x2c\x37\x27\x65\xd4\x3b\xdc\xd0\xe8\x04\+ \\xf1\x29\x0d\xc7\xcc\x00\xff\xa3\xb5\x39\x0f\x92\x69\x0f\xed\x0b\+ \\x66\x7b\x9f\xfb\xce\xdb\x7d\x9c\xa0\x91\xcf\x0b\xd9\x15\x5e\xa3\+ \\xbb\x13\x2f\x88\x51\x5b\xad\x24\x7b\x94\x79\xbf\x76\x3b\xd6\xeb\+ \\x37\x39\x2e\xb3\xcc\x11\x59\x79\x80\x26\xe2\x97\xf4\x2e\x31\x2d\+ \\x68\x42\xad\xa7\xc6\x6a\x2b\x3b\x12\x75\x4c\xcc\x78\x2e\xf1\x1c\+ \\x6a\x12\x42\x37\xb7\x92\x51\xe7\x06\xa1\xbb\xe6\x4b\xfb\x63\x50\+ \\x1a\x6b\x10\x18\x11\xca\xed\xfa\x3d\x25\xbd\xd8\xe2\xe1\xc3\xc9\+ \\x44\x42\x16\x59\x0a\x12\x13\x86\xd9\x0c\xec\x6e\xd5\xab\xea\x2a\+ \\x64\xaf\x67\x4e\xda\x86\xa8\x5f\xbe\xbf\xe9\x88\x64\xe4\xc3\xfe\+ \\x9d\xbc\x80\x57\xf0\xf7\xc0\x86\x60\x78\x7b\xf8\x60\x03\x60\x4d\+ \\xd1\xfd\x83\x46\xf6\x38\x1f\xb0\x77\x45\xae\x04\xd7\x36\xfc\xcc\+ \\x83\x42\x6b\x33\xf0\x1e\xab\x71\xb0\x80\x41\x87\x3c\x00\x5e\x5f\+ \\x77\xa0\x57\xbe\xbd\xe8\xae\x24\x55\x46\x42\x99\xbf\x58\x2e\x61\+ \\x4e\x58\xf4\x8f\xf2\xdd\xfd\xa2\xf4\x74\xef\x38\x87\x89\xbd\xc2\+ \\x53\x66\xf9\xc3\xc8\xb3\x8e\x74\xb4\x75\xf2\x55\x46\xfc\xd9\xb9\+ \\x7a\xeb\x26\x61\x8b\x1d\xdf\x84\x84\x6a\x0e\x79\x91\x5f\x95\xe2\+ \\x46\x6e\x59\x8e\x20\xb4\x57\x70\x8c\xd5\x55\x91\xc9\x02\xde\x4c\+ \\xb9\x0b\xac\xe1\xbb\x82\x05\xd0\x11\xa8\x62\x48\x75\x74\xa9\x9e\+ \\xb7\x7f\x19\xb6\xe0\xa9\xdc\x09\x66\x2d\x09\xa1\xc4\x32\x46\x33\+ \\xe8\x5a\x1f\x02\x09\xf0\xbe\x8c\x4a\x99\xa0\x25\x1d\x6e\xfe\x10\+ \\x1a\xb9\x3d\x1d\x0b\xa5\xa4\xdf\xa1\x86\xf2\x0f\x28\x68\xf1\x69\+ \\xdc\xb7\xda\x83\x57\x39\x06\xfe\xa1\xe2\xce\x9b\x4f\xcd\x7f\x52\+ \\x50\x11\x5e\x01\xa7\x06\x83\xfa\xa0\x02\xb5\xc4\x0d\xe6\xd0\x27\+ \\x9a\xf8\x8c\x27\x77\x3f\x86\x41\xc3\x60\x4c\x06\x61\xa8\x06\xb5\+ \\xf0\x17\x7a\x28\xc0\xf5\x86\xe0\x00\x60\x58\xaa\x30\xdc\x7d\x62\+ \\x11\xe6\x9e\xd7\x23\x38\xea\x63\x53\xc2\xdd\x94\xc2\xc2\x16\x34\+ \\xbb\xcb\xee\x56\x90\xbc\xb6\xde\xeb\xfc\x7d\xa1\xce\x59\x1d\x76\+ \\x6f\x05\xe4\x09\x4b\x7c\x01\x88\x39\x72\x0a\x3d\x7c\x92\x7c\x24\+ \\x86\xe3\x72\x5f\x72\x4d\x9d\xb9\x1a\xc1\x5b\xb4\xd3\x9e\xb8\xfc\+ \\xed\x54\x55\x78\x08\xfc\xa5\xb5\xd8\x3d\x7c\xd3\x4d\xad\x0f\xc4\+ \\x1e\x50\xef\x5e\xb1\x61\xe6\xf8\xa2\x85\x14\xd9\x6c\x51\x13\x3c\+ \\x6f\xd5\xc7\xe7\x56\xe1\x4e\xc4\x36\x2a\xbf\xce\xdd\xc6\xc8\x37\+ \\xd7\x9a\x32\x34\x92\x63\x82\x12\x67\x0e\xfa\x8e\x40\x60\x00\xe0\+ \\x3a\x39\xce\x37\xd3\xfa\xf5\xcf\xab\xc2\x77\x37\x5a\xc5\x2d\x1b\+ \\x5c\xb0\x67\x9e\x4f\xa3\x37\x42\xd3\x82\x27\x40\x99\xbc\x9b\xbe\+ \\xd5\x11\x8e\x9d\xbf\x0f\x73\x15\xd6\x2d\x1c\x7e\xc7\x00\xc4\x7b\+ \\xb7\x8c\x1b\x6b\x21\xa1\x90\x45\xb2\x6e\xb1\xbe\x6a\x36\x6e\xb4\+ \\x57\x48\xab\x2f\xbc\x94\x6e\x79\xc6\xa3\x76\xd2\x65\x49\xc2\xc8\+ \\x53\x0f\xf8\xee\x46\x8d\xde\x7d\xd5\x73\x0a\x1d\x4c\xd0\x4d\xc6\+ \\x29\x39\xbb\xdb\xa9\xba\x46\x50\xac\x95\x26\xe8\xbe\x5e\xe3\x04\+ \\xa1\xfa\xd5\xf0\x6a\x2d\x51\x9a\x63\xef\x8c\xe2\x9a\x86\xee\x22\+ \\xc0\x89\xc2\xb8\x43\x24\x2e\xf6\xa5\x1e\x03\xaa\x9c\xf2\xd0\xa4\+ \\x83\xc0\x61\xba\x9b\xe9\x6a\x4d\x8f\xe5\x15\x50\xba\x64\x5b\xd6\+ \\x28\x26\xa2\xf9\xa7\x3a\x3a\xe1\x4b\xa9\x95\x86\xef\x55\x62\xe9\+ \\xc7\x2f\xef\xd3\xf7\x52\xf7\xda\x3f\x04\x6f\x69\x77\xfa\x0a\x59\+ \\x80\xe4\xa9\x15\x87\xb0\x86\x01\x9b\x09\xe6\xad\x3b\x3e\xe5\x93\+ \\xe9\x90\xfd\x5a\x9e\x34\xd7\x97\x2c\xf0\xb7\xd9\x02\x2b\x8b\x51\+ \\x96\xd5\xac\x3a\x01\x7d\xa6\x7d\xd1\xcf\x3e\xd6\x7c\x7d\x2d\x28\+ \\x1f\x9f\x25\xcf\xad\xf2\xb8\x9b\x5a\xd6\xb4\x72\x5a\x88\xf5\x4c\+ \\xe0\x29\xac\x71\xe0\x19\xa5\xe6\x47\xb0\xac\xfd\xed\x93\xfa\x9b\+ \\xe8\xd3\xc4\x8d\x28\x3b\x57\xcc\xf8\xd5\x66\x29\x79\x13\x2e\x28\+ \\x78\x5f\x01\x91\xed\x75\x60\x55\xf7\x96\x0e\x44\xe3\xd3\x5e\x8c\+ \\x15\x05\x6d\xd4\x88\xf4\x6d\xba\x03\xa1\x61\x25\x05\x64\xf0\xbd\+ \\xc3\xeb\x9e\x15\x3c\x90\x57\xa2\x97\x27\x1a\xec\xa9\x3a\x07\x2a\+ \\x1b\x3f\x6d\x9b\x1e\x63\x21\xf5\xf5\x9c\x66\xfb\x26\xdc\xf3\x19\+ \\x75\x33\xd9\x28\xb1\x55\xfd\xf5\x03\x56\x34\x82\x8a\xba\x3c\xbb\+ \\x28\x51\x77\x11\xc2\x0a\xd9\xf8\xab\xcc\x51\x67\xcc\xad\x92\x5f\+ \\x4d\xe8\x17\x51\x38\x30\xdc\x8e\x37\x9d\x58\x62\x93\x20\xf9\x91\+ \\xea\x7a\x90\xc2\xfb\x3e\x7b\xce\x51\x21\xce\x64\x77\x4f\xbe\x32\+ \\xa8\xb6\xe3\x7e\xc3\x29\x3d\x46\x48\xde\x53\x69\x64\x13\xe6\x80\+ \\xa2\xae\x08\x10\xdd\x6d\xb2\x24\x69\x85\x2d\xfd\x09\x07\x21\x66\+ \\xb3\x9a\x46\x0a\x64\x45\xc0\xdd\x58\x6c\xde\xcf\x1c\x20\xc8\xae\+ \\x5b\xbe\xf7\xdd\x1b\x58\x8d\x40\xcc\xd2\x01\x7f\x6b\xb4\xe3\xbb\+ \\xdd\xa2\x6a\x7e\x3a\x59\xff\x45\x3e\x35\x0a\x44\xbc\xb4\xcd\xd5\+ \\x72\xea\xce\xa8\xfa\x64\x84\xbb\x8d\x66\x12\xae\xbf\x3c\x6f\x47\+ \\xd2\x9b\xe4\x63\x54\x2f\x5d\x9e\xae\xc2\x77\x1b\xf6\x4e\x63\x70\+ \\x74\x0e\x0d\x8d\xe7\x5b\x13\x57\xf8\x72\x16\x71\xaf\x53\x7d\x5d\+ \\x40\x40\xcb\x08\x4e\xb4\xe2\xcc\x34\xd2\x46\x6a\x01\x15\xaf\x84\+ \\xe1\xb0\x04\x28\x95\x98\x3a\x1d\x06\xb8\x9f\xb4\xce\x6e\xa0\x48\+ \\x6f\x3f\x3b\x82\x35\x20\xab\x82\x01\x1a\x1d\x4b\x27\x72\x27\xf8\+ \\x61\x15\x60\xb1\xe7\x93\x3f\xdc\xbb\x3a\x79\x2b\x34\x45\x25\xbd\+ \\xa0\x88\x39\xe1\x51\xce\x79\x4b\x2f\x32\xc9\xb7\xa0\x1f\xba\xc9\+ \\xe0\x1c\xc8\x7e\xbc\xc7\xd1\xf6\xcf\x01\x11\xc3\xa1\xe8\xaa\xc7\+ \\x1a\x90\x87\x49\xd4\x4f\xbd\x9a\xd0\xda\xde\xcb\xd5\x0a\xda\x38\+ \\x03\x39\xc3\x2a\xc6\x91\x36\x67\x8d\xf9\x31\x7c\xe0\xb1\x2b\x4f\+ \\xf7\x9e\x59\xb7\x43\xf5\xbb\x3a\xf2\xd5\x19\xff\x27\xd9\x45\x9c\+ \\xbf\x97\x22\x2c\x15\xe6\xfc\x2a\x0f\x91\xfc\x71\x9b\x94\x15\x25\+ \\xfa\xe5\x93\x61\xce\xb6\x9c\xeb\xc2\xa8\x64\x59\x12\xba\xa8\xd1\+ \\xb6\xc1\x07\x5e\xe3\x05\x6a\x0c\x10\xd2\x50\x65\xcb\x03\xa4\x42\+ \\xe0\xec\x6e\x0e\x16\x98\xdb\x3b\x4c\x98\xa0\xbe\x32\x78\xe9\x64\+ \\x9f\x1f\x95\x32\xe0\xd3\x92\xdf\xd3\xa0\x34\x2b\x89\x71\xf2\x1e\+ \\x1b\x0a\x74\x41\x4b\xa3\x34\x8c\xc5\xbe\x71\x20\xc3\x76\x32\xd8\+ \\xdf\x35\x9f\x8d\x9b\x99\x2f\x2e\xe6\x0b\x6f\x47\x0f\xe3\xf1\x1d\+ \\xe5\x4c\xda\x54\x1e\xda\xd8\x91\xce\x62\x79\xcf\xcd\x3e\x7e\x6f\+ \\x16\x18\xb1\x66\xfd\x2c\x1d\x05\x84\x8f\xd2\xc5\xf6\xfb\x22\x99\+ \\xf5\x23\xf3\x57\xa6\x32\x76\x23\x93\xa8\x35\x31\x56\xcc\xcd\x02\+ \\xac\xf0\x81\x62\x5a\x75\xeb\xb5\x6e\x16\x36\x97\x88\xd2\x73\xcc\+ \\xde\x96\x62\x92\x81\xb9\x49\xd0\x4c\x50\x90\x1b\x71\xc6\x56\x14\+ \\xe6\xc6\xc7\xbd\x32\x7a\x14\x0a\x45\xe1\xd0\x06\xc3\xf2\x7b\x9a\+ \\xc9\xaa\x53\xfd\x62\xa8\x0f\x00\xbb\x25\xbf\xe2\x35\xbd\xd2\xf6\+ \\x71\x12\x69\x05\xb2\x04\x02\x22\xb6\xcb\xcf\x7c\xcd\x76\x9c\x2b\+ \\x53\x11\x3e\xc0\x16\x40\xe3\xd3\x38\xab\xbd\x60\x25\x47\xad\xf0\+ \\xba\x38\x20\x9c\xf7\x46\xce\x76\x77\xaf\xa1\xc5\x20\x75\x60\x60\+ \\x85\xcb\xfe\x4e\x8a\xe8\x8d\xd8\x7a\xaa\xf9\xb0\x4c\xf9\xaa\x7e\+ \\x19\x48\xc2\x5c\x02\xfb\x8a\x8c\x01\xc3\x6a\xe4\xd6\xeb\xe1\xf9\+ \\x90\xd4\xf8\x69\xa6\x5c\xde\xa0\x3f\x09\x25\x2d\xc2\x08\xe6\x9f\+ \\xb7\x4e\x61\x32\xce\x77\xe2\x5b\x57\x8f\xdf\xe3\x3a\xc3\x72\xe6\+ \"#
Crypto/Cipher/Blowfish/Primitive.hs view
@@ -1,9 +1,3 @@--- |--- Module : Crypto.Cipher.Blowfish.Primitive--- License : BSD-style--- Stability : experimental--- Portability : Good- -- Rewritten by Vincent Hanquez (c) 2015 -- Lars Petersen (c) 2018 --@@ -12,32 +6,38 @@ -- based on: BlowfishAux.hs (C) 2002 HardCore SoftWare, Doug Hoyte -- (as found in Crypto-4.2.4) {-# LANGUAGE BangPatterns #-}-module Crypto.Cipher.Blowfish.Primitive- ( Context- , initBlowfish- , encrypt- , decrypt- , KeySchedule- , createKeySchedule- , freezeKeySchedule- , expandKey- , expandKeyWithSalt- , cipherBlockMutable- ) where -import Control.Monad (when)-import Data.Bits-import Data.Memory.Endian-import Data.Word+-- |+-- Module : Crypto.Cipher.Blowfish.Primitive+-- License : BSD-style+-- Stability : experimental+-- Portability : Good+module Crypto.Cipher.Blowfish.Primitive (+ Context,+ initBlowfish,+ encrypt,+ decrypt,+ KeySchedule,+ createKeySchedule,+ freezeKeySchedule,+ expandKey,+ expandKeyWithSalt,+ cipherBlockMutable,+) where -import Crypto.Cipher.Blowfish.Box-import Crypto.Error-import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess)-import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Crypto.Internal.WordArray+import Control.Monad (when)+import Data.Bits+import Data.Memory.Endian+import Data.Word +import Crypto.Cipher.Blowfish.Box+import Crypto.Error+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess)+import qualified Crypto.Internal.ByteArray as B+import Crypto.Internal.Compat+import Crypto.Internal.Imports+import Crypto.Internal.WordArray+ newtype Context = Context Array32 instance NFData Context where@@ -49,7 +49,7 @@ initBlowfish :: ByteArrayAccess key => key -> CryptoFailable Context initBlowfish key | B.length key > (448 `div` 8) = CryptoFailed CryptoError_KeySizeInvalid- | otherwise = CryptoPassed $ unsafeDoIO $ do+ | otherwise = CryptoPassed $ unsafeDoIO $ do ks <- createKeySchedule expandKey ks key freezeKeySchedule ks@@ -58,43 +58,53 @@ freezeKeySchedule :: KeySchedule -> IO Context freezeKeySchedule (KeySchedule ma) = Context `fmap` mutableArray32Freeze ma -expandKey :: (ByteArrayAccess key) => KeySchedule -> key -> IO ()+expandKey :: ByteArrayAccess key => KeySchedule -> key -> IO () expandKey ks@(KeySchedule ma) key = do- when (B.length key > 0) $ iterKeyStream key 0 0 $ \i l r a0 a1 cont-> do+ when (B.length key > 0) $ iterKeyStream key 0 0 $ \i l r a0 a1 cont -> do mutableArrayWriteXor32 ma i l mutableArrayWriteXor32 ma (i + 1) r when (i + 2 < 18) (cont a0 a1) loop 0 0 0- where- loop i l r = do- n <- cipherBlockMutable ks (fromIntegral l `shiftL` 32 .|. fromIntegral r)- let nl = fromIntegral (n `shiftR` 32)- nr = fromIntegral (n .&. 0xffffffff)- mutableArrayWrite32 ma i nl- mutableArrayWrite32 ma (i + 1) nr- when (i < 18 + 1024) (loop (i + 2) nl nr)+ where+ loop i l r = do+ n <- cipherBlockMutable ks (fromIntegral l `shiftL` 32 .|. fromIntegral r)+ let nl = fromIntegral (n `shiftR` 32)+ nr = fromIntegral (n .&. 0xffffffff)+ mutableArrayWrite32 ma i nl+ mutableArrayWrite32 ma (i + 1) nr+ when (i < 18 + 1024) (loop (i + 2) nl nr) -expandKeyWithSalt :: (ByteArrayAccess key, ByteArrayAccess salt)+expandKeyWithSalt+ :: (ByteArrayAccess key, ByteArrayAccess salt) => KeySchedule -> key -> salt -> IO () expandKeyWithSalt ks key salt- | B.length salt == 16 = expandKeyWithSalt128 ks key (fromBE $ B.toW64BE salt 0) (fromBE $ B.toW64BE salt 8)- | otherwise = expandKeyWithSaltAny ks key salt+ | B.length salt == 16 =+ expandKeyWithSalt128+ ks+ key+ (fromBE $ B.toW64BE salt 0)+ (fromBE $ B.toW64BE salt 8)+ | otherwise = expandKeyWithSaltAny ks key salt -expandKeyWithSaltAny :: (ByteArrayAccess key, ByteArrayAccess salt)- => KeySchedule -- ^ The key schedule- -> key -- ^ The key- -> salt -- ^ The salt+expandKeyWithSaltAny+ :: (ByteArrayAccess key, ByteArrayAccess salt)+ => KeySchedule+ -- ^ The key schedule+ -> key+ -- ^ The key+ -> salt+ -- ^ The salt -> IO () expandKeyWithSaltAny ks@(KeySchedule ma) key salt = do- when (B.length key > 0) $ iterKeyStream key 0 0 $ \i l r a0 a1 cont-> do+ when (B.length key > 0) $ iterKeyStream key 0 0 $ \i l r a0 a1 cont -> do mutableArrayWriteXor32 ma i l mutableArrayWriteXor32 ma (i + 1) r when (i + 2 < 18) (cont a0 a1) -- Go through the entire key schedule overwriting the P-Array and S-Boxes- when (B.length salt > 0) $ iterKeyStream salt 0 0 $ \i l r a0 a1 cont-> do+ when (B.length salt > 0) $ iterKeyStream salt 0 0 $ \i l r a0 a1 cont -> do let l' = xor l a0 let r' = xor r a1 n <- cipherBlockMutable ks (fromIntegral l' `shiftL` 32 .|. fromIntegral r')@@ -104,112 +114,119 @@ mutableArrayWrite32 ma (i + 1) nr when (i + 2 < 18 + 1024) (cont nl nr) -expandKeyWithSalt128 :: ByteArrayAccess ba- => KeySchedule -- ^ The key schedule- -> ba -- ^ The key- -> Word64 -- ^ First word of the salt- -> Word64 -- ^ Second word of the salt+expandKeyWithSalt128+ :: ByteArrayAccess ba+ => KeySchedule+ -- ^ The key schedule+ -> ba+ -- ^ The key+ -> Word64+ -- ^ First word of the salt+ -> Word64+ -- ^ Second word of the salt -> IO () expandKeyWithSalt128 ks@(KeySchedule ma) key salt1 salt2 = do- when (B.length key > 0) $ iterKeyStream key 0 0 $ \i l r a0 a1 cont-> do+ when (B.length key > 0) $ iterKeyStream key 0 0 $ \i l r a0 a1 cont -> do mutableArrayWriteXor32 ma i l mutableArrayWriteXor32 ma (i + 1) r when (i + 2 < 18) (cont a0 a1) -- Go through the entire key schedule overwriting the P-Array and S-Boxes loop 0 salt1 salt1 salt2- where- loop i input slt1 slt2- | i == 1042 = return ()- | otherwise = do- n <- cipherBlockMutable ks input- let nl = fromIntegral (n `shiftR` 32)- nr = fromIntegral (n .&. 0xffffffff)- mutableArrayWrite32 ma i nl- mutableArrayWrite32 ma (i+1) nr- loop (i+2) (n `xor` slt2) slt2 slt1+ where+ loop i input slt1 slt2+ | i == 1042 = return ()+ | otherwise = do+ n <- cipherBlockMutable ks input+ let nl = fromIntegral (n `shiftR` 32)+ nr = fromIntegral (n .&. 0xffffffff)+ mutableArrayWrite32 ma i nl+ mutableArrayWrite32 ma (i + 1) nr+ loop (i + 2) (n `xor` slt2) slt2 slt1 -- | Encrypt blocks -- -- Input need to be a multiple of 8 bytes encrypt :: ByteArray ba => Context -> ba -> ba encrypt ctx ba- | B.length ba == 0 = B.empty+ | B.length ba == 0 = B.empty | B.length ba `mod` 8 /= 0 = error "invalid data length"- | otherwise = B.mapAsWord64 (cipherBlock ctx False) ba+ | otherwise = B.mapAsWord64 (cipherBlock ctx False) ba -- | Decrypt blocks -- -- Input need to be a multiple of 8 bytes decrypt :: ByteArray ba => Context -> ba -> ba decrypt ctx ba- | B.length ba == 0 = B.empty+ | B.length ba == 0 = B.empty | B.length ba `mod` 8 /= 0 = error "invalid data length"- | otherwise = B.mapAsWord64 (cipherBlock ctx True) ba+ | otherwise = B.mapAsWord64 (cipherBlock ctx True) ba -- | Encrypt or decrypt a single block of 64 bits. -- -- The inverse argument decides whether to encrypt or decrypt. cipherBlock :: Context -> Bool -> Word64 -> Word64 cipherBlock (Context ar) inverse input = doRound input 0- where- -- | Transform the input over 16 rounds+ where+ -- \| Transform the input over 16 rounds doRound :: Word64 -> Int -> Word64 doRound !i roundIndex | roundIndex == 16 = let final = (fromIntegral (p 16) `shiftL` 32) .|. fromIntegral (p 17) in rotateL (i `xor` final) 32- | otherwise =+ | otherwise = let newr = fromIntegral (i `shiftR` 32) `xor` p roundIndex newi = ((i `shiftL` 32) `xor` f newr) .|. fromIntegral newr- in doRound newi (roundIndex+1)+ in doRound newi (roundIndex + 1) - -- | The Blowfish Feistel function F- f :: Word32 -> Word64- f t = let a = s0 (0xff .&. (t `shiftR` 24))- b = s1 (0xff .&. (t `shiftR` 16))- c = s2 (0xff .&. (t `shiftR` 8))- d = s3 (0xff .&. t)- in fromIntegral (((a + b) `xor` c) + d) `shiftL` 32+ -- \| The Blowfish Feistel function F+ f :: Word32 -> Word64+ f t =+ let a = s0 (0xff .&. (t `shiftR` 24))+ b = s1 (0xff .&. (t `shiftR` 16))+ c = s2 (0xff .&. (t `shiftR` 8))+ d = s3 (0xff .&. t)+ in fromIntegral (((a + b) `xor` c) + d) `shiftL` 32 - -- | S-Box arrays, each containing 256 32-bit words+ -- \| S-Box arrays, each containing 256 32-bit words -- The first 18 words contain the P-Array of subkeys s0, s1, s2, s3 :: Word32 -> Word32- s0 i = arrayRead32 ar (fromIntegral i + 18)- s1 i = arrayRead32 ar (fromIntegral i + 274)- s2 i = arrayRead32 ar (fromIntegral i + 530)- s3 i = arrayRead32 ar (fromIntegral i + 786)- p :: Int -> Word32- p i | inverse = arrayRead32 ar (17 - i)+ s0 i = arrayRead32 ar (fromIntegral i + 18)+ s1 i = arrayRead32 ar (fromIntegral i + 274)+ s2 i = arrayRead32 ar (fromIntegral i + 530)+ s3 i = arrayRead32 ar (fromIntegral i + 786)+ p :: Int -> Word32+ p i+ | inverse = arrayRead32 ar (17 - i) | otherwise = arrayRead32 ar i -- | Blowfish encrypt a Word using the current state of the key schedule cipherBlockMutable :: KeySchedule -> Word64 -> IO Word64 cipherBlockMutable (KeySchedule ma) input = doRound input 0- where- -- | Transform the input over 16 rounds+ where+ -- \| Transform the input over 16 rounds doRound !i roundIndex | roundIndex == 16 = do pVal1 <- mutableArrayRead32 ma 16 pVal2 <- mutableArrayRead32 ma 17 let final = (fromIntegral pVal1 `shiftL` 32) .|. fromIntegral pVal2 return $ rotateL (i `xor` final) 32- | otherwise = do+ | otherwise = do pVal <- mutableArrayRead32 ma roundIndex let newr = fromIntegral (i `shiftR` 32) `xor` pVal newr' <- f newr let newi = ((i `shiftL` 32) `xor` newr') .|. fromIntegral newr- doRound newi (roundIndex+1)+ doRound newi (roundIndex + 1) - -- | The Blowfish Feistel function F- f :: Word32 -> IO Word64+ -- \| The Blowfish Feistel function F+ f :: Word32 -> IO Word64 f t = do a <- s0 (0xff .&. (t `shiftR` 24)) b <- s1 (0xff .&. (t `shiftR` 16)) c <- s2 (0xff .&. (t `shiftR` 8))- d <- s3 (0xff .&. t)+ d <- s3 (0xff .&. t) return (fromIntegral (((a + b) `xor` c) + d) `shiftL` 32) - -- | S-Box arrays, each containing 256 32-bit words+ -- \| S-Box arrays, each containing 256 32-bit words -- The first 18 words contain the P-Array of subkeys s0, s1, s2, s3 :: Word32 -> IO Word32 s0 i = mutableArrayRead32 ma (fromIntegral i + 18)@@ -217,41 +234,50 @@ s2 i = mutableArrayRead32 ma (fromIntegral i + 530) s3 i = mutableArrayRead32 ma (fromIntegral i + 786) -iterKeyStream :: (ByteArrayAccess x)+iterKeyStream+ :: ByteArrayAccess x => x -> Word32 -> Word32- -> (Int -> Word32 -> Word32 -> Word32 -> Word32 -> (Word32 -> Word32 -> IO ()) -> IO ())+ -> ( Int+ -> Word32+ -> Word32+ -> Word32+ -> Word32+ -> (Word32 -> Word32 -> IO ())+ -> IO ()+ ) -> IO () iterKeyStream x a0 a1 g = f 0 0 a0 a1- where- len = B.length x- -- Avoiding the modulo operation when interating over the ring- -- buffer is assumed to be more efficient here. All other- -- implementations do this, too. The branch prediction shall prefer- -- the branch with the increment.- n j = if j + 1 >= len then 0 else j + 1- f i j0 b0 b1 = g i l r b0 b1 (f (i + 2) j8)- where- j1 = n j0- j2 = n j1- j3 = n j2- j4 = n j3- j5 = n j4- j6 = n j5- j7 = n j6- j8 = n j7- x0 = fromIntegral (B.index x j0)- x1 = fromIntegral (B.index x j1)- x2 = fromIntegral (B.index x j2)- x3 = fromIntegral (B.index x j3)- x4 = fromIntegral (B.index x j4)- x5 = fromIntegral (B.index x j5)- x6 = fromIntegral (B.index x j6)- x7 = fromIntegral (B.index x j7)- l = shiftL x0 24 .|. shiftL x1 16 .|. shiftL x2 8 .|. x3- r = shiftL x4 24 .|. shiftL x5 16 .|. shiftL x6 8 .|. x7+ where+ len = B.length x+ -- Avoiding the modulo operation when interating over the ring+ -- buffer is assumed to be more efficient here. All other+ -- implementations do this, too. The branch prediction shall prefer+ -- the branch with the increment.+ n j = if j + 1 >= len then 0 else j + 1+ f i j0 b0 b1 = g i l r b0 b1 (f (i + 2) j8)+ where+ j1 = n j0+ j2 = n j1+ j3 = n j2+ j4 = n j3+ j5 = n j4+ j6 = n j5+ j7 = n j6+ j8 = n j7+ x0 = fromIntegral (B.index x j0)+ x1 = fromIntegral (B.index x j1)+ x2 = fromIntegral (B.index x j2)+ x3 = fromIntegral (B.index x j3)+ x4 = fromIntegral (B.index x j4)+ x5 = fromIntegral (B.index x j5)+ x6 = fromIntegral (B.index x j6)+ x7 = fromIntegral (B.index x j7)+ l = shiftL x0 24 .|. shiftL x1 16 .|. shiftL x2 8 .|. x3+ r = shiftL x4 24 .|. shiftL x5 16 .|. shiftL x6 8 .|. x7 {-# INLINE iterKeyStream #-}+ -- Benchmarking shows that GHC considers this function too big to inline -- although forcing inlining causes an actual improvement. -- It is assumed that all function calls (especially the continuation)
Crypto/Cipher/CAST5.hs view
@@ -4,15 +4,14 @@ -- Maintainer : Olivier Chéron <olivier.cheron@gmail.com> -- Stability : stable -- Portability : good----module Crypto.Cipher.CAST5- ( CAST5- ) where+module Crypto.Cipher.CAST5 (+ CAST5,+) where -import Crypto.Error-import Crypto.Cipher.Types-import Crypto.Cipher.CAST5.Primitive-import Crypto.Internal.ByteArray (ByteArrayAccess)+import Crypto.Cipher.CAST5.Primitive+import Crypto.Cipher.Types+import Crypto.Error+import Crypto.Internal.ByteArray (ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B -- | CAST5 block cipher (also known as CAST-128). Key is between@@ -20,9 +19,9 @@ newtype CAST5 = CAST5 Key instance Cipher CAST5 where- cipherName _ = "CAST5"+ cipherName _ = "CAST5" cipherKeySize _ = KeySizeRange 5 16- cipherInit = initCAST5+ cipherInit = initCAST5 instance BlockCipher CAST5 where blockSize _ = 8@@ -31,12 +30,12 @@ initCAST5 :: ByteArrayAccess key => key -> CryptoFailable CAST5 initCAST5 bs- | len < 5 = CryptoFailed CryptoError_KeySizeInvalid- | len < 16 = CryptoPassed (CAST5 $ buildKey short padded)+ | len < 5 = CryptoFailed CryptoError_KeySizeInvalid+ | len < 16 = CryptoPassed (CAST5 $ buildKey short padded) | len == 16 = CryptoPassed (CAST5 $ buildKey False bs) | otherwise = CryptoFailed CryptoError_KeySizeInvalid where- len = B.length bs+ len = B.length bs short = len <= 10 padded :: B.Bytes
Crypto/Cipher/CAST5/Primitive.hs view
@@ -1,21 +1,20 @@ {-# LANGUAGE MagicHash #-} -----------------------------------------------------------------------------++-----------------------------------------------------------------------------+ -- | -- Module : Crypto.Cipher.CAST5.Primitive -- License : BSD-style -- -- Haskell implementation of the CAST-128 Encryption Algorithm------------------------------------------------------------------------------------module Crypto.Cipher.CAST5.Primitive- ( encrypt- , decrypt- , Key()- , buildKey- ) where+module Crypto.Cipher.CAST5.Primitive (+ encrypt,+ decrypt,+ Key (),+ buildKey,+) where import Control.Monad (void, (>=>)) @@ -23,23 +22,28 @@ import Data.Memory.Endian import Data.Word -import Crypto.Internal.ByteArray (ByteArrayAccess)+import Crypto.Internal.ByteArray (ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.WordArray-+import Crypto.Internal.WordArray -- Data Types -data P = P {-# UNPACK #-} !Word32 -- left word- {-# UNPACK #-} !Word32 -- right word+data P+ = P+ {-# UNPACK #-} !Word32 -- left word+ {-# UNPACK #-} !Word32 -- right word -data Q = Q {-# UNPACK #-} !Word32 {-# UNPACK #-} !Word32- {-# UNPACK #-} !Word32 {-# UNPACK #-} !Word32+data Q+ = Q+ {-# UNPACK #-} !Word32+ {-# UNPACK #-} !Word32+ {-# UNPACK #-} !Word32+ {-# UNPACK #-} !Word32 -- | All subkeys for 12 or 16 rounds-data Key = K12 {-# UNPACK #-} !Array32 -- [ km1, kr1, km2, kr2, ..., km12, kr12 ]- | K16 {-# UNPACK #-} !Array32 -- [ km1, kr1, km2, kr2, ..., km16, kr16 ]-+data Key+ = K12 {-# UNPACK #-} !Array32 -- [ km1, kr1, km2, kr2, ..., km12, kr12 ]+ | K16 {-# UNPACK #-} !Array32 -- [ km1, kr1, km2, kr2, ..., km16, kr16 ] -- Big-endian Transformations @@ -53,10 +57,9 @@ decomp32 x = let a = fromIntegral (x `shiftR` 24) b = fromIntegral (x `shiftR` 16)- c = fromIntegral (x `shiftR` 8)+ c = fromIntegral (x `shiftR` 8) d = fromIntegral x- in (a, b, c, d)-+ in (a, b, c, d) -- Encryption @@ -67,19 +70,18 @@ cast_enc :: Key -> P -> P cast_enc (K12 a) (P l0 r0) = P r12 r11 where- r1 = type1 a 0 l0 r0- r2 = type2 a 2 r0 r1- r3 = type3 a 4 r1 r2- r4 = type1 a 6 r2 r3- r5 = type2 a 8 r3 r4- r6 = type3 a 10 r4 r5- r7 = type1 a 12 r5 r6- r8 = type2 a 14 r6 r7- r9 = type3 a 16 r7 r8- r10 = type1 a 18 r8 r9- r11 = type2 a 20 r9 r10+ r1 = type1 a 0 l0 r0+ r2 = type2 a 2 r0 r1+ r3 = type3 a 4 r1 r2+ r4 = type1 a 6 r2 r3+ r5 = type2 a 8 r3 r4+ r6 = type3 a 10 r4 r5+ r7 = type1 a 12 r5 r6+ r8 = type2 a 14 r6 r7+ r9 = type3 a 16 r7 r8+ r10 = type1 a 18 r8 r9+ r11 = type2 a 20 r9 r10 r12 = type3 a 22 r10 r11- cast_enc (K16 a) p = P r16 r15 where P r12 r11 = cast_enc (K12 a) p@@ -99,18 +101,17 @@ cast_dec (K12 a) (P r12 r11) = P l0 r0 where r10 = type3 a 22 r12 r11- r9 = type2 a 20 r11 r10- r8 = type1 a 18 r10 r9- r7 = type3 a 16 r9 r8- r6 = type2 a 14 r8 r7- r5 = type1 a 12 r7 r6- r4 = type3 a 10 r6 r5- r3 = type2 a 8 r5 r4- r2 = type1 a 6 r4 r3- r1 = type3 a 4 r3 r2- r0 = type2 a 2 r2 r1- l0 = type1 a 0 r1 r0-+ r9 = type2 a 20 r11 r10+ r8 = type1 a 18 r10 r9+ r7 = type3 a 16 r9 r8+ r6 = type2 a 14 r8 r7+ r5 = type1 a 12 r7 r6+ r4 = type3 a 10 r6 r5+ r3 = type2 a 8 r5 r4+ r2 = type1 a 6 r4 r3+ r1 = type3 a 4 r3 r2+ r0 = type2 a 2 r2 r1+ l0 = type1 a 0 r1 r0 cast_dec (K16 a) (P r16 r15) = cast_dec (K12 a) (P r12 r11) where r14 = type1 a 30 r16 r15@@ -118,7 +119,6 @@ r12 = type2 a 26 r14 r13 r11 = type1 a 24 r13 r12 - -- Non-Identical Rounds type1 :: Array32 -> Int -> Word32 -> Word32 -> Word32@@ -145,14 +145,17 @@ (ja, jb, jc, jd) = decomp32 j in l `xor` (((sbox_s1 ja + sbox_s2 jb) `xor` sbox_s3 jc) - sbox_s4 jd) - -- Key Schedule -- | Precompute "masking" and "rotation" subkeys-buildKey :: ByteArrayAccess key- => Bool -- ^ @True@ for short keys that only need 12 rounds- -> key -- ^ Input key padded to 16 bytes- -> Key -- ^ Output data structure+buildKey+ :: ByteArrayAccess key+ => Bool+ -- ^ @True@ for short keys that only need 12 rounds+ -> key+ -- ^ Input key padded to 16 bytes+ -> Key+ -- ^ Output data structure buildKey isShort key = let P x0123 x4567 = decomp64 (fromBE $ B.toW64BE key 0) P x89AB xCDEF = decomp64 (fromBE $ B.toW64BE key 8)@@ -160,12 +163,10 @@ keySchedule :: Bool -> Q -> Key keySchedule isShort x- | isShort = K12 $ allocArray32AndFreeze 24 $ \ma ->+ | isShort = K12 $ allocArray32AndFreeze 24 $ \ma -> void (steps123 ma 0 x >>= skip4 >>= steps123 ma 1)- | otherwise = K16 $ allocArray32AndFreeze 32 $ \ma -> void (steps123 ma 0 x >>= step4 ma 24 >>= steps123 ma 1 >>= step4 ma 25)- where sbox_s56785 a b c d e = sbox_s5 a `xor` sbox_s6 b `xor` sbox_s7 c `xor` sbox_s8 d `xor` sbox_s5 e sbox_s56786 a b c d e = sbox_s5 a `xor` sbox_s6 b `xor` sbox_s7 c `xor` sbox_s8 d `xor` sbox_s6 e@@ -279,7 +280,9 @@ sbox_s1 :: Word8 -> Word32 sbox_s1 i = arrayRead32 t (fromIntegral i) where- t = array32FromAddrBE 256+ t =+ array32FromAddrBE+ 256 "\x30\xfb\x40\xd4\x9f\xa0\xff\x0b\x6b\xec\xcd\x2f\x3f\x25\x8c\x7a\x1e\x21\x3f\x2f\x9c\x00\x4d\xd3\x60\x03\xe5\x40\xcf\x9f\xc9\x49\ \\xbf\xd4\xaf\x27\x88\xbb\xbd\xb5\xe2\x03\x40\x90\x98\xd0\x96\x75\x6e\x63\xa0\xe0\x15\xc3\x61\xd2\xc2\xe7\x66\x1d\x22\xd4\xff\x8e\ \\x28\x68\x3b\x6f\xc0\x7f\xd0\x59\xff\x23\x79\xc8\x77\x5f\x50\xe2\x43\xc3\x40\xd3\xdf\x2f\x86\x56\x88\x7c\xa4\x1a\xa2\xd2\xbd\x2d\@@ -316,7 +319,9 @@ sbox_s2 :: Word8 -> Word32 sbox_s2 i = arrayRead32 t (fromIntegral i) where- t = array32FromAddrBE 256+ t =+ array32FromAddrBE+ 256 "\x1f\x20\x10\x94\xef\x0b\xa7\x5b\x69\xe3\xcf\x7e\x39\x3f\x43\x80\xfe\x61\xcf\x7a\xee\xc5\x20\x7a\x55\x88\x9c\x94\x72\xfc\x06\x51\ \\xad\xa7\xef\x79\x4e\x1d\x72\x35\xd5\x5a\x63\xce\xde\x04\x36\xba\x99\xc4\x30\xef\x5f\x0c\x07\x94\x18\xdc\xdb\x7d\xa1\xd6\xef\xf3\ \\xa0\xb5\x2f\x7b\x59\xe8\x36\x05\xee\x15\xb0\x94\xe9\xff\xd9\x09\xdc\x44\x00\x86\xef\x94\x44\x59\xba\x83\xcc\xb3\xe0\xc3\xcd\xfb\@@ -353,7 +358,9 @@ sbox_s3 :: Word8 -> Word32 sbox_s3 i = arrayRead32 t (fromIntegral i) where- t = array32FromAddrBE 256+ t =+ array32FromAddrBE+ 256 "\x8d\xef\xc2\x40\x25\xfa\x5d\x9f\xeb\x90\x3d\xbf\xe8\x10\xc9\x07\x47\x60\x7f\xff\x36\x9f\xe4\x4b\x8c\x1f\xc6\x44\xae\xce\xca\x90\ \\xbe\xb1\xf9\xbf\xee\xfb\xca\xea\xe8\xcf\x19\x50\x51\xdf\x07\xae\x92\x0e\x88\x06\xf0\xad\x05\x48\xe1\x3c\x8d\x83\x92\x70\x10\xd5\ \\x11\x10\x7d\x9f\x07\x64\x7d\xb9\xb2\xe3\xe4\xd4\x3d\x4f\x28\x5e\xb9\xaf\xa8\x20\xfa\xde\x82\xe0\xa0\x67\x26\x8b\x82\x72\x79\x2e\@@ -390,7 +397,9 @@ sbox_s4 :: Word8 -> Word32 sbox_s4 i = arrayRead32 t (fromIntegral i) where- t = array32FromAddrBE 256+ t =+ array32FromAddrBE+ 256 "\x9d\xb3\x04\x20\x1f\xb6\xe9\xde\xa7\xbe\x7b\xef\xd2\x73\xa2\x98\x4a\x4f\x7b\xdb\x64\xad\x8c\x57\x85\x51\x04\x43\xfa\x02\x0e\xd1\ \\x7e\x28\x7a\xff\xe6\x0f\xb6\x63\x09\x5f\x35\xa1\x79\xeb\xf1\x20\xfd\x05\x9d\x43\x64\x97\xb7\xb1\xf3\x64\x1f\x63\x24\x1e\x4a\xdf\ \\x28\x14\x7f\x5f\x4f\xa2\xb8\xcd\xc9\x43\x00\x40\x0c\xc3\x22\x20\xfd\xd3\x0b\x30\xc0\xa5\x37\x4f\x1d\x2d\x00\xd9\x24\x14\x7b\x15\@@ -427,7 +436,9 @@ sbox_s5 :: Word8 -> Word32 sbox_s5 i = arrayRead32 t (fromIntegral i) where- t = array32FromAddrBE 256+ t =+ array32FromAddrBE+ 256 "\x7e\xc9\x0c\x04\x2c\x6e\x74\xb9\x9b\x0e\x66\xdf\xa6\x33\x79\x11\xb8\x6a\x7f\xff\x1d\xd3\x58\xf5\x44\xdd\x9d\x44\x17\x31\x16\x7f\ \\x08\xfb\xf1\xfa\xe7\xf5\x11\xcc\xd2\x05\x1b\x00\x73\x5a\xba\x00\x2a\xb7\x22\xd8\x38\x63\x81\xcb\xac\xf6\x24\x3a\x69\xbe\xfd\x7a\ \\xe6\xa2\xe7\x7f\xf0\xc7\x20\xcd\xc4\x49\x48\x16\xcc\xf5\xc1\x80\x38\x85\x16\x40\x15\xb0\xa8\x48\xe6\x8b\x18\xcb\x4c\xaa\xde\xff\@@ -464,7 +475,9 @@ sbox_s6 :: Word8 -> Word32 sbox_s6 i = arrayRead32 t (fromIntegral i) where- t = array32FromAddrBE 256+ t =+ array32FromAddrBE+ 256 "\xf6\xfa\x8f\x9d\x2c\xac\x6c\xe1\x4c\xa3\x48\x67\xe2\x33\x7f\x7c\x95\xdb\x08\xe7\x01\x68\x43\xb4\xec\xed\x5c\xbc\x32\x55\x53\xac\ \\xbf\x9f\x09\x60\xdf\xa1\xe2\xed\x83\xf0\x57\x9d\x63\xed\x86\xb9\x1a\xb6\xa6\xb8\xde\x5e\xbe\x39\xf3\x8f\xf7\x32\x89\x89\xb1\x38\ \\x33\xf1\x49\x61\xc0\x19\x37\xbd\xf5\x06\xc6\xda\xe4\x62\x5e\x7e\xa3\x08\xea\x99\x4e\x23\xe3\x3c\x79\xcb\xd7\xcc\x48\xa1\x43\x67\@@ -501,7 +514,9 @@ sbox_s7 :: Word8 -> Word32 sbox_s7 i = arrayRead32 t (fromIntegral i) where- t = array32FromAddrBE 256+ t =+ array32FromAddrBE+ 256 "\x85\xe0\x40\x19\x33\x2b\xf5\x67\x66\x2d\xbf\xff\xcf\xc6\x56\x93\x2a\x8d\x7f\x6f\xab\x9b\xc9\x12\xde\x60\x08\xa1\x20\x28\xda\x1f\ \\x02\x27\xbc\xe7\x4d\x64\x29\x16\x18\xfa\xc3\x00\x50\xf1\x8b\x82\x2c\xb2\xcb\x11\xb2\x32\xe7\x5c\x4b\x36\x95\xf2\xb2\x87\x07\xde\ \\xa0\x5f\xbc\xf6\xcd\x41\x81\xe9\xe1\x50\x21\x0c\xe2\x4e\xf1\xbd\xb1\x68\xc3\x81\xfd\xe4\xe7\x89\x5c\x79\xb0\xd8\x1e\x8b\xfd\x43\@@ -538,7 +553,9 @@ sbox_s8 :: Word8 -> Word32 sbox_s8 i = arrayRead32 t (fromIntegral i) where- t = array32FromAddrBE 256+ t =+ array32FromAddrBE+ 256 "\xe2\x16\x30\x0d\xbb\xdd\xff\xfc\xa7\xeb\xda\xbd\x35\x64\x80\x95\x77\x89\xf8\xb7\xe6\xc1\x12\x1b\x0e\x24\x16\x00\x05\x2c\xe8\xb5\ \\x11\xa9\xcf\xb0\xe5\x95\x2f\x11\xec\xe7\x99\x0a\x93\x86\xd1\x74\x2a\x42\x93\x1c\x76\xe3\x81\x11\xb1\x2d\xef\x3a\x37\xdd\xdd\xfc\ \\xde\x9a\xde\xb1\x0a\x0c\xc3\x2c\xbe\x19\x70\x29\x84\xa0\x09\x40\xbb\x24\x3a\x0f\xb4\xd1\x37\xcf\xb4\x4e\x79\xf0\x04\x9e\xed\xfd\
Crypto/Cipher/Camellia.hs view
@@ -6,10 +6,9 @@ -- Portability : Good -- -- Camellia support. only 128 bit variant available for now.--module Crypto.Cipher.Camellia- ( Camellia128- ) where+module Crypto.Cipher.Camellia (+ Camellia128,+) where import Crypto.Cipher.Camellia.Primitive import Crypto.Cipher.Types@@ -18,9 +17,9 @@ newtype Camellia128 = Camellia128 Camellia instance Cipher Camellia128 where- cipherName _ = "Camellia128"+ cipherName _ = "Camellia128" cipherKeySize _ = KeySizeFixed 16- cipherInit k = Camellia128 `fmap` initCamellia k+ cipherInit k = Camellia128 `fmap` initCamellia k instance BlockCipher Camellia128 where blockSize _ = 16
Crypto/Cipher/Camellia/Primitive.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE MagicHash #-} -- | -- Module : Crypto.Cipher.Camellia.Primitive@@ -8,23 +9,22 @@ -- -- This only cover Camellia 128 bits for now. The API will change once -- 192 and 256 mode are implemented too.-{-# LANGUAGE MagicHash #-}-module Crypto.Cipher.Camellia.Primitive- ( Camellia- , initCamellia- , encrypt- , decrypt- ) where+module Crypto.Cipher.Camellia.Primitive (+ Camellia,+ initCamellia,+ encrypt,+ decrypt,+) where -import Data.Word-import Data.Bits+import Data.Bits+import Data.Word -import Crypto.Error-import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray)+import Crypto.Error+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.Words-import Crypto.Internal.WordArray-import Data.Memory.Endian+import Crypto.Internal.WordArray+import Crypto.Internal.Words+import Data.Memory.Endian data Mode = Decrypt | Encrypt @@ -33,30 +33,32 @@ w64tow8 :: Word64 -> (Word8, Word8, Word8, Word8, Word8, Word8, Word8, Word8) w64tow8 x = (t1, t2, t3, t4, t5, t6, t7, t8)- where- t1 = fromIntegral (x `shiftR` 56)- t2 = fromIntegral (x `shiftR` 48)- t3 = fromIntegral (x `shiftR` 40)- t4 = fromIntegral (x `shiftR` 32)- t5 = fromIntegral (x `shiftR` 24)- t6 = fromIntegral (x `shiftR` 16)- t7 = fromIntegral (x `shiftR` 8)- t8 = fromIntegral (x)+ where+ t1 = fromIntegral (x `shiftR` 56)+ t2 = fromIntegral (x `shiftR` 48)+ t3 = fromIntegral (x `shiftR` 40)+ t4 = fromIntegral (x `shiftR` 32)+ t5 = fromIntegral (x `shiftR` 24)+ t6 = fromIntegral (x `shiftR` 16)+ t7 = fromIntegral (x `shiftR` 8)+ t8 = fromIntegral (x) w8tow64 :: (Word8, Word8, Word8, Word8, Word8, Word8, Word8, Word8) -> Word64-w8tow64 (t1,t2,t3,t4,t5,t6,t7,t8) =- (fromIntegral t1 `shiftL` 56) .|.- (fromIntegral t2 `shiftL` 48) .|.- (fromIntegral t3 `shiftL` 40) .|.- (fromIntegral t4 `shiftL` 32) .|.- (fromIntegral t5 `shiftL` 24) .|.- (fromIntegral t6 `shiftL` 16) .|.- (fromIntegral t7 `shiftL` 8) .|.- (fromIntegral t8)+w8tow64 (t1, t2, t3, t4, t5, t6, t7, t8) =+ (fromIntegral t1 `shiftL` 56)+ .|. (fromIntegral t2 `shiftL` 48)+ .|. (fromIntegral t3 `shiftL` 40)+ .|. (fromIntegral t4 `shiftL` 32)+ .|. (fromIntegral t5 `shiftL` 24)+ .|. (fromIntegral t6 `shiftL` 16)+ .|. (fromIntegral t7 `shiftL` 8)+ .|. (fromIntegral t8) sbox :: Int -> Word8 sbox = arrayRead8 t- where t = array8+ where+ t =+ array8 "\x70\x82\x2c\xec\xb3\x27\xc0\xe5\xe4\x85\x57\x35\xea\x0c\xae\x41\ \\x23\xef\x6b\x93\x45\x19\xa5\x21\xed\x0e\x4f\x4e\x1d\x65\x92\xbd\ \\x86\xb8\xaf\x8f\x7c\xeb\x1f\xce\x3e\x30\xdc\x5f\x5e\xc5\x0b\x1a\@@ -95,116 +97,142 @@ sigma6 = 0xB05688C2B3E6C1FD rotl128 :: Word128 -> Int -> Word128-rotl128 v 0 = v+rotl128 v 0 = v rotl128 (Word128 x1 x2) 64 = Word128 x2 x1- rotl128 v@(Word128 x1 x2) w- | w > 64 = (v `rotl128` 64) `rotl128` (w - 64)+ | w > 64 = (v `rotl128` 64) `rotl128` (w - 64) | otherwise = Word128 (x1high .|. x2low) (x2high .|. x1low)- where- splitBits i = (i .&. complement x, i .&. x)- where x = 2 ^ w - 1- (x1high, x1low) = splitBits (x1 `rotateL` w)- (x2high, x2low) = splitBits (x2 `rotateL` w)+ where+ splitBits i = (i .&. complement x, i .&. x)+ where+ x = 2 ^ w - 1+ (x1high, x1low) = splitBits (x1 `rotateL` w)+ (x2high, x2low) = splitBits (x2 `rotateL` w) -- | Camellia context data Camellia = Camellia- { k :: Array64+ { k :: Array64 , kw :: Array64 , ke :: Array64 } -setKeyInterim :: ByteArrayAccess key => key -> (Word128, Word128, Word128, Word128)+setKeyInterim+ :: ByteArrayAccess key => key -> (Word128, Word128, Word128, Word128) setKeyInterim keyseed = (w64tow128 kL, w64tow128 kR, w64tow128 kA, w64tow128 kB)- where kL = (fromBE $ B.toW64BE keyseed 0, fromBE $ B.toW64BE keyseed 8)- kR = (0, 0)+ where+ kL = (fromBE $ B.toW64BE keyseed 0, fromBE $ B.toW64BE keyseed 8)+ kR = (0, 0) - kA = let d1 = (fst kL `xor` fst kR)- d2 = (snd kL `xor` snd kR)- d3 = d2 `xor` feistel d1 sigma1- d4 = d1 `xor` feistel d3 sigma2- d5 = d4 `xor` (fst kL)- d6 = d3 `xor` (snd kL)- d7 = d6 `xor` feistel d5 sigma3- d8 = d5 `xor` feistel d7 sigma4- in (d8, d7)+ kA =+ let d1 = (fst kL `xor` fst kR)+ d2 = (snd kL `xor` snd kR)+ d3 = d2 `xor` feistel d1 sigma1+ d4 = d1 `xor` feistel d3 sigma2+ d5 = d4 `xor` (fst kL)+ d6 = d3 `xor` (snd kL)+ d7 = d6 `xor` feistel d5 sigma3+ d8 = d5 `xor` feistel d7 sigma4+ in (d8, d7) - kB = let d1 = (fst kA `xor` fst kR)- d2 = (snd kA `xor` snd kR)- d3 = d2 `xor` feistel d1 sigma5- d4 = d1 `xor` feistel d3 sigma6- in (d4, d3)+ kB =+ let d1 = (fst kA `xor` fst kR)+ d2 = (snd kA `xor` snd kR)+ d3 = d2 `xor` feistel d1 sigma5+ d4 = d1 `xor` feistel d3 sigma6+ in (d4, d3) -- | Initialize a 128-bit key ----- Return the initialized key or a error message if the given +-- Return the initialized key or a error message if the given -- keyseed was not 16-bytes in length.-initCamellia :: ByteArray key- => key -- ^ The key to create the camellia context- -> CryptoFailable Camellia+initCamellia+ :: ByteArray key+ => key+ -- ^ The key to create the camellia context+ -> CryptoFailable Camellia initCamellia key | B.length key /= 16 = CryptoFailed $ CryptoError_KeySizeInvalid- | otherwise =- let (kL, _, kA, _) = setKeyInterim key in-- let (Word128 kw1 kw2) = (kL `rotl128` 0) in- let (Word128 k1 k2) = (kA `rotl128` 0) in- let (Word128 k3 k4) = (kL `rotl128` 15) in- let (Word128 k5 k6) = (kA `rotl128` 15) in- let (Word128 ke1 ke2) = (kA `rotl128` 30) in --ke1 = (KA <<< 30) >> 64; ke2 = (KA <<< 30) & MASK64;- let (Word128 k7 k8) = (kL `rotl128` 45) in --k7 = (KL <<< 45) >> 64; k8 = (KL <<< 45) & MASK64;- let (Word128 k9 _) = (kA `rotl128` 45) in --k9 = (KA <<< 45) >> 64;- let (Word128 _ k10) = (kL `rotl128` 60) in- let (Word128 k11 k12) = (kA `rotl128` 60) in- let (Word128 ke3 ke4) = (kL `rotl128` 77) in- let (Word128 k13 k14) = (kL `rotl128` 94) in- let (Word128 k15 k16) = (kA `rotl128` 94) in- let (Word128 k17 k18) = (kL `rotl128` 111) in- let (Word128 kw3 kw4) = (kA `rotl128` 111) in-- CryptoPassed $ Camellia- { kw = array64 4 [ kw1, kw2, kw3, kw4 ]- , ke = array64 4 [ ke1, ke2, ke3, ke4 ]- , k = array64 18 [ k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, k14, k15, k16, k17, k18 ]- }+ | otherwise =+ let (kL, _, kA, _) = setKeyInterim key+ in let (Word128 kw1 kw2) = (kL `rotl128` 0)+ in let (Word128 k1 k2) = (kA `rotl128` 0)+ in let (Word128 k3 k4) = (kL `rotl128` 15)+ in let (Word128 k5 k6) = (kA `rotl128` 15)+ in let (Word128 ke1 ke2) = (kA `rotl128` 30) -- ke1 = (KA <<< 30) >> 64; ke2 = (KA <<< 30) & MASK64;+ in let (Word128 k7 k8) = (kL `rotl128` 45) -- k7 = (KL <<< 45) >> 64; k8 = (KL <<< 45) & MASK64;+ in let (Word128 k9 _) = (kA `rotl128` 45) -- k9 = (KA <<< 45) >> 64;+ in let (Word128 _ k10) = (kL `rotl128` 60)+ in let (Word128 k11 k12) = (kA `rotl128` 60)+ in let (Word128 ke3 ke4) = (kL `rotl128` 77)+ in let (Word128 k13 k14) = (kL `rotl128` 94)+ in let (Word128 k15 k16) = (kA `rotl128` 94)+ in let (Word128 k17 k18) = (kL `rotl128` 111)+ in let (Word128 kw3 kw4) = (kA `rotl128` 111)+ in CryptoPassed $+ Camellia+ { kw = array64 4 [kw1, kw2, kw3, kw4]+ , ke = array64 4 [ke1, ke2, ke3, ke4]+ , k =+ array64+ 18+ [ k1+ , k2+ , k3+ , k4+ , k5+ , k6+ , k7+ , k8+ , k9+ , k10+ , k11+ , k12+ , k13+ , k14+ , k15+ , k16+ , k17+ , k18+ ]+ } feistel :: Word64 -> Word64 -> Word64-feistel fin sk = - let x = fin `xor` sk in- let (t1, t2, t3, t4, t5, t6, t7, t8) = w64tow8 x in- let t1' = sbox1 t1 in- let t2' = sbox2 t2 in- let t3' = sbox3 t3 in- let t4' = sbox4 t4 in- let t5' = sbox2 t5 in- let t6' = sbox3 t6 in- let t7' = sbox4 t7 in- let t8' = sbox1 t8 in- let y1 = t1' `xor` t3' `xor` t4' `xor` t6' `xor` t7' `xor` t8' in- let y2 = t1' `xor` t2' `xor` t4' `xor` t5' `xor` t7' `xor` t8' in- let y3 = t1' `xor` t2' `xor` t3' `xor` t5' `xor` t6' `xor` t8' in- let y4 = t2' `xor` t3' `xor` t4' `xor` t5' `xor` t6' `xor` t7' in- let y5 = t1' `xor` t2' `xor` t6' `xor` t7' `xor` t8' in- let y6 = t2' `xor` t3' `xor` t5' `xor` t7' `xor` t8' in- let y7 = t3' `xor` t4' `xor` t5' `xor` t6' `xor` t8' in- let y8 = t1' `xor` t4' `xor` t5' `xor` t6' `xor` t7' in- w8tow64 (y1, y2, y3, y4, y5, y6, y7, y8)+feistel fin sk =+ let x = fin `xor` sk+ in let (t1, t2, t3, t4, t5, t6, t7, t8) = w64tow8 x+ in let t1' = sbox1 t1+ in let t2' = sbox2 t2+ in let t3' = sbox3 t3+ in let t4' = sbox4 t4+ in let t5' = sbox2 t5+ in let t6' = sbox3 t6+ in let t7' = sbox4 t7+ in let t8' = sbox1 t8+ in let y1 = t1' `xor` t3' `xor` t4' `xor` t6' `xor` t7' `xor` t8'+ in let y2 = t1' `xor` t2' `xor` t4' `xor` t5' `xor` t7' `xor` t8'+ in let y3 = t1' `xor` t2' `xor` t3' `xor` t5' `xor` t6' `xor` t8'+ in let y4 = t2' `xor` t3' `xor` t4' `xor` t5' `xor` t6' `xor` t7'+ in let y5 = t1' `xor` t2' `xor` t6' `xor` t7' `xor` t8'+ in let y6 = t2' `xor` t3' `xor` t5' `xor` t7' `xor` t8'+ in let y7 = t3' `xor` t4' `xor` t5' `xor` t6' `xor` t8'+ in let y8 = t1' `xor` t4' `xor` t5' `xor` t6' `xor` t7'+ in w8tow64 (y1, y2, y3, y4, y5, y6, y7, y8) fl :: Word64 -> Word64 -> Word64 fl fin sk =- let (x1, x2) = w64to32 fin in- let (k1, k2) = w64to32 sk in- let y2 = x2 `xor` ((x1 .&. k1) `rotateL` 1) in- let y1 = x1 `xor` (y2 .|. k2) in- w32to64 (y1, y2)+ let (x1, x2) = w64to32 fin+ in let (k1, k2) = w64to32 sk+ in let y2 = x2 `xor` ((x1 .&. k1) `rotateL` 1)+ in let y1 = x1 `xor` (y2 .|. k2)+ in w32to64 (y1, y2) flinv :: Word64 -> Word64 -> Word64 flinv fin sk =- let (y1, y2) = w64to32 fin in- let (k1, k2) = w64to32 sk in- let x1 = y1 `xor` (y2 .|. k2) in- let x2 = y2 `xor` ((x1 .&. k1) `rotateL` 1) in- w32to64 (x1, x2)+ let (y1, y2) = w64to32 fin+ in let (k1, k2) = w64to32 sk+ in let x1 = y1 `xor` (y2 .|. k2)+ in let x2 = y2 `xor` ((x1 .&. k1) `rotateL` 1)+ in w32to64 (x1, x2) {- in decrypt mode 0->17 1->16 ... -} getKeyK :: Mode -> Camellia -> Int -> Word64@@ -231,34 +259,28 @@ -} doBlockRound :: Mode -> Camellia -> Word64 -> Word64 -> Int -> (Word64, Word64) doBlockRound mode key d1 d2 i =- let r1 = d2 `xor` feistel d1 (getKeyK mode key (0+i)) in {- Round 1+i -}- let r2 = d1 `xor` feistel r1 (getKeyK mode key (1+i)) in {- Round 2+i -}- let r3 = r1 `xor` feistel r2 (getKeyK mode key (2+i)) in {- Round 3+i -}- let r4 = r2 `xor` feistel r3 (getKeyK mode key (3+i)) in {- Round 4+i -}- let r5 = r3 `xor` feistel r4 (getKeyK mode key (4+i)) in {- Round 5+i -}- let r6 = r4 `xor` feistel r5 (getKeyK mode key (5+i)) in {- Round 6+i -}- (r6, r5)+ let r1 = d2 `xor` feistel d1 (getKeyK mode key (0 + i {- Round 1+i -}))+ in let r2 = d1 `xor` feistel r1 (getKeyK mode key (1 + i {- Round 2+i -}))+ in let r3 = r1 `xor` feistel r2 (getKeyK mode key (2 + i {- Round 3+i -}))+ in let r4 = r2 `xor` feistel r3 (getKeyK mode key (3 + i {- Round 4+i -}))+ in let r5 = r3 `xor` feistel r4 (getKeyK mode key (4 + i {- Round 5+i -}))+ in let r6 = r4 `xor` feistel r5 (getKeyK mode key (5 + i {- Round 6+i -}))+ in (r6, r5) doBlock :: Mode -> Camellia -> Word128 -> Word128 doBlock mode key (Word128 d1 d2) =- let d1a = d1 `xor` (getKeyKw mode key 0) in {- Prewhitening -}- let d2a = d2 `xor` (getKeyKw mode key 1) in-- let (d1b, d2b) = doBlockRound mode key d1a d2a 0 in-- let d1c = fl d1b (getKeyKe mode key 0) in {- FL -}- let d2c = flinv d2b (getKeyKe mode key 1) in {- FLINV -}-- let (d1d, d2d) = doBlockRound mode key d1c d2c 6 in-- let d1e = fl d1d (getKeyKe mode key 2) in {- FL -}- let d2e = flinv d2d (getKeyKe mode key 3) in {- FLINV -}-- let (d1f, d2f) = doBlockRound mode key d1e d2e 12 in-- let d2g = d2f `xor` (getKeyKw mode key 2) in {- Postwhitening -}- let d1g = d1f `xor` (getKeyKw mode key 3) in- w64tow128 (d2g, d1g)+ let d1a = d1 `xor` (getKeyKw mode key 0 {- Prewhitening -})+ in let d2a = d2 `xor` (getKeyKw mode key 1)+ in let (d1b, d2b) = doBlockRound mode key d1a d2a 0+ in let d1c = fl d1b (getKeyKe mode key 0 {- FL -})+ in let d2c = flinv d2b (getKeyKe mode key 1 {- FLINV -})+ in let (d1d, d2d) = doBlockRound mode key d1c d2c 6+ in let d1e = fl d1d (getKeyKe mode key 2 {- FL -})+ in let d2e = flinv d2d (getKeyKe mode key 3 {- FLINV -})+ in let (d1f, d2f) = doBlockRound mode key d1e d2e 12+ in let d2g = d2f `xor` (getKeyKw mode key 2 {- Postwhitening -})+ in let d1g = d1f `xor` (getKeyKw mode key 3)+ in w64tow128 (d2g, d1g) {- encryption for 128 bits blocks -} encryptBlock :: Camellia -> Word128 -> Word128@@ -269,15 +291,21 @@ decryptBlock = doBlock Decrypt -- | Encrypts the given ByteString using the given Key-encrypt :: ByteArray ba- => Camellia -- ^ The key to use- -> ba -- ^ The data to encrypt- -> ba+encrypt+ :: ByteArray ba+ => Camellia+ -- ^ The key to use+ -> ba+ -- ^ The data to encrypt+ -> ba encrypt key = B.mapAsWord128 (encryptBlock key) -- | Decrypts the given ByteString using the given Key-decrypt :: ByteArray ba- => Camellia -- ^ The key to use- -> ba -- ^ The data to decrypt- -> ba+decrypt+ :: ByteArray ba+ => Camellia+ -- ^ The key to use+ -> ba+ -- ^ The data to decrypt+ -> ba decrypt key = B.mapAsWord128 (decryptBlock key)
Crypto/Cipher/ChaCha.hs view
@@ -1,30 +1,35 @@+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.Cipher.ChaCha -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : stable -- Portability : good----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.Cipher.ChaCha- ( initialize- , initializeX- , combine- , generate- , State+module Crypto.Cipher.ChaCha (+ initialize,+ initializeX,+ combine,+ generate,+ State,+ -- * Simple interface for DRG purpose- , initializeSimple- , generateSimple- , StateSimple- ) where+ initializeSimple,+ generateSimple,+ StateSimple,+) where -import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, ScrubbedBytes)+import Crypto.Internal.ByteArray (+ ByteArray,+ ByteArrayAccess,+ ScrubbedBytes,+ ) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Foreign.Ptr-import Foreign.C.Types+import Crypto.Internal.Compat+import Crypto.Internal.Imports+import Foreign.C.Types+import Foreign.Ptr -- | ChaCha context newtype State = State ScrubbedBytes@@ -36,84 +41,109 @@ -- | Initialize a new ChaCha context with the number of rounds, -- the key and the nonce associated.-initialize :: (ByteArrayAccess key, ByteArrayAccess nonce)- => Int -- ^ number of rounds (8,12,20)- -> key -- ^ the key (128 or 256 bits)- -> nonce -- ^ the nonce (64 or 96 bits)- -> State -- ^ the initial ChaCha state+initialize+ :: (ByteArrayAccess key, ByteArrayAccess nonce)+ => Int+ -- ^ number of rounds (8,12,20)+ -> key+ -- ^ the key (128 or 256 bits)+ -> nonce+ -- ^ the nonce (64 or 96 bits)+ -> State+ -- ^ the initial ChaCha state initialize nbRounds key nonce- | kLen `notElem` [16,32] = error "ChaCha: key length should be 128 or 256 bits"- | nonceLen `notElem` [8,12] = error "ChaCha: nonce length should be 64 or 96 bits"- | nbRounds `notElem` [8,12,20] = error "ChaCha: rounds should be 8, 12 or 20"- | otherwise = unsafeDoIO $ do+ | kLen `notElem` [16, 32] =+ error "ChaCha: key length should be 128 or 256 bits"+ | nonceLen `notElem` [8, 12] =+ error "ChaCha: nonce length should be 64 or 96 bits"+ | nbRounds `notElem` [8, 12, 20] = error "ChaCha: rounds should be 8, 12 or 20"+ | otherwise = unsafeDoIO $ do stPtr <- B.alloc 132 $ \stPtr ->- B.withByteArray nonce $ \noncePtr ->- B.withByteArray key $ \keyPtr ->- ccrypton_chacha_init stPtr nbRounds kLen keyPtr nonceLen noncePtr+ B.withByteArray nonce $ \noncePtr ->+ B.withByteArray key $ \keyPtr ->+ ccrypton_chacha_init stPtr nbRounds kLen keyPtr nonceLen noncePtr return $ State stPtr- where kLen = B.length key- nonceLen = B.length nonce+ where+ kLen = B.length key+ nonceLen = B.length nonce -- | Initialize a new XChaCha context with the number of rounds, -- the key and the nonce associated. -- -- An XChaCha state can be used like a regular ChaCha state after initialisation.-initializeX :: (ByteArrayAccess key, ByteArrayAccess nonce)- => Int -- ^ number of rounds (8,12,20)- -> key -- ^ the key (256 bits)- -> nonce -- ^ the nonce (192 bits)- -> State -- ^ the initial ChaCha state+initializeX+ :: (ByteArrayAccess key, ByteArrayAccess nonce)+ => Int+ -- ^ number of rounds (8,12,20)+ -> key+ -- ^ the key (256 bits)+ -> nonce+ -- ^ the nonce (192 bits)+ -> State+ -- ^ the initial ChaCha state initializeX nbRounds key nonce- | kLen /= 32 = error "XChaCha: key length should be 256 bits"- | nonceLen /= 24 = error "XChaCha: nonce length should be 192 bits"- | nbRounds `notElem` [8,12,20] = error "XChaCha: rounds should be 8, 12 or 20"- | otherwise = unsafeDoIO $ do+ | kLen /= 32 =+ error "XChaCha: key length should be 256 bits"+ | nonceLen /= 24 =+ error "XChaCha: nonce length should be 192 bits"+ | nbRounds `notElem` [8, 12, 20] =+ error "XChaCha: rounds should be 8, 12 or 20"+ | otherwise = unsafeDoIO $ do stPtr <- B.alloc 132 $ \stPtr ->- B.withByteArray nonce $ \noncePtr ->- B.withByteArray key $ \keyPtr ->- ccrypton_xchacha_init stPtr nbRounds keyPtr noncePtr+ B.withByteArray nonce $ \noncePtr ->+ B.withByteArray key $ \keyPtr ->+ ccrypton_xchacha_init stPtr nbRounds keyPtr noncePtr return $ State stPtr- where kLen = B.length key- nonceLen = B.length nonce+ where+ kLen = B.length key+ nonceLen = B.length nonce -- | Initialize simple ChaCha State -- -- The seed need to be at least 40 bytes long-initializeSimple :: ByteArrayAccess seed- => seed -- ^ a 40 bytes long seed- -> StateSimple+initializeSimple+ :: ByteArrayAccess seed+ => seed+ -- ^ a 40 bytes long seed+ -> StateSimple initializeSimple seed | sLen < 40 = error "ChaCha Random: seed length should be 40 bytes" | otherwise = unsafeDoIO $ do stPtr <- B.alloc 64 $ \stPtr ->- B.withByteArray seed $ \seedPtr ->- ccrypton_chacha_init_core stPtr 32 seedPtr 8 (seedPtr `plusPtr` 32)+ B.withByteArray seed $ \seedPtr ->+ ccrypton_chacha_init_core stPtr 32 seedPtr 8 (seedPtr `plusPtr` 32) return $ StateSimple stPtr where sLen = B.length seed -- | Combine the chacha output and an arbitrary message with a xor, -- and return the combined output and the new state.-combine :: ByteArray ba- => State -- ^ the current ChaCha state- -> ba -- ^ the source to xor with the generator- -> (ba, State)+combine+ :: ByteArray ba+ => State+ -- ^ the current ChaCha state+ -> ba+ -- ^ the source to xor with the generator+ -> (ba, State) combine prevSt@(State prevStMem) src | B.null src = (B.empty, prevSt)- | otherwise = unsafeDoIO $ do+ | otherwise = unsafeDoIO $ do (out, st) <- B.copyRet prevStMem $ \ctx -> B.alloc (B.length src) $ \dstPtr ->- B.withByteArray src $ \srcPtr ->- ccrypton_chacha_combine dstPtr ctx srcPtr (fromIntegral $ B.length src)+ B.withByteArray src $ \srcPtr ->+ ccrypton_chacha_combine dstPtr ctx srcPtr (fromIntegral $ B.length src) return (out, State st) -- | Generate a number of bytes from the ChaCha output directly-generate :: ByteArray ba- => State -- ^ the current ChaCha state- -> Int -- ^ the length of data to generate- -> (ba, State)+generate+ :: ByteArray ba+ => State+ -- ^ the current ChaCha state+ -> Int+ -- ^ the length of data to generate+ -> (ba, State) generate prevSt@(State prevStMem) len- | len <= 0 = (B.empty, prevSt)+ | len <= 0 = (B.empty, prevSt) | otherwise = unsafeDoIO $ do (out, st) <- B.copyRet prevStMem $ \ctx -> B.alloc len $ \dstPtr ->@@ -121,22 +151,25 @@ return (out, State st) -- | similar to 'generate' but assume certains values-generateSimple :: ByteArray ba- => StateSimple- -> Int- -> (ba, StateSimple)+generateSimple+ :: ByteArray ba+ => StateSimple+ -> Int+ -> (ba, StateSimple) generateSimple (StateSimple prevSt) nbBytes = unsafeDoIO $ do- newSt <- B.copy prevSt (\_ -> return ())+ newSt <- B.copy prevSt (\_ -> return ()) output <- B.alloc nbBytes $ \dstPtr -> B.withByteArray newSt $ \stPtr -> ccrypton_chacha_random 8 dstPtr stPtr (fromIntegral nbBytes) return (output, StateSimple newSt) foreign import ccall "crypton_chacha_init_core"- ccrypton_chacha_init_core :: Ptr StateSimple -> Int -> Ptr Word8 -> Int -> Ptr Word8 -> IO ()+ ccrypton_chacha_init_core+ :: Ptr StateSimple -> Int -> Ptr Word8 -> Int -> Ptr Word8 -> IO () foreign import ccall "crypton_chacha_init"- ccrypton_chacha_init :: Ptr State -> Int -> Int -> Ptr Word8 -> Int -> Ptr Word8 -> IO ()+ ccrypton_chacha_init+ :: Ptr State -> Int -> Int -> Ptr Word8 -> Int -> Ptr Word8 -> IO () foreign import ccall "crypton_xchacha_init" ccrypton_xchacha_init :: Ptr State -> Int -> Ptr Word8 -> Ptr Word8 -> IO ()@@ -149,4 +182,3 @@ foreign import ccall "crypton_chacha_random" ccrypton_chacha_random :: Int -> Ptr Word8 -> Ptr StateSimple -> CUInt -> IO ()-
Crypto/Cipher/ChaChaPoly1305.hs view
@@ -34,63 +34,77 @@ -- > (out, st3) = C.encrypt plaintext st2 -- > auth = C.finalize st3 -- > return $ out `B.append` Data.ByteArray.convert auth----module Crypto.Cipher.ChaChaPoly1305- ( State- , Nonce- , XNonce- , nonce12- , nonce8- , nonce24- , incrementNonce- , initialize- , initializeX- , appendAAD- , finalizeAAD- , encrypt- , decrypt- , finalize- ) where+module Crypto.Cipher.ChaChaPoly1305 (+ -- * AEAD+ ChaCha20Poly1305,+ aeadChacha20poly1305Init, -import Control.Monad (when)-import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, Bytes, ScrubbedBytes)-import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.Imports-import Crypto.Error+ -- * Low level+ State,+ Nonce,+ XNonce,+ nonce12,+ nonce8,+ nonce24,+ incrementNonce,+ initialize,+ initializeX,+ appendAAD,+ finalizeAAD,+ encrypt,+ decrypt,+ finalize,+) where++import Control.Monad (when) import qualified Crypto.Cipher.ChaCha as ChaCha-import qualified Crypto.MAC.Poly1305 as Poly1305-import Data.Memory.Endian+import Crypto.Cipher.Types+import Crypto.Error+import Crypto.Internal.ByteArray (+ ByteArray,+ ByteArrayAccess,+ Bytes,+ ScrubbedBytes,+ )+import qualified Crypto.Internal.ByteArray as B+import Crypto.Internal.Imports+import qualified Crypto.MAC.Poly1305 as Poly1305 import qualified Data.ByteArray.Pack as P-import Foreign.Ptr-import Foreign.Storable+import Data.Memory.Endian+import Foreign.Ptr+import Foreign.Storable -- | A ChaChaPoly1305 State. -- -- The state is immutable, and only new state can be created-data State = State !ChaCha.State- !Poly1305.State- !Word64 -- AAD length- !Word64 -- ciphertext length+data State+ = State+ !ChaCha.State+ !Poly1305.State+ !Word64 -- AAD length+ !Word64 -- ciphertext length +-- | A ChaChaPoly1305 State.+type ChaCha20Poly1305 = State+ -- | Valid Nonce for ChaChaPoly1305. -- -- It can be created with 'nonce8' or 'nonce12' data Nonce = Nonce8 Bytes | Nonce12 Bytes instance ByteArrayAccess Nonce where- length (Nonce8 n) = B.length n- length (Nonce12 n) = B.length n+ length (Nonce8 n) = B.length n+ length (Nonce12 n) = B.length n - withByteArray (Nonce8 n) = B.withByteArray n- withByteArray (Nonce12 n) = B.withByteArray n+ withByteArray (Nonce8 n) = B.withByteArray n+ withByteArray (Nonce12 n) = B.withByteArray n -- | Extended nonce for XChaChaPoly1305. newtype XNonce = Nonce24 Bytes instance ByteArrayAccess XNonce where- length (Nonce24 n) = B.length n- withByteArray (Nonce24 n) = B.withByteArray n-+ length (Nonce24 n) = B.length n+ withByteArray (Nonce24 n) = B.withByteArray n -- Based on the following pseudo code: --@@ -108,7 +122,7 @@ pad16 :: Word64 -> Bytes pad16 n | modLen == 0 = B.empty- | otherwise = B.replicate (16 - modLen) 0+ | otherwise = B.replicate (16 - modLen) 0 where modLen = fromIntegral (n `mod` 16) @@ -116,78 +130,84 @@ nonce12 :: ByteArrayAccess iv => iv -> CryptoFailable Nonce nonce12 iv | B.length iv /= 12 = CryptoFailed CryptoError_IvSizeInvalid- | otherwise = CryptoPassed . Nonce12 . B.convert $ iv+ | otherwise = CryptoPassed . Nonce12 . B.convert $ iv -- | 8 bytes IV, nonce constructor-nonce8 :: ByteArrayAccess ba- => ba -- ^ 4 bytes constant- -> ba -- ^ 8 bytes IV- -> CryptoFailable Nonce+nonce8+ :: ByteArrayAccess ba+ => ba+ -- ^ 4 bytes constant+ -> ba+ -- ^ 8 bytes IV+ -> CryptoFailable Nonce nonce8 constant iv | B.length constant /= 4 = CryptoFailed CryptoError_IvSizeInvalid- | B.length iv /= 8 = CryptoFailed CryptoError_IvSizeInvalid- | otherwise = CryptoPassed . Nonce8 . B.concat $ [constant, iv]+ | B.length iv /= 8 = CryptoFailed CryptoError_IvSizeInvalid+ | otherwise = CryptoPassed . Nonce8 . B.concat $ [constant, iv] -- | 24 bytes IV, extended nonce constructor-nonce24 :: ByteArrayAccess ba- => ba -> CryptoFailable XNonce+nonce24+ :: ByteArrayAccess ba+ => ba -> CryptoFailable XNonce nonce24 iv | B.length iv /= 24 = CryptoFailed CryptoError_IvSizeInvalid- | otherwise = CryptoPassed . Nonce24 . B.convert $ iv+ | otherwise = CryptoPassed . Nonce24 . B.convert $ iv -- | Increment a nonce incrementNonce :: Nonce -> Nonce-incrementNonce (Nonce8 n) = Nonce8 $ incrementNonce' n 4+incrementNonce (Nonce8 n) = Nonce8 $ incrementNonce' n 4 incrementNonce (Nonce12 n) = Nonce12 $ incrementNonce' n 0 incrementNonce' :: Bytes -> Int -> Bytes incrementNonce' b offset = B.copyAndFreeze b $ \s -> loop s (s `plusPtr` offset)- where- loop :: Ptr Word8 -> Ptr Word8 -> IO ()- loop s p- | s == (p `plusPtr` (B.length b - offset - 1)) = peek s >>= poke s . (+) 1- | otherwise = do- r <- (+) 1 <$> peek p- poke p r- when (r == 0) $ loop s (p `plusPtr` 1)+ where+ loop :: Ptr Word8 -> Ptr Word8 -> IO ()+ loop s p+ | s == (p `plusPtr` (B.length b - offset - 1)) = peek s >>= poke s . (+) 1+ | otherwise = do+ r <- (+) 1 <$> peek p+ poke p r+ when (r == 0) $ loop s (p `plusPtr` 1) -- | Initialize a new ChaChaPoly1305 State -- -- The key length need to be 256 bits, and the nonce -- procured using either `nonce8` or `nonce12`-initialize :: ByteArrayAccess key- => key -> Nonce -> CryptoFailable State-initialize key (Nonce8 nonce) = initialize' key nonce+initialize+ :: ByteArrayAccess key+ => key -> Nonce -> CryptoFailable State+initialize key (Nonce8 nonce) = initialize' key nonce initialize key (Nonce12 nonce) = initialize' key nonce --initialize' :: ByteArrayAccess key- => key -> Bytes -> CryptoFailable State+initialize'+ :: ByteArrayAccess key+ => key -> Bytes -> CryptoFailable State initialize' key nonce | B.length key /= 32 = CryptoFailed CryptoError_KeySizeInvalid- | otherwise = CryptoPassed $ initFromRootState rootState- where rootState = ChaCha.initialize 20 key nonce-+ | otherwise = CryptoPassed $ initFromRootState rootState+ where+ rootState = ChaCha.initialize 20 key nonce initFromRootState :: ChaCha.State -> State initFromRootState rootState = State encState polyState 0 0 where (polyKey, encState) = ChaCha.generate rootState 64- polyState = throwCryptoError $ Poly1305.initialize (B.take 32 polyKey :: ScrubbedBytes)-+ polyState =+ throwCryptoError $ Poly1305.initialize (B.take 32 polyKey :: ScrubbedBytes) -- | Initialize a new XChaChaPoly1305 State -- -- The key length needs to be 256 bits, and the nonce -- procured using `nonce24`.-initializeX :: ByteArrayAccess key- => key -> XNonce -> CryptoFailable State+initializeX+ :: ByteArrayAccess key+ => key -> XNonce -> CryptoFailable State initializeX key (Nonce24 nonce) | B.length key /= 32 = CryptoFailed CryptoError_KeySizeInvalid- | otherwise = CryptoPassed $ initFromRootState rootState- where rootState = ChaCha.initializeX 20 key nonce-+ | otherwise = CryptoPassed $ initFromRootState rootState+ where+ rootState = ChaCha.initializeX 20 key nonce -- | Append Authenticated Data to the State and return -- the new modified State.@@ -199,7 +219,7 @@ State encState newMacState newLength plainLength where newMacState = Poly1305.update macState ba- newLength = aadLength + fromIntegral (B.length ba)+ newLength = aadLength + fromIntegral (B.length ba) -- | Finalize the Authenticated Data and return the finalized State finalizeAAD :: State -> State@@ -215,8 +235,8 @@ (output, State newEncState newMacState aadLength newPlainLength) where (output, newEncState) = ChaCha.combine encState input- newMacState = Poly1305.update macState output- newPlainLength = plainLength + fromIntegral (B.length input)+ newMacState = Poly1305.update macState output+ newPlainLength = plainLength + fromIntegral (B.length input) -- | Decrypt a piece of data and returns the decrypted Data and the -- updated State.@@ -225,13 +245,32 @@ (output, State newEncState newMacState aadLength newPlainLength) where (output, newEncState) = ChaCha.combine encState input- newMacState = Poly1305.update macState input- newPlainLength = plainLength + fromIntegral (B.length input)+ newMacState = Poly1305.update macState input+ newPlainLength = plainLength + fromIntegral (B.length input) -- | Generate an authentication tag from the State. finalize :: State -> Poly1305.Auth finalize (State _ macState aadLength plainLength) =- Poly1305.finalize $ Poly1305.updates macState- [ pad16 plainLength- , either (error "finalize: internal error") id $ P.fill 16 (P.putStorable (toLE aadLength) >> P.putStorable (toLE plainLength))- ]+ Poly1305.finalize $+ Poly1305.updates+ macState+ [ pad16 plainLength+ , either (error "finalize: internal error") id $+ P.fill 16 (P.putStorable (toLE aadLength) >> P.putStorable (toLE plainLength))+ ]++-- | Setting up AEAD for ChaCha20Poly1305.+aeadChacha20poly1305Init+ :: (ByteArrayAccess k, ByteArrayAccess n)+ => k -> n -> CryptoFailable (AEAD ChaCha20Poly1305)+aeadChacha20poly1305Init key nonce = do+ st0 <- nonce12 nonce >>= initialize key+ return $ AEAD model st0+ where+ model =+ AEADModeImpl+ { aeadImplAppendHeader = \st aad -> finalizeAAD $ appendAAD aad st+ , aeadImplEncrypt = \st plain -> encrypt plain st+ , aeadImplDecrypt = \st cipher -> decrypt cipher st+ , aeadImplFinalize = \st _ -> let Poly1305.Auth tag = finalize st in AuthTag tag+ }
Crypto/Cipher/DES.hs view
@@ -4,27 +4,26 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : stable -- Portability : good----module Crypto.Cipher.DES- ( DES- ) where+module Crypto.Cipher.DES (+ DES,+) where -import Data.Word-import Crypto.Error-import Crypto.Cipher.Types-import Crypto.Cipher.DES.Primitive-import Crypto.Internal.ByteArray (ByteArrayAccess)+import Crypto.Cipher.DES.Primitive+import Crypto.Cipher.Types+import Crypto.Error+import Crypto.Internal.ByteArray (ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B-import Data.Memory.Endian+import Data.Memory.Endian+import Data.Word -- | DES Context data DES = DES Word64 deriving (Eq) instance Cipher DES where- cipherName _ = "DES"+ cipherName _ = "DES" cipherKeySize _ = KeySizeFixed 8- cipherInit k = initDES k+ cipherInit k = initDES k instance BlockCipher DES where blockSize _ = 8@@ -33,7 +32,8 @@ initDES :: ByteArrayAccess key => key -> CryptoFailable DES initDES k- | len == 8 = CryptoPassed $ DES key+ | len == 8 = CryptoPassed $ DES key | otherwise = CryptoFailed $ CryptoError_KeySizeInvalid- where len = B.length k- key = fromBE $ B.toW64BE k 0+ where+ len = B.length k+ key = fromBE $ B.toW64BE k 0
Crypto/Cipher/DES/Primitive.hs view
@@ -1,33 +1,32 @@ {-# LANGUAGE FlexibleInstances #-} -----------------------------------------------------------------------------++-----------------------------------------------------------------------------+ -- | -- Module : Crypto.Cipher.DES.Primitive -- License : BSD-style -- -- This module is copy of DES module from Crypto package. -- http://hackage.haskell.org/package/Crypto------------------------------------------------------------------------------------module Crypto.Cipher.DES.Primitive- ( encrypt- , decrypt- , Block(..)- ) where+module Crypto.Cipher.DES.Primitive (+ encrypt,+ decrypt,+ Block (..),+) where -import Data.Word import Data.Bits+import Data.Word -- | a DES block (64 bits)-newtype Block = Block { unBlock :: Word64 }+newtype Block = Block {unBlock :: Word64} type Rotation = Int-type Key = Word64+type Key = Word64 -type Bits4 = [Bool]-type Bits6 = [Bool]+type Bits4 = [Bool]+type Bits6 = [Bool] type Bits32 = [Bool] type Bits48 = [Bool] type Bits56 = [Bool]@@ -38,20 +37,84 @@ desRotate :: [Bool] -> Int -> [Bool] desRotate bits rot = drop rot' bits ++ take rot' bits- where rot' = rot `mod` length bits+ where+ rot' = rot `mod` length bits bitify :: Word64 -> Bits64-bitify w = map (\b -> w .&. (shiftL 1 b) /= 0) [63,62..0]+bitify w = map (\b -> w .&. (shiftL 1 b) /= 0) [63, 62 .. 0] unbitify :: Bits64 -> Word64 unbitify bs = foldl (\i b -> if b then 1 + shiftL i 1 else shiftL i 1) 0 bs initial_permutation :: Bits64 -> Bits64 initial_permutation mb = map ((!!) mb) i- where i = [57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,- 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7,- 56, 48, 40, 32, 24, 16, 8, 0, 58, 50, 42, 34, 26, 18, 10, 2,- 60, 52, 44, 36, 28, 20, 12, 4, 62, 54, 46, 38, 30, 22, 14, 6]+ where+ i =+ [ 57+ , 49+ , 41+ , 33+ , 25+ , 17+ , 9+ , 1+ , 59+ , 51+ , 43+ , 35+ , 27+ , 19+ , 11+ , 3+ , 61+ , 53+ , 45+ , 37+ , 29+ , 21+ , 13+ , 5+ , 63+ , 55+ , 47+ , 39+ , 31+ , 23+ , 15+ , 7+ , 56+ , 48+ , 40+ , 32+ , 24+ , 16+ , 8+ , 0+ , 58+ , 50+ , 42+ , 34+ , 26+ , 18+ , 10+ , 2+ , 60+ , 52+ , 44+ , 36+ , 28+ , 20+ , 12+ , 4+ , 62+ , 54+ , 46+ , 38+ , 30+ , 22+ , 14+ , 6+ ] {- "\x39\x31\x29\x21\x19\x11\x09\x01\x3b\x33\x2b\x23\x1b\x13\@@ -63,10 +126,66 @@ key_transformation :: Bits64 -> Bits56 key_transformation kb = map ((!!) kb) i- where i = [56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17,- 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35,- 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21,- 13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3]+ where+ i =+ [ 56+ , 48+ , 40+ , 32+ , 24+ , 16+ , 8+ , 0+ , 57+ , 49+ , 41+ , 33+ , 25+ , 17+ , 9+ , 1+ , 58+ , 50+ , 42+ , 34+ , 26+ , 18+ , 10+ , 2+ , 59+ , 51+ , 43+ , 35+ , 62+ , 54+ , 46+ , 38+ , 30+ , 22+ , 14+ , 6+ , 61+ , 53+ , 45+ , 37+ , 29+ , 21+ , 13+ , 5+ , 60+ , 52+ , 44+ , 36+ , 28+ , 20+ , 12+ , 4+ , 27+ , 19+ , 11+ , 3+ ]+ {- "\x38\x30\x28\x20\x18\x10\x08\x00\x39\x31\x29\x21\x19\x11\ \\x09\x01\x3a\x32\x2a\x22\x1a\x12\x0a\x02\x3b\x33\x2b\x23\@@ -74,143 +193,371 @@ \\x0d\x05\x3c\x34\x2c\x24\x1c\x14\x0c\x04\x1b\x13\x0b\x03" -} - des_enc :: Block -> Key -> Block-des_enc = do_des [1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28]+des_enc = do_des [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28] des_dec :: Block -> Key -> Block-des_dec = do_des [28,27,25,23,21,19,17,15,14,12,10,8,6,4,2,1]+des_dec = do_des [28, 27, 25, 23, 21, 19, 17, 15, 14, 12, 10, 8, 6, 4, 2, 1] do_des :: [Rotation] -> Block -> Key -> Block do_des rots (Block m) k = Block $ des_work rots (takeDrop 32 mb) kb- where kb = key_transformation $ bitify k- mb = initial_permutation $ bitify m+ where+ kb = key_transformation $ bitify k+ mb = initial_permutation $ bitify m des_work :: [Rotation] -> (Bits32, Bits32) -> Bits56 -> Word64 des_work [] (ml, mr) _ = unbitify $ final_perm $ (mr ++ ml)-des_work (r:rs) mb kb = des_work rs mb' kb- where mb' = do_round r mb kb+des_work (r : rs) mb kb = des_work rs mb' kb+ where+ mb' = do_round r mb kb do_round :: Rotation -> (Bits32, Bits32) -> Bits56 -> (Bits32, Bits32) do_round r (ml, mr) kb = (mr, m')- where kb' = get_key kb r- comp_kb = compression_permutation kb'- expa_mr = expansion_permutation mr- res = comp_kb `desXor` expa_mr- res' = tail $ iterate (trans 6) ([], res)- trans n (_, b) = (take n b, drop n b)- res_s = concat $ zipWith (\f (x,_) -> f x) [s_box_1, s_box_2,- s_box_3, s_box_4,- s_box_5, s_box_6,- s_box_7, s_box_8] res'- res_p = p_box res_s- m' = res_p `desXor` ml+ where+ kb' = get_key kb r+ comp_kb = compression_permutation kb'+ expa_mr = expansion_permutation mr+ res = comp_kb `desXor` expa_mr+ res' = drop 1 $ iterate (trans 6) ([], res)+ trans n (_, b) = (take n b, drop n b)+ res_s =+ concat $+ zipWith+ (\f (x, _) -> f x)+ [ s_box_1+ , s_box_2+ , s_box_3+ , s_box_4+ , s_box_5+ , s_box_6+ , s_box_7+ , s_box_8+ ]+ res'+ res_p = p_box res_s+ m' = res_p `desXor` ml get_key :: Bits56 -> Rotation -> Bits56 get_key kb r = kb'- where (kl, kr) = takeDrop 28 kb- kb' = desRotate kl r ++ desRotate kr r+ where+ (kl, kr) = takeDrop 28 kb+ kb' = desRotate kl r ++ desRotate kr r compression_permutation :: Bits56 -> Bits48 compression_permutation kb = map ((!!) kb) i- where i = [13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9,- 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1,- 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,- 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31]+ where+ i =+ [ 13+ , 16+ , 10+ , 23+ , 0+ , 4+ , 2+ , 27+ , 14+ , 5+ , 20+ , 9+ , 22+ , 18+ , 11+ , 3+ , 25+ , 7+ , 15+ , 6+ , 26+ , 19+ , 12+ , 1+ , 40+ , 51+ , 30+ , 36+ , 46+ , 54+ , 29+ , 39+ , 50+ , 44+ , 32+ , 47+ , 43+ , 48+ , 38+ , 55+ , 33+ , 52+ , 45+ , 41+ , 49+ , 35+ , 28+ , 31+ ] expansion_permutation :: Bits32 -> Bits48 expansion_permutation mb = map ((!!) mb) i- where i = [31, 0, 1, 2, 3, 4, 3, 4, 5, 6, 7, 8,- 7, 8, 9, 10, 11, 12, 11, 12, 13, 14, 15, 16,- 15, 16, 17, 18, 19, 20, 19, 20, 21, 22, 23, 24,- 23, 24, 25, 26, 27, 28, 27, 28, 29, 30, 31, 0]+ where+ i =+ [ 31+ , 0+ , 1+ , 2+ , 3+ , 4+ , 3+ , 4+ , 5+ , 6+ , 7+ , 8+ , 7+ , 8+ , 9+ , 10+ , 11+ , 12+ , 11+ , 12+ , 13+ , 14+ , 15+ , 16+ , 15+ , 16+ , 17+ , 18+ , 19+ , 20+ , 19+ , 20+ , 21+ , 22+ , 23+ , 24+ , 23+ , 24+ , 25+ , 26+ , 27+ , 28+ , 27+ , 28+ , 29+ , 30+ , 31+ , 0+ ] s_box :: [[Word8]] -> Bits6 -> Bits4-s_box s [a,b,c,d,e,f] = to_bool 4 $ (s !! row) !! col- where row = sum $ zipWith numericise [a,f] [1, 0]- col = sum $ zipWith numericise [b,c,d,e] [3, 2, 1, 0]- numericise :: Bool -> Int -> Int- numericise = (\x y -> if x then 2^y else 0)+s_box s [a, b, c, d, e, f] = to_bool 4 $ (s !! row) !! col+ where+ row = sum $ zipWith numericise [a, f] [1, 0]+ col = sum $ zipWith numericise [b, c, d, e] [3, 2, 1, 0]+ numericise :: Bool -> Int -> Int+ numericise = (\x y -> if x then 2 ^ y else 0) - to_bool :: Int -> Word8 -> [Bool]- to_bool 0 _ = []- to_bool n i = ((i .&. 8) == 8):to_bool (n-1) (shiftL i 1)-s_box _ _ = error "DES: internal error bits6 more than 6 elements"+ to_bool :: Int -> Word8 -> [Bool]+ to_bool 0 _ = []+ to_bool n i = ((i .&. 8) == 8) : to_bool (n - 1) (shiftL i 1)+s_box _ _ = error "DES: internal error bits6 more than 6 elements" s_box_1 :: Bits6 -> Bits4 s_box_1 = s_box i- where i = [[14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],- [ 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],- [ 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],- [15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13]]+ where+ i =+ [ [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7]+ , [0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8]+ , [4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0]+ , [15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13]+ ] s_box_2 :: Bits6 -> Bits4 s_box_2 = s_box i- where i = [[15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],- [3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],- [0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],- [13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9]]+ where+ i =+ [ [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10]+ , [3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5]+ , [0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15]+ , [13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9]+ ] s_box_3 :: Bits6 -> Bits4 s_box_3 = s_box i- where i = [[10, 0, 9, 14 , 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],- [13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],- [13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],- [1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12]]+ where+ i =+ [ [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8]+ , [13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1]+ , [13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7]+ , [1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12]+ ] s_box_4 :: Bits6 -> Bits4 s_box_4 = s_box i- where i = [[7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],- [13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],- [10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],- [3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14]]+ where+ i =+ [ [7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15]+ , [13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9]+ , [10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4]+ , [3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14]+ ] s_box_5 :: Bits6 -> Bits4 s_box_5 = s_box i- where i = [[2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],- [14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],- [4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],- [11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3]]+ where+ i =+ [ [2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9]+ , [14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6]+ , [4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14]+ , [11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3]+ ] s_box_6 :: Bits6 -> Bits4 s_box_6 = s_box i- where i = [[12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],- [10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],- [9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],- [4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13]]+ where+ i =+ [ [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11]+ , [10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8]+ , [9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6]+ , [4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13]+ ] s_box_7 :: Bits6 -> Bits4 s_box_7 = s_box i- where i = [[4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],- [13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],- [1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],- [6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]]+ where+ i =+ [ [4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1]+ , [13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6]+ , [1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2]+ , [6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]+ ] s_box_8 :: Bits6 -> Bits4 s_box_8 = s_box i- where i = [[13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],- [1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],- [7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],- [2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]]+ where+ i =+ [ [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7]+ , [1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2]+ , [7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8]+ , [2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]+ ] p_box :: Bits32 -> Bits32 p_box kb = map ((!!) kb) i- where i = [15, 6, 19, 20, 28, 11, 27, 16, 0, 14, 22, 25, 4, 17, 30, 9,- 1, 7, 23, 13, 31, 26, 2, 8, 18, 12, 29, 5, 21, 10, 3, 24]+ where+ i =+ [ 15+ , 6+ , 19+ , 20+ , 28+ , 11+ , 27+ , 16+ , 0+ , 14+ , 22+ , 25+ , 4+ , 17+ , 30+ , 9+ , 1+ , 7+ , 23+ , 13+ , 31+ , 26+ , 2+ , 8+ , 18+ , 12+ , 29+ , 5+ , 21+ , 10+ , 3+ , 24+ ] final_perm :: Bits64 -> Bits64 final_perm kb = map ((!!) kb) i- where i = [39, 7, 47, 15, 55, 23, 63, 31, 38, 6, 46, 14, 54, 22, 62, 30,- 37, 5, 45, 13, 53, 21, 61, 29, 36, 4, 44, 12, 52, 20, 60, 28,- 35, 3, 43, 11, 51, 19, 59, 27, 34, 2, 42, 10, 50, 18, 58, 26,- 33, 1, 41, 9, 49, 17, 57, 25, 32, 0, 40 , 8, 48, 16, 56, 24]+ where+ i =+ [ 39+ , 7+ , 47+ , 15+ , 55+ , 23+ , 63+ , 31+ , 38+ , 6+ , 46+ , 14+ , 54+ , 22+ , 62+ , 30+ , 37+ , 5+ , 45+ , 13+ , 53+ , 21+ , 61+ , 29+ , 36+ , 4+ , 44+ , 12+ , 52+ , 20+ , 60+ , 28+ , 35+ , 3+ , 43+ , 11+ , 51+ , 19+ , 59+ , 27+ , 34+ , 2+ , 42+ , 10+ , 50+ , 18+ , 58+ , 26+ , 33+ , 1+ , 41+ , 9+ , 49+ , 17+ , 57+ , 25+ , 32+ , 0+ , 40+ , 8+ , 48+ , 16+ , 56+ , 24+ ] takeDrop :: Int -> [a] -> ([a], [a]) takeDrop _ [] = ([], []) takeDrop 0 xs = ([], xs)-takeDrop n (x:xs) = (x:ys, zs)- where (ys, zs) = takeDrop (n-1) xs-+takeDrop n (x : xs) = (x : ys, zs)+ where+ (ys, zs) = takeDrop (n - 1) xs -- | Basic DES encryption which takes a key and a block of plaintext -- and returns the encrypted block of ciphertext according to the standard.
Crypto/Cipher/RC4.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.Cipher.RC4 -- License : BSD-style@@ -11,23 +14,24 @@ -- Initial FFI implementation by Peter White <peter@janrain.com> -- -- Reorganized and simplified to have an opaque context.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.Cipher.RC4- ( initialize- , combine- , generate- , State- ) where+module Crypto.Cipher.RC4 (+ initialize,+ combine,+ generate,+ State,+) where -import Data.Word-import Foreign.Ptr-import Crypto.Internal.ByteArray (ScrubbedBytes, ByteArray, ByteArrayAccess)+import Crypto.Internal.ByteArray (+ ByteArray,+ ByteArrayAccess,+ ScrubbedBytes,+ ) import qualified Crypto.Internal.ByteArray as B+import Data.Word+import Foreign.Ptr -import Crypto.Internal.Compat-import Crypto.Internal.Imports+import Crypto.Internal.Compat+import Crypto.Internal.Imports -- | The encryption state for RC4 --@@ -36,29 +40,41 @@ -- and change in future versions. The bytearray should not be used as input to -- cryptographic algorithms. newtype State = State ScrubbedBytes- deriving (ByteArrayAccess,NFData)+ deriving (ByteArrayAccess, NFData) -- | C Call for initializing the encryptor foreign import ccall unsafe "crypton_rc4.h crypton_rc4_init"- c_rc4_init :: Ptr Word8 -- ^ The rc4 key- -> Word32 -- ^ The key length- -> Ptr State -- ^ The context- -> IO ()+ c_rc4_init+ :: Ptr Word8+ -- ^ The rc4 key+ -> Word32+ -- ^ The key length+ -> Ptr State+ -- ^ The context+ -> IO () foreign import ccall unsafe "crypton_rc4.h crypton_rc4_combine"- c_rc4_combine :: Ptr State -- ^ Pointer to the permutation- -> Ptr Word8 -- ^ Pointer to the clear text- -> Word32 -- ^ Length of the clear text- -> Ptr Word8 -- ^ Output buffer- -> IO ()+ c_rc4_combine+ :: Ptr State+ -- ^ Pointer to the permutation+ -> Ptr Word8+ -- ^ Pointer to the clear text+ -> Word32+ -- ^ Length of the clear text+ -> Ptr Word8+ -- ^ Output buffer+ -> IO () -- | RC4 context initialization. -- -- seed the context with an initial key. the key size need to be -- adequate otherwise security takes a hit.-initialize :: ByteArrayAccess key- => key -- ^ The key- -> State -- ^ The RC4 context with the key mixed in+initialize+ :: ByteArrayAccess key+ => key+ -- ^ The key+ -> State+ -- ^ The RC4 context with the key mixed in initialize key = unsafeDoIO $ do st <- B.alloc 264 $ \stPtr -> B.withByteArray key $ \keyPtr -> c_rc4_init keyPtr (fromIntegral $ B.length key) (castPtr stPtr)@@ -70,15 +86,20 @@ generate ctx len = combine ctx (B.zero len) -- | RC4 xor combination of the rc4 stream with an input-combine :: ByteArray ba- => State -- ^ rc4 context- -> ba -- ^ input- -> (State, ba) -- ^ new rc4 context, and the output+combine+ :: ByteArray ba+ => State+ -- ^ rc4 context+ -> ba+ -- ^ input+ -> (State, ba)+ -- ^ new rc4 context, and the output combine (State prevSt) clearText = unsafeDoIO $- B.allocRet len $ \outptr ->- B.withByteArray clearText $ \clearPtr -> do- st <- B.copy prevSt $ \stPtr ->+ B.allocRet len $ \outptr ->+ B.withByteArray clearText $ \clearPtr -> do+ st <- B.copy prevSt $ \stPtr -> c_rc4_combine (castPtr stPtr) clearPtr (fromIntegral len) outptr- return $! State st- --return $! (State st, B.PS outfptr 0 len)- where len = B.length clearText+ return $! State st+ where+ -- return $! (State st, B.PS outfptr 0 len)+ len = B.length clearText
Crypto/Cipher/Salsa.hs view
@@ -1,25 +1,29 @@+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.Cipher.Salsa -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : stable -- Portability : good----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.Cipher.Salsa- ( initialize- , combine- , generate- , State(..)- ) where+module Crypto.Cipher.Salsa (+ initialize,+ combine,+ generate,+ State (..),+) where -import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, ScrubbedBytes)+import Crypto.Internal.ByteArray (+ ByteArray,+ ByteArrayAccess,+ ScrubbedBytes,+ ) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Foreign.Ptr-import Foreign.C.Types+import Crypto.Internal.Compat+import Crypto.Internal.Imports+import Foreign.C.Types+import Foreign.Ptr -- | Salsa context newtype State = State ScrubbedBytes@@ -27,46 +31,60 @@ -- | Initialize a new Salsa context with the number of rounds, -- the key and the nonce associated.-initialize :: (ByteArrayAccess key, ByteArrayAccess nonce)- => Int -- ^ number of rounds (8,12,20)- -> key -- ^ the key (128 or 256 bits)- -> nonce -- ^ the nonce (64 or 96 bits)- -> State -- ^ the initial Salsa state+initialize+ :: (ByteArrayAccess key, ByteArrayAccess nonce)+ => Int+ -- ^ number of rounds (8,12,20)+ -> key+ -- ^ the key (128 or 256 bits)+ -> nonce+ -- ^ the nonce (64 or 96 bits)+ -> State+ -- ^ the initial Salsa state initialize nbRounds key nonce- | kLen `notElem` [16,32] = error "Salsa: key length should be 128 or 256 bits"- | nonceLen `notElem` [8,12] = error "Salsa: nonce length should be 64 or 96 bits"- | nbRounds `notElem` [8,12,20] = error "Salsa: rounds should be 8, 12 or 20"+ | kLen `notElem` [16, 32] =+ error "Salsa: key length should be 128 or 256 bits"+ | nonceLen `notElem` [8, 12] =+ error "Salsa: nonce length should be 64 or 96 bits"+ | nbRounds `notElem` [8, 12, 20] = error "Salsa: rounds should be 8, 12 or 20" | otherwise = unsafeDoIO $ do stPtr <- B.alloc 132 $ \stPtr ->- B.withByteArray nonce $ \noncePtr ->- B.withByteArray key $ \keyPtr ->- ccrypton_salsa_init stPtr nbRounds kLen keyPtr nonceLen noncePtr+ B.withByteArray nonce $ \noncePtr ->+ B.withByteArray key $ \keyPtr ->+ ccrypton_salsa_init stPtr nbRounds kLen keyPtr nonceLen noncePtr return $ State stPtr- where kLen = B.length key- nonceLen = B.length nonce+ where+ kLen = B.length key+ nonceLen = B.length nonce -- | Combine the salsa output and an arbitrary message with a xor, -- and return the combined output and the new state.-combine :: ByteArray ba- => State -- ^ the current Salsa state- -> ba -- ^ the source to xor with the generator- -> (ba, State)+combine+ :: ByteArray ba+ => State+ -- ^ the current Salsa state+ -> ba+ -- ^ the source to xor with the generator+ -> (ba, State) combine prevSt@(State prevStMem) src | B.null src = (B.empty, prevSt)- | otherwise = unsafeDoIO $ do+ | otherwise = unsafeDoIO $ do (out, st) <- B.copyRet prevStMem $ \ctx -> B.alloc (B.length src) $ \dstPtr ->- B.withByteArray src $ \srcPtr -> do- ccrypton_salsa_combine dstPtr ctx srcPtr (fromIntegral $ B.length src)+ B.withByteArray src $ \srcPtr -> do+ ccrypton_salsa_combine dstPtr ctx srcPtr (fromIntegral $ B.length src) return (out, State st) -- | Generate a number of bytes from the Salsa output directly-generate :: ByteArray ba- => State -- ^ the current Salsa state- -> Int -- ^ the length of data to generate- -> (ba, State)+generate+ :: ByteArray ba+ => State+ -- ^ the current Salsa state+ -> Int+ -- ^ the length of data to generate+ -> (ba, State) generate prevSt@(State prevStMem) len- | len <= 0 = (B.empty, prevSt)+ | len <= 0 = (B.empty, prevSt) | otherwise = unsafeDoIO $ do (out, st) <- B.copyRet prevStMem $ \ctx -> B.alloc len $ \dstPtr ->@@ -74,7 +92,8 @@ return (out, State st) foreign import ccall "crypton_salsa_init"- ccrypton_salsa_init :: Ptr State -> Int -> Int -> Ptr Word8 -> Int -> Ptr Word8 -> IO ()+ ccrypton_salsa_init+ :: Ptr State -> Int -> Int -> Ptr Word8 -> Int -> Ptr Word8 -> IO () foreign import ccall "crypton_salsa_combine" ccrypton_salsa_combine :: Ptr Word8 -> Ptr State -> Ptr Word8 -> CUInt -> IO ()
Crypto/Cipher/TripleDES.hs view
@@ -3,28 +3,27 @@ -- License : BSD-style -- Stability : experimental -- Portability : ???--module Crypto.Cipher.TripleDES- ( DES_EEE3- , DES_EDE3- , DES_EEE2- , DES_EDE2- ) where+module Crypto.Cipher.TripleDES (+ DES_EEE3,+ DES_EDE3,+ DES_EEE2,+ DES_EDE2,+) where -import Data.Word-import Crypto.Error-import Crypto.Cipher.Types-import Crypto.Cipher.DES.Primitive-import Crypto.Internal.ByteArray (ByteArrayAccess)+import Crypto.Cipher.DES.Primitive+import Crypto.Cipher.Types+import Crypto.Error+import Crypto.Internal.ByteArray (ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B-import Data.Memory.Endian+import Data.Memory.Endian+import Data.Word -- | 3DES with 3 different keys used all in the same direction data DES_EEE3 = DES_EEE3 Word64 Word64 Word64 deriving (Eq) -- | 3DES with 3 different keys used in alternative direction-data DES_EDE3 = DES_EDE3 Word64 Word64 Word64 +data DES_EDE3 = DES_EDE3 Word64 Word64 Word64 deriving (Eq) -- | 3DES where the first and third keys are equal, used in the same direction@@ -36,24 +35,24 @@ deriving (Eq) instance Cipher DES_EEE3 where- cipherName _ = "3DES_EEE"+ cipherName _ = "3DES_EEE" cipherKeySize _ = KeySizeFixed 24- cipherInit k = init3DES DES_EEE3 k+ cipherInit k = init3DES DES_EEE3 k instance Cipher DES_EDE3 where- cipherName _ = "3DES_EDE"+ cipherName _ = "3DES_EDE" cipherKeySize _ = KeySizeFixed 24- cipherInit k = init3DES DES_EDE3 k+ cipherInit k = init3DES DES_EDE3 k instance Cipher DES_EDE2 where- cipherName _ = "2DES_EDE"+ cipherName _ = "2DES_EDE" cipherKeySize _ = KeySizeFixed 16- cipherInit k = init2DES DES_EDE2 k+ cipherInit k = init2DES DES_EDE2 k instance Cipher DES_EEE2 where- cipherName _ = "2DES_EEE"+ cipherName _ = "2DES_EEE" cipherKeySize _ = KeySizeFixed 16- cipherInit k = init2DES DES_EEE2 k+ cipherInit k = init2DES DES_EEE2 k instance BlockCipher DES_EEE3 where blockSize _ = 8@@ -75,16 +74,21 @@ ecbEncrypt (DES_EDE2 k1 k2) = B.mapAsWord64 (unBlock . (encrypt k1 . decrypt k2 . encrypt k1) . Block) ecbDecrypt (DES_EDE2 k1 k2) = B.mapAsWord64 (unBlock . (decrypt k1 . encrypt k2 . decrypt k1) . Block) -init3DES :: ByteArrayAccess key => (Word64 -> Word64 -> Word64 -> a) -> key -> CryptoFailable a+init3DES+ :: ByteArrayAccess key+ => (Word64 -> Word64 -> Word64 -> a) -> key -> CryptoFailable a init3DES constr k | len == 24 = CryptoPassed $ constr k1 k2 k3 | otherwise = CryptoFailed CryptoError_KeySizeInvalid- where len = B.length k- (k1, k2, k3) = (fromBE $ B.toW64BE k 0, fromBE $ B.toW64BE k 8, fromBE $ B.toW64BE k 16)+ where+ len = B.length k+ (k1, k2, k3) = (fromBE $ B.toW64BE k 0, fromBE $ B.toW64BE k 8, fromBE $ B.toW64BE k 16) -init2DES :: ByteArrayAccess key => (Word64 -> Word64 -> a) -> key -> CryptoFailable a+init2DES+ :: ByteArrayAccess key => (Word64 -> Word64 -> a) -> key -> CryptoFailable a init2DES constr k | len == 16 = CryptoPassed $ constr k1 k2 | otherwise = CryptoFailed CryptoError_KeySizeInvalid- where len = B.length k- (k1, k2) = (fromBE $ B.toW64BE k 0, fromBE $ B.toW64BE k 8)+ where+ len = B.length k+ (k1, k2) = (fromBE $ B.toW64BE k 0, fromBE $ B.toW64BE k 8)
Crypto/Cipher/Twofish.hs view
@@ -1,8 +1,8 @@-module Crypto.Cipher.Twofish- ( Twofish128- , Twofish192- , Twofish256- ) where+module Crypto.Cipher.Twofish (+ Twofish128,+ Twofish192,+ Twofish256,+) where import Crypto.Cipher.Twofish.Primitive import Crypto.Cipher.Types@@ -11,35 +11,38 @@ newtype Twofish128 = Twofish128 Twofish instance Cipher Twofish128 where- cipherName _ = "Twofish128"+ cipherName _ = "Twofish128" cipherKeySize _ = KeySizeFixed 16- cipherInit key = Twofish128 <$> (initTwofish =<< validateKeySize (undefined :: Twofish128) key)+ cipherInit key =+ Twofish128 <$> (initTwofish =<< validateKeySize (undefined :: Twofish128) key) instance BlockCipher Twofish128 where- blockSize _ = 16+ blockSize _ = 16 ecbEncrypt (Twofish128 key) = encrypt key ecbDecrypt (Twofish128 key) = decrypt key newtype Twofish192 = Twofish192 Twofish instance Cipher Twofish192 where- cipherName _ = "Twofish192"+ cipherName _ = "Twofish192" cipherKeySize _ = KeySizeFixed 24- cipherInit key = Twofish192 <$> (initTwofish =<< validateKeySize (undefined :: Twofish192) key)+ cipherInit key =+ Twofish192 <$> (initTwofish =<< validateKeySize (undefined :: Twofish192) key) instance BlockCipher Twofish192 where- blockSize _ = 16+ blockSize _ = 16 ecbEncrypt (Twofish192 key) = encrypt key ecbDecrypt (Twofish192 key) = decrypt key newtype Twofish256 = Twofish256 Twofish instance Cipher Twofish256 where- cipherName _ = "Twofish256"+ cipherName _ = "Twofish256" cipherKeySize _ = KeySizeFixed 32- cipherInit key = Twofish256 <$> (initTwofish =<< validateKeySize (undefined :: Twofish256) key)+ cipherInit key =+ Twofish256 <$> (initTwofish =<< validateKeySize (undefined :: Twofish256) key) instance BlockCipher Twofish256 where- blockSize _ = 16+ blockSize _ = 16 ecbEncrypt (Twofish256 key) = encrypt key ecbDecrypt (Twofish256 key) = decrypt key
Crypto/Cipher/Twofish/Primitive.hs view
@@ -1,39 +1,44 @@-{-# LANGUAGE MagicHash #-} {-# LANGUAGE BangPatterns #-}-module Crypto.Cipher.Twofish.Primitive- ( Twofish- , initTwofish- , encrypt- , decrypt- ) where+{-# LANGUAGE MagicHash #-}+{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} -import Crypto.Error-import Crypto.Internal.ByteArray (ByteArray)+module Crypto.Cipher.Twofish.Primitive (+ Twofish,+ initTwofish,+ encrypt,+ decrypt,+) where++import Crypto.Error+import Crypto.Internal.ByteArray (ByteArray) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.WordArray-import Data.Word-import Data.Bits-import Data.List+import Crypto.Internal.WordArray+import Data.Bits+import Data.List (foldl')+import Data.Word -- Based on the Golang referance implementation -- https://github.com/golang/crypto/blob/master/twofish/twofish.go - -- BlockSize is the constant block size of Twofish. blockSize :: Int blockSize = 16 mdsPolynomial, rsPolynomial :: Word32 mdsPolynomial = 0x169 -- x^8 + x^6 + x^5 + x^3 + 1, see [TWOFISH] 4.2-rsPolynomial = 0x14d -- x^8 + x^6 + x^3 + x^2 + 1, see [TWOFISH] 4.3+rsPolynomial = 0x14d -- x^8 + x^6 + x^3 + x^2 + 1, see [TWOFISH] 4.3 -data Twofish = Twofish { s :: (Array32, Array32, Array32, Array32)- , k :: Array32 }+data Twofish = Twofish+ { s :: (Array32, Array32, Array32, Array32)+ , k :: Array32+ } data ByteSize = Bytes16 | Bytes24 | Bytes32 deriving (Eq) -data KeyPackage ba = KeyPackage { rawKeyBytes :: ba- , byteSize :: ByteSize }+data KeyPackage ba = KeyPackage+ { rawKeyBytes :: ba+ , byteSize :: ByteSize+ } buildPackage :: ByteArray ba => ba -> Maybe (KeyPackage ba) buildPackage key@@ -46,89 +51,159 @@ -- -- Return the initialized key or a error message if the given -- keyseed was not 16-bytes in length.-initTwofish :: ByteArray key- => key -- ^ The key to create the twofish context- -> CryptoFailable Twofish+initTwofish+ :: ByteArray key+ => key+ -- ^ The key to create the twofish context+ -> CryptoFailable Twofish initTwofish key =- case buildPackage key of Nothing -> CryptoFailed CryptoError_KeySizeInvalid- Just keyPackage -> CryptoPassed Twofish { k = generatedK, s = generatedS }- where generatedK = array32 40 $ genK keyPackage- generatedS = genSboxes keyPackage $ sWords key+ case buildPackage key of+ Nothing -> CryptoFailed CryptoError_KeySizeInvalid+ Just keyPackage -> CryptoPassed Twofish{k = generatedK, s = generatedS}+ where+ generatedK = array32 40 $ genK keyPackage+ generatedS = genSboxes keyPackage $ sWords key mapBlocks :: ByteArray ba => (ba -> ba) -> ba -> ba mapBlocks operation input | B.null rest = blockOutput | otherwise = blockOutput `B.append` mapBlocks operation rest- where (block, rest) = B.splitAt blockSize input- blockOutput = operation block+ where+ (block, rest) = B.splitAt blockSize input+ blockOutput = operation block -- | Encrypts the given ByteString using the given Key-encrypt :: ByteArray ba- => Twofish -- ^ The key to use- -> ba -- ^ The data to encrypt- -> ba+encrypt+ :: ByteArray ba+ => Twofish+ -- ^ The key to use+ -> ba+ -- ^ The data to encrypt+ -> ba encrypt cipher = mapBlocks (encryptBlock cipher) encryptBlock :: ByteArray ba => Twofish -> ba -> ba-encryptBlock Twofish { s = (s1, s2, s3, s4), k = ks } message = store32ls ts- where (a, b, c, d) = load32ls message- a' = a `xor` arrayRead32 ks 0- b' = b `xor` arrayRead32 ks 1- c' = c `xor` arrayRead32 ks 2- d' = d `xor` arrayRead32 ks 3- (!a'', !b'', !c'', !d'') = foldl' shuffle (a', b', c', d') [0..7]- ts = (c'' `xor` arrayRead32 ks 4, d'' `xor` arrayRead32 ks 5, a'' `xor` arrayRead32 ks 6, b'' `xor` arrayRead32 ks 7)+encryptBlock Twofish{s = (s1, s2, s3, s4), k = ks} message = store32ls ts+ where+ (a, b, c, d) = load32ls message+ a' = a `xor` arrayRead32 ks 0+ b' = b `xor` arrayRead32 ks 1+ c' = c `xor` arrayRead32 ks 2+ d' = d `xor` arrayRead32 ks 3+ (!a'', !b'', !c'', !d'') = foldl' shuffle (a', b', c', d') [0 .. 7]+ ts =+ ( c'' `xor` arrayRead32 ks 4+ , d'' `xor` arrayRead32 ks 5+ , a'' `xor` arrayRead32 ks 6+ , b'' `xor` arrayRead32 ks 7+ ) - shuffle :: (Word32, Word32, Word32, Word32) -> Int -> (Word32, Word32, Word32, Word32)- shuffle (!retA, !retB, !retC, !retD) ind = (retA', retB', retC', retD')- where [k0, k1, k2, k3] = fmap (\offset -> arrayRead32 ks $ (8 + 4 * ind) + offset) [0..3]- t2 = byteIndex s2 retB `xor` byteIndex s3 (shiftR retB 8) `xor` byteIndex s4 (shiftR retB 16) `xor` byteIndex s1 (shiftR retB 24)- t1 = (byteIndex s1 retA `xor` byteIndex s2 (shiftR retA 8) `xor` byteIndex s3 (shiftR retA 16) `xor` byteIndex s4 (shiftR retA 24)) + t2- retC' = rotateR (retC `xor` (t1 + k0)) 1- retD' = rotateL retD 1 `xor` (t1 + t2 + k1)- t2' = byteIndex s2 retD' `xor` byteIndex s3 (shiftR retD' 8) `xor` byteIndex s4 (shiftR retD' 16) `xor` byteIndex s1 (shiftR retD' 24)- t1' = (byteIndex s1 retC' `xor` byteIndex s2 (shiftR retC' 8) `xor` byteIndex s3 (shiftR retC' 16) `xor` byteIndex s4 (shiftR retC' 24)) + t2'- retA' = rotateR (retA `xor` (t1' + k2)) 1- retB' = rotateL retB 1 `xor` (t1' + t2' + k3)+ shuffle+ :: (Word32, Word32, Word32, Word32) -> Int -> (Word32, Word32, Word32, Word32)+ shuffle (!retA, !retB, !retC, !retD) ind = (retA', retB', retC', retD')+ where+ [k0, k1, k2, k3] = fmap (\offset -> arrayRead32 ks $ (8 + 4 * ind) + offset) [0 .. 3]+ t2 =+ byteIndex s2 retB+ `xor` byteIndex s3 (shiftR retB 8)+ `xor` byteIndex s4 (shiftR retB 16)+ `xor` byteIndex s1 (shiftR retB 24)+ t1 =+ ( byteIndex s1 retA+ `xor` byteIndex s2 (shiftR retA 8)+ `xor` byteIndex s3 (shiftR retA 16)+ `xor` byteIndex s4 (shiftR retA 24)+ )+ + t2+ retC' = rotateR (retC `xor` (t1 + k0)) 1+ retD' = rotateL retD 1 `xor` (t1 + t2 + k1)+ t2' =+ byteIndex s2 retD'+ `xor` byteIndex s3 (shiftR retD' 8)+ `xor` byteIndex s4 (shiftR retD' 16)+ `xor` byteIndex s1 (shiftR retD' 24)+ t1' =+ ( byteIndex s1 retC'+ `xor` byteIndex s2 (shiftR retC' 8)+ `xor` byteIndex s3 (shiftR retC' 16)+ `xor` byteIndex s4 (shiftR retC' 24)+ )+ + t2'+ retA' = rotateR (retA `xor` (t1' + k2)) 1+ retB' = rotateL retB 1 `xor` (t1' + t2' + k3) -- Unsafe, no bounds checking byteIndex :: Array32 -> Word32 -> Word32-byteIndex xs ind = arrayRead32 xs $ fromIntegral byte- where byte = ind `mod` 256+byteIndex xs ind = arrayRead32 xs $ fromIntegral byte+ where+ byte = ind `mod` 256 -- | Decrypts the given ByteString using the given Key-decrypt :: ByteArray ba- => Twofish -- ^ The key to use- -> ba -- ^ The data to decrypt- -> ba+decrypt+ :: ByteArray ba+ => Twofish+ -- ^ The key to use+ -> ba+ -- ^ The data to decrypt+ -> ba decrypt cipher = mapBlocks (decryptBlock cipher) {- decryption for 128 bits blocks -} decryptBlock :: ByteArray ba => Twofish -> ba -> ba-decryptBlock Twofish { s = (s1, s2, s3, s4), k = ks } message = store32ls ixs- where (a, b, c, d) = load32ls message- a' = c `xor` arrayRead32 ks 6- b' = d `xor` arrayRead32 ks 7- c' = a `xor` arrayRead32 ks 4- d' = b `xor` arrayRead32 ks 5- (!a'', !b'', !c'', !d'') = foldl' unshuffle (a', b', c', d') [8, 7..1]- ixs = (a'' `xor` arrayRead32 ks 0, b'' `xor` arrayRead32 ks 1, c'' `xor` arrayRead32 ks 2, d'' `xor` arrayRead32 ks 3)+decryptBlock Twofish{s = (s1, s2, s3, s4), k = ks} message = store32ls ixs+ where+ (a, b, c, d) = load32ls message+ a' = c `xor` arrayRead32 ks 6+ b' = d `xor` arrayRead32 ks 7+ c' = a `xor` arrayRead32 ks 4+ d' = b `xor` arrayRead32 ks 5+ (!a'', !b'', !c'', !d'') = foldl' unshuffle (a', b', c', d') [8, 7 .. 1]+ ixs =+ ( a'' `xor` arrayRead32 ks 0+ , b'' `xor` arrayRead32 ks 1+ , c'' `xor` arrayRead32 ks 2+ , d'' `xor` arrayRead32 ks 3+ ) - unshuffle :: (Word32, Word32, Word32, Word32) -> Int -> (Word32, Word32, Word32, Word32)- unshuffle (!retA, !retB, !retC, !retD) ind = (retA', retB', retC', retD')- where [k0, k1, k2, k3] = fmap (\offset -> arrayRead32 ks $ (4 + 4 * ind) + offset) [0..3]- t2 = byteIndex s2 retD `xor` byteIndex s3 (shiftR retD 8) `xor` byteIndex s4 (shiftR retD 16) `xor` byteIndex s1 (shiftR retD 24)- t1 = (byteIndex s1 retC `xor` byteIndex s2 (shiftR retC 8) `xor` byteIndex s3 (shiftR retC 16) `xor` byteIndex s4 (shiftR retC 24)) + t2- retA' = rotateL retA 1 `xor` (t1 + k2)- retB' = rotateR (retB `xor` (t2 + t1 + k3)) 1- t2' = byteIndex s2 retB' `xor` byteIndex s3 (shiftR retB' 8) `xor` byteIndex s4 (shiftR retB' 16) `xor` byteIndex s1 (shiftR retB' 24)- t1' = (byteIndex s1 retA' `xor` byteIndex s2 (shiftR retA' 8) `xor` byteIndex s3 (shiftR retA' 16) `xor` byteIndex s4 (shiftR retA' 24)) + t2'- retC' = rotateL retC 1 `xor` (t1' + k0)- retD' = rotateR (retD `xor` (t2' + t1' + k1)) 1+ unshuffle+ :: (Word32, Word32, Word32, Word32) -> Int -> (Word32, Word32, Word32, Word32)+ unshuffle (!retA, !retB, !retC, !retD) ind = (retA', retB', retC', retD')+ where+ [k0, k1, k2, k3] = fmap (\offset -> arrayRead32 ks $ (4 + 4 * ind) + offset) [0 .. 3]+ t2 =+ byteIndex s2 retD+ `xor` byteIndex s3 (shiftR retD 8)+ `xor` byteIndex s4 (shiftR retD 16)+ `xor` byteIndex s1 (shiftR retD 24)+ t1 =+ ( byteIndex s1 retC+ `xor` byteIndex s2 (shiftR retC 8)+ `xor` byteIndex s3 (shiftR retC 16)+ `xor` byteIndex s4 (shiftR retC 24)+ )+ + t2+ retA' = rotateL retA 1 `xor` (t1 + k2)+ retB' = rotateR (retB `xor` (t2 + t1 + k3)) 1+ t2' =+ byteIndex s2 retB'+ `xor` byteIndex s3 (shiftR retB' 8)+ `xor` byteIndex s4 (shiftR retB' 16)+ `xor` byteIndex s1 (shiftR retB' 24)+ t1' =+ ( byteIndex s1 retA'+ `xor` byteIndex s2 (shiftR retA' 8)+ `xor` byteIndex s3 (shiftR retA' 16)+ `xor` byteIndex s4 (shiftR retA' 24)+ )+ + t2'+ retC' = rotateL retC 1 `xor` (t1' + k0)+ retD' = rotateR (retD `xor` (t2' + t1' + k1)) 1 sbox0 :: Int -> Word8 sbox0 = arrayRead8 t- where t = array8+ where+ t =+ array8 "\xa9\x67\xb3\xe8\x04\xfd\xa3\x76\x9a\x92\x80\x78\xe4\xdd\xd1\x38\ \\x0d\xc6\x35\x98\x18\xf7\xec\x6c\x43\x75\x37\x26\xfa\x13\x94\x48\ \\xf2\xd0\x8b\x30\x84\x54\xdf\x23\x19\x5b\x3d\x59\xf3\xae\xa2\x82\@@ -148,7 +223,9 @@ sbox1 :: Int -> Word8 sbox1 = arrayRead8 t- where t = array8+ where+ t =+ array8 "\x75\xf3\xc6\xf4\xdb\x7b\xfb\xc8\x4a\xd3\xe6\x6b\x45\x7d\xe8\x4b\ \\xd6\x32\xd8\xfd\x37\x71\xf1\xe1\x30\x0f\xf8\x1b\x87\xfa\x06\x3f\ \\x5e\xba\xae\x5b\x8a\x00\xbc\x9d\x6d\xc1\xb1\x0e\x80\x5d\xd2\xd5\@@ -167,145 +244,281 @@ \\xd7\x61\x1e\xb4\x50\x04\xf6\xc2\x16\x25\x86\x56\x55\x09\xbe\x91"# rs :: [[Word8]]-rs = [ [0x01, 0xA4, 0x55, 0x87, 0x5A, 0x58, 0xDB, 0x9E]- , [0xA4, 0x56, 0x82, 0xF3, 0x1E, 0xC6, 0x68, 0xE5]- , [0x02, 0xA1, 0xFC, 0xC1, 0x47, 0xAE, 0x3D, 0x19]- , [0xA4, 0x55, 0x87, 0x5A, 0x58, 0xDB, 0x9E, 0x03] ]--+rs =+ [ [0x01, 0xA4, 0x55, 0x87, 0x5A, 0x58, 0xDB, 0x9E]+ , [0xA4, 0x56, 0x82, 0xF3, 0x1E, 0xC6, 0x68, 0xE5]+ , [0x02, 0xA1, 0xFC, 0xC1, 0x47, 0xAE, 0x3D, 0x19]+ , [0xA4, 0x55, 0x87, 0x5A, 0x58, 0xDB, 0x9E, 0x03]+ ] load32ls :: ByteArray ba => ba -> (Word32, Word32, Word32, Word32) load32ls message = (intify q1, intify q2, intify q3, intify q4)- where (half1, half2) = B.splitAt 8 message- (q1, q2) = B.splitAt 4 half1- (q3, q4) = B.splitAt 4 half2+ where+ (half1, half2) = B.splitAt 8 message+ (q1, q2) = B.splitAt 4 half1+ (q3, q4) = B.splitAt 4 half2 - intify :: ByteArray ba => ba -> Word32- intify bytes = foldl' (\int (!word, !ind) -> int .|. shiftL (fromIntegral word) (ind * 8) ) 0 (zip (B.unpack bytes) [0..])+ intify :: ByteArray ba => ba -> Word32+ intify bytes =+ foldl'+ (\int (!word, !ind) -> int .|. shiftL (fromIntegral word) (ind * 8))+ 0+ (zip (B.unpack bytes) [0 ..]) store32ls :: ByteArray ba => (Word32, Word32, Word32, Word32) -> ba store32ls (a, b, c, d) = B.pack $ concatMap splitWordl [a, b, c, d]- where splitWordl :: Word32 -> [Word8]- splitWordl w = fmap (\ind -> fromIntegral $ shiftR w (8 * ind)) [0..3]-+ where+ splitWordl :: Word32 -> [Word8]+ splitWordl w = fmap (\ind -> fromIntegral $ shiftR w (8 * ind)) [0 .. 3] -- Create S words sWords :: ByteArray ba => ba -> [Word8] sWords key = sWord- where word64Count = B.length key `div` 2- sWord = concatMap (\wordIndex ->- map (\rsRow ->- foldl' (\acc (!rsVal, !colIndex) ->+ where+ word64Count = B.length key `div` 2+ sWord =+ concatMap+ ( \wordIndex ->+ map+ ( \rsRow ->+ foldl'+ ( \acc (!rsVal, !colIndex) -> acc `xor` gfMult rsPolynomial (B.index key $ 8 * wordIndex + colIndex) rsVal- ) 0 (zip rsRow [0..])- ) rs- ) [0..word64Count - 1]+ )+ 0+ (zip rsRow [0 ..])+ )+ rs+ )+ [0 .. word64Count - 1] data Column = Zero | One | Two | Three deriving (Show, Eq, Enum, Bounded) genSboxes :: KeyPackage ba -> [Word8] -> (Array32, Array32, Array32, Array32) genSboxes keyPackage ws = (mkArray b0', mkArray b1', mkArray b2', mkArray b3')- where range = [0..255]- mkArray = array32 256- [w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15] = take 16 ws- (b0', b1', b2', b3') = sboxBySize $ byteSize keyPackage-- sboxBySize :: ByteSize -> ([Word32], [Word32], [Word32], [Word32])- sboxBySize Bytes16 = (b0, b1, b2, b3)- where !b0 = fmap mapper range- where mapper :: Int -> Word32- mapper byte = mdsColumnMult ((sbox1 . fromIntegral) ((sbox0 . fromIntegral $ sbox0 byte `xor` w0) `xor` w4)) Zero- !b1 = fmap mapper range- where mapper byte = mdsColumnMult ((sbox0 . fromIntegral) ((sbox0 . fromIntegral $ sbox1 byte `xor` w1) `xor` w5)) One- !b2 = fmap mapper range- where mapper byte = mdsColumnMult ((sbox1 . fromIntegral) ((sbox1 . fromIntegral $ sbox0 byte `xor` w2) `xor` w6)) Two- !b3 = fmap mapper range- where mapper byte = mdsColumnMult ((sbox0 . fromIntegral) ((sbox1 . fromIntegral $ sbox1 byte `xor` w3) `xor` w7)) Three-- sboxBySize Bytes24 = (b0, b1, b2, b3)- where !b0 = fmap mapper range- where mapper byte = mdsColumnMult ((sbox1 . fromIntegral) ((sbox0 . fromIntegral) ((sbox0 . fromIntegral $ sbox1 byte `xor` w0) `xor` w4) `xor` w8)) Zero- !b1 = fmap mapper range- where mapper byte = mdsColumnMult ((sbox0 . fromIntegral) ((sbox0 . fromIntegral) ((sbox1 . fromIntegral $ sbox1 byte `xor` w1) `xor` w5) `xor` w9)) One- !b2 = fmap mapper range- where mapper byte = mdsColumnMult ((sbox1 . fromIntegral) ((sbox1 . fromIntegral) ((sbox0 . fromIntegral $ sbox0 byte `xor` w2) `xor` w6) `xor` w10)) Two- !b3 = fmap mapper range- where mapper byte = mdsColumnMult ((sbox0 . fromIntegral) ((sbox1 . fromIntegral) ((sbox1 . fromIntegral $ sbox0 byte `xor` w3) `xor` w7) `xor` w11)) Three-- sboxBySize Bytes32 = (b0, b1, b2, b3)- where !b0 = fmap mapper range- where mapper byte = mdsColumnMult ((sbox1 . fromIntegral) ((sbox0 . fromIntegral) ((sbox0 . fromIntegral) ((sbox1 . fromIntegral $ sbox1 byte `xor` w0) `xor` w4) `xor` w8) `xor` w12)) Zero- !b1 = fmap mapper range- where mapper byte = mdsColumnMult ((sbox0 . fromIntegral) ((sbox0 . fromIntegral) ((sbox1 . fromIntegral) ((sbox1 . fromIntegral $ sbox0 byte `xor` w1) `xor` w5) `xor` w9) `xor` w13)) One- !b2 = fmap mapper range- where mapper byte = mdsColumnMult ((sbox1 . fromIntegral) ((sbox1 . fromIntegral) ((sbox0 . fromIntegral) ((sbox0 . fromIntegral $ sbox0 byte `xor` w2) `xor` w6) `xor` w10) `xor` w14)) Two- !b3 = fmap mapper range- where mapper byte = mdsColumnMult ((sbox0 . fromIntegral) ((sbox1 . fromIntegral) ((sbox1 . fromIntegral) ((sbox0 . fromIntegral $ sbox1 byte `xor` w3) `xor` w7) `xor` w11) `xor` w15)) Three--genK :: (ByteArray ba) => KeyPackage ba -> [Word32]-genK keyPackage = concatMap makeTuple [0..19]- where makeTuple :: Word8 -> [Word32]- makeTuple idx = [a + b', rotateL (2 * b' + a) 9]- where tmp1 = replicate 4 $ 2 * idx- tmp2 = fmap (+1) tmp1- a = h tmp1 keyPackage 0- b = h tmp2 keyPackage 1- b' = rotateL b 8+ where+ range = [0 .. 255]+ mkArray = array32 256+ [w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15] = take 16 ws+ (b0', b1', b2', b3') = sboxBySize $ byteSize keyPackage -h :: (ByteArray ba) => [Word8] -> KeyPackage ba -> Int -> Word32-h input keyPackage offset = foldl' xorMdsColMult 0 $ zip [y0f, y1f, y2f, y3f] $ enumFrom Zero- where key = rawKeyBytes keyPackage- [y0, y1, y2, y3] = take 4 input- (!y0f, !y1f, !y2f, !y3f) = run (y0, y1, y2, y3) $ byteSize keyPackage+ sboxBySize :: ByteSize -> ([Word32], [Word32], [Word32], [Word32])+ sboxBySize Bytes16 = (b0, b1, b2, b3)+ where+ !b0 = fmap mapper range+ where+ mapper :: Int -> Word32+ mapper byte =+ mdsColumnMult+ ((sbox1 . fromIntegral) ((sbox0 . fromIntegral $ sbox0 byte `xor` w0) `xor` w4))+ Zero+ !b1 = fmap mapper range+ where+ mapper byte =+ mdsColumnMult+ ((sbox0 . fromIntegral) ((sbox0 . fromIntegral $ sbox1 byte `xor` w1) `xor` w5))+ One+ !b2 = fmap mapper range+ where+ mapper byte =+ mdsColumnMult+ ((sbox1 . fromIntegral) ((sbox1 . fromIntegral $ sbox0 byte `xor` w2) `xor` w6))+ Two+ !b3 = fmap mapper range+ where+ mapper byte =+ mdsColumnMult+ ((sbox0 . fromIntegral) ((sbox1 . fromIntegral $ sbox1 byte `xor` w3) `xor` w7))+ Three+ sboxBySize Bytes24 = (b0, b1, b2, b3)+ where+ !b0 = fmap mapper range+ where+ mapper byte =+ mdsColumnMult+ ( (sbox1 . fromIntegral)+ ( (sbox0 . fromIntegral) ((sbox0 . fromIntegral $ sbox1 byte `xor` w0) `xor` w4)+ `xor` w8+ )+ )+ Zero+ !b1 = fmap mapper range+ where+ mapper byte =+ mdsColumnMult+ ( (sbox0 . fromIntegral)+ ( (sbox0 . fromIntegral) ((sbox1 . fromIntegral $ sbox1 byte `xor` w1) `xor` w5)+ `xor` w9+ )+ )+ One+ !b2 = fmap mapper range+ where+ mapper byte =+ mdsColumnMult+ ( (sbox1 . fromIntegral)+ ( (sbox1 . fromIntegral) ((sbox0 . fromIntegral $ sbox0 byte `xor` w2) `xor` w6)+ `xor` w10+ )+ )+ Two+ !b3 = fmap mapper range+ where+ mapper byte =+ mdsColumnMult+ ( (sbox0 . fromIntegral)+ ( (sbox1 . fromIntegral) ((sbox1 . fromIntegral $ sbox0 byte `xor` w3) `xor` w7)+ `xor` w11+ )+ )+ Three+ sboxBySize Bytes32 = (b0, b1, b2, b3)+ where+ !b0 = fmap mapper range+ where+ mapper byte =+ mdsColumnMult+ ( (sbox1 . fromIntegral)+ ( (sbox0 . fromIntegral)+ ( (sbox0 . fromIntegral) ((sbox1 . fromIntegral $ sbox1 byte `xor` w0) `xor` w4)+ `xor` w8+ )+ `xor` w12+ )+ )+ Zero+ !b1 = fmap mapper range+ where+ mapper byte =+ mdsColumnMult+ ( (sbox0 . fromIntegral)+ ( (sbox0 . fromIntegral)+ ( (sbox1 . fromIntegral) ((sbox1 . fromIntegral $ sbox0 byte `xor` w1) `xor` w5)+ `xor` w9+ )+ `xor` w13+ )+ )+ One+ !b2 = fmap mapper range+ where+ mapper byte =+ mdsColumnMult+ ( (sbox1 . fromIntegral)+ ( (sbox1 . fromIntegral)+ ( (sbox0 . fromIntegral) ((sbox0 . fromIntegral $ sbox0 byte `xor` w2) `xor` w6)+ `xor` w10+ )+ `xor` w14+ )+ )+ Two+ !b3 = fmap mapper range+ where+ mapper byte =+ mdsColumnMult+ ( (sbox0 . fromIntegral)+ ( (sbox1 . fromIntegral)+ ( (sbox1 . fromIntegral) ((sbox0 . fromIntegral $ sbox1 byte `xor` w3) `xor` w7)+ `xor` w11+ )+ `xor` w15+ )+ )+ Three - run :: (Word8, Word8, Word8, Word8) -> ByteSize -> (Word8, Word8, Word8, Word8)- run (!y0'', !y1'', !y2'', !y3'') Bytes32 = run (y0', y1', y2', y3') Bytes24- where y0' = sbox1 (fromIntegral y0'') `xor` B.index key (4 * (6 + offset) + 0)- y1' = sbox0 (fromIntegral y1'') `xor` B.index key (4 * (6 + offset) + 1)- y2' = sbox0 (fromIntegral y2'') `xor` B.index key (4 * (6 + offset) + 2)- y3' = sbox1 (fromIntegral y3'') `xor` B.index key (4 * (6 + offset) + 3)+genK :: ByteArray ba => KeyPackage ba -> [Word32]+genK keyPackage = concatMap makeTuple [0 .. 19]+ where+ makeTuple :: Word8 -> [Word32]+ makeTuple idx = [a + b', rotateL (2 * b' + a) 9]+ where+ tmp1 = replicate 4 $ 2 * idx+ tmp2 = fmap (+ 1) tmp1+ a = h tmp1 keyPackage 0+ b = h tmp2 keyPackage 1+ b' = rotateL b 8 - run (!y0'', !y1'', !y2'', !y3'') Bytes24 = run (y0', y1', y2', y3') Bytes16- where y0' = sbox1 (fromIntegral y0'') `xor` B.index key (4 * (4 + offset) + 0)- y1' = sbox1 (fromIntegral y1'') `xor` B.index key (4 * (4 + offset) + 1)- y2' = sbox0 (fromIntegral y2'') `xor` B.index key (4 * (4 + offset) + 2)- y3' = sbox0 (fromIntegral y3'') `xor` B.index key (4 * (4 + offset) + 3)+h :: ByteArray ba => [Word8] -> KeyPackage ba -> Int -> Word32+h input keyPackage offset = foldl' xorMdsColMult 0 $ zip [y0f, y1f, y2f, y3f] $ enumFrom Zero+ where+ key = rawKeyBytes keyPackage+ [y0, y1, y2, y3] = take 4 input+ (!y0f, !y1f, !y2f, !y3f) = run (y0, y1, y2, y3) $ byteSize keyPackage - run (!y0'', !y1'', !y2'', !y3'') Bytes16 = (y0', y1', y2', y3')- where y0' = sbox1 . fromIntegral $ (sbox0 . fromIntegral $ (sbox0 (fromIntegral y0'') `xor` B.index key (4 * (2 + offset) + 0))) `xor` B.index key (4 * (0 + offset) + 0)- y1' = sbox0 . fromIntegral $ (sbox0 . fromIntegral $ (sbox1 (fromIntegral y1'') `xor` B.index key (4 * (2 + offset) + 1))) `xor` B.index key (4 * (0 + offset) + 1)- y2' = sbox1 . fromIntegral $ (sbox1 . fromIntegral $ (sbox0 (fromIntegral y2'') `xor` B.index key (4 * (2 + offset) + 2))) `xor` B.index key (4 * (0 + offset) + 2)- y3' = sbox0 . fromIntegral $ (sbox1 . fromIntegral $ (sbox1 (fromIntegral y3'') `xor` B.index key (4 * (2 + offset) + 3))) `xor` B.index key (4 * (0 + offset) + 3)+ run :: (Word8, Word8, Word8, Word8) -> ByteSize -> (Word8, Word8, Word8, Word8)+ run (!y0'', !y1'', !y2'', !y3'') Bytes32 = run (y0', y1', y2', y3') Bytes24+ where+ y0' = sbox1 (fromIntegral y0'') `xor` B.index key (4 * (6 + offset) + 0)+ y1' = sbox0 (fromIntegral y1'') `xor` B.index key (4 * (6 + offset) + 1)+ y2' = sbox0 (fromIntegral y2'') `xor` B.index key (4 * (6 + offset) + 2)+ y3' = sbox1 (fromIntegral y3'') `xor` B.index key (4 * (6 + offset) + 3)+ run (!y0'', !y1'', !y2'', !y3'') Bytes24 = run (y0', y1', y2', y3') Bytes16+ where+ y0' = sbox1 (fromIntegral y0'') `xor` B.index key (4 * (4 + offset) + 0)+ y1' = sbox1 (fromIntegral y1'') `xor` B.index key (4 * (4 + offset) + 1)+ y2' = sbox0 (fromIntegral y2'') `xor` B.index key (4 * (4 + offset) + 2)+ y3' = sbox0 (fromIntegral y3'') `xor` B.index key (4 * (4 + offset) + 3)+ run (!y0'', !y1'', !y2'', !y3'') Bytes16 = (y0', y1', y2', y3')+ where+ y0' =+ sbox1 . fromIntegral $+ ( sbox0 . fromIntegral $+ (sbox0 (fromIntegral y0'') `xor` B.index key (4 * (2 + offset) + 0))+ )+ `xor` B.index key (4 * (0 + offset) + 0)+ y1' =+ sbox0 . fromIntegral $+ ( sbox0 . fromIntegral $+ (sbox1 (fromIntegral y1'') `xor` B.index key (4 * (2 + offset) + 1))+ )+ `xor` B.index key (4 * (0 + offset) + 1)+ y2' =+ sbox1 . fromIntegral $+ ( sbox1 . fromIntegral $+ (sbox0 (fromIntegral y2'') `xor` B.index key (4 * (2 + offset) + 2))+ )+ `xor` B.index key (4 * (0 + offset) + 2)+ y3' =+ sbox0 . fromIntegral $+ ( sbox1 . fromIntegral $+ (sbox1 (fromIntegral y3'') `xor` B.index key (4 * (2 + offset) + 3))+ )+ `xor` B.index key (4 * (0 + offset) + 3) - xorMdsColMult :: Word32 -> (Word8, Column) -> Word32- xorMdsColMult acc wordAndIndex = acc `xor` uncurry mdsColumnMult wordAndIndex+ xorMdsColMult :: Word32 -> (Word8, Column) -> Word32+ xorMdsColMult acc wordAndIndex = acc `xor` uncurry mdsColumnMult wordAndIndex mdsColumnMult :: Word8 -> Column -> Word32 mdsColumnMult !byte !col =- case col of Zero -> input .|. rotateL mul5B 8 .|. rotateL mulEF 16 .|. rotateL mulEF 24- One -> mulEF .|. rotateL mulEF 8 .|. rotateL mul5B 16 .|. rotateL input 24- Two -> mul5B .|. rotateL mulEF 8 .|. rotateL input 16 .|. rotateL mulEF 24- Three -> mul5B .|. rotateL input 8 .|. rotateL mulEF 16 .|. rotateL mul5B 24- where input = fromIntegral byte- mul5B = fromIntegral $ gfMult mdsPolynomial byte 0x5B- mulEF = fromIntegral $ gfMult mdsPolynomial byte 0xEF+ case col of+ Zero -> input .|. rotateL mul5B 8 .|. rotateL mulEF 16 .|. rotateL mulEF 24+ One -> mulEF .|. rotateL mulEF 8 .|. rotateL mul5B 16 .|. rotateL input 24+ Two -> mul5B .|. rotateL mulEF 8 .|. rotateL input 16 .|. rotateL mulEF 24+ Three -> mul5B .|. rotateL input 8 .|. rotateL mulEF 16 .|. rotateL mul5B 24+ where+ input = fromIntegral byte+ mul5B = fromIntegral $ gfMult mdsPolynomial byte 0x5B+ mulEF = fromIntegral $ gfMult mdsPolynomial byte 0xEF -tupInd :: (Bits b) => b -> (a, a) -> a+tupInd :: Bits b => b -> (a, a) -> a tupInd b | testBit b 0 = snd | otherwise = fst gfMult :: Word32 -> Word8 -> Word8 -> Word8 gfMult p a b = fromIntegral $ run a b' p' result 0- where b' = (0, fromIntegral b)- p' = (0, p)- result = 0+ where+ b' = (0, fromIntegral b)+ p' = (0, p)+ result = 0 - run :: Word8 -> (Word32, Word32) -> (Word32, Word32) -> Word32 -> Int -> Word32- run a' b'' p'' result' count =- if count == 7+ run :: Word8 -> (Word32, Word32) -> (Word32, Word32) -> Word32 -> Int -> Word32+ run a' b'' p'' result' count =+ if count == 7 then result'' else run a'' b''' p'' result'' (count + 1)- where result'' = result' `xor` tupInd (a' .&. 1) b''- a'' = shiftR a' 1- b''' = (fst b'', tupInd (shiftR (snd b'') 7) p'' `xor` shiftL (snd b'') 1)+ where+ result'' = result' `xor` tupInd (a' .&. 1) b''+ a'' = shiftR a' 1+ b''' = (fst b'', tupInd (shiftR (snd b'') 7) p'' `xor` shiftL (snd b'') 1)
Crypto/Cipher/Types.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE DeriveDataTypeable #-}+ -- | -- Module : Crypto.Cipher.Types -- License : BSD-style@@ -6,34 +8,34 @@ -- Portability : Excellent -- -- Symmetric cipher basic types----{-# LANGUAGE DeriveDataTypeable #-}-module Crypto.Cipher.Types- (+module Crypto.Cipher.Types ( -- * Cipher classes- Cipher(..)- , BlockCipher(..)- , BlockCipher128(..)- , StreamCipher(..)- , DataUnitOffset- , KeySizeSpecifier(..)+ Cipher (..),+ BlockCipher (..),+ BlockCipher128 (..),+ StreamCipher (..),+ DataUnitOffset,+ KeySizeSpecifier (..), -- , cfb8Encrypt -- , cfb8Decrypt+ -- * AEAD functions- , AEADMode(..)- , CCM_M(..)- , CCM_L(..)- , module Crypto.Cipher.Types.AEAD+ AEADMode (..),+ CCM_M (..),+ CCM_L (..),+ module Crypto.Cipher.Types.AEAD,+ -- * Initial Vector type and constructor- , IV- , makeIV- , nullIV- , ivAdd+ IV,+ makeIV,+ nullIV,+ ivAdd,+ -- * Authentification Tag- , AuthTag(..)- ) where+ AuthTag (..),+) where +import Crypto.Cipher.Types.AEAD import Crypto.Cipher.Types.Base import Crypto.Cipher.Types.Block import Crypto.Cipher.Types.Stream-import Crypto.Cipher.Types.AEAD
Crypto/Cipher/Types/AEAD.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE Rank2Types #-}+ -- | -- Module : Crypto.Cipher.Types.AEAD -- License : BSD-style@@ -6,28 +9,25 @@ -- Portability : Excellent -- -- AEAD cipher basic types----{-# LANGUAGE ExistentialQuantification #-}-{-# LANGUAGE Rank2Types #-} module Crypto.Cipher.Types.AEAD where -import Crypto.Cipher.Types.Base-import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray)+import Crypto.Cipher.Types.Base+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.Imports+import Crypto.Internal.Imports -- | AEAD Implementation data AEADModeImpl st = AEADModeImpl- { aeadImplAppendHeader :: forall ba . ByteArrayAccess ba => st -> ba -> st- , aeadImplEncrypt :: forall ba . ByteArray ba => st -> ba -> (ba, st)- , aeadImplDecrypt :: forall ba . ByteArray ba => st -> ba -> (ba, st)- , aeadImplFinalize :: st -> Int -> AuthTag+ { aeadImplAppendHeader :: forall ba. ByteArrayAccess ba => st -> ba -> st+ , aeadImplEncrypt :: forall ba. ByteArray ba => st -> ba -> (ba, st)+ , aeadImplDecrypt :: forall ba. ByteArray ba => st -> ba -> (ba, st)+ , aeadImplFinalize :: st -> Int -> AuthTag } -- | Authenticated Encryption with Associated Data algorithms-data AEAD cipher = forall st . AEAD+data AEAD cipher = forall st. AEAD { aeadModeImpl :: AEADModeImpl st- , aeadState :: !st+ , aeadState :: !st } -- | Append some header information to an AEAD context@@ -47,28 +47,41 @@ aeadFinalize (AEAD impl st) = aeadImplFinalize impl st -- | Simple AEAD encryption-aeadSimpleEncrypt :: (ByteArrayAccess aad, ByteArray ba)- => AEAD a -- ^ A new AEAD Context- -> aad -- ^ Optional Authentication data header- -> ba -- ^ Optional Plaintext- -> Int -- ^ Tag length- -> (AuthTag, ba) -- ^ Authentication tag and ciphertext+aeadSimpleEncrypt+ :: (ByteArrayAccess aad, ByteArray ba)+ => AEAD a+ -- ^ A new AEAD Context+ -> aad+ -- ^ Optional Authentication data header+ -> ba+ -- ^ Optional Plaintext+ -> Int+ -- ^ Tag length+ -> (AuthTag, ba)+ -- ^ Authentication tag and ciphertext aeadSimpleEncrypt aeadIni header input taglen = (tag, output)- where aead = aeadAppendHeader aeadIni header- (output, aeadFinal) = aeadEncrypt aead input- tag = aeadFinalize aeadFinal taglen+ where+ aead = aeadAppendHeader aeadIni header+ (output, aeadFinal) = aeadEncrypt aead input+ tag = aeadFinalize aeadFinal taglen -- | Simple AEAD decryption-aeadSimpleDecrypt :: (ByteArrayAccess aad, ByteArray ba)- => AEAD a -- ^ A new AEAD Context- -> aad -- ^ Optional Authentication data header- -> ba -- ^ Ciphertext- -> AuthTag -- ^ The authentication tag- -> Maybe ba -- ^ Plaintext+aeadSimpleDecrypt+ :: (ByteArrayAccess aad, ByteArray ba)+ => AEAD a+ -- ^ A new AEAD Context+ -> aad+ -- ^ Optional Authentication data header+ -> ba+ -- ^ Ciphertext+ -> AuthTag+ -- ^ The authentication tag+ -> Maybe ba+ -- ^ Plaintext aeadSimpleDecrypt aeadIni header input authTag | tag == authTag = Just output- | otherwise = Nothing- where aead = aeadAppendHeader aeadIni header- (output, aeadFinal) = aeadDecrypt aead input- tag = aeadFinalize aeadFinal (B.length authTag)-+ | otherwise = Nothing+ where+ aead = aeadAppendHeader aeadIni header+ (output, aeadFinal) = aeadDecrypt aead input+ tag = aeadFinalize aeadFinal (B.length authTag)
Crypto/Cipher/Types/Base.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.Cipher.Types.Base -- License : BSD-style@@ -6,60 +9,63 @@ -- Portability : Excellent -- -- Symmetric cipher basic types----{-# LANGUAGE ExistentialQuantification #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.Cipher.Types.Base- ( KeySizeSpecifier(..)- , Cipher(..)- , AuthTag(..)- , AEADMode(..)- , CCM_M(..)- , CCM_L(..)- , DataUnitOffset- ) where+module Crypto.Cipher.Types.Base (+ KeySizeSpecifier (..),+ Cipher (..),+ AuthTag (..),+ AEADMode (..),+ CCM_M (..),+ CCM_L (..),+ DataUnitOffset,+) where -import Data.Word-import Crypto.Internal.ByteArray (Bytes, ByteArrayAccess, ByteArray)+import Crypto.Error+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess, Bytes) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.DeepSeq-import Crypto.Error+import Crypto.Internal.DeepSeq+import Data.Word -- | Different specifier for key size in bytes-data KeySizeSpecifier =- KeySizeRange Int Int -- ^ in the range [min,max]- | KeySizeEnum [Int] -- ^ one of the specified values- | KeySizeFixed Int -- ^ a specific size- deriving (Show,Eq)+data KeySizeSpecifier+ = -- | in the range [min,max]+ KeySizeRange Int Int+ | -- | one of the specified values+ KeySizeEnum [Int]+ | -- | a specific size+ KeySizeFixed Int+ deriving (Show, Eq) -- | Offset inside an XTS data unit, measured in block size. type DataUnitOffset = Word32 -- | Authentication Tag for AE cipher mode-newtype AuthTag = AuthTag { unAuthTag :: Bytes }+newtype AuthTag = AuthTag {unAuthTag :: Bytes} deriving (Show, ByteArrayAccess, NFData) instance Eq AuthTag where (AuthTag a) == (AuthTag b) = B.constEq a b -data CCM_M = CCM_M4 | CCM_M6 | CCM_M8 | CCM_M10 | CCM_M12 | CCM_M14 | CCM_M16 deriving (Show, Eq)+data CCM_M = CCM_M4 | CCM_M6 | CCM_M8 | CCM_M10 | CCM_M12 | CCM_M14 | CCM_M16+ deriving (Show, Eq) data CCM_L = CCM_L2 | CCM_L3 | CCM_L4 deriving (Show, Eq) -- | AEAD Mode-data AEADMode =- AEAD_OCB -- OCB3+data AEADMode+ = AEAD_OCB -- OCB3 | AEAD_CCM Int CCM_M CCM_L | AEAD_EAX | AEAD_CWC | AEAD_GCM- deriving (Show,Eq)+ deriving (Show, Eq) -- | Symmetric cipher class. class Cipher cipher where -- | Initialize a cipher context from a key- cipherInit :: ByteArray key => key -> CryptoFailable cipher+ cipherInit :: ByteArray key => key -> CryptoFailable cipher+ -- | Cipher name- cipherName :: cipher -> String+ cipherName :: cipher -> String+ -- | return the size of the key required for this cipher. -- Some cipher accept any size for key cipherKeySize :: cipher -> KeySizeSpecifier
Crypto/Cipher/Types/Block.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE ViewPatterns #-}+ -- | -- Module : Crypto.Cipher.Types.Block -- License : BSD-style@@ -6,51 +11,55 @@ -- Portability : Excellent -- -- Block cipher basic types----{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE ExistentialQuantification #-}-{-# LANGUAGE ViewPatterns #-}-{-# LANGUAGE Rank2Types #-}-module Crypto.Cipher.Types.Block- (+module Crypto.Cipher.Types.Block ( -- * BlockCipher- BlockCipher(..)- , BlockCipher128(..)+ BlockCipher (..),+ BlockCipher128 (..),+ -- * Initialization vector (IV)- , IV(..)- , makeIV- , nullIV- , ivAdd+ IV (..),+ makeIV,+ nullIV,+ ivAdd,+ -- * XTS- , XTS+ XTS,+ -- * AEAD- , AEAD(..)+ AEAD (..), -- , AEADState(..)- , AEADModeImpl(..)- , aeadAppendHeader- , aeadEncrypt- , aeadDecrypt- , aeadFinalize+ AEADModeImpl (..),+ aeadAppendHeader,+ aeadEncrypt,+ aeadDecrypt,+ aeadFinalize,+ -- * CFB 8 bits- --, cfb8Encrypt- --, cfb8Decrypt- ) where+) where -import Data.Word-import Crypto.Error-import Crypto.Cipher.Types.Base-import Crypto.Cipher.Types.GF-import Crypto.Cipher.Types.AEAD-import Crypto.Cipher.Types.Utils+-- , cfb8Encrypt+-- , cfb8Decrypt -import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, withByteArray, Bytes)+import Crypto.Cipher.Types.AEAD+import Crypto.Cipher.Types.Base+import Crypto.Cipher.Types.GF+import Crypto.Cipher.Types.Utils+import Crypto.Error+import Data.Word++import Crypto.Internal.ByteArray (+ ByteArray,+ ByteArrayAccess,+ Bytes,+ withByteArray,+ ) import qualified Crypto.Internal.ByteArray as B -import Foreign.Ptr-import Foreign.Storable+import Foreign.Ptr+import Foreign.Storable -- | an IV parametrized by the cipher-data IV c = forall byteArray . ByteArray byteArray => IV !byteArray+data IV c = forall byteArray. ByteArray byteArray => IV !byteArray instance BlockCipher c => ByteArrayAccess (IV c) where withByteArray (IV z) f = withByteArray z f@@ -59,16 +68,21 @@ (IV a) == (IV b) = B.eq a b -- | XTS callback-type XTS ba cipher = (cipher, cipher)- -> IV cipher -- ^ Usually represent the Data Unit (e.g. disk sector)- -> DataUnitOffset -- ^ Offset in the data unit in number of blocks- -> ba -- ^ Data- -> ba -- ^ Processed Data+type XTS ba cipher =+ (cipher, cipher)+ -> IV cipher+ -- ^ Usually represent the Data Unit (e.g. disk sector)+ -> DataUnitOffset+ -- ^ Offset in the data unit in number of blocks+ -> ba+ -- ^ Data+ -> ba+ -- ^ Processed Data -- | Symmetric block cipher class class Cipher cipher => BlockCipher cipher where -- | Return the size of block required for this block cipher- blockSize :: cipher -> Int+ blockSize :: cipher -> Int -- | Encrypt blocks --@@ -85,6 +99,7 @@ -- input need to be a multiple of the blocksize cbcEncrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba cbcEncrypt = cbcEncryptGeneric+ -- | decrypt using the CBC mode. -- -- input need to be a multiple of the blocksize@@ -96,6 +111,7 @@ -- input need to be a multiple of the blocksize cfbEncrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba cfbEncrypt = cfbEncryptGeneric+ -- | decrypt using the CFB mode. -- -- input need to be a multiple of the blocksize@@ -116,7 +132,8 @@ -- | Initialize a new AEAD State -- -- When Nothing is returns, it means the mode is not handled.- aeadInit :: ByteArrayAccess iv => AEADMode -> cipher -> iv -> CryptoFailable (AEAD cipher)+ aeadInit+ :: ByteArrayAccess iv => AEADMode -> cipher -> iv -> CryptoFailable (AEAD cipher) aeadInit _ _ _ = CryptoFailed CryptoError_AEADModeNotSupported -- | class of block cipher with a 128 bits block size@@ -125,96 +142,117 @@ -- -- input need to be a multiple of the blocksize, and the cipher -- need to process 128 bits block only- xtsEncrypt :: ByteArray ba- => (cipher, cipher)- -> IV cipher -- ^ Usually represent the Data Unit (e.g. disk sector)- -> DataUnitOffset -- ^ Offset in the data unit in number of blocks- -> ba -- ^ Plaintext- -> ba -- ^ Ciphertext+ xtsEncrypt+ :: ByteArray ba+ => (cipher, cipher)+ -> IV cipher+ -- ^ Usually represent the Data Unit (e.g. disk sector)+ -> DataUnitOffset+ -- ^ Offset in the data unit in number of blocks+ -> ba+ -- ^ Plaintext+ -> ba+ -- ^ Ciphertext xtsEncrypt = xtsEncryptGeneric -- | decrypt using the XTS mode. -- -- input need to be a multiple of the blocksize, and the cipher -- need to process 128 bits block only- xtsDecrypt :: ByteArray ba- => (cipher, cipher)- -> IV cipher -- ^ Usually represent the Data Unit (e.g. disk sector)- -> DataUnitOffset -- ^ Offset in the data unit in number of blocks- -> ba -- ^ Ciphertext- -> ba -- ^ Plaintext+ xtsDecrypt+ :: ByteArray ba+ => (cipher, cipher)+ -> IV cipher+ -- ^ Usually represent the Data Unit (e.g. disk sector)+ -> DataUnitOffset+ -- ^ Offset in the data unit in number of blocks+ -> ba+ -- ^ Ciphertext+ -> ba+ -- ^ Plaintext xtsDecrypt = xtsDecryptGeneric -- | Create an IV for a specified block cipher makeIV :: (ByteArrayAccess b, BlockCipher c) => b -> Maybe (IV c) makeIV b = toIV undefined- where toIV :: BlockCipher c => c -> Maybe (IV c)- toIV cipher- | B.length b == sz = Just $ IV (B.convert b :: Bytes)- | otherwise = Nothing- where sz = blockSize cipher+ where+ toIV :: BlockCipher c => c -> Maybe (IV c)+ toIV cipher+ | B.length b == sz = Just $ IV (B.convert b :: Bytes)+ | otherwise = Nothing+ where+ sz = blockSize cipher -- | Create an IV that is effectively representing the number 0 nullIV :: BlockCipher c => IV c nullIV = toIV undefined- where toIV :: BlockCipher c => c -> IV c- toIV cipher = IV (B.zero (blockSize cipher) :: Bytes)+ where+ toIV :: BlockCipher c => c -> IV c+ toIV cipher = IV (B.zero (blockSize cipher) :: Bytes) -- | Increment an IV by a number. -- -- Assume the IV is in Big Endian format. ivAdd :: IV c -> Int -> IV c ivAdd (IV b) i = IV $ copy b- where copy :: ByteArray bs => bs -> bs- copy bs = B.copyAndFreeze bs $ loop i (B.length bs - 1)+ where+ copy :: ByteArray bs => bs -> bs+ copy bs = B.copyAndFreeze bs $ loop i (B.length bs - 1) - loop :: Int -> Int -> Ptr Word8 -> IO ()- loop acc ofs p- | ofs < 0 = return ()- | otherwise = do- v <- peek (p `plusPtr` ofs) :: IO Word8- let accv = acc + fromIntegral v- (hi,lo) = accv `divMod` 256- poke (p `plusPtr` ofs) (fromIntegral lo :: Word8)- loop hi (ofs - 1) p+ loop :: Int -> Int -> Ptr Word8 -> IO ()+ loop acc ofs p+ | ofs < 0 = return ()+ | otherwise = do+ v <- peek (p `plusPtr` ofs) :: IO Word8+ let accv = acc + fromIntegral v+ (hi, lo) = accv `divMod` 256+ poke (p `plusPtr` ofs) (fromIntegral lo :: Word8)+ loop hi (ofs - 1) p -cbcEncryptGeneric :: (ByteArray ba, BlockCipher cipher) => cipher -> IV cipher -> ba -> ba+cbcEncryptGeneric+ :: (ByteArray ba, BlockCipher cipher) => cipher -> IV cipher -> ba -> ba cbcEncryptGeneric cipher ivini input = mconcat $ doEnc ivini $ chunk (blockSize cipher) input- where doEnc _ [] = []- doEnc iv (i:is) =- let o = ecbEncrypt cipher $ B.xor iv i- in o : doEnc (IV o) is+ where+ doEnc _ [] = []+ doEnc iv (i : is) =+ let o = ecbEncrypt cipher $ B.xor iv i+ in o : doEnc (IV o) is -cbcDecryptGeneric :: (ByteArray ba, BlockCipher cipher) => cipher -> IV cipher -> ba -> ba+cbcDecryptGeneric+ :: (ByteArray ba, BlockCipher cipher) => cipher -> IV cipher -> ba -> ba cbcDecryptGeneric cipher ivini input = mconcat $ doDec ivini $ chunk (blockSize cipher) input where- doDec _ [] = []- doDec iv (i:is) =- let o = B.xor iv $ ecbDecrypt cipher i- in o : doDec (IV i) is+ doDec _ [] = []+ doDec iv (i : is) =+ let o = B.xor iv $ ecbDecrypt cipher i+ in o : doDec (IV i) is -cfbEncryptGeneric :: (ByteArray ba, BlockCipher cipher) => cipher -> IV cipher -> ba -> ba+cfbEncryptGeneric+ :: (ByteArray ba, BlockCipher cipher) => cipher -> IV cipher -> ba -> ba cfbEncryptGeneric cipher ivini input = mconcat $ doEnc ivini $ chunk (blockSize cipher) input where- doEnc _ [] = []- doEnc (IV iv) (i:is) =- let o = B.xor i $ ecbEncrypt cipher iv- in o : doEnc (IV o) is+ doEnc _ [] = []+ doEnc (IV iv) (i : is) =+ let o = B.xor i $ ecbEncrypt cipher iv+ in o : doEnc (IV o) is -cfbDecryptGeneric :: (ByteArray ba, BlockCipher cipher) => cipher -> IV cipher -> ba -> ba+cfbDecryptGeneric+ :: (ByteArray ba, BlockCipher cipher) => cipher -> IV cipher -> ba -> ba cfbDecryptGeneric cipher ivini input = mconcat $ doDec ivini $ chunk (blockSize cipher) input where- doDec _ [] = []- doDec (IV iv) (i:is) =- let o = B.xor i $ ecbEncrypt cipher iv- in o : doDec (IV i) is+ doDec _ [] = []+ doDec (IV iv) (i : is) =+ let o = B.xor i $ ecbEncrypt cipher iv+ in o : doDec (IV i) is -ctrCombineGeneric :: (ByteArray ba, BlockCipher cipher) => cipher -> IV cipher -> ba -> ba+ctrCombineGeneric+ :: (ByteArray ba, BlockCipher cipher) => cipher -> IV cipher -> ba -> ba ctrCombineGeneric cipher ivini input = mconcat $ doCnt ivini $ chunk (blockSize cipher) input- where doCnt _ [] = []- doCnt iv@(IV ivd) (i:is) =- let ivEnc = ecbEncrypt cipher ivd- in B.xor i ivEnc : doCnt (ivAdd iv 1) is+ where+ doCnt _ [] = []+ doCnt iv@(IV ivd) (i : is) =+ let ivEnc = ecbEncrypt cipher ivd+ in B.xor i ivEnc : doCnt (ivAdd iv 1) is xtsEncryptGeneric :: (ByteArray ba, BlockCipher128 cipher) => XTS ba cipher xtsEncryptGeneric = xtsGeneric ecbEncrypt@@ -222,21 +260,23 @@ xtsDecryptGeneric :: (ByteArray ba, BlockCipher128 cipher) => XTS ba cipher xtsDecryptGeneric = xtsGeneric ecbDecrypt -xtsGeneric :: (ByteArray ba, BlockCipher128 cipher)- => (cipher -> ba -> ba)- -> (cipher, cipher)- -> IV cipher- -> DataUnitOffset- -> ba- -> ba+xtsGeneric+ :: (ByteArray ba, BlockCipher128 cipher)+ => (cipher -> ba -> ba)+ -> (cipher, cipher)+ -> IV cipher+ -> DataUnitOffset+ -> ba+ -> ba xtsGeneric f (cipher, tweakCipher) (IV iv) sPoint input = mconcat $ doXts iniTweak $ chunk (blockSize cipher) input- where encTweak = ecbEncrypt tweakCipher iv- iniTweak = iterate xtsGFMul encTweak !! fromIntegral sPoint- doXts _ [] = []- doXts tweak (i:is) =- let o = B.xor (f cipher $ B.xor i tweak) tweak- in o : doXts (xtsGFMul tweak) is+ where+ encTweak = ecbEncrypt tweakCipher iv+ iniTweak = iterate xtsGFMul encTweak !! fromIntegral sPoint+ doXts _ [] = []+ doXts tweak (i : is) =+ let o = B.xor (f cipher $ B.xor i tweak) tweak+ in o : doXts (xtsGFMul tweak) is {- -- | Encrypt using CFB mode in 8 bit output
Crypto/Cipher/Types/GF.hs view
@@ -6,19 +6,17 @@ -- Portability : Excellent -- -- Slow Galois Field arithmetic for generic XTS and GCM implementation----module Crypto.Cipher.Types.GF- (+module Crypto.Cipher.Types.GF ( -- * XTS support- xtsGFMul- ) where+ xtsGFMul,+) where -import Crypto.Internal.Imports-import Crypto.Internal.ByteArray (ByteArray, withByteArray)+import Crypto.Internal.ByteArray (ByteArray, withByteArray) import qualified Crypto.Internal.ByteArray as B-import Foreign.Storable-import Foreign.Ptr-import Data.Bits+import Crypto.Internal.Imports+import Data.Bits+import Foreign.Ptr+import Foreign.Storable -- | Compute the gfmul with the XTS polynomial --@@ -29,19 +27,22 @@ xtsGFMul b | len == 16 = B.allocAndFreeze len $ \dst ->- withByteArray b $ \src -> do- (hi,lo) <- gf <$> peek (castPtr src) <*> peek (castPtr src `plusPtr` 8)- poke (castPtr dst) lo- poke (castPtr dst `plusPtr` 8) hi+ withByteArray b $ \src -> do+ (hi, lo) <- gf <$> peek (castPtr src) <*> peek (castPtr src `plusPtr` 8)+ poke (castPtr dst) lo+ poke (castPtr dst `plusPtr` 8) hi | otherwise = error "unsupported block size in GF"- where gf :: Word64 -> Word64 -> (Word64, Word64)- gf srcLo srcHi =- ((if carryLo then (.|. 1) else id) (srcHi `shiftL` 1)- ,(if carryHi then xor 0x87 else id) $ (srcLo `shiftL` 1)- )- where carryHi = srcHi `testBit` 63 - carryLo = srcLo `testBit` 63- len = B.length b+ where+ gf :: Word64 -> Word64 -> (Word64, Word64)+ gf srcLo srcHi =+ ( (if carryLo then (.|. 1) else id) (srcHi `shiftL` 1)+ , (if carryHi then xor 0x87 else id) $ (srcLo `shiftL` 1)+ )+ where+ carryHi = srcHi `testBit` 63+ carryLo = srcLo `testBit` 63+ len = B.length b+ {- const uint64_t gf_mask = cpu_to_le64(0x8000000000000000ULL); uint64_t r = ((a->q[1] & gf_mask) ? cpu_to_le64(0x87) : 0);
Crypto/Cipher/Types/Stream.hs view
@@ -6,10 +6,9 @@ -- Portability : Excellent -- -- Stream cipher basic types----module Crypto.Cipher.Types.Stream- ( StreamCipher(..)- ) where+module Crypto.Cipher.Types.Stream (+ StreamCipher (..),+) where import Crypto.Cipher.Types.Base import Crypto.Internal.ByteArray (ByteArray)
Crypto/Cipher/Types/Utils.hs view
@@ -6,16 +6,17 @@ -- Portability : Excellent -- -- Basic utility for cipher related stuff--- module Crypto.Cipher.Types.Utils where -import Crypto.Internal.ByteArray (ByteArray)+import Crypto.Internal.ByteArray (ByteArray) import qualified Crypto.Internal.ByteArray as B -- | Chunk some input byte array into @sz byte list of byte array. chunk :: ByteArray b => Int -> b -> [b] chunk sz bs = split bs- where split b | B.length b <= sz = [b]- | otherwise =- let (b1, b2) = B.splitAt sz b- in b1 : split b2+ where+ split b+ | B.length b <= sz = [b]+ | otherwise =+ let (b1, b2) = B.splitAt sz b+ in b1 : split b2
Crypto/Cipher/Utils.hs view
@@ -1,18 +1,21 @@-module Crypto.Cipher.Utils- ( validateKeySize- ) where+module Crypto.Cipher.Utils (+ validateKeySize,+) where -import Crypto.Error import Crypto.Cipher.Types+import Crypto.Error import Data.ByteArray as BA -validateKeySize :: (ByteArrayAccess key, Cipher cipher) => cipher -> key -> CryptoFailable key-validateKeySize c k = if validKeyLength- then CryptoPassed k- else CryptoFailed CryptoError_KeySizeInvalid- where keyLength = BA.length k- validKeyLength = case cipherKeySize c of- KeySizeRange low high -> keyLength >= low && keyLength <= high- KeySizeEnum lengths -> keyLength `elem` lengths- KeySizeFixed s -> keyLength == s+validateKeySize+ :: (ByteArrayAccess key, Cipher cipher) => cipher -> key -> CryptoFailable key+validateKeySize c k =+ if validKeyLength+ then CryptoPassed k+ else CryptoFailed CryptoError_KeySizeInvalid+ where+ keyLength = BA.length k+ validKeyLength = case cipherKeySize c of+ KeySizeRange low high -> keyLength >= low && keyLength <= high+ KeySizeEnum lengths -> keyLength `elem` lengths+ KeySizeFixed s -> keyLength == s
Crypto/Cipher/XSalsa.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE ForeignFunctionInterface #-}+ -- | -- Module : Crypto.Cipher.XSalsa -- License : BSD-style@@ -8,42 +10,48 @@ -- Implementation of XSalsa20 algorithm -- <https://cr.yp.to/snuffle/xsalsa-20081128.pdf> -- Based on the Salsa20 algorithm with 256 bit key extended with 192 bit nonce--{-# LANGUAGE ForeignFunctionInterface #-}-module Crypto.Cipher.XSalsa- ( initialize- , derive- , combine- , generate- , State- ) where+module Crypto.Cipher.XSalsa (+ initialize,+ derive,+ combine,+ generate,+ State,+) where -import Crypto.Internal.ByteArray (ByteArrayAccess)+import Crypto.Cipher.Salsa hiding (initialize)+import Crypto.Internal.ByteArray (ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Foreign.Ptr-import Crypto.Cipher.Salsa hiding (initialize)+import Crypto.Internal.Compat+import Crypto.Internal.Imports+import Foreign.Ptr -- | Initialize a new XSalsa context with the number of rounds, -- the key and the nonce associated.-initialize :: (ByteArrayAccess key, ByteArrayAccess nonce)- => Int -- ^ number of rounds (8,12,20)- -> key -- ^ the key (256 bits)- -> nonce -- ^ the nonce (192 bits)- -> State -- ^ the initial XSalsa state+initialize+ :: (ByteArrayAccess key, ByteArrayAccess nonce)+ => Int+ -- ^ number of rounds (8,12,20)+ -> key+ -- ^ the key (256 bits)+ -> nonce+ -- ^ the nonce (192 bits)+ -> State+ -- ^ the initial XSalsa state initialize nbRounds key nonce- | kLen /= 32 = error "XSalsa: key length should be 256 bits"- | nonceLen /= 24 = error "XSalsa: nonce length should be 192 bits"- | nbRounds `notElem` [8,12,20] = error "XSalsa: rounds should be 8, 12 or 20"+ | kLen /= 32 =+ error "XSalsa: key length should be 256 bits"+ | nonceLen /= 24 =+ error "XSalsa: nonce length should be 192 bits"+ | nbRounds `notElem` [8, 12, 20] = error "XSalsa: rounds should be 8, 12 or 20" | otherwise = unsafeDoIO $ do stPtr <- B.alloc 132 $ \stPtr ->- B.withByteArray nonce $ \noncePtr ->- B.withByteArray key $ \keyPtr ->- ccrypton_xsalsa_init stPtr nbRounds kLen keyPtr nonceLen noncePtr+ B.withByteArray nonce $ \noncePtr ->+ B.withByteArray key $ \keyPtr ->+ ccrypton_xsalsa_init stPtr nbRounds kLen keyPtr nonceLen noncePtr return $ State stPtr- where kLen = B.length key- nonceLen = B.length nonce+ where+ kLen = B.length key+ nonceLen = B.length nonce -- | Use an already initialized context and new nonce material to derive another -- XSalsa context.@@ -55,21 +63,27 @@ -- -- The output context always uses the same number of rounds as the input -- context.-derive :: ByteArrayAccess nonce- => State -- ^ base XSalsa state- -> nonce -- ^ the remainder nonce (128 bits)- -> State -- ^ the new XSalsa state+derive+ :: ByteArrayAccess nonce+ => State+ -- ^ base XSalsa state+ -> nonce+ -- ^ the remainder nonce (128 bits)+ -> State+ -- ^ the new XSalsa state derive (State stPtr') nonce | nonceLen /= 16 = error "XSalsa: nonce length should be 128 bits" | otherwise = unsafeDoIO $ do stPtr <- B.copy stPtr' $ \stPtr ->- B.withByteArray nonce $ \noncePtr ->+ B.withByteArray nonce $ \noncePtr -> ccrypton_xsalsa_derive stPtr nonceLen noncePtr return $ State stPtr- where nonceLen = B.length nonce+ where+ nonceLen = B.length nonce foreign import ccall "crypton_xsalsa_init"- ccrypton_xsalsa_init :: Ptr State -> Int -> Int -> Ptr Word8 -> Int -> Ptr Word8 -> IO ()+ ccrypton_xsalsa_init+ :: Ptr State -> Int -> Int -> Ptr Word8 -> Int -> Ptr Word8 -> IO () foreign import ccall "crypton_xsalsa_derive" ccrypton_xsalsa_derive :: Ptr State -> Int -> Ptr Word8 -> IO ()
Crypto/ConstructHash/MiyaguchiPreneel.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.ConstructHash.MiyaguchiPreneel -- License : BSD-style@@ -7,40 +9,42 @@ -- -- Provide the hash function construction method from block cipher -- <https://en.wikipedia.org/wiki/One-way_compression_function>----{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.ConstructHash.MiyaguchiPreneel- ( compute, compute'- , MiyaguchiPreneel- ) where+module Crypto.ConstructHash.MiyaguchiPreneel (+ compute,+ compute',+ MiyaguchiPreneel,+) where -import Data.List (foldl')+import Data.List (foldl') -import Crypto.Data.Padding (pad, Format (ZERO))-import Crypto.Cipher.Types-import Crypto.Error (throwCryptoError)-import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, Bytes)+import Crypto.Cipher.Types+import Crypto.Data.Padding (Format (ZERO), pad)+import Crypto.Error (throwCryptoError)+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess, Bytes) import qualified Crypto.Internal.ByteArray as B - newtype MiyaguchiPreneel a = MP Bytes deriving (ByteArrayAccess) instance Eq (MiyaguchiPreneel a) where- MP b1 == MP b2 = B.constEq b1 b2-+ MP b1 == MP b2 = B.constEq b1 b2 -- | Compute Miyaguchi-Preneel one way compress using the supplied block cipher.-compute' :: (ByteArrayAccess bin, BlockCipher cipher)- => (Bytes -> cipher) -- ^ key build function to compute Miyaguchi-Preneel. care about block-size and key-size- -> bin -- ^ input message- -> MiyaguchiPreneel cipher -- ^ output tag-compute' g = MP . foldl' (step $ g) (B.replicate bsz 0) . chunks . pad (ZERO bsz) . B.convert+compute'+ :: (ByteArrayAccess bin, BlockCipher cipher)+ => (Bytes -> cipher)+ -- ^ key build function to compute Miyaguchi-Preneel. care about block-size and key-size+ -> bin+ -- ^ input message+ -> MiyaguchiPreneel cipher+ -- ^ output tag+compute' g =+ MP . foldl' (step $ g) (B.replicate bsz 0) . chunks . pad (ZERO bsz) . B.convert where- bsz = blockSize ( g B.empty {- dummy to get block size -} )+ bsz = blockSize (g B.empty {- dummy to get block size -}) chunks msg- | B.null msg = []- | otherwise = (hd :: Bytes) : chunks tl+ | B.null msg = []+ | otherwise = (hd :: Bytes) : chunks tl where (hd, tl) = B.splitAt bsz msg @@ -48,17 +52,21 @@ -- Only safe when KEY-SIZE equals to BLOCK-SIZE. -- -- Simple usage /mp' msg :: MiyaguchiPreneel AES128/-compute :: (ByteArrayAccess bin, BlockCipher cipher)- => bin -- ^ input message- -> MiyaguchiPreneel cipher -- ^ output tag+compute+ :: (ByteArrayAccess bin, BlockCipher cipher)+ => bin+ -- ^ input message+ -> MiyaguchiPreneel cipher+ -- ^ output tag compute = compute' $ throwCryptoError . cipherInit -- | computation step of Miyaguchi-Preneel-step :: (ByteArray ba, BlockCipher k)- => (ba -> k)- -> ba- -> ba- -> ba+step+ :: (ByteArray ba, BlockCipher k)+ => (ba -> k)+ -> ba+ -> ba+ -> ba step g iv msg = ecbEncrypt k msg `bxor` iv `bxor` msg where
Crypto/Data/AFIS.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE ScopedTypeVariables #-}+ -- | -- Module : Crypto.Data.AFIS -- License : BSD-style@@ -11,26 +13,24 @@ -- The algorithm bloats an arbitrary secret with many bits that are necessary for -- the recovery of the key (merge), and allow greater way to permanently -- destroy a key stored on disk.----{-# LANGUAGE ScopedTypeVariables #-}-module Crypto.Data.AFIS- ( split- , merge- ) where+module Crypto.Data.AFIS (+ split,+ merge,+) where -import Crypto.Hash-import Crypto.Random.Types-import Crypto.Internal.Compat-import Control.Monad (forM_, foldM)-import Data.Word-import Data.Bits-import Foreign.Storable-import Foreign.Ptr+import Control.Monad (foldM, forM_)+import Crypto.Hash+import Crypto.Internal.Compat+import Crypto.Random.Types+import Data.Bits+import Data.Word+import Foreign.Ptr+import Foreign.Storable -import Crypto.Internal.ByteArray (ByteArray, Bytes, MemView(..))+import Crypto.Internal.ByteArray (ByteArray, Bytes, MemView (..)) import qualified Crypto.Internal.ByteArray as B -import Data.Memory.PtrMethods (memSet, memCopy)+import Data.Memory.PtrMethods (memCopy, memSet) -- | Split data to diffused data, using a random generator and -- an hash algorithm.@@ -49,57 +49,69 @@ -- -- where acc is : -- acc(n+1) = hash (n ++ rand(n)) ^ acc(n)----split :: (ByteArray ba, HashAlgorithm hash, DRG rng)- => hash -- ^ Hash algorithm to use as diffuser- -> rng -- ^ Random generator to use- -> Int -- ^ Number of times to diffuse the data.- -> ba -- ^ original data to diffuse.- -> (ba, rng) -- ^ The diffused data+split+ :: (ByteArray ba, HashAlgorithm hash, DRG rng)+ => hash+ -- ^ Hash algorithm to use as diffuser+ -> rng+ -- ^ Random generator to use+ -> Int+ -- ^ Number of times to diffuse the data.+ -> ba+ -- ^ original data to diffuse.+ -> (ba, rng)+ -- ^ The diffused data {-# NOINLINE split #-} split hashAlg rng expandTimes src | expandTimes <= 1 = error "invalid expandTimes value"- | otherwise = unsafeDoIO $ do+ | otherwise = unsafeDoIO $ do (rng', bs) <- B.allocRet diffusedLen runOp return (bs, rng')- where diffusedLen = blockSize * expandTimes- blockSize = B.length src- runOp dstPtr = do- let lastBlock = dstPtr `plusPtr` (blockSize * (expandTimes-1))- memSet lastBlock 0 blockSize- let randomBlockPtrs = map (plusPtr dstPtr . (*) blockSize) [0..(expandTimes-2)]- rng' <- foldM fillRandomBlock rng randomBlockPtrs- mapM_ (addRandomBlock lastBlock) randomBlockPtrs- B.withByteArray src $ \srcPtr -> xorMem srcPtr lastBlock blockSize- return rng'- addRandomBlock lastBlock blockPtr = do- xorMem blockPtr lastBlock blockSize- diffuse hashAlg lastBlock blockSize- fillRandomBlock g blockPtr = do- let (rand :: Bytes, g') = randomBytesGenerate blockSize g- B.withByteArray rand $ \randPtr -> memCopy blockPtr randPtr blockSize- return g'+ where+ diffusedLen = blockSize * expandTimes+ blockSize = B.length src+ runOp dstPtr = do+ let lastBlock = dstPtr `plusPtr` (blockSize * (expandTimes - 1))+ memSet lastBlock 0 blockSize+ let randomBlockPtrs = map (plusPtr dstPtr . (*) blockSize) [0 .. (expandTimes - 2)]+ rng' <- foldM fillRandomBlock rng randomBlockPtrs+ mapM_ (addRandomBlock lastBlock) randomBlockPtrs+ B.withByteArray src $ \srcPtr -> xorMem srcPtr lastBlock blockSize+ return rng'+ addRandomBlock lastBlock blockPtr = do+ xorMem blockPtr lastBlock blockSize+ diffuse hashAlg lastBlock blockSize+ fillRandomBlock g blockPtr = do+ let (rand :: Bytes, g') = randomBytesGenerate blockSize g+ B.withByteArray rand $ \randPtr -> memCopy blockPtr randPtr blockSize+ return g' -- | Merge previously diffused data back to the original data.-merge :: (ByteArray ba, HashAlgorithm hash)- => hash -- ^ Hash algorithm used as diffuser- -> Int -- ^ Number of times to un-diffuse the data- -> ba -- ^ Diffused data- -> ba -- ^ Original data+merge+ :: (ByteArray ba, HashAlgorithm hash)+ => hash+ -- ^ Hash algorithm used as diffuser+ -> Int+ -- ^ Number of times to un-diffuse the data+ -> ba+ -- ^ Diffused data+ -> ba+ -- ^ Original data {-# NOINLINE merge #-} merge hashAlg expandTimes bs- | r /= 0 = error "diffused data not a multiple of expandTimes"+ | r /= 0 = error "diffused data not a multiple of expandTimes" | originalSize <= 0 = error "diffused data null"- | otherwise = B.allocAndFreeze originalSize $ \dstPtr ->+ | otherwise = B.allocAndFreeze originalSize $ \dstPtr -> B.withByteArray bs $ \srcPtr -> do memSet dstPtr 0 originalSize- forM_ [0..(expandTimes-2)] $ \i -> do+ forM_ [0 .. (expandTimes - 2)] $ \i -> do xorMem (srcPtr `plusPtr` (i * originalSize)) dstPtr originalSize diffuse hashAlg dstPtr originalSize- xorMem (srcPtr `plusPtr` ((expandTimes-1) * originalSize)) dstPtr originalSize+ xorMem (srcPtr `plusPtr` ((expandTimes - 1) * originalSize)) dstPtr originalSize return ()- where (originalSize,r) = len `quotRem` expandTimes- len = B.length bs+ where+ (originalSize, r) = len `quotRem` expandTimes+ len = B.length bs -- | inplace Xor with an input -- dst = src `xor` dst@@ -107,42 +119,51 @@ xorMem src dst sz | sz `mod` 64 == 0 = loop 8 (castPtr src :: Ptr Word64) (castPtr dst) sz | sz `mod` 32 == 0 = loop 4 (castPtr src :: Ptr Word32) (castPtr dst) sz- | otherwise = loop 1 (src :: Ptr Word8) dst sz- where loop _ _ _ 0 = return ()- loop incr s d n = do a <- peek s- b <- peek d- poke d (a `xor` b)- loop incr (s `plusPtr` incr) (d `plusPtr` incr) (n-incr)+ | otherwise = loop 1 (src :: Ptr Word8) dst sz+ where+ loop _ _ _ 0 = return ()+ loop incr s d n = do+ a <- peek s+ b <- peek d+ poke d (a `xor` b)+ loop incr (s `plusPtr` incr) (d `plusPtr` incr) (n - incr) -diffuse :: HashAlgorithm hash- => hash -- ^ Hash function to use as diffuser- -> Ptr Word8 -- ^ buffer to diffuse, modify in place- -> Int -- ^ length of buffer to diffuse- -> IO ()+diffuse+ :: HashAlgorithm hash+ => hash+ -- ^ Hash function to use as diffuser+ -> Ptr Word8+ -- ^ buffer to diffuse, modify in place+ -> Int+ -- ^ length of buffer to diffuse+ -> IO () diffuse hashAlg src sz = loop src 0- where (full,pad) = sz `quotRem` digestSize - loop s i- | i < full = do h <- hashBlock i s digestSize- B.withByteArray h $ \hPtr -> memCopy s hPtr digestSize- loop (s `plusPtr` digestSize) (i+1)- | pad /= 0 = do h <- hashBlock i s pad- B.withByteArray h $ \hPtr -> memCopy s hPtr pad- return ()- | otherwise = return ()+ where+ (full, pad) = sz `quotRem` digestSize+ loop s i+ | i < full = do+ h <- hashBlock i s digestSize+ B.withByteArray h $ \hPtr -> memCopy s hPtr digestSize+ loop (s `plusPtr` digestSize) (i + 1)+ | pad /= 0 = do+ h <- hashBlock i s pad+ B.withByteArray h $ \hPtr -> memCopy s hPtr pad+ return ()+ | otherwise = return () - digestSize = hashDigestSize hashAlg+ digestSize = hashDigestSize hashAlg - -- Hash [ BE32(n), (p .. p+hashSz) ]- hashBlock n p hashSz = do- let ctx = hashInitWith hashAlg- return $! hashFinalize $ hashUpdate (hashUpdate ctx (be32 n)) (MemView p hashSz)+ -- Hash [ BE32(n), (p .. p+hashSz) ]+ hashBlock n p hashSz = do+ let ctx = hashInitWith hashAlg+ return $! hashFinalize $ hashUpdate (hashUpdate ctx (be32 n)) (MemView p hashSz) - be32 :: Int -> Bytes- be32 n = B.allocAndFreeze 4 $ \ptr -> do- poke ptr (f8 (n `shiftR` 24))- poke (ptr `plusPtr` 1) (f8 (n `shiftR` 16))- poke (ptr `plusPtr` 2) (f8 (n `shiftR` 8))- poke (ptr `plusPtr` 3) (f8 n)- where- f8 :: Int -> Word8- f8 = fromIntegral+ be32 :: Int -> Bytes+ be32 n = B.allocAndFreeze 4 $ \ptr -> do+ poke ptr (f8 (n `shiftR` 24))+ poke (ptr `plusPtr` 1) (f8 (n `shiftR` 16))+ poke (ptr `plusPtr` 2) (f8 (n `shiftR` 8))+ poke (ptr `plusPtr` 3) (f8 n)+ where+ f8 :: Int -> Word8+ f8 = fromIntegral
Crypto/Data/Padding.hs view
@@ -7,59 +7,61 @@ -- -- Various cryptographic padding commonly used for block ciphers -- or asymmetric systems.----module Crypto.Data.Padding- ( Format(..)- , pad- , unpad- ) where+module Crypto.Data.Padding (+ Format (..),+ pad,+ unpad,+) where -import Data.ByteArray (ByteArray, Bytes)+import Data.ByteArray (ByteArray, Bytes) import qualified Data.ByteArray as B -- | Format of padding-data Format =- PKCS5 -- ^ PKCS5: PKCS7 with hardcoded size of 8- | PKCS7 Int -- ^ PKCS7 with padding size between 1 and 255- | ZERO Int -- ^ zero padding with block size+data Format+ = -- | PKCS5: PKCS7 with hardcoded size of 8+ PKCS5+ | -- | PKCS7 with padding size between 1 and 255+ PKCS7 Int+ | -- | zero padding with block size+ ZERO Int deriving (Show, Eq) -- | Apply some pad to a bytearray pad :: ByteArray byteArray => Format -> byteArray -> byteArray-pad PKCS5 bin = pad (PKCS7 8) bin+pad PKCS5 bin = pad (PKCS7 8) bin pad (PKCS7 sz) bin = bin `B.append` paddingString where paddingString = B.replicate paddingByte (fromIntegral paddingByte)- paddingByte = sz - (B.length bin `mod` sz)-pad (ZERO sz) bin = bin `B.append` paddingString+ paddingByte = sz - (B.length bin `mod` sz)+pad (ZERO sz) bin = bin `B.append` paddingString where paddingString = B.replicate paddingSz 0 paddingSz- | len == 0 = sz- | m == 0 = 0- | otherwise = sz - m+ | len == 0 = sz+ | m == 0 = 0+ | otherwise = sz - m m = len `mod` sz len = B.length bin -- | Try to remove some padding from a bytearray. unpad :: ByteArray byteArray => Format -> byteArray -> Maybe byteArray-unpad PKCS5 bin = unpad (PKCS7 8) bin+unpad PKCS5 bin = unpad (PKCS7 8) bin unpad (PKCS7 sz) bin- | len == 0 = Nothing- | (len `mod` sz) /= 0 = Nothing- | paddingSz < 1 || paddingSz > len = Nothing+ | len == 0 = Nothing+ | (len `mod` sz) /= 0 = Nothing+ | paddingSz < 1 || paddingSz > len = Nothing | paddingWitness `B.constEq` padding = Just content- | otherwise = Nothing+ | otherwise = Nothing where- len = B.length bin+ len = B.length bin paddingByte = B.index bin (len - 1)- paddingSz = fromIntegral paddingByte+ paddingSz = fromIntegral paddingByte (content, padding) = B.splitAt (len - paddingSz) bin- paddingWitness = B.replicate paddingSz paddingByte :: Bytes-unpad (ZERO sz) bin- | len == 0 = Nothing- | (len `mod` sz) /= 0 = Nothing- | B.index bin (len - 1) /= 0 = Just bin- | otherwise = Nothing+ paddingWitness = B.replicate paddingSz paddingByte :: Bytes+unpad (ZERO sz) bin+ | len == 0 = Nothing+ | (len `mod` sz) /= 0 = Nothing+ | B.index bin (len - 1) /= 0 = Just bin+ | otherwise = Nothing where- len = B.length bin+ len = B.length bin
Crypto/ECC.hs view
@@ -1,3 +1,9 @@+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.ECC -- License : BSD-style@@ -6,69 +12,76 @@ -- Portability : unknown -- -- Elliptic Curve Cryptography----{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE ScopedTypeVariables #-}-module Crypto.ECC- ( Curve_P256R1(..)- , Curve_P384R1(..)- , Curve_P521R1(..)- , Curve_X25519(..)- , Curve_X448(..)- , Curve_Edwards25519(..)- , EllipticCurve(..)- , EllipticCurveDH(..)- , EllipticCurveArith(..)- , EllipticCurveBasepointArith(..)- , KeyPair(..)- , SharedSecret(..)- ) where+module Crypto.ECC (+ Curve_P256R1 (..),+ Curve_P384R1 (..),+ Curve_P521R1 (..),+ Curve_X25519 (..),+ Curve_X448 (..),+ Curve_Edwards25519 (..),+ EllipticCurve (..),+ EllipticCurveDH (..),+ EllipticCurveArith (..),+ EllipticCurveBasepointArith (..),+ KeyPair (..),+ SharedSecret (..),+) where -import qualified Crypto.PubKey.ECC.P256 as P256 import qualified Crypto.ECC.Edwards25519 as Edwards25519-import qualified Crypto.ECC.Simple.Types as Simple import qualified Crypto.ECC.Simple.Prim as Simple-import Crypto.Random-import Crypto.Error-import Crypto.Internal.Imports-import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess, ScrubbedBytes)+import qualified Crypto.ECC.Simple.Types as Simple+import Crypto.Error+import Crypto.Internal.ByteArray (+ ByteArray,+ ByteArrayAccess,+ ScrubbedBytes,+ ) import qualified Crypto.Internal.ByteArray as B-import Crypto.Number.Basic (numBits)-import Crypto.Number.Serialize (i2ospOf_, os2ip)+import Crypto.Internal.Imports+import Crypto.Number.Basic (numBits)+import Crypto.Number.Serialize (i2ospOf_, os2ip) import qualified Crypto.Number.Serialize.LE as LE import qualified Crypto.PubKey.Curve25519 as X25519 import qualified Crypto.PubKey.Curve448 as X448-import Data.ByteArray (convert)-import Data.Data (Data())-import Data.Kind (Type)-import Data.Proxy+import qualified Crypto.PubKey.ECC.P256 as P256+import Crypto.Random+import Data.ByteArray (convert)+import Data.Data (Data ())+import Data.Kind (Type)+import Data.Proxy -- | An elliptic curve key pair composed of the private part (a scalar), and -- the associated point. data KeyPair curve = KeyPair- { keypairGetPublic :: !(Point curve)+ { keypairGetPublic :: !(Point curve) , keypairGetPrivate :: !(Scalar curve) } +-- | Secret shared via key exchange newtype SharedSecret = SharedSecret ScrubbedBytes deriving (Eq, ByteArrayAccess, NFData) +instance Semigroup SharedSecret where+ SharedSecret x <> SharedSecret y = SharedSecret (x <> y)++instance Monoid SharedSecret where+ mempty = SharedSecret mempty+ class EllipticCurve curve where -- | Point on an Elliptic Curve- type Point curve :: Type+ type Point curve :: Type -- | Scalar in the Elliptic Curve domain type Scalar curve :: Type -- | Generate a new random scalar on the curve. -- The scalar will represent a number between 1 and the order of the curve non included- curveGenerateScalar :: MonadRandom randomly => proxy curve -> randomly (Scalar curve)+ curveGenerateScalar+ :: MonadRandom randomly => proxy curve -> randomly (Scalar curve) -- | Generate a new random keypair- curveGenerateKeyPair :: MonadRandom randomly => proxy curve -> randomly (KeyPair curve)+ curveGenerateKeyPair+ :: MonadRandom randomly => proxy curve -> randomly (KeyPair curve) -- | Get the curve size in bits curveSizeBits :: proxy curve -> Int@@ -79,6 +92,15 @@ -- | Try to decode the binary form of an elliptic curve point decodePoint :: ByteArray bs => proxy curve -> bs -> CryptoFailable (Point curve) + -- | Encode an elliptic curve scalar into big-endian form+ encodeScalar :: ByteArray bs => proxy curve -> Scalar curve -> bs++ -- | Try to decode the big-endian form of an elliptic curve scalar+ decodeScalar+ :: ByteArray bs => proxy curve -> bs -> CryptoFailable (Scalar curve)++ scalarToPoint :: proxy curve -> Scalar curve -> Point curve+ class EllipticCurve curve => EllipticCurveDH curve where -- | Generate a Diffie hellman secret value. --@@ -100,7 +122,8 @@ -- This additional test avoids risks existing with function 'ecdhRaw'. -- Implementations always return a 'CryptoError' instead of a special -- value or an exception.- ecdh :: proxy curve -> Scalar curve -> Point curve -> CryptoFailable SharedSecret+ ecdh+ :: proxy curve -> Scalar curve -> Point curve -> CryptoFailable SharedSecret class (EllipticCurve curve, Eq (Point curve)) => EllipticCurveArith curve where -- | Add points on a curve@@ -115,7 +138,10 @@ -- -- | Scalar Inverse -- scalarInverse :: Scalar curve -> Scalar curve -class (EllipticCurveArith curve, Eq (Scalar curve)) => EllipticCurveBasepointArith curve where+class+ (EllipticCurveArith curve, Eq (Scalar curve)) =>+ EllipticCurveBasepointArith curve+ where -- | Get the curve order size in bits curveOrderBits :: proxy curve -> Int @@ -123,15 +149,10 @@ pointBaseSmul :: proxy curve -> Scalar curve -> Point curve -- | Multiply the point @p@ with @s2@ and add a lifted to curve value @s1@- pointsSmulVarTime :: proxy curve -> Scalar curve -> Scalar curve -> Point curve -> Point curve+ pointsSmulVarTime+ :: proxy curve -> Scalar curve -> Scalar curve -> Point curve -> Point curve pointsSmulVarTime prx s1 s2 p = pointAdd prx (pointBaseSmul prx s1) (pointSmul prx s2 p) - -- | Encode an elliptic curve scalar into big-endian form- encodeScalar :: ByteArray bs => proxy curve -> Scalar curve -> bs-- -- | Try to decode the big-endian form of an elliptic curve scalar- decodeScalar :: ByteArray bs => proxy curve -> bs -> CryptoFailable (Scalar curve)- -- | Convert an elliptic curve scalar to an integer scalarToInteger :: proxy curve -> Scalar curve -> Integer @@ -148,7 +169,7 @@ -- -- also known as P256 data Curve_P256R1 = Curve_P256R1- deriving (Show,Data)+ deriving (Show, Data) instance EllipticCurve Curve_P256R1 where type Point Curve_P256R1 = P256.Point@@ -156,7 +177,8 @@ curveSizeBits _ = 256 curveGenerateScalar _ = P256.scalarGenerate curveGenerateKeyPair _ = toKeyPair <$> P256.scalarGenerate- where toKeyPair scalar = KeyPair (P256.toPoint scalar) scalar+ where+ toKeyPair scalar = KeyPair (P256.toPoint scalar) scalar encodePoint _ p = mxy where mxy :: forall bs. ByteArray bs => bs@@ -167,33 +189,34 @@ xy = P256.pointToBinary p decodePoint _ mxy = case B.uncons mxy of Nothing -> CryptoFailed CryptoError_PointSizeInvalid- Just (m,xy)+ Just (m, xy) -- uncompressed | m == 4 -> P256.pointFromBinary xy | otherwise -> CryptoFailed CryptoError_PointFormatInvalid+ encodeScalar _ = P256.scalarToBinary+ decodeScalar _ = P256.scalarFromBinary+ scalarToPoint _ = P256.toPoint instance EllipticCurveArith Curve_P256R1 where- pointAdd _ a b = P256.pointAdd a b+ pointAdd _ a b = P256.pointAdd a b pointNegate _ p = P256.pointNegate p pointSmul _ s p = P256.pointMul s p instance EllipticCurveDH Curve_P256R1 where ecdhRaw _ s p = SharedSecret $ P256.pointDh s p- ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p)+ ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p) instance EllipticCurveBasepointArith Curve_P256R1 where curveOrderBits _ = 256 pointBaseSmul _ = P256.toPoint pointsSmulVarTime _ = P256.pointsMulVarTime- encodeScalar _ = P256.scalarToBinary- decodeScalar _ = P256.scalarFromBinary scalarToInteger _ = P256.scalarToInteger scalarFromInteger _ = P256.scalarFromInteger scalarAdd _ = P256.scalarAdd scalarMul _ = P256.scalarMul data Curve_P384R1 = Curve_P384R1- deriving (Show,Data)+ deriving (Show, Data) instance EllipticCurve Curve_P384R1 where type Point Curve_P384R1 = Simple.Point Simple.SEC_p384r1@@ -201,9 +224,13 @@ curveSizeBits _ = 384 curveGenerateScalar _ = Simple.scalarGenerate curveGenerateKeyPair _ = toKeyPair <$> Simple.scalarGenerate- where toKeyPair scalar = KeyPair (Simple.pointBaseMul scalar) scalar+ where+ toKeyPair scalar = KeyPair (Simple.pointBaseMul scalar) scalar encodePoint _ point = encodeECPoint point decodePoint _ bs = decodeECPoint bs+ encodeScalar _ = ecScalarToBinary+ decodeScalar _ = ecScalarFromBinary+ scalarToPoint _ = Simple.pointBaseMul instance EllipticCurveArith Curve_P384R1 where pointAdd _ a b = Simple.pointAdd a b@@ -219,15 +246,13 @@ curveOrderBits _ = 384 pointBaseSmul _ = Simple.pointBaseMul pointsSmulVarTime _ = ecPointsMulVarTime- encodeScalar _ = ecScalarToBinary- decodeScalar _ = ecScalarFromBinary scalarToInteger _ = ecScalarToInteger scalarFromInteger _ = ecScalarFromInteger scalarAdd _ = ecScalarAdd scalarMul _ = ecScalarMul data Curve_P521R1 = Curve_P521R1- deriving (Show,Data)+ deriving (Show, Data) instance EllipticCurve Curve_P521R1 where type Point Curve_P521R1 = Simple.Point Simple.SEC_p521r1@@ -235,9 +260,13 @@ curveSizeBits _ = 521 curveGenerateScalar _ = Simple.scalarGenerate curveGenerateKeyPair _ = toKeyPair <$> Simple.scalarGenerate- where toKeyPair scalar = KeyPair (Simple.pointBaseMul scalar) scalar+ where+ toKeyPair scalar = KeyPair (Simple.pointBaseMul scalar) scalar encodePoint _ point = encodeECPoint point decodePoint _ bs = decodeECPoint bs+ encodeScalar _ = ecScalarToBinary+ decodeScalar _ = ecScalarFromBinary+ scalarToPoint _ = Simple.pointBaseMul instance EllipticCurveArith Curve_P521R1 where pointAdd _ a b = Simple.pointAdd a b@@ -253,15 +282,13 @@ curveOrderBits _ = 521 pointBaseSmul _ = Simple.pointBaseMul pointsSmulVarTime _ = ecPointsMulVarTime- encodeScalar _ = ecScalarToBinary- decodeScalar _ = ecScalarFromBinary scalarToInteger _ = ecScalarToInteger scalarFromInteger _ = ecScalarFromInteger scalarAdd _ = ecScalarAdd scalarMul _ = ecScalarMul data Curve_X25519 = Curve_X25519- deriving (Show,Data)+ deriving (Show, Data) instance EllipticCurve Curve_X25519 where type Point Curve_X25519 = X25519.PublicKey@@ -273,14 +300,18 @@ return $ KeyPair (X25519.toPublic s) s encodePoint _ p = B.convert p decodePoint _ bs = X25519.publicKey bs+ encodeScalar _ s = convert s+ decodeScalar _ bs = X25519.secretKey bs+ scalarToPoint _ s = X25519.toPublic s instance EllipticCurveDH Curve_X25519 where ecdhRaw _ s p = SharedSecret $ convert secret- where secret = X25519.dh p s+ where+ secret = X25519.dh p s ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p) data Curve_X448 = Curve_X448- deriving (Show,Data)+ deriving (Show, Data) instance EllipticCurve Curve_X448 where type Point Curve_X448 = X448.PublicKey@@ -292,14 +323,18 @@ return $ KeyPair (X448.toPublic s) s encodePoint _ p = B.convert p decodePoint _ bs = X448.publicKey bs+ encodeScalar _ s = convert s+ decodeScalar _ bs = X448.secretKey bs+ scalarToPoint _ s = X448.toPublic s instance EllipticCurveDH Curve_X448 where ecdhRaw _ s p = SharedSecret $ convert secret- where secret = X448.dh p s+ where+ secret = X448.dh p s ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p) data Curve_Edwards25519 = Curve_Edwards25519- deriving (Show,Data)+ deriving (Show, Data) instance EllipticCurve Curve_Edwards25519 where type Point Curve_Edwards25519 = Edwards25519.Point@@ -307,9 +342,15 @@ curveSizeBits _ = 255 curveGenerateScalar _ = Edwards25519.scalarGenerate curveGenerateKeyPair _ = toKeyPair <$> Edwards25519.scalarGenerate- where toKeyPair scalar = KeyPair (Edwards25519.toPoint scalar) scalar+ where+ toKeyPair scalar = KeyPair (Edwards25519.toPoint scalar) scalar encodePoint _ point = Edwards25519.pointEncode point decodePoint _ bs = Edwards25519.pointDecode bs+ encodeScalar _ = B.reverse . Edwards25519.scalarEncode+ decodeScalar _ bs+ | B.length bs == 32 = Edwards25519.scalarDecodeLong (B.reverse bs)+ | otherwise = CryptoFailed CryptoError_SecretKeySizeInvalid+ scalarToPoint _ = Edwards25519.toPoint instance EllipticCurveArith Curve_Edwards25519 where pointAdd _ a b = Edwards25519.pointAdd a b@@ -320,10 +361,6 @@ curveOrderBits _ = 253 pointBaseSmul _ = Edwards25519.toPoint pointsSmulVarTime _ = Edwards25519.pointsMulVarTime- encodeScalar _ = B.reverse . Edwards25519.scalarEncode- decodeScalar _ bs- | B.length bs == 32 = Edwards25519.scalarDecodeLong (B.reverse bs)- | otherwise = CryptoFailed CryptoError_SecretKeySizeInvalid scalarToInteger _ s = LE.os2ip (Edwards25519.scalarEncode s :: B.Bytes) scalarFromInteger _ i = case LE.i2ospOf 32 i of@@ -335,15 +372,18 @@ checkNonZeroDH :: SharedSecret -> CryptoFailable SharedSecret checkNonZeroDH s@(SharedSecret b) | B.constAllZero b = CryptoFailed CryptoError_ScalarMultiplicationInvalid- | otherwise = CryptoPassed s+ | otherwise = CryptoPassed s -encodeECShared :: Simple.Curve curve => Proxy curve -> Simple.Point curve -> CryptoFailable SharedSecret-encodeECShared _ Simple.PointO = CryptoFailed CryptoError_ScalarMultiplicationInvalid+encodeECShared+ :: Simple.Curve curve+ => Proxy curve -> Simple.Point curve -> CryptoFailable SharedSecret+encodeECShared _ Simple.PointO = CryptoFailed CryptoError_ScalarMultiplicationInvalid encodeECShared prx (Simple.Point x _) = CryptoPassed . SharedSecret $ i2ospOf_ (Simple.curveSizeBytes prx) x -encodeECPoint :: forall curve bs . (Simple.Curve curve, ByteArray bs) => Simple.Point curve -> bs-encodeECPoint Simple.PointO = error "encodeECPoint: cannot serialize point at infinity"-encodeECPoint (Simple.Point x y) = B.concat [uncompressed,xb,yb]+encodeECPoint+ :: forall curve bs. (Simple.Curve curve, ByteArray bs) => Simple.Point curve -> bs+encodeECPoint Simple.PointO = error "encodeECPoint: cannot serialize point at infinity"+encodeECPoint (Simple.Point x y) = B.concat [uncompressed, xb, yb] where size = Simple.curveSizeBytes (Proxy :: Proxy curve) uncompressed, xb, yb :: bs@@ -351,58 +391,79 @@ xb = i2ospOf_ size x yb = i2ospOf_ size y -decodeECPoint :: (Simple.Curve curve, ByteArray bs) => bs -> CryptoFailable (Simple.Point curve)+decodeECPoint+ :: (Simple.Curve curve, ByteArray bs) => bs -> CryptoFailable (Simple.Point curve) decodeECPoint mxy = case B.uncons mxy of- Nothing -> CryptoFailed CryptoError_PointSizeInvalid- Just (m,xy)+ Nothing -> CryptoFailed CryptoError_PointSizeInvalid+ Just (m, xy) -- uncompressed | m == 4 -> let siz = B.length xy `div` 2- (xb,yb) = B.splitAt siz xy+ (xb, yb) = B.splitAt siz xy x = os2ip xb y = os2ip yb- in Simple.pointFromIntegers (x,y)+ in Simple.pointFromIntegers (x, y) | otherwise -> CryptoFailed CryptoError_PointFormatInvalid -ecPointsMulVarTime :: forall curve . Simple.Curve curve- => Simple.Scalar curve- -> Simple.Scalar curve -> Simple.Point curve- -> Simple.Point curve+ecPointsMulVarTime+ :: forall curve+ . Simple.Curve curve+ => Simple.Scalar curve+ -> Simple.Scalar curve+ -> Simple.Point curve+ -> Simple.Point curve ecPointsMulVarTime n1 = Simple.pointAddTwoMuls n1 g- where g = Simple.curveEccG $ Simple.curveParameters (Proxy :: Proxy curve)+ where+ g = Simple.curveEccG $ Simple.curveParameters (Proxy :: Proxy curve) -ecScalarFromBinary :: forall curve bs . (Simple.Curve curve, ByteArrayAccess bs)- => bs -> CryptoFailable (Simple.Scalar curve)+ecScalarFromBinary+ :: forall curve bs+ . (Simple.Curve curve, ByteArrayAccess bs)+ => bs -> CryptoFailable (Simple.Scalar curve) ecScalarFromBinary ba | B.length ba /= size = CryptoFailed CryptoError_SecretKeySizeInvalid- | otherwise = CryptoPassed (Simple.Scalar $ os2ip ba)- where size = ecCurveOrderBytes (Proxy :: Proxy curve)+ | otherwise = CryptoPassed (Simple.Scalar $ os2ip ba)+ where+ size = ecCurveOrderBytes (Proxy :: Proxy curve) -ecScalarToBinary :: forall curve bs . (Simple.Curve curve, ByteArray bs)- => Simple.Scalar curve -> bs+ecScalarToBinary+ :: forall curve bs+ . (Simple.Curve curve, ByteArray bs)+ => Simple.Scalar curve -> bs ecScalarToBinary (Simple.Scalar s) = i2ospOf_ size s- where size = ecCurveOrderBytes (Proxy :: Proxy curve)+ where+ size = ecCurveOrderBytes (Proxy :: Proxy curve) -ecScalarFromInteger :: forall curve . Simple.Curve curve- => Integer -> CryptoFailable (Simple.Scalar curve)+ecScalarFromInteger+ :: forall curve+ . Simple.Curve curve+ => Integer -> CryptoFailable (Simple.Scalar curve) ecScalarFromInteger s | numBits s > nb = CryptoFailed CryptoError_SecretKeySizeInvalid- | otherwise = CryptoPassed (Simple.Scalar s)- where nb = 8 * ecCurveOrderBytes (Proxy :: Proxy curve)+ | otherwise = CryptoPassed (Simple.Scalar s)+ where+ nb = 8 * ecCurveOrderBytes (Proxy :: Proxy curve) ecScalarToInteger :: Simple.Scalar curve -> Integer ecScalarToInteger (Simple.Scalar s) = s ecCurveOrderBytes :: Simple.Curve c => proxy c -> Int ecCurveOrderBytes prx = (numBits n + 7) `div` 8- where n = Simple.curveEccN $ Simple.curveParameters prx+ where+ n = Simple.curveEccN $ Simple.curveParameters prx -ecScalarAdd :: forall curve . Simple.Curve curve- => Simple.Scalar curve -> Simple.Scalar curve -> Simple.Scalar curve+ecScalarAdd+ :: forall curve+ . Simple.Curve curve+ => Simple.Scalar curve -> Simple.Scalar curve -> Simple.Scalar curve ecScalarAdd (Simple.Scalar a) (Simple.Scalar b) = Simple.Scalar ((a + b) `mod` n)- where n = Simple.curveEccN $ Simple.curveParameters (Proxy :: Proxy curve)+ where+ n = Simple.curveEccN $ Simple.curveParameters (Proxy :: Proxy curve) -ecScalarMul :: forall curve . Simple.Curve curve- => Simple.Scalar curve -> Simple.Scalar curve -> Simple.Scalar curve+ecScalarMul+ :: forall curve+ . Simple.Curve curve+ => Simple.Scalar curve -> Simple.Scalar curve -> Simple.Scalar curve ecScalarMul (Simple.Scalar a) (Simple.Scalar b) = Simple.Scalar ((a * b) `mod` n)- where n = Simple.curveEccN $ Simple.curveParameters (Proxy :: Proxy curve)+ where+ n = Simple.curveEccN $ Simple.curveParameters (Proxy :: Proxy curve)
Crypto/ECC/Edwards25519.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.ECC.Edwards25519 -- License : BSD-style@@ -48,55 +50,55 @@ -- 3. Because of modular reduction in this implementation it is not -- possible to multiply points directly by scalars like 8.s or L. -- This has to be decomposed into several steps.----{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.ECC.Edwards25519- ( Scalar- , Point+module Crypto.ECC.Edwards25519 (+ Scalar,+ Point,+ -- * Scalars- , scalarGenerate- , scalarDecodeLong- , scalarEncode+ scalarGenerate,+ scalarDecodeLong,+ scalarEncode,+ -- * Points- , pointDecode- , pointEncode- , pointHasPrimeOrder+ pointDecode,+ pointEncode,+ pointHasPrimeOrder,+ -- * Arithmetic functions- , toPoint- , scalarAdd- , scalarMul- , pointNegate- , pointAdd- , pointDouble- , pointMul- , pointMulByCofactor- , pointsMulVarTime- ) where+ toPoint,+ scalarAdd,+ scalarMul,+ pointNegate,+ pointAdd,+ pointDouble,+ pointMul,+ pointMulByCofactor,+ pointsMulVarTime,+) where -import Data.Word-import Foreign.C.Types-import Foreign.Ptr+import Data.Word+import Foreign.C.Types+import Foreign.Ptr -import Crypto.Error-import Crypto.Internal.ByteArray (Bytes, ScrubbedBytes, withByteArray)+import Crypto.Error+import Crypto.Internal.ByteArray (Bytes, ScrubbedBytes, withByteArray) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Crypto.Random-+import Crypto.Internal.Compat+import Crypto.Internal.Imports+import Crypto.Random scalarArraySize :: Int scalarArraySize = 40 -- maximum [9 * 4 {- 32 bits -}, 5 * 8 {- 64 bits -}] -- | A scalar modulo prime order of curve edwards25519. newtype Scalar = Scalar ScrubbedBytes- deriving (Show,NFData)+ deriving (Show, NFData) instance Eq Scalar where (Scalar s1) == (Scalar s2) = unsafeDoIO $ withByteArray s1 $ \ps1 ->- withByteArray s2 $ \ps2 ->- fmap (/= 0) (ed25519_scalar_eq ps1 ps2)+ withByteArray s2 $ \ps2 ->+ fmap (/= 0) (ed25519_scalar_eq ps1 ps2) {-# NOINLINE (==) #-} pointArraySize :: Int@@ -104,19 +106,20 @@ -- | A point on curve edwards25519. newtype Point = Point Bytes- deriving NFData+ deriving (NFData) instance Show Point where showsPrec d p = let bs = pointEncode p :: Bytes- in showParen (d > 10) $ showString "Point "- . shows (B.convertToBase B.Base16 bs :: Bytes)+ in showParen (d > 10) $+ showString "Point "+ . shows (B.convertToBase B.Base16 bs :: Bytes) instance Eq Point where (Point p1) == (Point p2) = unsafeDoIO $ withByteArray p1 $ \pp1 ->- withByteArray p2 $ \pp2 ->- fmap (/= 0) (ed25519_point_eq pp1 pp2)+ withByteArray p2 $ \pp2 ->+ fmap (/= 0) (ed25519_point_eq pp1 pp2) {-# NOINLINE (==) #-} -- | Generate a random scalar.@@ -148,12 +151,12 @@ scalarDecodeLong :: B.ByteArrayAccess bs => bs -> CryptoFailable Scalar scalarDecodeLong bs | B.length bs > 64 = CryptoFailed CryptoError_EcScalarOutOfBounds- | otherwise = unsafeDoIO $ withByteArray bs initialize+ | otherwise = unsafeDoIO $ withByteArray bs initialize where len = fromIntegral $ B.length bs initialize inp = do s <- B.alloc scalarArraySize $ \ps ->- ed25519_scalar_decode_long ps inp len+ ed25519_scalar_decode_long ps inp len return $ CryptoPassed (Scalar s) {-# NOINLINE scalarDecodeLong #-} @@ -162,16 +165,16 @@ scalarAdd (Scalar a) (Scalar b) = Scalar $ B.allocAndFreeze scalarArraySize $ \out -> withByteArray a $ \pa ->- withByteArray b $ \pb ->- ed25519_scalar_add out pa pb+ withByteArray b $ \pb ->+ ed25519_scalar_add out pa pb -- | Multiply two scalars. scalarMul :: Scalar -> Scalar -> Scalar scalarMul (Scalar a) (Scalar b) = Scalar $ B.allocAndFreeze scalarArraySize $ \out -> withByteArray a $ \pa ->- withByteArray b $ \pb ->- ed25519_scalar_mul out pa pb+ withByteArray b $ \pb ->+ ed25519_scalar_mul out pa pb -- | Multiplies a scalar with the curve base point. toPoint :: Scalar -> Point@@ -188,7 +191,7 @@ pointEncode (Point p) = B.allocAndFreeze 32 $ \out -> withByteArray p $ \pp ->- ed25519_point_encode out pp+ ed25519_point_encode out pp -- | Deserialize a 32-byte array as a point, ensuring the point is -- valid on edwards25519.@@ -197,13 +200,14 @@ pointDecode :: B.ByteArrayAccess bs => bs -> CryptoFailable Point pointDecode bs | B.length bs == 32 = unsafeDoIO $ withByteArray bs initialize- | otherwise = CryptoFailed CryptoError_PointSizeInvalid+ | otherwise = CryptoFailed CryptoError_PointSizeInvalid where initialize inp = do (res, p) <- B.allocRet pointArraySize $ \pp ->- ed25519_point_decode_vartime pp inp- if res == 0 then return $ CryptoFailed CryptoError_PointCoordinatesInvalid- else return $ CryptoPassed (Point p)+ ed25519_point_decode_vartime pp inp+ if res == 0+ then return $ CryptoFailed CryptoError_PointCoordinatesInvalid+ else return $ CryptoPassed (Point p) {-# NOINLINE pointDecode #-} -- | Test whether a point belongs to the prime-order subgroup@@ -224,15 +228,15 @@ pointNegate (Point a) = Point $ B.allocAndFreeze pointArraySize $ \out -> withByteArray a $ \pa ->- ed25519_point_negate out pa+ ed25519_point_negate out pa -- | Add two points. pointAdd :: Point -> Point -> Point pointAdd (Point a) (Point b) = Point $ B.allocAndFreeze pointArraySize $ \out -> withByteArray a $ \pa ->- withByteArray b $ \pb ->- ed25519_point_add out pa pb+ withByteArray b $ \pb ->+ ed25519_point_add out pa pb -- | Add a point to itself. --@@ -243,7 +247,7 @@ pointDouble (Point a) = Point $ B.allocAndFreeze pointArraySize $ \out -> withByteArray a $ \pa ->- ed25519_point_double out pa+ ed25519_point_double out pa -- | Multiply a point by h = 8. --@@ -254,7 +258,7 @@ pointMulByCofactor (Point a) = Point $ B.allocAndFreeze pointArraySize $ \out -> withByteArray a $ \pa ->- ed25519_point_mul_by_cofactor out pa+ ed25519_point_mul_by_cofactor out pa -- | Scalar multiplication over curve edwards25519. --@@ -265,8 +269,8 @@ pointMul (Scalar scalar) (Point base) = Point $ B.allocAndFreeze pointArraySize $ \out -> withByteArray scalar $ \pscalar ->- withByteArray base $ \pbase ->- ed25519_point_scalarmul out pbase pscalar+ withByteArray base $ \pbase ->+ ed25519_point_scalarmul out pbase pscalar -- | Multiply the point @p@ with @s2@ and add a lifted to curve value @s1@. --@@ -279,92 +283,108 @@ pointsMulVarTime (Scalar s1) (Scalar s2) (Point p) = Point $ B.allocAndFreeze pointArraySize $ \out -> withByteArray s1 $ \ps1 ->- withByteArray s2 $ \ps2 ->- withByteArray p $ \pp ->- ed25519_base_double_scalarmul_vartime out ps1 pp ps2+ withByteArray s2 $ \ps2 ->+ withByteArray p $ \pp ->+ ed25519_base_double_scalarmul_vartime out ps1 pp ps2 foreign import ccall unsafe "crypton_ed25519_scalar_eq"- ed25519_scalar_eq :: Ptr Scalar- -> Ptr Scalar- -> IO CInt+ ed25519_scalar_eq+ :: Ptr Scalar+ -> Ptr Scalar+ -> IO CInt foreign import ccall unsafe "crypton_ed25519_scalar_encode"- ed25519_scalar_encode :: Ptr Word8- -> Ptr Scalar- -> IO ()+ ed25519_scalar_encode+ :: Ptr Word8+ -> Ptr Scalar+ -> IO () foreign import ccall unsafe "crypton_ed25519_scalar_decode_long"- ed25519_scalar_decode_long :: Ptr Scalar- -> Ptr Word8- -> CSize- -> IO ()+ ed25519_scalar_decode_long+ :: Ptr Scalar+ -> Ptr Word8+ -> CSize+ -> IO () foreign import ccall unsafe "crypton_ed25519_scalar_add"- ed25519_scalar_add :: Ptr Scalar -- sum- -> Ptr Scalar -- a- -> Ptr Scalar -- b- -> IO ()+ ed25519_scalar_add+ :: Ptr Scalar -- sum+ -> Ptr Scalar -- a+ -> Ptr Scalar -- b+ -> IO () foreign import ccall unsafe "crypton_ed25519_scalar_mul"- ed25519_scalar_mul :: Ptr Scalar -- out- -> Ptr Scalar -- a- -> Ptr Scalar -- b- -> IO ()+ ed25519_scalar_mul+ :: Ptr Scalar -- out+ -> Ptr Scalar -- a+ -> Ptr Scalar -- b+ -> IO () foreign import ccall unsafe "crypton_ed25519_point_encode"- ed25519_point_encode :: Ptr Word8- -> Ptr Point- -> IO ()+ ed25519_point_encode+ :: Ptr Word8+ -> Ptr Point+ -> IO () foreign import ccall unsafe "crypton_ed25519_point_decode_vartime"- ed25519_point_decode_vartime :: Ptr Point- -> Ptr Word8- -> IO CInt+ ed25519_point_decode_vartime+ :: Ptr Point+ -> Ptr Word8+ -> IO CInt foreign import ccall unsafe "crypton_ed25519_point_eq"- ed25519_point_eq :: Ptr Point- -> Ptr Point- -> IO CInt+ ed25519_point_eq+ :: Ptr Point+ -> Ptr Point+ -> IO CInt foreign import ccall "crypton_ed25519_point_has_prime_order"- ed25519_point_has_prime_order :: Ptr Point- -> IO CInt+ ed25519_point_has_prime_order+ :: Ptr Point+ -> IO CInt foreign import ccall unsafe "crypton_ed25519_point_negate"- ed25519_point_negate :: Ptr Point -- minus_a- -> Ptr Point -- a- -> IO ()+ ed25519_point_negate+ :: Ptr Point -- minus_a+ -> Ptr Point -- a+ -> IO () foreign import ccall unsafe "crypton_ed25519_point_add"- ed25519_point_add :: Ptr Point -- sum- -> Ptr Point -- a- -> Ptr Point -- b- -> IO ()+ ed25519_point_add+ :: Ptr Point -- sum+ -> Ptr Point -- a+ -> Ptr Point -- b+ -> IO () foreign import ccall unsafe "crypton_ed25519_point_double"- ed25519_point_double :: Ptr Point -- two_a- -> Ptr Point -- a- -> IO ()+ ed25519_point_double+ :: Ptr Point -- two_a+ -> Ptr Point -- a+ -> IO () foreign import ccall unsafe "crypton_ed25519_point_mul_by_cofactor"- ed25519_point_mul_by_cofactor :: Ptr Point -- eight_a- -> Ptr Point -- a- -> IO ()+ ed25519_point_mul_by_cofactor+ :: Ptr Point -- eight_a+ -> Ptr Point -- a+ -> IO () foreign import ccall "crypton_ed25519_point_base_scalarmul"- ed25519_point_base_scalarmul :: Ptr Point -- scaled- -> Ptr Scalar -- scalar- -> IO ()+ ed25519_point_base_scalarmul+ :: Ptr Point -- scaled+ -> Ptr Scalar -- scalar+ -> IO () foreign import ccall "crypton_ed25519_point_scalarmul"- ed25519_point_scalarmul :: Ptr Point -- scaled- -> Ptr Point -- base- -> Ptr Scalar -- scalar- -> IO ()+ ed25519_point_scalarmul+ :: Ptr Point -- scaled+ -> Ptr Point -- base+ -> Ptr Scalar -- scalar+ -> IO () foreign import ccall "crypton_ed25519_base_double_scalarmul_vartime"- ed25519_base_double_scalarmul_vartime :: Ptr Point -- combo- -> Ptr Scalar -- scalar1- -> Ptr Point -- base2- -> Ptr Scalar -- scalar2- -> IO ()+ ed25519_base_double_scalarmul_vartime+ :: Ptr Point -- combo+ -> Ptr Scalar -- scalar1+ -> Ptr Point -- base2+ -> Ptr Scalar -- scalar2+ -> IO ()
Crypto/ECC/Simple/Prim.hs view
@@ -1,56 +1,60 @@+{-# LANGUAGE ScopedTypeVariables #-}+ -- | Elliptic Curve Arithmetic. -- -- /WARNING:/ These functions are vulnerable to timing attacks.-{-# LANGUAGE ScopedTypeVariables #-}-module Crypto.ECC.Simple.Prim- ( scalarGenerate- , scalarFromInteger- , pointAdd- , pointNegate- , pointDouble- , pointBaseMul- , pointMul- , pointAddTwoMuls- , pointFromIntegers- , isPointAtInfinity- , isPointValid- ) where+module Crypto.ECC.Simple.Prim (+ scalarGenerate,+ scalarFromInteger,+ pointAdd,+ pointNegate,+ pointDouble,+ pointBaseMul,+ pointMul,+ pointAddTwoMuls,+ pointFromIntegers,+ isPointAtInfinity,+ isPointValid,+) where -import Data.Maybe-import Data.Proxy-import Crypto.Number.ModArithmetic-import Crypto.Number.F2m-import Crypto.Number.Generate (generateBetween) import Crypto.ECC.Simple.Types import Crypto.Error+import Crypto.Number.F2m+import Crypto.Number.Generate (generateBetween)+import Crypto.Number.ModArithmetic import Crypto.Random+import Data.Maybe+import Data.Proxy -- | Generate a valid scalar for a specific Curve-scalarGenerate :: forall randomly curve . (MonadRandom randomly, Curve curve) => randomly (Scalar curve)+scalarGenerate+ :: forall randomly curve+ . (MonadRandom randomly, Curve curve) => randomly (Scalar curve) scalarGenerate = Scalar <$> generateBetween 1 (n - 1) where n = curveEccN $ curveParameters (Proxy :: Proxy curve) -scalarFromInteger :: forall curve . Curve curve => Integer -> CryptoFailable (Scalar curve)+scalarFromInteger+ :: forall curve. Curve curve => Integer -> CryptoFailable (Scalar curve) scalarFromInteger n- | n < 0 || n >= mx = CryptoFailed $ CryptoError_EcScalarOutOfBounds- | otherwise = CryptoPassed $ Scalar n+ | n < 0 || n >= mx = CryptoFailed $ CryptoError_EcScalarOutOfBounds+ | otherwise = CryptoPassed $ Scalar n where mx = case curveType (Proxy :: Proxy curve) of- CurveBinary (CurveBinaryParam b) -> b- CurvePrime (CurvePrimeParam p) -> p+ CurveBinary (CurveBinaryParam b) -> b+ CurvePrime (CurvePrimeParam p) -> p ---TODO: Extract helper function for `fromMaybe PointO...`+-- TODO: Extract helper function for `fromMaybe PointO...` -- | Elliptic Curve point negation: -- @pointNegate p@ returns point @q@ such that @pointAdd p q == PointO@. pointNegate :: Curve curve => Point curve -> Point curve-pointNegate PointO = PointO+pointNegate PointO = PointO pointNegate point@(Point x y) = case curveType point of CurvePrime (CurvePrimeParam p) -> Point x (p - y)- CurveBinary {} -> Point x (x `addF2m` y)+ CurveBinary{} -> Point x (x `addF2m` y) -- | Elliptic Curve point addition. --@@ -60,13 +64,13 @@ pointAdd PointO q = q pointAdd p PointO = p pointAdd p q- | p == q = pointDouble p- | p == pointNegate q = PointO+ | p == q = pointDouble p+ | p == pointNegate q = PointO pointAdd point@(Point xp yp) (Point xq yq) = case ty of CurvePrime (CurvePrimeParam pr) -> fromMaybe PointO $ do s <- divmod (yp - yq) (xp - xq) pr- let xr = (s ^ (2::Int) - xp - xq) `mod` pr+ let xr = (s ^ (2 :: Int) - xp - xq) `mod` pr yr = (s * (xp - xr) - yp) `mod` pr return $ Point xr yr CurveBinary (CurveBinaryParam fx) -> fromMaybe PointO $ do@@ -77,7 +81,7 @@ where ty = curveType point cc = curveParameters point- a = curveEccA cc+ a = curveEccA cc -- | Elliptic Curve point doubling. --@@ -94,19 +98,18 @@ -- > s = xp + (yp / xp) -- > xr = s ^ 2 + s + a -- > yr = xp ^ 2 + (s+1) * xr--- pointDouble :: Curve curve => Point curve -> Point curve pointDouble PointO = PointO pointDouble point@(Point xp yp) = case ty of CurvePrime (CurvePrimeParam pr) -> fromMaybe PointO $ do- lambda <- divmod (3 * xp ^ (2::Int) + a) (2 * yp) pr- let xr = (lambda ^ (2::Int) - 2 * xp) `mod` pr+ lambda <- divmod (3 * xp ^ (2 :: Int) + a) (2 * yp) pr+ let xr = (lambda ^ (2 :: Int) - 2 * xp) `mod` pr yr = (lambda * (xp - xr) - yp) `mod` pr return $ Point xr yr CurveBinary (CurveBinaryParam fx)- | xp == 0 -> PointO- | otherwise -> fromMaybe PointO $ do+ | xp == 0 -> PointO+ | otherwise -> fromMaybe PointO $ do s <- return . addF2m xp =<< divF2m fx yp xp let xr = mulF2m fx s s `addF2m` s `addF2m` a yr = mulF2m fx xp xp `addF2m` mulF2m fx xr (s `addF2m` 1)@@ -114,7 +117,7 @@ where ty = curveType point cc = curveParameters point- a = curveEccA cc+ a = curveEccA cc -- | Elliptic curve point multiplication using the base --@@ -128,9 +131,9 @@ pointMul :: Curve curve => Scalar curve -> Point curve -> Point curve pointMul _ PointO = PointO pointMul (Scalar n) p- | n == 0 = PointO- | n == 1 = p- | odd n = pointAdd p (pointMul (Scalar (n - 1)) p)+ | n == 0 = PointO+ | n == 1 = p+ | odd n = pointAdd p (pointMul (Scalar (n - 1)) p) | otherwise = pointMul (Scalar (n `div` 2)) (pointDouble p) -- | Elliptic curve double-scalar multiplication (uses Shamir's trick).@@ -139,36 +142,40 @@ -- > (pointMul n2 p2) -- -- /WARNING:/ Vulnerable to timing attacks.-pointAddTwoMuls :: Curve curve => Scalar curve -> Point curve -> Scalar curve -> Point curve -> Point curve-pointAddTwoMuls _ PointO _ PointO = PointO-pointAddTwoMuls _ PointO n2 p2 = pointMul n2 p2-pointAddTwoMuls n1 p1 _ PointO = pointMul n1 p1+pointAddTwoMuls+ :: Curve curve+ => Scalar curve -> Point curve -> Scalar curve -> Point curve -> Point curve+pointAddTwoMuls _ PointO _ PointO = PointO+pointAddTwoMuls _ PointO n2 p2 = pointMul n2 p2+pointAddTwoMuls n1 p1 _ PointO = pointMul n1 p1 pointAddTwoMuls (Scalar n1) p1 (Scalar n2) p2 = go (n1, n2) where p0 = pointAdd p1 p2 - go (0, 0 ) = PointO+ go (0, 0) = PointO go (k1, k2) = let q = pointDouble $ go (k1 `div` 2, k2 `div` 2)- in case (odd k1, odd k2) of- (True , True ) -> pointAdd p0 q- (True , False ) -> pointAdd p1 q- (False , True ) -> pointAdd p2 q- (False , False ) -> q+ in case (odd k1, odd k2) of+ (True, True) -> pointAdd p0 q+ (True, False) -> pointAdd p1 q+ (False, True) -> pointAdd p2 q+ (False, False) -> q -- | Check if a point is the point at infinity. isPointAtInfinity :: Point curve -> Bool isPointAtInfinity PointO = True-isPointAtInfinity _ = False+isPointAtInfinity _ = False -- | Make a point on a curve from integer (x,y) coordinate -- -- if the point is not valid related to the curve then an error is -- returned instead of a point-pointFromIntegers :: forall curve . Curve curve => (Integer, Integer) -> CryptoFailable (Point curve)-pointFromIntegers (x,y)+pointFromIntegers+ :: forall curve. Curve curve => (Integer, Integer) -> CryptoFailable (Point curve)+pointFromIntegers (x, y) | isPointValid (Proxy :: Proxy curve) x y = CryptoPassed $ Point x y- | otherwise = CryptoFailed $ CryptoError_PointCoordinatesInvalid+ | otherwise =+ CryptoFailed $ CryptoError_PointCoordinatesInvalid -- | check if a point is on specific curve --@@ -181,18 +188,19 @@ isPointValid proxy x y = case ty of CurvePrime (CurvePrimeParam p) ->- let a = curveEccA cc- b = curveEccB cc+ let a = curveEccA cc+ b = curveEccB cc eqModP z1 z2 = (z1 `mod` p) == (z2 `mod` p) isValid e = e >= 0 && e < p in isValid x && isValid y && (y ^ (2 :: Int)) `eqModP` (x ^ (3 :: Int) + a * x + b) CurveBinary (CurveBinaryParam fx) ->- let a = curveEccA cc- b = curveEccB cc+ let a = curveEccA cc+ b = curveEccB cc add = addF2m mul = mulF2m fx isValid e = modF2m fx e == e- in and [ isValid x+ in and+ [ isValid x , isValid y , ((((x `add` a) `mul` x `add` y) `mul` x) `add` b `add` (squareF2m fx y)) == 0 ]
Crypto/ECC/Simple/Types.hs view
@@ -1,5 +1,7 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# OPTIONS_GHC -fno-warn-missing-signatures #-}+ -- | -- Module : Crypto.ECC.Simple.Types -- License : BSD-style@@ -9,57 +11,56 @@ -- -- References: -- <https://tools.ietf.org/html/rfc5915>----{-# OPTIONS_GHC -fno-warn-missing-signatures #-}-module Crypto.ECC.Simple.Types- ( Curve(..)- , Point(..)- , Scalar(..)- , CurveType(..)- , CurveBinaryParam(..)- , CurvePrimeParam(..)- , curveSizeBits- , curveSizeBytes- , CurveParameters(..)+module Crypto.ECC.Simple.Types (+ Curve (..),+ Point (..),+ Scalar (..),+ CurveType (..),+ CurveBinaryParam (..),+ CurvePrimeParam (..),+ curveSizeBits,+ curveSizeBytes,+ CurveParameters (..),+ -- * Specific curves definition- , SEC_p112r1(..)- , SEC_p112r2(..)- , SEC_p128r1(..)- , SEC_p128r2(..)- , SEC_p160k1(..)- , SEC_p160r1(..)- , SEC_p160r2(..)- , SEC_p192k1(..)- , SEC_p192r1(..) -- aka prime192v1- , SEC_p224k1(..)- , SEC_p224r1(..)- , SEC_p256k1(..)- , SEC_p256r1(..) -- aka prime256v1- , SEC_p384r1(..)- , SEC_p521r1(..)- , SEC_t113r1(..)- , SEC_t113r2(..)- , SEC_t131r1(..)- , SEC_t131r2(..)- , SEC_t163k1(..)- , SEC_t163r1(..)- , SEC_t163r2(..)- , SEC_t193r1(..)- , SEC_t193r2(..)- , SEC_t233k1(..) -- aka NIST K-233- , SEC_t233r1(..)- , SEC_t239k1(..)- , SEC_t283k1(..)- , SEC_t283r1(..)- , SEC_t409k1(..)- , SEC_t409r1(..)- , SEC_t571k1(..)- , SEC_t571r1(..)- ) where+ SEC_p112r1 (..),+ SEC_p112r2 (..),+ SEC_p128r1 (..),+ SEC_p128r2 (..),+ SEC_p160k1 (..),+ SEC_p160r1 (..),+ SEC_p160r2 (..),+ SEC_p192k1 (..),+ SEC_p192r1 (..), -- aka prime192v1+ SEC_p224k1 (..),+ SEC_p224r1 (..),+ SEC_p256k1 (..),+ SEC_p256r1 (..), -- aka prime256v1+ SEC_p384r1 (..),+ SEC_p521r1 (..),+ SEC_t113r1 (..),+ SEC_t113r2 (..),+ SEC_t131r1 (..),+ SEC_t131r2 (..),+ SEC_t163k1 (..),+ SEC_t163r1 (..),+ SEC_t163r2 (..),+ SEC_t193r1 (..),+ SEC_t193r2 (..),+ SEC_t233k1 (..), -- aka NIST K-233+ SEC_t233r1 (..),+ SEC_t239k1 (..),+ SEC_t283k1 (..),+ SEC_t283r1 (..),+ SEC_t409k1 (..),+ SEC_t409r1 (..),+ SEC_t571k1 (..),+ SEC_t571r1 (..),+) where -import Data.Data-import Crypto.Internal.Imports-import Crypto.Number.Basic (numBits)+import Crypto.Internal.Imports+import Crypto.Number.Basic (numBits)+import Data.Data class Curve curve where curveParameters :: proxy curve -> CurveParameters curve@@ -69,7 +70,7 @@ curveSizeBits :: Curve curve => proxy curve -> Int curveSizeBits proxy = case curveType proxy of- CurvePrime (CurvePrimeParam p) -> numBits p+ CurvePrime (CurvePrimeParam p) -> numBits p CurveBinary (CurveBinaryParam c) -> numBits c - 1 -- | get the size of the curve in bytes@@ -79,71 +80,78 @@ -- | Define common parameters in a curve definition -- of the form: y^2 = x^3 + ax + b. data CurveParameters curve = CurveParameters- { curveEccA :: Integer -- ^ curve parameter a- , curveEccB :: Integer -- ^ curve parameter b- , curveEccG :: Point curve -- ^ base point- , curveEccN :: Integer -- ^ order of G- , curveEccH :: Integer -- ^ cofactor- } deriving (Show,Eq,Data)+ { curveEccA :: Integer+ -- ^ curve parameter a+ , curveEccB :: Integer+ -- ^ curve parameter b+ , curveEccG :: Point curve+ -- ^ base point+ , curveEccN :: Integer+ -- ^ order of G+ , curveEccH :: Integer+ -- ^ cofactor+ }+ deriving (Show, Eq, Data) newtype CurveBinaryParam = CurveBinaryParam Integer- deriving (Show,Read,Eq,Data)+ deriving (Show, Read, Eq, Data) newtype CurvePrimeParam = CurvePrimeParam Integer- deriving (Show,Read,Eq,Data)+ deriving (Show, Read, Eq, Data) -data CurveType =- CurveBinary CurveBinaryParam+data CurveType+ = CurveBinary CurveBinaryParam | CurvePrime CurvePrimeParam- deriving (Show,Read,Eq,Data)+ deriving (Show, Read, Eq, Data) -- | ECC Private Number newtype Scalar curve = Scalar Integer- deriving (Show,Read,Eq,Data,NFData)+ deriving (Show, Read, Eq, Data, NFData) -- | Define a point on a curve.-data Point curve =- Point Integer Integer- | PointO -- ^ Point at Infinity- deriving (Show,Read,Eq,Data)+data Point curve+ = Point Integer Integer+ | -- | Point at Infinity+ PointO+ deriving (Show, Read, Eq, Data) instance NFData (Point curve) where rnf (Point x y) = x `seq` y `seq` () rnf PointO = () -data SEC_p112r1 = SEC_p112r1 deriving (Show,Read,Eq)-data SEC_p112r2 = SEC_p112r2 deriving (Show,Read,Eq)-data SEC_p128r1 = SEC_p128r1 deriving (Show,Read,Eq)-data SEC_p128r2 = SEC_p128r2 deriving (Show,Read,Eq)-data SEC_p160k1 = SEC_p160k1 deriving (Show,Read,Eq)-data SEC_p160r1 = SEC_p160r1 deriving (Show,Read,Eq)-data SEC_p160r2 = SEC_p160r2 deriving (Show,Read,Eq)-data SEC_p192k1 = SEC_p192k1 deriving (Show,Read,Eq)-data SEC_p192r1 = SEC_p192r1 deriving (Show,Read,Eq)-data SEC_p224k1 = SEC_p224k1 deriving (Show,Read,Eq)-data SEC_p224r1 = SEC_p224r1 deriving (Show,Read,Eq)-data SEC_p256k1 = SEC_p256k1 deriving (Show,Read,Eq)-data SEC_p256r1 = SEC_p256r1 deriving (Show,Read,Eq)-data SEC_p384r1 = SEC_p384r1 deriving (Show,Read,Eq)-data SEC_p521r1 = SEC_p521r1 deriving (Show,Read,Eq)-data SEC_t113r1 = SEC_t113r1 deriving (Show,Read,Eq)-data SEC_t113r2 = SEC_t113r2 deriving (Show,Read,Eq)-data SEC_t131r1 = SEC_t131r1 deriving (Show,Read,Eq)-data SEC_t131r2 = SEC_t131r2 deriving (Show,Read,Eq)-data SEC_t163k1 = SEC_t163k1 deriving (Show,Read,Eq)-data SEC_t163r1 = SEC_t163r1 deriving (Show,Read,Eq)-data SEC_t163r2 = SEC_t163r2 deriving (Show,Read,Eq)-data SEC_t193r1 = SEC_t193r1 deriving (Show,Read,Eq)-data SEC_t193r2 = SEC_t193r2 deriving (Show,Read,Eq)-data SEC_t233k1 = SEC_t233k1 deriving (Show,Read,Eq)-data SEC_t233r1 = SEC_t233r1 deriving (Show,Read,Eq)-data SEC_t239k1 = SEC_t239k1 deriving (Show,Read,Eq)-data SEC_t283k1 = SEC_t283k1 deriving (Show,Read,Eq)-data SEC_t283r1 = SEC_t283r1 deriving (Show,Read,Eq)-data SEC_t409k1 = SEC_t409k1 deriving (Show,Read,Eq)-data SEC_t409r1 = SEC_t409r1 deriving (Show,Read,Eq)-data SEC_t571k1 = SEC_t571k1 deriving (Show,Read,Eq)-data SEC_t571r1 = SEC_t571r1 deriving (Show,Read,Eq)+data SEC_p112r1 = SEC_p112r1 deriving (Show, Read, Eq)+data SEC_p112r2 = SEC_p112r2 deriving (Show, Read, Eq)+data SEC_p128r1 = SEC_p128r1 deriving (Show, Read, Eq)+data SEC_p128r2 = SEC_p128r2 deriving (Show, Read, Eq)+data SEC_p160k1 = SEC_p160k1 deriving (Show, Read, Eq)+data SEC_p160r1 = SEC_p160r1 deriving (Show, Read, Eq)+data SEC_p160r2 = SEC_p160r2 deriving (Show, Read, Eq)+data SEC_p192k1 = SEC_p192k1 deriving (Show, Read, Eq)+data SEC_p192r1 = SEC_p192r1 deriving (Show, Read, Eq)+data SEC_p224k1 = SEC_p224k1 deriving (Show, Read, Eq)+data SEC_p224r1 = SEC_p224r1 deriving (Show, Read, Eq)+data SEC_p256k1 = SEC_p256k1 deriving (Show, Read, Eq)+data SEC_p256r1 = SEC_p256r1 deriving (Show, Read, Eq)+data SEC_p384r1 = SEC_p384r1 deriving (Show, Read, Eq)+data SEC_p521r1 = SEC_p521r1 deriving (Show, Read, Eq)+data SEC_t113r1 = SEC_t113r1 deriving (Show, Read, Eq)+data SEC_t113r2 = SEC_t113r2 deriving (Show, Read, Eq)+data SEC_t131r1 = SEC_t131r1 deriving (Show, Read, Eq)+data SEC_t131r2 = SEC_t131r2 deriving (Show, Read, Eq)+data SEC_t163k1 = SEC_t163k1 deriving (Show, Read, Eq)+data SEC_t163r1 = SEC_t163r1 deriving (Show, Read, Eq)+data SEC_t163r2 = SEC_t163r2 deriving (Show, Read, Eq)+data SEC_t193r1 = SEC_t193r1 deriving (Show, Read, Eq)+data SEC_t193r2 = SEC_t193r2 deriving (Show, Read, Eq)+data SEC_t233k1 = SEC_t233k1 deriving (Show, Read, Eq)+data SEC_t233r1 = SEC_t233r1 deriving (Show, Read, Eq)+data SEC_t239k1 = SEC_t239k1 deriving (Show, Read, Eq)+data SEC_t283k1 = SEC_t283k1 deriving (Show, Read, Eq)+data SEC_t283r1 = SEC_t283r1 deriving (Show, Read, Eq)+data SEC_t409k1 = SEC_t409k1 deriving (Show, Read, Eq)+data SEC_t409r1 = SEC_t409r1 deriving (Show, Read, Eq)+data SEC_t571k1 = SEC_t571k1 deriving (Show, Read, Eq)+data SEC_t571r1 = SEC_t571r1 deriving (Show, Read, Eq) -- | Define names for known recommended curves. instance Curve SEC_p112r1 where@@ -318,299 +326,468 @@ -} typeSEC_p112r1 = CurvePrime $ CurvePrimeParam 0xdb7c2abf62e35e668076bead208b-paramSEC_p112r1 = CurveParameters- { curveEccA = 0xdb7c2abf62e35e668076bead2088- , curveEccB = 0x659ef8ba043916eede8911702b22- , curveEccG = Point 0x09487239995a5ee76b55f9c2f098- 0xa89ce5af8724c0a23e0e0ff77500- , curveEccN = 0xdb7c2abf62e35e7628dfac6561c5- , curveEccH = 1- }+paramSEC_p112r1 =+ CurveParameters+ { curveEccA = 0xdb7c2abf62e35e668076bead2088+ , curveEccB = 0x659ef8ba043916eede8911702b22+ , curveEccG =+ Point+ 0x09487239995a5ee76b55f9c2f098+ 0xa89ce5af8724c0a23e0e0ff77500+ , curveEccN = 0xdb7c2abf62e35e7628dfac6561c5+ , curveEccH = 1+ } typeSEC_p112r2 = CurvePrime $ CurvePrimeParam 0xdb7c2abf62e35e668076bead208b-paramSEC_p112r2 = CurveParameters- { curveEccA = 0x6127c24c05f38a0aaaf65c0ef02c- , curveEccB = 0x51def1815db5ed74fcc34c85d709- , curveEccG = Point 0x4ba30ab5e892b4e1649dd0928643- 0xadcd46f5882e3747def36e956e97- , curveEccN = 0x36df0aafd8b8d7597ca10520d04b- , curveEccH = 4- }+paramSEC_p112r2 =+ CurveParameters+ { curveEccA = 0x6127c24c05f38a0aaaf65c0ef02c+ , curveEccB = 0x51def1815db5ed74fcc34c85d709+ , curveEccG =+ Point+ 0x4ba30ab5e892b4e1649dd0928643+ 0xadcd46f5882e3747def36e956e97+ , curveEccN = 0x36df0aafd8b8d7597ca10520d04b+ , curveEccH = 4+ } typeSEC_p128r1 = CurvePrime $ CurvePrimeParam 0xfffffffdffffffffffffffffffffffff-paramSEC_p128r1 = CurveParameters- { curveEccA = 0xfffffffdfffffffffffffffffffffffc- , curveEccB = 0xe87579c11079f43dd824993c2cee5ed3- , curveEccG = Point 0x161ff7528b899b2d0c28607ca52c5b86- 0xcf5ac8395bafeb13c02da292dded7a83- , curveEccN = 0xfffffffe0000000075a30d1b9038a115- , curveEccH = 1- }+paramSEC_p128r1 =+ CurveParameters+ { curveEccA = 0xfffffffdfffffffffffffffffffffffc+ , curveEccB = 0xe87579c11079f43dd824993c2cee5ed3+ , curveEccG =+ Point+ 0x161ff7528b899b2d0c28607ca52c5b86+ 0xcf5ac8395bafeb13c02da292dded7a83+ , curveEccN = 0xfffffffe0000000075a30d1b9038a115+ , curveEccH = 1+ } typeSEC_p128r2 = CurvePrime $ CurvePrimeParam 0xfffffffdffffffffffffffffffffffff-paramSEC_p128r2 = CurveParameters- { curveEccA = 0xd6031998d1b3bbfebf59cc9bbff9aee1- , curveEccB = 0x5eeefca380d02919dc2c6558bb6d8a5d- , curveEccG = Point 0x7b6aa5d85e572983e6fb32a7cdebc140- 0x27b6916a894d3aee7106fe805fc34b44- , curveEccN = 0x3fffffff7fffffffbe0024720613b5a3- , curveEccH = 4- }+paramSEC_p128r2 =+ CurveParameters+ { curveEccA = 0xd6031998d1b3bbfebf59cc9bbff9aee1+ , curveEccB = 0x5eeefca380d02919dc2c6558bb6d8a5d+ , curveEccG =+ Point+ 0x7b6aa5d85e572983e6fb32a7cdebc140+ 0x27b6916a894d3aee7106fe805fc34b44+ , curveEccN = 0x3fffffff7fffffffbe0024720613b5a3+ , curveEccH = 4+ } typeSEC_p160k1 = CurvePrime $ CurvePrimeParam 0x00fffffffffffffffffffffffffffffffeffffac73-paramSEC_p160k1 = CurveParameters- { curveEccA = 0x000000000000000000000000000000000000000000- , curveEccB = 0x000000000000000000000000000000000000000007- , curveEccG = Point 0x003b4c382ce37aa192a4019e763036f4f5dd4d7ebb- 0x00938cf935318fdced6bc28286531733c3f03c4fee- , curveEccN = 0x0100000000000000000001b8fa16dfab9aca16b6b3- , curveEccH = 1- }+paramSEC_p160k1 =+ CurveParameters+ { curveEccA = 0x000000000000000000000000000000000000000000+ , curveEccB = 0x000000000000000000000000000000000000000007+ , curveEccG =+ Point+ 0x003b4c382ce37aa192a4019e763036f4f5dd4d7ebb+ 0x00938cf935318fdced6bc28286531733c3f03c4fee+ , curveEccN = 0x0100000000000000000001b8fa16dfab9aca16b6b3+ , curveEccH = 1+ } typeSEC_p160r1 = CurvePrime $ CurvePrimeParam 0x00ffffffffffffffffffffffffffffffff7fffffff-paramSEC_p160r1 = CurveParameters- { curveEccA = 0x00ffffffffffffffffffffffffffffffff7ffffffc- , curveEccB = 0x001c97befc54bd7a8b65acf89f81d4d4adc565fa45- , curveEccG = Point 0x004a96b5688ef573284664698968c38bb913cbfc82- 0x0023a628553168947d59dcc912042351377ac5fb32- , curveEccN = 0x0100000000000000000001f4c8f927aed3ca752257- , curveEccH = 1- }+paramSEC_p160r1 =+ CurveParameters+ { curveEccA = 0x00ffffffffffffffffffffffffffffffff7ffffffc+ , curveEccB = 0x001c97befc54bd7a8b65acf89f81d4d4adc565fa45+ , curveEccG =+ Point+ 0x004a96b5688ef573284664698968c38bb913cbfc82+ 0x0023a628553168947d59dcc912042351377ac5fb32+ , curveEccN = 0x0100000000000000000001f4c8f927aed3ca752257+ , curveEccH = 1+ } typeSEC_p160r2 = CurvePrime $ CurvePrimeParam 0x00fffffffffffffffffffffffffffffffeffffac73-paramSEC_p160r2 = CurveParameters- { curveEccA = 0x00fffffffffffffffffffffffffffffffeffffac70- , curveEccB = 0x00b4e134d3fb59eb8bab57274904664d5af50388ba- , curveEccG = Point 0x0052dcb034293a117e1f4ff11b30f7199d3144ce6d- 0x00feaffef2e331f296e071fa0df9982cfea7d43f2e- , curveEccN = 0x0100000000000000000000351ee786a818f3a1a16b- , curveEccH = 1- }-typeSEC_p192k1 = CurvePrime $ CurvePrimeParam 0xfffffffffffffffffffffffffffffffffffffffeffffee37-paramSEC_p192k1 = CurveParameters- { curveEccA = 0x000000000000000000000000000000000000000000000000- , curveEccB = 0x000000000000000000000000000000000000000000000003- , curveEccG = Point 0xdb4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d- 0x9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d- , curveEccN = 0xfffffffffffffffffffffffe26f2fc170f69466a74defd8d- , curveEccH = 1- }-typeSEC_p192r1 = CurvePrime $ CurvePrimeParam 0xfffffffffffffffffffffffffffffffeffffffffffffffff-paramSEC_p192r1 = CurveParameters- { curveEccA = 0xfffffffffffffffffffffffffffffffefffffffffffffffc- , curveEccB = 0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1- , curveEccG = Point 0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012- 0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811- , curveEccN = 0xffffffffffffffffffffffff99def836146bc9b1b4d22831- , curveEccH = 1- }-typeSEC_p224k1 = CurvePrime $ CurvePrimeParam 0x00fffffffffffffffffffffffffffffffffffffffffffffffeffffe56d-paramSEC_p224k1 = CurveParameters- { curveEccA = 0x0000000000000000000000000000000000000000000000000000000000- , curveEccB = 0x0000000000000000000000000000000000000000000000000000000005- , curveEccG = Point 0x00a1455b334df099df30fc28a169a467e9e47075a90f7e650eb6b7a45c- 0x007e089fed7fba344282cafbd6f7e319f7c0b0bd59e2ca4bdb556d61a5- , curveEccN = 0x010000000000000000000000000001dce8d2ec6184caf0a971769fb1f7- , curveEccH = 1- }-typeSEC_p224r1 = CurvePrime $ CurvePrimeParam 0xffffffffffffffffffffffffffffffff000000000000000000000001-paramSEC_p224r1 = CurveParameters- { curveEccA = 0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe- , curveEccB = 0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4- , curveEccG = Point 0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21- 0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34- , curveEccN = 0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d- , curveEccH = 1- }-typeSEC_p256k1 = CurvePrime $ CurvePrimeParam 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f-paramSEC_p256k1 = CurveParameters- { curveEccA = 0x0000000000000000000000000000000000000000000000000000000000000000- , curveEccB = 0x0000000000000000000000000000000000000000000000000000000000000007- , curveEccG = Point 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798- 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8- , curveEccN = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141- , curveEccH = 1- }-typeSEC_p256r1 = CurvePrime $ CurvePrimeParam 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff-paramSEC_p256r1 = CurveParameters- { curveEccA = 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc- , curveEccB = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b- , curveEccG = Point 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296- 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5- , curveEccN = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551- , curveEccH = 1- }-typeSEC_p384r1 = CurvePrime $ CurvePrimeParam 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff-paramSEC_p384r1 = CurveParameters- { curveEccA = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc- , curveEccB = 0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef- , curveEccG = Point 0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7- 0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f- , curveEccN = 0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973- , curveEccH = 1- }-typeSEC_p521r1 = CurvePrime $ CurvePrimeParam 0x01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-paramSEC_p521r1 = CurveParameters- { curveEccA = 0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc- , curveEccB = 0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00- , curveEccG = Point 0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66- 0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650- , curveEccN = 0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409- , curveEccH = 1- }+paramSEC_p160r2 =+ CurveParameters+ { curveEccA = 0x00fffffffffffffffffffffffffffffffeffffac70+ , curveEccB = 0x00b4e134d3fb59eb8bab57274904664d5af50388ba+ , curveEccG =+ Point+ 0x0052dcb034293a117e1f4ff11b30f7199d3144ce6d+ 0x00feaffef2e331f296e071fa0df9982cfea7d43f2e+ , curveEccN = 0x0100000000000000000000351ee786a818f3a1a16b+ , curveEccH = 1+ }+typeSEC_p192k1 =+ CurvePrime $ CurvePrimeParam 0xfffffffffffffffffffffffffffffffffffffffeffffee37+paramSEC_p192k1 =+ CurveParameters+ { curveEccA = 0x000000000000000000000000000000000000000000000000+ , curveEccB = 0x000000000000000000000000000000000000000000000003+ , curveEccG =+ Point+ 0xdb4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d+ 0x9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d+ , curveEccN = 0xfffffffffffffffffffffffe26f2fc170f69466a74defd8d+ , curveEccH = 1+ }+typeSEC_p192r1 =+ CurvePrime $ CurvePrimeParam 0xfffffffffffffffffffffffffffffffeffffffffffffffff+paramSEC_p192r1 =+ CurveParameters+ { curveEccA = 0xfffffffffffffffffffffffffffffffefffffffffffffffc+ , curveEccB = 0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1+ , curveEccG =+ Point+ 0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012+ 0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811+ , curveEccN = 0xffffffffffffffffffffffff99def836146bc9b1b4d22831+ , curveEccH = 1+ }+typeSEC_p224k1 =+ CurvePrime $+ CurvePrimeParam 0x00fffffffffffffffffffffffffffffffffffffffffffffffeffffe56d+paramSEC_p224k1 =+ CurveParameters+ { curveEccA = 0x0000000000000000000000000000000000000000000000000000000000+ , curveEccB = 0x0000000000000000000000000000000000000000000000000000000005+ , curveEccG =+ Point+ 0x00a1455b334df099df30fc28a169a467e9e47075a90f7e650eb6b7a45c+ 0x007e089fed7fba344282cafbd6f7e319f7c0b0bd59e2ca4bdb556d61a5+ , curveEccN = 0x010000000000000000000000000001dce8d2ec6184caf0a971769fb1f7+ , curveEccH = 1+ }+typeSEC_p224r1 =+ CurvePrime $+ CurvePrimeParam 0xffffffffffffffffffffffffffffffff000000000000000000000001+paramSEC_p224r1 =+ CurveParameters+ { curveEccA = 0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe+ , curveEccB = 0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4+ , curveEccG =+ Point+ 0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21+ 0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34+ , curveEccN = 0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d+ , curveEccH = 1+ }+typeSEC_p256k1 =+ CurvePrime $+ CurvePrimeParam+ 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f+paramSEC_p256k1 =+ CurveParameters+ { curveEccA = 0x0000000000000000000000000000000000000000000000000000000000000000+ , curveEccB = 0x0000000000000000000000000000000000000000000000000000000000000007+ , curveEccG =+ Point+ 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798+ 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8+ , curveEccN = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141+ , curveEccH = 1+ }+typeSEC_p256r1 =+ CurvePrime $+ CurvePrimeParam+ 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff+paramSEC_p256r1 =+ CurveParameters+ { curveEccA = 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc+ , curveEccB = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b+ , curveEccG =+ Point+ 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296+ 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5+ , curveEccN = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551+ , curveEccH = 1+ }+typeSEC_p384r1 =+ CurvePrime $+ CurvePrimeParam+ 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff+paramSEC_p384r1 =+ CurveParameters+ { curveEccA =+ 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc+ , curveEccB =+ 0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef+ , curveEccG =+ Point+ 0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7+ 0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f+ , curveEccN =+ 0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973+ , curveEccH = 1+ }+typeSEC_p521r1 =+ CurvePrime $+ CurvePrimeParam+ 0x01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff+paramSEC_p521r1 =+ CurveParameters+ { curveEccA =+ 0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc+ , curveEccB =+ 0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00+ , curveEccG =+ Point+ 0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66+ 0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650+ , curveEccN =+ 0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409+ , curveEccH = 1+ } typeSEC_t113r1 = CurveBinary $ CurveBinaryParam 0x020000000000000000000000000201-paramSEC_t113r1 = CurveParameters- { curveEccA = 0x003088250ca6e7c7fe649ce85820f7- , curveEccB = 0x00e8bee4d3e2260744188be0e9c723- , curveEccG = Point 0x009d73616f35f4ab1407d73562c10f- 0x00a52830277958ee84d1315ed31886- , curveEccN = 0x0100000000000000d9ccec8a39e56f- , curveEccH = 2- }+paramSEC_t113r1 =+ CurveParameters+ { curveEccA = 0x003088250ca6e7c7fe649ce85820f7+ , curveEccB = 0x00e8bee4d3e2260744188be0e9c723+ , curveEccG =+ Point+ 0x009d73616f35f4ab1407d73562c10f+ 0x00a52830277958ee84d1315ed31886+ , curveEccN = 0x0100000000000000d9ccec8a39e56f+ , curveEccH = 2+ } typeSEC_t113r2 = CurveBinary $ CurveBinaryParam 0x020000000000000000000000000201-paramSEC_t113r2 = CurveParameters- { curveEccA = 0x00689918dbec7e5a0dd6dfc0aa55c7- , curveEccB = 0x0095e9a9ec9b297bd4bf36e059184f- , curveEccG = Point 0x01a57a6a7b26ca5ef52fcdb8164797- 0x00b3adc94ed1fe674c06e695baba1d- , curveEccN = 0x010000000000000108789b2496af93- , curveEccH = 2- }+paramSEC_t113r2 =+ CurveParameters+ { curveEccA = 0x00689918dbec7e5a0dd6dfc0aa55c7+ , curveEccB = 0x0095e9a9ec9b297bd4bf36e059184f+ , curveEccG =+ Point+ 0x01a57a6a7b26ca5ef52fcdb8164797+ 0x00b3adc94ed1fe674c06e695baba1d+ , curveEccN = 0x010000000000000108789b2496af93+ , curveEccH = 2+ } typeSEC_t131r1 = CurveBinary $ CurveBinaryParam 0x080000000000000000000000000000010d-paramSEC_t131r1 = CurveParameters- { curveEccA = 0x07a11b09a76b562144418ff3ff8c2570b8- , curveEccB = 0x0217c05610884b63b9c6c7291678f9d341- , curveEccG = Point 0x0081baf91fdf9833c40f9c181343638399- 0x078c6e7ea38c001f73c8134b1b4ef9e150- , curveEccN = 0x0400000000000000023123953a9464b54d- , curveEccH = 2- }+paramSEC_t131r1 =+ CurveParameters+ { curveEccA = 0x07a11b09a76b562144418ff3ff8c2570b8+ , curveEccB = 0x0217c05610884b63b9c6c7291678f9d341+ , curveEccG =+ Point+ 0x0081baf91fdf9833c40f9c181343638399+ 0x078c6e7ea38c001f73c8134b1b4ef9e150+ , curveEccN = 0x0400000000000000023123953a9464b54d+ , curveEccH = 2+ } typeSEC_t131r2 = CurveBinary $ CurveBinaryParam 0x080000000000000000000000000000010d-paramSEC_t131r2 = CurveParameters- { curveEccA = 0x03e5a88919d7cafcbf415f07c2176573b2- , curveEccB = 0x04b8266a46c55657ac734ce38f018f2192- , curveEccG = Point 0x0356dcd8f2f95031ad652d23951bb366a8- 0x0648f06d867940a5366d9e265de9eb240f- , curveEccN = 0x0400000000000000016954a233049ba98f- , curveEccH = 2- }+paramSEC_t131r2 =+ CurveParameters+ { curveEccA = 0x03e5a88919d7cafcbf415f07c2176573b2+ , curveEccB = 0x04b8266a46c55657ac734ce38f018f2192+ , curveEccG =+ Point+ 0x0356dcd8f2f95031ad652d23951bb366a8+ 0x0648f06d867940a5366d9e265de9eb240f+ , curveEccN = 0x0400000000000000016954a233049ba98f+ , curveEccH = 2+ } typeSEC_t163k1 = CurveBinary $ CurveBinaryParam 0x0800000000000000000000000000000000000000c9-paramSEC_t163k1 = CurveParameters- { curveEccA = 0x000000000000000000000000000000000000000001- , curveEccB = 0x000000000000000000000000000000000000000001- , curveEccG = Point 0x02fe13c0537bbc11acaa07d793de4e6d5e5c94eee8- 0x0289070fb05d38ff58321f2e800536d538ccdaa3d9- , curveEccN = 0x04000000000000000000020108a2e0cc0d99f8a5ef- , curveEccH = 2- }+paramSEC_t163k1 =+ CurveParameters+ { curveEccA = 0x000000000000000000000000000000000000000001+ , curveEccB = 0x000000000000000000000000000000000000000001+ , curveEccG =+ Point+ 0x02fe13c0537bbc11acaa07d793de4e6d5e5c94eee8+ 0x0289070fb05d38ff58321f2e800536d538ccdaa3d9+ , curveEccN = 0x04000000000000000000020108a2e0cc0d99f8a5ef+ , curveEccH = 2+ } typeSEC_t163r1 = CurveBinary $ CurveBinaryParam 0x0800000000000000000000000000000000000000c9-paramSEC_t163r1 = CurveParameters- { curveEccA = 0x07b6882caaefa84f9554ff8428bd88e246d2782ae2- , curveEccB = 0x0713612dcddcb40aab946bda29ca91f73af958afd9- , curveEccG = Point 0x0369979697ab43897789566789567f787a7876a654- 0x00435edb42efafb2989d51fefce3c80988f41ff883- , curveEccN = 0x03ffffffffffffffffffff48aab689c29ca710279b- , curveEccH = 2- }+paramSEC_t163r1 =+ CurveParameters+ { curveEccA = 0x07b6882caaefa84f9554ff8428bd88e246d2782ae2+ , curveEccB = 0x0713612dcddcb40aab946bda29ca91f73af958afd9+ , curveEccG =+ Point+ 0x0369979697ab43897789566789567f787a7876a654+ 0x00435edb42efafb2989d51fefce3c80988f41ff883+ , curveEccN = 0x03ffffffffffffffffffff48aab689c29ca710279b+ , curveEccH = 2+ } typeSEC_t163r2 = CurveBinary $ CurveBinaryParam 0x0800000000000000000000000000000000000000c9-paramSEC_t163r2 = CurveParameters- { curveEccA = 0x000000000000000000000000000000000000000001- , curveEccB = 0x020a601907b8c953ca1481eb10512f78744a3205fd- , curveEccG = Point 0x03f0eba16286a2d57ea0991168d4994637e8343e36- 0x00d51fbc6c71a0094fa2cdd545b11c5c0c797324f1- , curveEccN = 0x040000000000000000000292fe77e70c12a4234c33- , curveEccH = 2- }-typeSEC_t193r1 = CurveBinary $ CurveBinaryParam 0x02000000000000000000000000000000000000000000008001-paramSEC_t193r1 = CurveParameters- { curveEccA = 0x0017858feb7a98975169e171f77b4087de098ac8a911df7b01- , curveEccB = 0x00fdfb49bfe6c3a89facadaa7a1e5bbc7cc1c2e5d831478814- , curveEccG = Point 0x01f481bc5f0ff84a74ad6cdf6fdef4bf6179625372d8c0c5e1- 0x0025e399f2903712ccf3ea9e3a1ad17fb0b3201b6af7ce1b05- , curveEccN = 0x01000000000000000000000000c7f34a778f443acc920eba49- , curveEccH = 2- }-typeSEC_t193r2 = CurveBinary $ CurveBinaryParam 0x02000000000000000000000000000000000000000000008001-paramSEC_t193r2 = CurveParameters- { curveEccA = 0x0163f35a5137c2ce3ea6ed8667190b0bc43ecd69977702709b- , curveEccB = 0x00c9bb9e8927d4d64c377e2ab2856a5b16e3efb7f61d4316ae- , curveEccG = Point 0x00d9b67d192e0367c803f39e1a7e82ca14a651350aae617e8f- 0x01ce94335607c304ac29e7defbd9ca01f596f927224cdecf6c- , curveEccN = 0x010000000000000000000000015aab561b005413ccd4ee99d5- , curveEccH = 2- }-typeSEC_t233k1 = CurveBinary $ CurveBinaryParam 0x020000000000000000000000000000000000000004000000000000000001-paramSEC_t233k1 = CurveParameters- { curveEccA = 0x000000000000000000000000000000000000000000000000000000000000- , curveEccB = 0x000000000000000000000000000000000000000000000000000000000001- , curveEccG = Point 0x017232ba853a7e731af129f22ff4149563a419c26bf50a4c9d6eefad6126- 0x01db537dece819b7f70f555a67c427a8cd9bf18aeb9b56e0c11056fae6a3- , curveEccN = 0x008000000000000000000000000000069d5bb915bcd46efb1ad5f173abdf- , curveEccH = 4- }-typeSEC_t233r1 = CurveBinary $ CurveBinaryParam 0x020000000000000000000000000000000000000004000000000000000001-paramSEC_t233r1 = CurveParameters- { curveEccA = 0x000000000000000000000000000000000000000000000000000000000001- , curveEccB = 0x0066647ede6c332c7f8c0923bb58213b333b20e9ce4281fe115f7d8f90ad- , curveEccG = Point 0x00fac9dfcbac8313bb2139f1bb755fef65bc391f8b36f8f8eb7371fd558b- 0x01006a08a41903350678e58528bebf8a0beff867a7ca36716f7e01f81052- , curveEccN = 0x01000000000000000000000000000013e974e72f8a6922031d2603cfe0d7- , curveEccH = 2- }-typeSEC_t239k1 = CurveBinary $ CurveBinaryParam 0x800000000000000000004000000000000000000000000000000000000001-paramSEC_t239k1 = CurveParameters- { curveEccA = 0x000000000000000000000000000000000000000000000000000000000000- , curveEccB = 0x000000000000000000000000000000000000000000000000000000000001- , curveEccG = Point 0x29a0b6a887a983e9730988a68727a8b2d126c44cc2cc7b2a6555193035dc- 0x76310804f12e549bdb011c103089e73510acb275fc312a5dc6b76553f0ca- , curveEccN = 0x2000000000000000000000000000005a79fec67cb6e91f1c1da800e478a5- , curveEccH = 4- }-typeSEC_t283k1 = CurveBinary $ CurveBinaryParam 0x0800000000000000000000000000000000000000000000000000000000000000000010a1-paramSEC_t283k1 = CurveParameters- { curveEccA = 0x000000000000000000000000000000000000000000000000000000000000000000000000- , curveEccB = 0x000000000000000000000000000000000000000000000000000000000000000000000001- , curveEccG = Point 0x0503213f78ca44883f1a3b8162f188e553cd265f23c1567a16876913b0c2ac2458492836- 0x01ccda380f1c9e318d90f95d07e5426fe87e45c0e8184698e45962364e34116177dd2259- , curveEccN = 0x01ffffffffffffffffffffffffffffffffffe9ae2ed07577265dff7f94451e061e163c61- , curveEccH = 4- }-typeSEC_t283r1 = CurveBinary $ CurveBinaryParam 0x0800000000000000000000000000000000000000000000000000000000000000000010a1-paramSEC_t283r1 = CurveParameters- { curveEccA = 0x000000000000000000000000000000000000000000000000000000000000000000000001- , curveEccB = 0x027b680ac8b8596da5a4af8a19a0303fca97fd7645309fa2a581485af6263e313b79a2f5- , curveEccG = Point 0x05f939258db7dd90e1934f8c70b0dfec2eed25b8557eac9c80e2e198f8cdbecd86b12053- 0x03676854fe24141cb98fe6d4b20d02b4516ff702350eddb0826779c813f0df45be8112f4- , curveEccN = 0x03ffffffffffffffffffffffffffffffffffef90399660fc938a90165b042a7cefadb307- , curveEccH = 2- }-typeSEC_t409k1 = CurveBinary $ CurveBinaryParam 0x02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001-paramSEC_t409k1 = CurveParameters- { curveEccA = 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000- , curveEccB = 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001- , curveEccG = Point 0x0060f05f658f49c1ad3ab1890f7184210efd0987e307c84c27accfb8f9f67cc2c460189eb5aaaa62ee222eb1b35540cfe9023746- 0x01e369050b7c4e42acba1dacbf04299c3460782f918ea427e6325165e9ea10e3da5f6c42e9c55215aa9ca27a5863ec48d8e0286b- , curveEccN = 0x007ffffffffffffffffffffffffffffffffffffffffffffffffffe5f83b2d4ea20400ec4557d5ed3e3e7ca5b4b5c83b8e01e5fcf- , curveEccH = 4- }-typeSEC_t409r1 = CurveBinary $ CurveBinaryParam 0x02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001-paramSEC_t409r1 = CurveParameters- { curveEccA = 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001- , curveEccB = 0x0021a5c2c8ee9feb5c4b9a753b7b476b7fd6422ef1f3dd674761fa99d6ac27c8a9a197b272822f6cd57a55aa4f50ae317b13545f- , curveEccG = Point 0x015d4860d088ddb3496b0c6064756260441cde4af1771d4db01ffe5b34e59703dc255a868a1180515603aeab60794e54bb7996a7- 0x0061b1cfab6be5f32bbfa78324ed106a7636b9c5a7bd198d0158aa4f5488d08f38514f1fdf4b4f40d2181b3681c364ba0273c706- , curveEccN = 0x010000000000000000000000000000000000000000000000000001e2aad6a612f33307be5fa47c3c9e052f838164cd37d9a21173- , curveEccH = 2- }-typeSEC_t571k1 = CurveBinary $ CurveBinaryParam 0x080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425-paramSEC_t571k1 = CurveParameters- { curveEccA = 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000- , curveEccB = 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001- , curveEccG = Point 0x026eb7a859923fbc82189631f8103fe4ac9ca2970012d5d46024804801841ca44370958493b205e647da304db4ceb08cbbd1ba39494776fb988b47174dca88c7e2945283a01c8972- 0x0349dc807f4fbf374f4aeade3bca95314dd58cec9f307a54ffc61efc006d8a2c9d4979c0ac44aea74fbebbb9f772aedcb620b01a7ba7af1b320430c8591984f601cd4c143ef1c7a3- , curveEccN = 0x020000000000000000000000000000000000000000000000000000000000000000000000131850e1f19a63e4b391a8db917f4138b630d84be5d639381e91deb45cfe778f637c1001- , curveEccH = 4- }-typeSEC_t571r1 = CurveBinary $ CurveBinaryParam 0x080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425-paramSEC_t571r1 = CurveParameters- { curveEccA = 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001- , curveEccB = 0x02f40e7e2221f295de297117b7f3d62f5c6a97ffcb8ceff1cd6ba8ce4a9a18ad84ffabbd8efa59332be7ad6756a66e294afd185a78ff12aa520e4de739baca0c7ffeff7f2955727a- , curveEccG = Point 0x0303001d34b856296c16c0d40d3cd7750a93d1d2955fa80aa5f40fc8db7b2abdbde53950f4c0d293cdd711a35b67fb1499ae60038614f1394abfa3b4c850d927e1e7769c8eec2d19- 0x037bf27342da639b6dccfffeb73d69d78c6c27a6009cbbca1980f8533921e8a684423e43bab08a576291af8f461bb2a8b3531d2f0485c19b16e2f1516e23dd3c1a4827af1b8ac15b- , curveEccN = 0x03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47- , curveEccH = 2- }+paramSEC_t163r2 =+ CurveParameters+ { curveEccA = 0x000000000000000000000000000000000000000001+ , curveEccB = 0x020a601907b8c953ca1481eb10512f78744a3205fd+ , curveEccG =+ Point+ 0x03f0eba16286a2d57ea0991168d4994637e8343e36+ 0x00d51fbc6c71a0094fa2cdd545b11c5c0c797324f1+ , curveEccN = 0x040000000000000000000292fe77e70c12a4234c33+ , curveEccH = 2+ }+typeSEC_t193r1 =+ CurveBinary $+ CurveBinaryParam 0x02000000000000000000000000000000000000000000008001+paramSEC_t193r1 =+ CurveParameters+ { curveEccA = 0x0017858feb7a98975169e171f77b4087de098ac8a911df7b01+ , curveEccB = 0x00fdfb49bfe6c3a89facadaa7a1e5bbc7cc1c2e5d831478814+ , curveEccG =+ Point+ 0x01f481bc5f0ff84a74ad6cdf6fdef4bf6179625372d8c0c5e1+ 0x0025e399f2903712ccf3ea9e3a1ad17fb0b3201b6af7ce1b05+ , curveEccN = 0x01000000000000000000000000c7f34a778f443acc920eba49+ , curveEccH = 2+ }+typeSEC_t193r2 =+ CurveBinary $+ CurveBinaryParam 0x02000000000000000000000000000000000000000000008001+paramSEC_t193r2 =+ CurveParameters+ { curveEccA = 0x0163f35a5137c2ce3ea6ed8667190b0bc43ecd69977702709b+ , curveEccB = 0x00c9bb9e8927d4d64c377e2ab2856a5b16e3efb7f61d4316ae+ , curveEccG =+ Point+ 0x00d9b67d192e0367c803f39e1a7e82ca14a651350aae617e8f+ 0x01ce94335607c304ac29e7defbd9ca01f596f927224cdecf6c+ , curveEccN = 0x010000000000000000000000015aab561b005413ccd4ee99d5+ , curveEccH = 2+ }+typeSEC_t233k1 =+ CurveBinary $+ CurveBinaryParam 0x020000000000000000000000000000000000000004000000000000000001+paramSEC_t233k1 =+ CurveParameters+ { curveEccA = 0x000000000000000000000000000000000000000000000000000000000000+ , curveEccB = 0x000000000000000000000000000000000000000000000000000000000001+ , curveEccG =+ Point+ 0x017232ba853a7e731af129f22ff4149563a419c26bf50a4c9d6eefad6126+ 0x01db537dece819b7f70f555a67c427a8cd9bf18aeb9b56e0c11056fae6a3+ , curveEccN = 0x008000000000000000000000000000069d5bb915bcd46efb1ad5f173abdf+ , curveEccH = 4+ }+typeSEC_t233r1 =+ CurveBinary $+ CurveBinaryParam 0x020000000000000000000000000000000000000004000000000000000001+paramSEC_t233r1 =+ CurveParameters+ { curveEccA = 0x000000000000000000000000000000000000000000000000000000000001+ , curveEccB = 0x0066647ede6c332c7f8c0923bb58213b333b20e9ce4281fe115f7d8f90ad+ , curveEccG =+ Point+ 0x00fac9dfcbac8313bb2139f1bb755fef65bc391f8b36f8f8eb7371fd558b+ 0x01006a08a41903350678e58528bebf8a0beff867a7ca36716f7e01f81052+ , curveEccN = 0x01000000000000000000000000000013e974e72f8a6922031d2603cfe0d7+ , curveEccH = 2+ }+typeSEC_t239k1 =+ CurveBinary $+ CurveBinaryParam 0x800000000000000000004000000000000000000000000000000000000001+paramSEC_t239k1 =+ CurveParameters+ { curveEccA = 0x000000000000000000000000000000000000000000000000000000000000+ , curveEccB = 0x000000000000000000000000000000000000000000000000000000000001+ , curveEccG =+ Point+ 0x29a0b6a887a983e9730988a68727a8b2d126c44cc2cc7b2a6555193035dc+ 0x76310804f12e549bdb011c103089e73510acb275fc312a5dc6b76553f0ca+ , curveEccN = 0x2000000000000000000000000000005a79fec67cb6e91f1c1da800e478a5+ , curveEccH = 4+ }+typeSEC_t283k1 =+ CurveBinary $+ CurveBinaryParam+ 0x0800000000000000000000000000000000000000000000000000000000000000000010a1+paramSEC_t283k1 =+ CurveParameters+ { curveEccA =+ 0x000000000000000000000000000000000000000000000000000000000000000000000000+ , curveEccB =+ 0x000000000000000000000000000000000000000000000000000000000000000000000001+ , curveEccG =+ Point+ 0x0503213f78ca44883f1a3b8162f188e553cd265f23c1567a16876913b0c2ac2458492836+ 0x01ccda380f1c9e318d90f95d07e5426fe87e45c0e8184698e45962364e34116177dd2259+ , curveEccN =+ 0x01ffffffffffffffffffffffffffffffffffe9ae2ed07577265dff7f94451e061e163c61+ , curveEccH = 4+ }+typeSEC_t283r1 =+ CurveBinary $+ CurveBinaryParam+ 0x0800000000000000000000000000000000000000000000000000000000000000000010a1+paramSEC_t283r1 =+ CurveParameters+ { curveEccA =+ 0x000000000000000000000000000000000000000000000000000000000000000000000001+ , curveEccB =+ 0x027b680ac8b8596da5a4af8a19a0303fca97fd7645309fa2a581485af6263e313b79a2f5+ , curveEccG =+ Point+ 0x05f939258db7dd90e1934f8c70b0dfec2eed25b8557eac9c80e2e198f8cdbecd86b12053+ 0x03676854fe24141cb98fe6d4b20d02b4516ff702350eddb0826779c813f0df45be8112f4+ , curveEccN =+ 0x03ffffffffffffffffffffffffffffffffffef90399660fc938a90165b042a7cefadb307+ , curveEccH = 2+ }+typeSEC_t409k1 =+ CurveBinary $+ CurveBinaryParam+ 0x02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001+paramSEC_t409k1 =+ CurveParameters+ { curveEccA =+ 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000+ , curveEccB =+ 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001+ , curveEccG =+ Point+ 0x0060f05f658f49c1ad3ab1890f7184210efd0987e307c84c27accfb8f9f67cc2c460189eb5aaaa62ee222eb1b35540cfe9023746+ 0x01e369050b7c4e42acba1dacbf04299c3460782f918ea427e6325165e9ea10e3da5f6c42e9c55215aa9ca27a5863ec48d8e0286b+ , curveEccN =+ 0x007ffffffffffffffffffffffffffffffffffffffffffffffffffe5f83b2d4ea20400ec4557d5ed3e3e7ca5b4b5c83b8e01e5fcf+ , curveEccH = 4+ }+typeSEC_t409r1 =+ CurveBinary $+ CurveBinaryParam+ 0x02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001+paramSEC_t409r1 =+ CurveParameters+ { curveEccA =+ 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001+ , curveEccB =+ 0x0021a5c2c8ee9feb5c4b9a753b7b476b7fd6422ef1f3dd674761fa99d6ac27c8a9a197b272822f6cd57a55aa4f50ae317b13545f+ , curveEccG =+ Point+ 0x015d4860d088ddb3496b0c6064756260441cde4af1771d4db01ffe5b34e59703dc255a868a1180515603aeab60794e54bb7996a7+ 0x0061b1cfab6be5f32bbfa78324ed106a7636b9c5a7bd198d0158aa4f5488d08f38514f1fdf4b4f40d2181b3681c364ba0273c706+ , curveEccN =+ 0x010000000000000000000000000000000000000000000000000001e2aad6a612f33307be5fa47c3c9e052f838164cd37d9a21173+ , curveEccH = 2+ }+typeSEC_t571k1 =+ CurveBinary $+ CurveBinaryParam+ 0x080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425+paramSEC_t571k1 =+ CurveParameters+ { curveEccA =+ 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000+ , curveEccB =+ 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001+ , curveEccG =+ Point+ 0x026eb7a859923fbc82189631f8103fe4ac9ca2970012d5d46024804801841ca44370958493b205e647da304db4ceb08cbbd1ba39494776fb988b47174dca88c7e2945283a01c8972+ 0x0349dc807f4fbf374f4aeade3bca95314dd58cec9f307a54ffc61efc006d8a2c9d4979c0ac44aea74fbebbb9f772aedcb620b01a7ba7af1b320430c8591984f601cd4c143ef1c7a3+ , curveEccN =+ 0x020000000000000000000000000000000000000000000000000000000000000000000000131850e1f19a63e4b391a8db917f4138b630d84be5d639381e91deb45cfe778f637c1001+ , curveEccH = 4+ }+typeSEC_t571r1 =+ CurveBinary $+ CurveBinaryParam+ 0x080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425+paramSEC_t571r1 =+ CurveParameters+ { curveEccA =+ 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001+ , curveEccB =+ 0x02f40e7e2221f295de297117b7f3d62f5c6a97ffcb8ceff1cd6ba8ce4a9a18ad84ffabbd8efa59332be7ad6756a66e294afd185a78ff12aa520e4de739baca0c7ffeff7f2955727a+ , curveEccG =+ Point+ 0x0303001d34b856296c16c0d40d3cd7750a93d1d2955fa80aa5f40fc8db7b2abdbde53950f4c0d293cdd711a35b67fb1499ae60038614f1394abfa3b4c850d927e1e7769c8eec2d19+ 0x037bf27342da639b6dccfffeb73d69d78c6c27a6009cbbca1980f8533921e8a684423e43bab08a576291af8f461bb2a8b3531d2f0485c19b16e2f1516e23dd3c1a4827af1b8ac15b+ , curveEccN =+ 0x03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47+ , curveEccH = 2+ }
Crypto/Error.hs view
@@ -4,9 +4,8 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : Stable -- Portability : Excellent----module Crypto.Error- ( module Crypto.Error.Types- ) where+module Crypto.Error (+ module Crypto.Error.Types,+) where import Crypto.Error.Types
Crypto/Error/Types.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Error.Types -- License : BSD-style@@ -6,53 +9,50 @@ -- Portability : Good -- -- Cryptographic Error enumeration and handling----{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Error.Types- ( CryptoError(..)- , CryptoFailable(..)- , throwCryptoErrorIO- , throwCryptoError- , onCryptoFailure- , eitherCryptoError- , maybeCryptoError- ) where+module Crypto.Error.Types (+ CryptoError (..),+ CryptoFailable (..),+ throwCryptoErrorIO,+ throwCryptoError,+ onCryptoFailure,+ eitherCryptoError,+ maybeCryptoError,+) where import qualified Control.Exception as E-import Data.Data+import Data.Data -import Basement.Monad (MonadFailure(..))+import Basement.Monad (MonadFailure (..)) -- | Enumeration of all possible errors that can be found in this library-data CryptoError =- -- symmetric cipher errors+data CryptoError+ = -- symmetric cipher errors CryptoError_KeySizeInvalid | CryptoError_IvSizeInvalid | CryptoError_SeedSizeInvalid | CryptoError_AEADModeNotSupported- -- public key cryptography error- | CryptoError_SecretKeySizeInvalid+ | -- public key cryptography error+ CryptoError_SecretKeySizeInvalid | CryptoError_SecretKeyStructureInvalid | CryptoError_PublicKeySizeInvalid | CryptoError_SharedSecretSizeInvalid- -- elliptic cryptography error- | CryptoError_EcScalarOutOfBounds+ | -- elliptic cryptography error+ CryptoError_EcScalarOutOfBounds | CryptoError_PointSizeInvalid | CryptoError_PointFormatInvalid | CryptoError_PointFormatUnsupported | CryptoError_PointCoordinatesInvalid | CryptoError_ScalarMultiplicationInvalid- -- Message authentification error- | CryptoError_MacKeyInvalid+ | -- Message authentification error+ CryptoError_MacKeyInvalid | CryptoError_AuthenticationTagSizeInvalid- -- Prime generation error- | CryptoError_PrimeSizeInvalid- -- Parameter errors- | CryptoError_SaltTooSmall+ | -- Prime generation error+ CryptoError_PrimeSizeInvalid+ | -- Parameter errors+ CryptoError_SaltTooSmall | CryptoError_OutputLengthTooSmall | CryptoError_OutputLengthTooBig- deriving (Show,Eq,Enum,Data)+ deriving (Show, Eq, Enum, Data) instance E.Exception CryptoError @@ -63,23 +63,22 @@ -- * 'CryptoPassed' : The computation succeeded, and contains the result of the computation -- -- * 'CryptoFailed' : The computation failed, and contains the cryptographic error associated----data CryptoFailable a =- CryptoPassed a+data CryptoFailable a+ = CryptoPassed a | CryptoFailed CryptoError deriving (Show) instance Eq a => Eq (CryptoFailable a) where- (==) (CryptoPassed a) (CryptoPassed b) = a == b+ (==) (CryptoPassed a) (CryptoPassed b) = a == b (==) (CryptoFailed e1) (CryptoFailed e2) = e1 == e2- (==) _ _ = False+ (==) _ _ = False instance Functor CryptoFailable where fmap f (CryptoPassed a) = CryptoPassed (f a) fmap _ (CryptoFailed r) = CryptoFailed r instance Applicative CryptoFailable where- pure a = CryptoPassed a+ pure a = CryptoPassed a (<*>) fm m = fm >>= \p -> m >>= \r2 -> return (p r2) instance Monad CryptoFailable where return = pure@@ -105,8 +104,8 @@ -- | Simple 'either' like combinator for CryptoFailable type onCryptoFailure :: (CryptoError -> r) -> (a -> r) -> CryptoFailable a -> r-onCryptoFailure onError _ (CryptoFailed e) = onError e-onCryptoFailure _ onSuccess (CryptoPassed r) = onSuccess r+onCryptoFailure onError _ (CryptoFailed e) = onError e+onCryptoFailure _ onSuccess (CryptoPassed r) = onSuccess r -- | Transform a CryptoFailable to an Either eitherCryptoError :: CryptoFailable a -> Either CryptoError a
Crypto/Hash.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE ScopedTypeVariables #-}+ -- | -- Module : Crypto.Hash -- License : BSD-style@@ -15,54 +18,55 @@ -- > -- > hexSha3_512 :: ByteString -> String -- > hexSha3_512 bs = show (hash bs :: Digest SHA3_512)----{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE BangPatterns #-}-module Crypto.Hash- (+module Crypto.Hash ( -- * Types- Context- , Digest+ Context,+ Digest,+ -- * Functions- , digestFromByteString+ digestFromByteString,+ -- * Hash methods parametrized by algorithm- , hashInitWith- , hashWith- , hashPrefixWith+ hashInitWith,+ hashWith,+ hashPrefixWith,+ -- * Hash methods- , hashInit- , hashUpdates- , hashUpdate- , hashFinalize- , hashFinalizePrefix- , hashBlockSize- , hashDigestSize- , hash- , hashPrefix- , hashlazy+ hashInit,+ hashUpdates,+ hashUpdate,+ hashFinalize,+ hashFinalizePrefix,+ hashBlockSize,+ hashDigestSize,+ hash,+ hashPrefix,+ hashlazy,+ -- * Hash algorithms- , module Crypto.Hash.Algorithms- ) where+ module Crypto.Hash.Algorithms,+) where -import Basement.Types.OffsetSize (CountOf (..))-import Basement.Block (Block, unsafeFreeze)-import Basement.Block.Mutable (copyFromPtr, new)-import Crypto.Internal.Compat (unsafeDoIO)-import Crypto.Hash.Types-import Crypto.Hash.Algorithms-import Foreign.Ptr (Ptr, plusPtr)-import Crypto.Internal.ByteArray (ByteArrayAccess)+import Basement.Block (Block, unsafeFreeze)+import Basement.Block.Mutable (copyFromPtr, new)+import Basement.Types.OffsetSize (CountOf (..))+import Crypto.Hash.Algorithms+import Crypto.Hash.Types+import Crypto.Internal.ByteArray (ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B+import Crypto.Internal.Compat (unsafeDoIO) import qualified Data.ByteString.Lazy as L-import Data.Word (Word8)-import Data.Int (Int32)+import Data.Int (Int32)+import Data.Word (Word8)+import Foreign.Ptr (Ptr, plusPtr) -- | Hash a strict bytestring into a digest. hash :: (ByteArrayAccess ba, HashAlgorithm a) => ba -> Digest a hash bs = hashFinalize $ hashUpdate hashInit bs -- | Hash the first N bytes of a bytestring, with code path independent from N.-hashPrefix :: (ByteArrayAccess ba, HashAlgorithmPrefix a) => ba -> Int -> Digest a+hashPrefix+ :: (ByteArrayAccess ba, HashAlgorithmPrefix a) => ba -> Int -> Digest a hashPrefix = hashFinalizePrefix hashInit -- | Hash a lazy bytestring into a digest.@@ -70,24 +74,27 @@ hashlazy lbs = hashFinalize $ hashUpdates hashInit (L.toChunks lbs) -- | Initialize a new context for this hash algorithm-hashInit :: forall a . HashAlgorithm a => Context a+hashInit :: forall a. HashAlgorithm a => Context a hashInit = Context $ B.allocAndFreeze (hashInternalContextSize (undefined :: a)) $ \(ptr :: Ptr (Context a)) -> hashInternalInit ptr -- | run hashUpdates on one single bytestring and return the updated context.-hashUpdate :: (ByteArrayAccess ba, HashAlgorithm a) => Context a -> ba -> Context a+hashUpdate+ :: (ByteArrayAccess ba, HashAlgorithm a) => Context a -> ba -> Context a hashUpdate ctx b- | B.null b = ctx+ | B.null b = ctx | otherwise = hashUpdates ctx [b] -- | Update the context with a list of strict bytestring, -- and return a new context with the updates.-hashUpdates :: forall a ba . (HashAlgorithm a, ByteArrayAccess ba)- => Context a- -> [ba]- -> Context a+hashUpdates+ :: forall a ba+ . (HashAlgorithm a, ByteArrayAccess ba)+ => Context a+ -> [ba]+ -> Context a hashUpdates c l- | null ls = c+ | null ls = c | otherwise = Context $ B.copyAndFreeze c $ \(ctx :: Ptr (Context a)) -> mapM_ (\b -> B.withByteArray b (processBlocks ctx (B.length b))) ls where@@ -97,14 +104,19 @@ | bytesLeft == 0 = return () | otherwise = do hashInternalUpdate ctx dataPtr (fromIntegral actuallyProcessed)- processBlocks ctx (bytesLeft - actuallyProcessed) (dataPtr `plusPtr` actuallyProcessed)- where- actuallyProcessed = min bytesLeft (fromIntegral (maxBound :: Int32))+ processBlocks+ ctx+ (bytesLeft - actuallyProcessed)+ (dataPtr `plusPtr` actuallyProcessed)+ where+ actuallyProcessed = min bytesLeft (fromIntegral (maxBound :: Int32)) -- | Finalize a context and return a digest.-hashFinalize :: forall a . HashAlgorithm a- => Context a- -> Digest a+hashFinalize+ :: forall a+ . HashAlgorithm a+ => Context a+ -> Digest a hashFinalize !c = Digest $ B.allocAndFreeze (hashDigestSize (undefined :: a)) $ \(dig :: Ptr (Digest a)) -> do ((!_) :: B.Bytes) <- B.copy c $ \(ctx :: Ptr (Context a)) -> hashInternalFinalize ctx dig@@ -116,16 +128,23 @@ -- order to exclude a variable padding, without leaking the padding length. The -- begining of the message, never impacted by the padding, should preferably go -- through 'hashUpdate' for better performance.-hashFinalizePrefix :: forall a ba . (HashAlgorithmPrefix a, ByteArrayAccess ba)- => Context a- -> ba- -> Int- -> Digest a+hashFinalizePrefix+ :: forall a ba+ . (HashAlgorithmPrefix a, ByteArrayAccess ba)+ => Context a+ -> ba+ -> Int+ -> Digest a hashFinalizePrefix !c b len = Digest $ B.allocAndFreeze (hashDigestSize (undefined :: a)) $ \(dig :: Ptr (Digest a)) -> do ((!_) :: B.Bytes) <- B.copy c $ \(ctx :: Ptr (Context a)) -> B.withByteArray b $ \d ->- hashInternalFinalizePrefix ctx d (fromIntegral $ B.length b) (fromIntegral len) dig+ hashInternalFinalizePrefix+ ctx+ d+ (fromIntegral $ B.length b)+ (fromIntegral len)+ dig return () -- | Initialize a new context for a specified hash algorithm@@ -137,25 +156,28 @@ hashWith _ = hash -- | Run the 'hashPrefix' function but takes an explicit hash algorithm parameter-hashPrefixWith :: (ByteArrayAccess ba, HashAlgorithmPrefix alg) => alg -> ba -> Int -> Digest alg+hashPrefixWith+ :: (ByteArrayAccess ba, HashAlgorithmPrefix alg) => alg -> ba -> Int -> Digest alg hashPrefixWith _ = hashPrefix -- | Try to transform a bytearray into a Digest of specific algorithm. -- -- If the digest is not the right size for the algorithm specified, then -- Nothing is returned.-digestFromByteString :: forall a ba . (HashAlgorithm a, ByteArrayAccess ba) => ba -> Maybe (Digest a)+digestFromByteString+ :: forall a ba. (HashAlgorithm a, ByteArrayAccess ba) => ba -> Maybe (Digest a) digestFromByteString = from undefined where- from :: a -> ba -> Maybe (Digest a)- from alg bs- | B.length bs == (hashDigestSize alg) = Just $ Digest $ unsafeDoIO $ copyBytes bs- | otherwise = Nothing+ from :: a -> ba -> Maybe (Digest a)+ from alg bs+ | B.length bs == (hashDigestSize alg) =+ Just $ Digest $ unsafeDoIO $ copyBytes bs+ | otherwise = Nothing - copyBytes :: ba -> IO (Block Word8)- copyBytes ba = do- muArray <- new count- B.withByteArray ba $ \ptr -> copyFromPtr ptr muArray 0 count- unsafeFreeze muArray- where- count = CountOf (B.length ba)+ copyBytes :: ba -> IO (Block Word8)+ copyBytes ba = do+ muArray <- new count+ B.withByteArray ba $ \ptr -> copyFromPtr ptr muArray 0 count+ unsafeFreeze muArray+ where+ count = CountOf (B.length ba)
Crypto/Hash/Algorithms.hs view
@@ -6,75 +6,77 @@ -- Portability : unknown -- -- Definitions of known hash algorithms----module Crypto.Hash.Algorithms- ( HashAlgorithm- , HashAlgorithmPrefix+module Crypto.Hash.Algorithms (+ HashAlgorithm,+ HashAlgorithmPrefix,+ -- * Hash algorithms- , Blake2s_160(..)- , Blake2s_224(..)- , Blake2s_256(..)- , Blake2sp_224(..)- , Blake2sp_256(..)- , Blake2b_160(..)- , Blake2b_224(..)- , Blake2b_256(..)- , Blake2b_384(..)- , Blake2b_512(..)- , Blake2bp_512(..)- , MD2(..)- , MD4(..)- , MD5(..)- , SHA1(..)- , SHA224(..)- , SHA256(..)- , SHA384(..)- , SHA512(..)- , SHA512t_224(..)- , SHA512t_256(..)- , RIPEMD160(..)- , Tiger(..)- , Keccak_224(..)- , Keccak_256(..)- , Keccak_384(..)- , Keccak_512(..)- , SHA3_224(..)- , SHA3_256(..)- , SHA3_384(..)- , SHA3_512(..)- , SHAKE128(..)- , SHAKE256(..)- , Blake2b(..), Blake2bp(..)- , Blake2s(..), Blake2sp(..)- , Skein256_224(..)- , Skein256_256(..)- , Skein512_224(..)- , Skein512_256(..)- , Skein512_384(..)- , Skein512_512(..)- , Whirlpool(..)- ) where+ Blake2s_160 (..),+ Blake2s_224 (..),+ Blake2s_256 (..),+ Blake2sp_224 (..),+ Blake2sp_256 (..),+ Blake2b_160 (..),+ Blake2b_224 (..),+ Blake2b_256 (..),+ Blake2b_384 (..),+ Blake2b_512 (..),+ Blake2bp_512 (..),+ MD2 (..),+ MD4 (..),+ MD5 (..),+ SHA1 (..),+ SHA224 (..),+ SHA256 (..),+ SHA384 (..),+ SHA512 (..),+ SHA512t_224 (..),+ SHA512t_256 (..),+ RIPEMD160 (..),+ Tiger (..),+ Keccak_224 (..),+ Keccak_256 (..),+ Keccak_384 (..),+ Keccak_512 (..),+ SHA3_224 (..),+ SHA3_256 (..),+ SHA3_384 (..),+ SHA3_512 (..),+ SHAKE128 (..),+ SHAKE256 (..),+ Blake2b (..),+ Blake2bp (..),+ Blake2s (..),+ Blake2sp (..),+ Skein256_224 (..),+ Skein256_256 (..),+ Skein512_224 (..),+ Skein512_256 (..),+ Skein512_384 (..),+ Skein512_512 (..),+ Whirlpool (..),+) where -import Crypto.Hash.Types (HashAlgorithm, HashAlgorithmPrefix)-import Crypto.Hash.Blake2s-import Crypto.Hash.Blake2sp-import Crypto.Hash.Blake2b-import Crypto.Hash.Blake2bp-import Crypto.Hash.MD2-import Crypto.Hash.MD4-import Crypto.Hash.MD5-import Crypto.Hash.SHA1-import Crypto.Hash.SHA224-import Crypto.Hash.SHA256-import Crypto.Hash.SHA384-import Crypto.Hash.SHA512-import Crypto.Hash.SHA512t-import Crypto.Hash.SHA3-import Crypto.Hash.Keccak-import Crypto.Hash.RIPEMD160-import Crypto.Hash.Tiger-import Crypto.Hash.Skein256-import Crypto.Hash.Skein512-import Crypto.Hash.Whirlpool-import Crypto.Hash.SHAKE-import Crypto.Hash.Blake2+import Crypto.Hash.Blake2+import Crypto.Hash.Blake2b+import Crypto.Hash.Blake2bp+import Crypto.Hash.Blake2s+import Crypto.Hash.Blake2sp+import Crypto.Hash.Keccak+import Crypto.Hash.MD2+import Crypto.Hash.MD4+import Crypto.Hash.MD5+import Crypto.Hash.RIPEMD160+import Crypto.Hash.SHA1+import Crypto.Hash.SHA224+import Crypto.Hash.SHA256+import Crypto.Hash.SHA3+import Crypto.Hash.SHA384+import Crypto.Hash.SHA512+import Crypto.Hash.SHA512t+import Crypto.Hash.SHAKE+import Crypto.Hash.Skein256+import Crypto.Hash.Skein512+import Crypto.Hash.Tiger+import Crypto.Hash.Types (HashAlgorithm, HashAlgorithmPrefix)+import Crypto.Hash.Whirlpool
Crypto/Hash/Blake2.hs view
@@ -1,3 +1,10 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.Blake2 -- License : BSD-style@@ -25,31 +32,23 @@ -- id-blake2s224 | 32-bit | 2**112 | 28 | -- id-blake2s256 | 32-bit | 2**128 | 32 | -- ---------------+--------+-----------+-------------+----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.Blake2- ( HashBlake2(..)- , Blake2s(..)- , Blake2sp(..)- , Blake2b(..)- , Blake2bp(..)- ) where+module Crypto.Hash.Blake2 (+ HashBlake2 (..),+ Blake2s (..),+ Blake2sp (..),+ Blake2b (..),+ Blake2bp (..),+) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)-import GHC.TypeLits (Nat, KnownNat)-import Crypto.Internal.Nat+import Crypto.Hash.Types+import Crypto.Internal.Nat+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr)+import GHC.TypeLits (KnownNat, Nat) -- | Typeclass for the Blake2 family of digest functions. class HashAlgorithm a => HashBlake2 a where- -- | Init Blake2 algorithm with the specified key of the specified length. -- The key length is specified in bytes. blake2InternalKeyedInit :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()@@ -63,28 +62,38 @@ -- * Blake2s 160 -- * Blake2s 224 -- * Blake2s 256--- data Blake2s (bitlen :: Nat) = Blake2s- deriving (Show,Data)+ deriving (Show, Data) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256)- => HashAlgorithm (Blake2s bitlen)- where- type HashBlockSize (Blake2s bitlen) = 64- type HashDigestSize (Blake2s bitlen) = Div8 bitlen+instance+ ( IsDivisibleBy8 bitlen+ , KnownNat bitlen+ , IsAtLeast bitlen 8+ , IsAtMost bitlen 256+ )+ => HashAlgorithm (Blake2s bitlen)+ where+ type HashBlockSize (Blake2s bitlen) = 64+ type HashDigestSize (Blake2s bitlen) = Div8 bitlen type HashInternalContextSize (Blake2s bitlen) = 136- hashBlockSize _ = 64- hashDigestSize _ = byteLen (Proxy :: Proxy bitlen)+ hashBlockSize _ = 64+ hashDigestSize _ = byteLen (Proxy :: Proxy bitlen) hashInternalContextSize _ = 136- hashInternalInit p = c_blake2s_init p (integralNatVal (Proxy :: Proxy bitlen))- hashInternalUpdate = c_blake2s_update- hashInternalFinalize p = c_blake2s_finalize p (integralNatVal (Proxy :: Proxy bitlen))+ hashInternalInit p = c_blake2s_init p (integralNatVal (Proxy :: Proxy bitlen))+ hashInternalUpdate = c_blake2s_update+ hashInternalFinalize p = c_blake2s_finalize p (integralNatVal (Proxy :: Proxy bitlen)) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256)- => HashBlake2 (Blake2s bitlen)- where+instance+ ( IsDivisibleBy8 bitlen+ , KnownNat bitlen+ , IsAtLeast bitlen 8+ , IsAtMost bitlen 256+ )+ => HashBlake2 (Blake2s bitlen)+ where blake2InternalKeyedInit p = c_blake2s_init_key p outLen- where outLen = integralNatVal (Proxy :: Proxy bitlen)+ where+ outLen = integralNatVal (Proxy :: Proxy bitlen) foreign import ccall unsafe "crypton_blake2s_init" c_blake2s_init :: Ptr (Context a) -> Word32 -> IO ()@@ -106,28 +115,38 @@ -- * Blake2b 256 -- * Blake2b 384 -- * Blake2b 512--- data Blake2b (bitlen :: Nat) = Blake2b- deriving (Show,Data)+ deriving (Show, Data) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512)- => HashAlgorithm (Blake2b bitlen)- where- type HashBlockSize (Blake2b bitlen) = 128- type HashDigestSize (Blake2b bitlen) = Div8 bitlen+instance+ ( IsDivisibleBy8 bitlen+ , KnownNat bitlen+ , IsAtLeast bitlen 8+ , IsAtMost bitlen 512+ )+ => HashAlgorithm (Blake2b bitlen)+ where+ type HashBlockSize (Blake2b bitlen) = 128+ type HashDigestSize (Blake2b bitlen) = Div8 bitlen type HashInternalContextSize (Blake2b bitlen) = 248- hashBlockSize _ = 128- hashDigestSize _ = byteLen (Proxy :: Proxy bitlen)+ hashBlockSize _ = 128+ hashDigestSize _ = byteLen (Proxy :: Proxy bitlen) hashInternalContextSize _ = 248- hashInternalInit p = c_blake2b_init p (integralNatVal (Proxy :: Proxy bitlen))- hashInternalUpdate = c_blake2b_update- hashInternalFinalize p = c_blake2b_finalize p (integralNatVal (Proxy :: Proxy bitlen))+ hashInternalInit p = c_blake2b_init p (integralNatVal (Proxy :: Proxy bitlen))+ hashInternalUpdate = c_blake2b_update+ hashInternalFinalize p = c_blake2b_finalize p (integralNatVal (Proxy :: Proxy bitlen)) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512)- => HashBlake2 (Blake2b bitlen)- where+instance+ ( IsDivisibleBy8 bitlen+ , KnownNat bitlen+ , IsAtLeast bitlen 8+ , IsAtMost bitlen 512+ )+ => HashBlake2 (Blake2b bitlen)+ where blake2InternalKeyedInit p = c_blake2b_init_key p outLen- where outLen = integralNatVal (Proxy :: Proxy bitlen)+ where+ outLen = integralNatVal (Proxy :: Proxy bitlen) foreign import ccall unsafe "crypton_blake2b_init" c_blake2b_init :: Ptr (Context a) -> Word32 -> IO ()@@ -139,26 +158,37 @@ c_blake2b_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () data Blake2sp (bitlen :: Nat) = Blake2sp- deriving (Show,Data)+ deriving (Show, Data) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256)- => HashAlgorithm (Blake2sp bitlen)- where- type HashBlockSize (Blake2sp bitlen) = 64- type HashDigestSize (Blake2sp bitlen) = Div8 bitlen+instance+ ( IsDivisibleBy8 bitlen+ , KnownNat bitlen+ , IsAtLeast bitlen 8+ , IsAtMost bitlen 256+ )+ => HashAlgorithm (Blake2sp bitlen)+ where+ type HashBlockSize (Blake2sp bitlen) = 64+ type HashDigestSize (Blake2sp bitlen) = Div8 bitlen type HashInternalContextSize (Blake2sp bitlen) = 2185- hashBlockSize _ = 64- hashDigestSize _ = byteLen (Proxy :: Proxy bitlen)+ hashBlockSize _ = 64+ hashDigestSize _ = byteLen (Proxy :: Proxy bitlen) hashInternalContextSize _ = 2185- hashInternalInit p = c_blake2sp_init p (integralNatVal (Proxy :: Proxy bitlen))- hashInternalUpdate = c_blake2sp_update- hashInternalFinalize p = c_blake2sp_finalize p (integralNatVal (Proxy :: Proxy bitlen))+ hashInternalInit p = c_blake2sp_init p (integralNatVal (Proxy :: Proxy bitlen))+ hashInternalUpdate = c_blake2sp_update+ hashInternalFinalize p = c_blake2sp_finalize p (integralNatVal (Proxy :: Proxy bitlen)) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256)- => HashBlake2 (Blake2sp bitlen)- where+instance+ ( IsDivisibleBy8 bitlen+ , KnownNat bitlen+ , IsAtLeast bitlen 8+ , IsAtMost bitlen 256+ )+ => HashBlake2 (Blake2sp bitlen)+ where blake2InternalKeyedInit p = c_blake2sp_init_key p outLen- where outLen = integralNatVal (Proxy :: Proxy bitlen)+ where+ outLen = integralNatVal (Proxy :: Proxy bitlen) foreign import ccall unsafe "crypton_blake2sp_init" c_blake2sp_init :: Ptr (Context a) -> Word32 -> IO ()@@ -170,26 +200,37 @@ c_blake2sp_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () data Blake2bp (bitlen :: Nat) = Blake2bp- deriving (Show,Data)+ deriving (Show, Data) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512)- => HashAlgorithm (Blake2bp bitlen)- where- type HashBlockSize (Blake2bp bitlen) = 128- type HashDigestSize (Blake2bp bitlen) = Div8 bitlen+instance+ ( IsDivisibleBy8 bitlen+ , KnownNat bitlen+ , IsAtLeast bitlen 8+ , IsAtMost bitlen 512+ )+ => HashAlgorithm (Blake2bp bitlen)+ where+ type HashBlockSize (Blake2bp bitlen) = 128+ type HashDigestSize (Blake2bp bitlen) = Div8 bitlen type HashInternalContextSize (Blake2bp bitlen) = 2325- hashBlockSize _ = 128- hashDigestSize _ = byteLen (Proxy :: Proxy bitlen)+ hashBlockSize _ = 128+ hashDigestSize _ = byteLen (Proxy :: Proxy bitlen) hashInternalContextSize _ = 2325- hashInternalInit p = c_blake2bp_init p (integralNatVal (Proxy :: Proxy bitlen))- hashInternalUpdate = c_blake2bp_update- hashInternalFinalize p = c_blake2bp_finalize p (integralNatVal (Proxy :: Proxy bitlen))+ hashInternalInit p = c_blake2bp_init p (integralNatVal (Proxy :: Proxy bitlen))+ hashInternalUpdate = c_blake2bp_update+ hashInternalFinalize p = c_blake2bp_finalize p (integralNatVal (Proxy :: Proxy bitlen)) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512)- => HashBlake2 (Blake2bp bitlen)- where+instance+ ( IsDivisibleBy8 bitlen+ , KnownNat bitlen+ , IsAtLeast bitlen 8+ , IsAtMost bitlen 512+ )+ => HashBlake2 (Blake2bp bitlen)+ where blake2InternalKeyedInit p = c_blake2bp_init_key p outLen- where outLen = integralNatVal (Proxy :: Proxy bitlen)+ where+ outLen = integralNatVal (Proxy :: Proxy bitlen) foreign import ccall unsafe "crypton_blake2bp_init" c_blake2bp_init :: Ptr (Context a) -> Word32 -> IO ()
Crypto/Hash/Blake2b.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.Blake2b -- License : BSD-style@@ -7,96 +12,93 @@ -- -- Module containing the binding functions to work with the -- Blake2b cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.Blake2b- ( Blake2b_160 (..), Blake2b_224 (..), Blake2b_256 (..), Blake2b_384 (..), Blake2b_512 (..)- ) where--import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+module Crypto.Hash.Blake2b (+ Blake2b_160 (..),+ Blake2b_224 (..),+ Blake2b_256 (..),+ Blake2b_384 (..),+ Blake2b_512 (..),+) where +import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | Blake2b (160 bits) cryptographic hash algorithm data Blake2b_160 = Blake2b_160- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Blake2b_160 where- type HashBlockSize Blake2b_160 = 128- type HashDigestSize Blake2b_160 = 20+ type HashBlockSize Blake2b_160 = 128+ type HashDigestSize Blake2b_160 = 20 type HashInternalContextSize Blake2b_160 = 248- hashBlockSize _ = 128- hashDigestSize _ = 20+ hashBlockSize _ = 128+ hashDigestSize _ = 20 hashInternalContextSize _ = 248- hashInternalInit p = c_blake2b_init p 160- hashInternalUpdate = c_blake2b_update- hashInternalFinalize p = c_blake2b_finalize p 160+ hashInternalInit p = c_blake2b_init p 160+ hashInternalUpdate = c_blake2b_update+ hashInternalFinalize p = c_blake2b_finalize p 160 -- | Blake2b (224 bits) cryptographic hash algorithm data Blake2b_224 = Blake2b_224- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Blake2b_224 where- type HashBlockSize Blake2b_224 = 128- type HashDigestSize Blake2b_224 = 28+ type HashBlockSize Blake2b_224 = 128+ type HashDigestSize Blake2b_224 = 28 type HashInternalContextSize Blake2b_224 = 248- hashBlockSize _ = 128- hashDigestSize _ = 28+ hashBlockSize _ = 128+ hashDigestSize _ = 28 hashInternalContextSize _ = 248- hashInternalInit p = c_blake2b_init p 224- hashInternalUpdate = c_blake2b_update- hashInternalFinalize p = c_blake2b_finalize p 224+ hashInternalInit p = c_blake2b_init p 224+ hashInternalUpdate = c_blake2b_update+ hashInternalFinalize p = c_blake2b_finalize p 224 -- | Blake2b (256 bits) cryptographic hash algorithm data Blake2b_256 = Blake2b_256- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Blake2b_256 where- type HashBlockSize Blake2b_256 = 128- type HashDigestSize Blake2b_256 = 32+ type HashBlockSize Blake2b_256 = 128+ type HashDigestSize Blake2b_256 = 32 type HashInternalContextSize Blake2b_256 = 248- hashBlockSize _ = 128- hashDigestSize _ = 32+ hashBlockSize _ = 128+ hashDigestSize _ = 32 hashInternalContextSize _ = 248- hashInternalInit p = c_blake2b_init p 256- hashInternalUpdate = c_blake2b_update- hashInternalFinalize p = c_blake2b_finalize p 256+ hashInternalInit p = c_blake2b_init p 256+ hashInternalUpdate = c_blake2b_update+ hashInternalFinalize p = c_blake2b_finalize p 256 -- | Blake2b (384 bits) cryptographic hash algorithm data Blake2b_384 = Blake2b_384- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Blake2b_384 where- type HashBlockSize Blake2b_384 = 128- type HashDigestSize Blake2b_384 = 48+ type HashBlockSize Blake2b_384 = 128+ type HashDigestSize Blake2b_384 = 48 type HashInternalContextSize Blake2b_384 = 248- hashBlockSize _ = 128- hashDigestSize _ = 48+ hashBlockSize _ = 128+ hashDigestSize _ = 48 hashInternalContextSize _ = 248- hashInternalInit p = c_blake2b_init p 384- hashInternalUpdate = c_blake2b_update- hashInternalFinalize p = c_blake2b_finalize p 384+ hashInternalInit p = c_blake2b_init p 384+ hashInternalUpdate = c_blake2b_update+ hashInternalFinalize p = c_blake2b_finalize p 384 -- | Blake2b (512 bits) cryptographic hash algorithm data Blake2b_512 = Blake2b_512- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Blake2b_512 where- type HashBlockSize Blake2b_512 = 128- type HashDigestSize Blake2b_512 = 64+ type HashBlockSize Blake2b_512 = 128+ type HashDigestSize Blake2b_512 = 64 type HashInternalContextSize Blake2b_512 = 248- hashBlockSize _ = 128- hashDigestSize _ = 64+ hashBlockSize _ = 128+ hashDigestSize _ = 64 hashInternalContextSize _ = 248- hashInternalInit p = c_blake2b_init p 512- hashInternalUpdate = c_blake2b_update- hashInternalFinalize p = c_blake2b_finalize p 512-+ hashInternalInit p = c_blake2b_init p 512+ hashInternalUpdate = c_blake2b_update+ hashInternalFinalize p = c_blake2b_finalize p 512 foreign import ccall unsafe "crypton_blake2b_init" c_blake2b_init :: Ptr (Context a) -> Word32 -> IO ()
Crypto/Hash/Blake2bp.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.Blake2bp -- License : BSD-style@@ -7,36 +12,29 @@ -- -- Module containing the binding functions to work with the -- Blake2bp cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.Blake2bp- ( Blake2bp_512 (..)- ) where--import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+module Crypto.Hash.Blake2bp (+ Blake2bp_512 (..),+) where +import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | Blake2bp (512 bits) cryptographic hash algorithm data Blake2bp_512 = Blake2bp_512- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Blake2bp_512 where- type HashBlockSize Blake2bp_512 = 128- type HashDigestSize Blake2bp_512 = 64+ type HashBlockSize Blake2bp_512 = 128+ type HashDigestSize Blake2bp_512 = 64 type HashInternalContextSize Blake2bp_512 = 1768- hashBlockSize _ = 128- hashDigestSize _ = 64+ hashBlockSize _ = 128+ hashDigestSize _ = 64 hashInternalContextSize _ = 1768- hashInternalInit p = c_blake2bp_init p 512- hashInternalUpdate = c_blake2bp_update- hashInternalFinalize p = c_blake2bp_finalize p 512-+ hashInternalInit p = c_blake2bp_init p 512+ hashInternalUpdate = c_blake2bp_update+ hashInternalFinalize p = c_blake2bp_finalize p 512 foreign import ccall unsafe "crypton_blake2bp_init" c_blake2bp_init :: Ptr (Context a) -> Word32 -> IO ()
Crypto/Hash/Blake2s.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.Blake2s -- License : BSD-style@@ -7,66 +12,61 @@ -- -- Module containing the binding functions to work with the -- Blake2s cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.Blake2s- ( Blake2s_160 (..), Blake2s_224 (..), Blake2s_256 (..)- ) where--import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+module Crypto.Hash.Blake2s (+ Blake2s_160 (..),+ Blake2s_224 (..),+ Blake2s_256 (..),+) where +import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | Blake2s (160 bits) cryptographic hash algorithm data Blake2s_160 = Blake2s_160- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Blake2s_160 where- type HashBlockSize Blake2s_160 = 64- type HashDigestSize Blake2s_160 = 20+ type HashBlockSize Blake2s_160 = 64+ type HashDigestSize Blake2s_160 = 20 type HashInternalContextSize Blake2s_160 = 136- hashBlockSize _ = 64- hashDigestSize _ = 20+ hashBlockSize _ = 64+ hashDigestSize _ = 20 hashInternalContextSize _ = 136- hashInternalInit p = c_blake2s_init p 160- hashInternalUpdate = c_blake2s_update- hashInternalFinalize p = c_blake2s_finalize p 160+ hashInternalInit p = c_blake2s_init p 160+ hashInternalUpdate = c_blake2s_update+ hashInternalFinalize p = c_blake2s_finalize p 160 -- | Blake2s (224 bits) cryptographic hash algorithm data Blake2s_224 = Blake2s_224- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Blake2s_224 where- type HashBlockSize Blake2s_224 = 64- type HashDigestSize Blake2s_224 = 28+ type HashBlockSize Blake2s_224 = 64+ type HashDigestSize Blake2s_224 = 28 type HashInternalContextSize Blake2s_224 = 136- hashBlockSize _ = 64- hashDigestSize _ = 28+ hashBlockSize _ = 64+ hashDigestSize _ = 28 hashInternalContextSize _ = 136- hashInternalInit p = c_blake2s_init p 224- hashInternalUpdate = c_blake2s_update- hashInternalFinalize p = c_blake2s_finalize p 224+ hashInternalInit p = c_blake2s_init p 224+ hashInternalUpdate = c_blake2s_update+ hashInternalFinalize p = c_blake2s_finalize p 224 -- | Blake2s (256 bits) cryptographic hash algorithm data Blake2s_256 = Blake2s_256- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Blake2s_256 where- type HashBlockSize Blake2s_256 = 64- type HashDigestSize Blake2s_256 = 32+ type HashBlockSize Blake2s_256 = 64+ type HashDigestSize Blake2s_256 = 32 type HashInternalContextSize Blake2s_256 = 136- hashBlockSize _ = 64- hashDigestSize _ = 32+ hashBlockSize _ = 64+ hashDigestSize _ = 32 hashInternalContextSize _ = 136- hashInternalInit p = c_blake2s_init p 256- hashInternalUpdate = c_blake2s_update- hashInternalFinalize p = c_blake2s_finalize p 256-+ hashInternalInit p = c_blake2s_init p 256+ hashInternalUpdate = c_blake2s_update+ hashInternalFinalize p = c_blake2s_finalize p 256 foreign import ccall unsafe "crypton_blake2s_init" c_blake2s_init :: Ptr (Context a) -> Word32 -> IO ()
Crypto/Hash/Blake2sp.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.Blake2sp -- License : BSD-style@@ -7,51 +12,45 @@ -- -- Module containing the binding functions to work with the -- Blake2sp cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.Blake2sp- ( Blake2sp_224 (..), Blake2sp_256 (..)- ) where--import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+module Crypto.Hash.Blake2sp (+ Blake2sp_224 (..),+ Blake2sp_256 (..),+) where +import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | Blake2sp (224 bits) cryptographic hash algorithm data Blake2sp_224 = Blake2sp_224- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Blake2sp_224 where- type HashBlockSize Blake2sp_224 = 64- type HashDigestSize Blake2sp_224 = 28+ type HashBlockSize Blake2sp_224 = 64+ type HashDigestSize Blake2sp_224 = 28 type HashInternalContextSize Blake2sp_224 = 1752- hashBlockSize _ = 64- hashDigestSize _ = 28+ hashBlockSize _ = 64+ hashDigestSize _ = 28 hashInternalContextSize _ = 1752- hashInternalInit p = c_blake2sp_init p 224- hashInternalUpdate = c_blake2sp_update- hashInternalFinalize p = c_blake2sp_finalize p 224+ hashInternalInit p = c_blake2sp_init p 224+ hashInternalUpdate = c_blake2sp_update+ hashInternalFinalize p = c_blake2sp_finalize p 224 -- | Blake2sp (256 bits) cryptographic hash algorithm data Blake2sp_256 = Blake2sp_256- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Blake2sp_256 where- type HashBlockSize Blake2sp_256 = 64- type HashDigestSize Blake2sp_256 = 32+ type HashBlockSize Blake2sp_256 = 64+ type HashDigestSize Blake2sp_256 = 32 type HashInternalContextSize Blake2sp_256 = 1752- hashBlockSize _ = 64- hashDigestSize _ = 32+ hashBlockSize _ = 64+ hashDigestSize _ = 32 hashInternalContextSize _ = 1752- hashInternalInit p = c_blake2sp_init p 256- hashInternalUpdate = c_blake2sp_update- hashInternalFinalize p = c_blake2sp_finalize p 256-+ hashInternalInit p = c_blake2sp_init p 256+ hashInternalUpdate = c_blake2sp_update+ hashInternalFinalize p = c_blake2sp_finalize p 256 foreign import ccall unsafe "crypton_blake2sp_init" c_blake2sp_init :: Ptr (Context a) -> Word32 -> IO ()
Crypto/Hash/IO.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE ScopedTypeVariables #-}+ -- | -- Module : Crypto.Hash.IO -- License : BSD-style@@ -6,22 +9,19 @@ -- Portability : unknown -- -- Generalized impure cryptographic hash interface----{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE ScopedTypeVariables #-}-module Crypto.Hash.IO- ( HashAlgorithm(..)- , MutableContext- , hashMutableInit- , hashMutableInitWith- , hashMutableUpdate- , hashMutableFinalize- , hashMutableReset- ) where+module Crypto.Hash.IO (+ HashAlgorithm (..),+ MutableContext,+ hashMutableInit,+ hashMutableInitWith,+ hashMutableUpdate,+ hashMutableFinalize,+ hashMutableReset,+) where -import Crypto.Hash.Types+import Crypto.Hash.Types import qualified Crypto.Internal.ByteArray as B-import Foreign.Ptr+import Foreign.Ptr -- | A Mutable hash context --@@ -38,8 +38,10 @@ hashMutableInit :: HashAlgorithm alg => IO (MutableContext alg) hashMutableInit = doInit undefined B.alloc where- doInit :: HashAlgorithm a => a -> (Int -> (Ptr (Context a) -> IO ()) -> IO B.Bytes) -> IO (MutableContext a)- doInit alg alloc = MutableContext `fmap` alloc (hashInternalContextSize alg) hashInternalInit+ doInit+ :: HashAlgorithm a+ => a -> (Int -> (Ptr (Context a) -> IO ()) -> IO B.Bytes) -> IO (MutableContext a)+ doInit alg alloc = MutableContext `fmap` alloc (hashInternalContextSize alg) hashInternalInit -- | Create a new mutable hash context. --@@ -48,16 +50,21 @@ hashMutableInitWith _ = hashMutableInit -- | Update a mutable hash context in place-hashMutableUpdate :: (B.ByteArrayAccess ba, HashAlgorithm a) => MutableContext a -> ba -> IO ()+hashMutableUpdate+ :: (B.ByteArrayAccess ba, HashAlgorithm a) => MutableContext a -> ba -> IO () hashMutableUpdate mc dat = doUpdate mc (B.withByteArray mc)- where doUpdate :: HashAlgorithm a => MutableContext a -> ((Ptr (Context a) -> IO ()) -> IO ()) -> IO ()- doUpdate _ withCtx =- withCtx $ \ctx ->- B.withByteArray dat $ \d ->+ where+ doUpdate+ :: HashAlgorithm a+ => MutableContext a -> ((Ptr (Context a) -> IO ()) -> IO ()) -> IO ()+ doUpdate _ withCtx =+ withCtx $ \ctx ->+ B.withByteArray dat $ \d -> hashInternalUpdate ctx d (fromIntegral $ B.length dat) -- | Finalize a mutable hash context and compute a digest-hashMutableFinalize :: forall a . HashAlgorithm a => MutableContext a -> IO (Digest a)+hashMutableFinalize+ :: forall a. HashAlgorithm a => MutableContext a -> IO (Digest a) hashMutableFinalize mc = do b <- B.alloc (hashDigestSize (undefined :: a)) $ \dig -> B.withByteArray mc $ \(ctx :: Ptr (Context a)) -> hashInternalFinalize ctx dig return $ Digest b@@ -66,5 +73,7 @@ hashMutableReset :: HashAlgorithm a => MutableContext a -> IO () hashMutableReset mc = doReset mc (B.withByteArray mc) where- doReset :: HashAlgorithm a => MutableContext a -> ((Ptr (Context a) -> IO ()) -> IO ()) -> IO ()+ doReset+ :: HashAlgorithm a+ => MutableContext a -> ((Ptr (Context a) -> IO ()) -> IO ()) -> IO () doReset _ withCtx = withCtx hashInternalInit
Crypto/Hash/Keccak.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.Keccak -- License : BSD-style@@ -7,81 +12,77 @@ -- -- Module containing the binding functions to work with the -- Keccak cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.Keccak- ( Keccak_224 (..), Keccak_256 (..), Keccak_384 (..), Keccak_512 (..)- ) where--import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+module Crypto.Hash.Keccak (+ Keccak_224 (..),+ Keccak_256 (..),+ Keccak_384 (..),+ Keccak_512 (..),+) where +import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | Keccak (224 bits) cryptographic hash algorithm data Keccak_224 = Keccak_224- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Keccak_224 where- type HashBlockSize Keccak_224 = 144- type HashDigestSize Keccak_224 = 28+ type HashBlockSize Keccak_224 = 144+ type HashDigestSize Keccak_224 = 28 type HashInternalContextSize Keccak_224 = 352- hashBlockSize _ = 144- hashDigestSize _ = 28+ hashBlockSize _ = 144+ hashDigestSize _ = 28 hashInternalContextSize _ = 352- hashInternalInit p = c_keccak_init p 224- hashInternalUpdate = c_keccak_update- hashInternalFinalize p = c_keccak_finalize p 224+ hashInternalInit p = c_keccak_init p 224+ hashInternalUpdate = c_keccak_update+ hashInternalFinalize p = c_keccak_finalize p 224 -- | Keccak (256 bits) cryptographic hash algorithm data Keccak_256 = Keccak_256- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Keccak_256 where- type HashBlockSize Keccak_256 = 136- type HashDigestSize Keccak_256 = 32+ type HashBlockSize Keccak_256 = 136+ type HashDigestSize Keccak_256 = 32 type HashInternalContextSize Keccak_256 = 344- hashBlockSize _ = 136- hashDigestSize _ = 32+ hashBlockSize _ = 136+ hashDigestSize _ = 32 hashInternalContextSize _ = 344- hashInternalInit p = c_keccak_init p 256- hashInternalUpdate = c_keccak_update- hashInternalFinalize p = c_keccak_finalize p 256+ hashInternalInit p = c_keccak_init p 256+ hashInternalUpdate = c_keccak_update+ hashInternalFinalize p = c_keccak_finalize p 256 -- | Keccak (384 bits) cryptographic hash algorithm data Keccak_384 = Keccak_384- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Keccak_384 where- type HashBlockSize Keccak_384 = 104- type HashDigestSize Keccak_384 = 48+ type HashBlockSize Keccak_384 = 104+ type HashDigestSize Keccak_384 = 48 type HashInternalContextSize Keccak_384 = 312- hashBlockSize _ = 104- hashDigestSize _ = 48+ hashBlockSize _ = 104+ hashDigestSize _ = 48 hashInternalContextSize _ = 312- hashInternalInit p = c_keccak_init p 384- hashInternalUpdate = c_keccak_update- hashInternalFinalize p = c_keccak_finalize p 384+ hashInternalInit p = c_keccak_init p 384+ hashInternalUpdate = c_keccak_update+ hashInternalFinalize p = c_keccak_finalize p 384 -- | Keccak (512 bits) cryptographic hash algorithm data Keccak_512 = Keccak_512- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Keccak_512 where- type HashBlockSize Keccak_512 = 72- type HashDigestSize Keccak_512 = 64+ type HashBlockSize Keccak_512 = 72+ type HashDigestSize Keccak_512 = 64 type HashInternalContextSize Keccak_512 = 280- hashBlockSize _ = 72- hashDigestSize _ = 64+ hashBlockSize _ = 72+ hashDigestSize _ = 64 hashInternalContextSize _ = 280- hashInternalInit p = c_keccak_init p 512- hashInternalUpdate = c_keccak_update- hashInternalFinalize p = c_keccak_finalize p 512-+ hashInternalInit p = c_keccak_init p 512+ hashInternalUpdate = c_keccak_update+ hashInternalFinalize p = c_keccak_finalize p 512 foreign import ccall unsafe "crypton_keccak_init" c_keccak_init :: Ptr (Context a) -> Word32 -> IO ()
Crypto/Hash/MD2.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.MD2 -- License : BSD-style@@ -7,35 +12,30 @@ -- -- Module containing the binding functions to work with the -- MD2 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.MD2 ( MD2 (..) ) where+module Crypto.Hash.MD2 (MD2 (..)) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | MD2 cryptographic hash algorithm data MD2 = MD2- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm MD2 where- type HashBlockSize MD2 = 16- type HashDigestSize MD2 = 16+ type HashBlockSize MD2 = 16+ type HashDigestSize MD2 = 16 type HashInternalContextSize MD2 = 96- hashBlockSize _ = 16- hashDigestSize _ = 16+ hashBlockSize _ = 16+ hashDigestSize _ = 16 hashInternalContextSize _ = 96- hashInternalInit = c_md2_init- hashInternalUpdate = c_md2_update- hashInternalFinalize = c_md2_finalize+ hashInternalInit = c_md2_init+ hashInternalUpdate = c_md2_update+ hashInternalFinalize = c_md2_finalize foreign import ccall unsafe "crypton_md2_init"- c_md2_init :: Ptr (Context a)-> IO ()+ c_md2_init :: Ptr (Context a) -> IO () foreign import ccall "crypton_md2_update" c_md2_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
Crypto/Hash/MD4.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.MD4 -- License : BSD-style@@ -7,35 +12,30 @@ -- -- Module containing the binding functions to work with the -- MD4 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.MD4 ( MD4 (..) ) where+module Crypto.Hash.MD4 (MD4 (..)) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | MD4 cryptographic hash algorithm data MD4 = MD4- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm MD4 where- type HashBlockSize MD4 = 64- type HashDigestSize MD4 = 16+ type HashBlockSize MD4 = 64+ type HashDigestSize MD4 = 16 type HashInternalContextSize MD4 = 96- hashBlockSize _ = 64- hashDigestSize _ = 16+ hashBlockSize _ = 64+ hashDigestSize _ = 16 hashInternalContextSize _ = 96- hashInternalInit = c_md4_init- hashInternalUpdate = c_md4_update- hashInternalFinalize = c_md4_finalize+ hashInternalInit = c_md4_init+ hashInternalUpdate = c_md4_update+ hashInternalFinalize = c_md4_finalize foreign import ccall unsafe "crypton_md4_init"- c_md4_init :: Ptr (Context a)-> IO ()+ c_md4_init :: Ptr (Context a) -> IO () foreign import ccall "crypton_md4_update" c_md4_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
Crypto/Hash/MD5.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.MD5 -- License : BSD-style@@ -7,38 +12,33 @@ -- -- Module containing the binding functions to work with the -- MD5 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.MD5 ( MD5 (..) ) where+module Crypto.Hash.MD5 (MD5 (..)) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | MD5 cryptographic hash algorithm data MD5 = MD5- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm MD5 where- type HashBlockSize MD5 = 64- type HashDigestSize MD5 = 16+ type HashBlockSize MD5 = 64+ type HashDigestSize MD5 = 16 type HashInternalContextSize MD5 = 96- hashBlockSize _ = 64- hashDigestSize _ = 16+ hashBlockSize _ = 64+ hashDigestSize _ = 16 hashInternalContextSize _ = 96- hashInternalInit = c_md5_init- hashInternalUpdate = c_md5_update- hashInternalFinalize = c_md5_finalize+ hashInternalInit = c_md5_init+ hashInternalUpdate = c_md5_update+ hashInternalFinalize = c_md5_finalize instance HashAlgorithmPrefix MD5 where hashInternalFinalizePrefix = c_md5_finalize_prefix foreign import ccall unsafe "crypton_md5_init"- c_md5_init :: Ptr (Context a)-> IO ()+ c_md5_init :: Ptr (Context a) -> IO () foreign import ccall "crypton_md5_update" c_md5_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()@@ -47,4 +47,5 @@ c_md5_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () foreign import ccall "crypton_md5_finalize_prefix"- c_md5_finalize_prefix :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()+ c_md5_finalize_prefix+ :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/RIPEMD160.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.RIPEMD160 -- License : BSD-style@@ -7,35 +12,30 @@ -- -- Module containing the binding functions to work with the -- RIPEMD160 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.RIPEMD160 ( RIPEMD160 (..) ) where+module Crypto.Hash.RIPEMD160 (RIPEMD160 (..)) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | RIPEMD160 cryptographic hash algorithm data RIPEMD160 = RIPEMD160- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm RIPEMD160 where- type HashBlockSize RIPEMD160 = 64- type HashDigestSize RIPEMD160 = 20+ type HashBlockSize RIPEMD160 = 64+ type HashDigestSize RIPEMD160 = 20 type HashInternalContextSize RIPEMD160 = 128- hashBlockSize _ = 64- hashDigestSize _ = 20+ hashBlockSize _ = 64+ hashDigestSize _ = 20 hashInternalContextSize _ = 128- hashInternalInit = c_ripemd160_init- hashInternalUpdate = c_ripemd160_update- hashInternalFinalize = c_ripemd160_finalize+ hashInternalInit = c_ripemd160_init+ hashInternalUpdate = c_ripemd160_update+ hashInternalFinalize = c_ripemd160_finalize foreign import ccall unsafe "crypton_ripemd160_init"- c_ripemd160_init :: Ptr (Context a)-> IO ()+ c_ripemd160_init :: Ptr (Context a) -> IO () foreign import ccall "crypton_ripemd160_update" c_ripemd160_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
Crypto/Hash/SHA1.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.SHA1 -- License : BSD-style@@ -7,38 +12,33 @@ -- -- Module containing the binding functions to work with the -- SHA1 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.SHA1 ( SHA1 (..) ) where+module Crypto.Hash.SHA1 (SHA1 (..)) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | SHA1 cryptographic hash algorithm data SHA1 = SHA1- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm SHA1 where- type HashBlockSize SHA1 = 64- type HashDigestSize SHA1 = 20+ type HashBlockSize SHA1 = 64+ type HashDigestSize SHA1 = 20 type HashInternalContextSize SHA1 = 96- hashBlockSize _ = 64- hashDigestSize _ = 20+ hashBlockSize _ = 64+ hashDigestSize _ = 20 hashInternalContextSize _ = 96- hashInternalInit = c_sha1_init- hashInternalUpdate = c_sha1_update- hashInternalFinalize = c_sha1_finalize+ hashInternalInit = c_sha1_init+ hashInternalUpdate = c_sha1_update+ hashInternalFinalize = c_sha1_finalize instance HashAlgorithmPrefix SHA1 where hashInternalFinalizePrefix = c_sha1_finalize_prefix foreign import ccall unsafe "crypton_sha1_init"- c_sha1_init :: Ptr (Context a)-> IO ()+ c_sha1_init :: Ptr (Context a) -> IO () foreign import ccall "crypton_sha1_update" c_sha1_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()@@ -47,4 +47,5 @@ c_sha1_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () foreign import ccall "crypton_sha1_finalize_prefix"- c_sha1_finalize_prefix :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()+ c_sha1_finalize_prefix+ :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA224.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.SHA224 -- License : BSD-style@@ -7,38 +12,33 @@ -- -- Module containing the binding functions to work with the -- SHA224 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.SHA224 ( SHA224 (..) ) where+module Crypto.Hash.SHA224 (SHA224 (..)) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | SHA224 cryptographic hash algorithm data SHA224 = SHA224- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm SHA224 where- type HashBlockSize SHA224 = 64- type HashDigestSize SHA224 = 28+ type HashBlockSize SHA224 = 64+ type HashDigestSize SHA224 = 28 type HashInternalContextSize SHA224 = 192- hashBlockSize _ = 64- hashDigestSize _ = 28+ hashBlockSize _ = 64+ hashDigestSize _ = 28 hashInternalContextSize _ = 192- hashInternalInit = c_sha224_init- hashInternalUpdate = c_sha224_update- hashInternalFinalize = c_sha224_finalize+ hashInternalInit = c_sha224_init+ hashInternalUpdate = c_sha224_update+ hashInternalFinalize = c_sha224_finalize instance HashAlgorithmPrefix SHA224 where hashInternalFinalizePrefix = c_sha224_finalize_prefix foreign import ccall unsafe "crypton_sha224_init"- c_sha224_init :: Ptr (Context a)-> IO ()+ c_sha224_init :: Ptr (Context a) -> IO () foreign import ccall "crypton_sha224_update" c_sha224_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()@@ -47,4 +47,5 @@ c_sha224_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () foreign import ccall "crypton_sha224_finalize_prefix"- c_sha224_finalize_prefix :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()+ c_sha224_finalize_prefix+ :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA256.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.SHA256 -- License : BSD-style@@ -7,38 +12,33 @@ -- -- Module containing the binding functions to work with the -- SHA256 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.SHA256 ( SHA256 (..) ) where+module Crypto.Hash.SHA256 (SHA256 (..)) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | SHA256 cryptographic hash algorithm data SHA256 = SHA256- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm SHA256 where- type HashBlockSize SHA256 = 64- type HashDigestSize SHA256 = 32+ type HashBlockSize SHA256 = 64+ type HashDigestSize SHA256 = 32 type HashInternalContextSize SHA256 = 192- hashBlockSize _ = 64- hashDigestSize _ = 32+ hashBlockSize _ = 64+ hashDigestSize _ = 32 hashInternalContextSize _ = 192- hashInternalInit = c_sha256_init- hashInternalUpdate = c_sha256_update- hashInternalFinalize = c_sha256_finalize+ hashInternalInit = c_sha256_init+ hashInternalUpdate = c_sha256_update+ hashInternalFinalize = c_sha256_finalize instance HashAlgorithmPrefix SHA256 where hashInternalFinalizePrefix = c_sha256_finalize_prefix foreign import ccall unsafe "crypton_sha256_init"- c_sha256_init :: Ptr (Context a)-> IO ()+ c_sha256_init :: Ptr (Context a) -> IO () foreign import ccall "crypton_sha256_update" c_sha256_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()@@ -47,4 +47,5 @@ c_sha256_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () foreign import ccall "crypton_sha256_finalize_prefix"- c_sha256_finalize_prefix :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()+ c_sha256_finalize_prefix+ :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA3.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.SHA3 -- License : BSD-style@@ -7,81 +12,77 @@ -- -- Module containing the binding functions to work with the -- SHA3 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.SHA3- ( SHA3_224 (..), SHA3_256 (..), SHA3_384 (..), SHA3_512 (..)- ) where--import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+module Crypto.Hash.SHA3 (+ SHA3_224 (..),+ SHA3_256 (..),+ SHA3_384 (..),+ SHA3_512 (..),+) where +import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | SHA3 (224 bits) cryptographic hash algorithm data SHA3_224 = SHA3_224- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm SHA3_224 where- type HashBlockSize SHA3_224 = 144- type HashDigestSize SHA3_224 = 28+ type HashBlockSize SHA3_224 = 144+ type HashDigestSize SHA3_224 = 28 type HashInternalContextSize SHA3_224 = 352- hashBlockSize _ = 144- hashDigestSize _ = 28+ hashBlockSize _ = 144+ hashDigestSize _ = 28 hashInternalContextSize _ = 352- hashInternalInit p = c_sha3_init p 224- hashInternalUpdate = c_sha3_update- hashInternalFinalize p = c_sha3_finalize p 224+ hashInternalInit p = c_sha3_init p 224+ hashInternalUpdate = c_sha3_update+ hashInternalFinalize p = c_sha3_finalize p 224 -- | SHA3 (256 bits) cryptographic hash algorithm data SHA3_256 = SHA3_256- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm SHA3_256 where- type HashBlockSize SHA3_256 = 136- type HashDigestSize SHA3_256 = 32+ type HashBlockSize SHA3_256 = 136+ type HashDigestSize SHA3_256 = 32 type HashInternalContextSize SHA3_256 = 344- hashBlockSize _ = 136- hashDigestSize _ = 32+ hashBlockSize _ = 136+ hashDigestSize _ = 32 hashInternalContextSize _ = 344- hashInternalInit p = c_sha3_init p 256- hashInternalUpdate = c_sha3_update- hashInternalFinalize p = c_sha3_finalize p 256+ hashInternalInit p = c_sha3_init p 256+ hashInternalUpdate = c_sha3_update+ hashInternalFinalize p = c_sha3_finalize p 256 -- | SHA3 (384 bits) cryptographic hash algorithm data SHA3_384 = SHA3_384- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm SHA3_384 where- type HashBlockSize SHA3_384 = 104- type HashDigestSize SHA3_384 = 48+ type HashBlockSize SHA3_384 = 104+ type HashDigestSize SHA3_384 = 48 type HashInternalContextSize SHA3_384 = 312- hashBlockSize _ = 104- hashDigestSize _ = 48+ hashBlockSize _ = 104+ hashDigestSize _ = 48 hashInternalContextSize _ = 312- hashInternalInit p = c_sha3_init p 384- hashInternalUpdate = c_sha3_update- hashInternalFinalize p = c_sha3_finalize p 384+ hashInternalInit p = c_sha3_init p 384+ hashInternalUpdate = c_sha3_update+ hashInternalFinalize p = c_sha3_finalize p 384 -- | SHA3 (512 bits) cryptographic hash algorithm data SHA3_512 = SHA3_512- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm SHA3_512 where- type HashBlockSize SHA3_512 = 72- type HashDigestSize SHA3_512 = 64+ type HashBlockSize SHA3_512 = 72+ type HashDigestSize SHA3_512 = 64 type HashInternalContextSize SHA3_512 = 280- hashBlockSize _ = 72- hashDigestSize _ = 64+ hashBlockSize _ = 72+ hashDigestSize _ = 64 hashInternalContextSize _ = 280- hashInternalInit p = c_sha3_init p 512- hashInternalUpdate = c_sha3_update- hashInternalFinalize p = c_sha3_finalize p 512-+ hashInternalInit p = c_sha3_init p 512+ hashInternalUpdate = c_sha3_update+ hashInternalFinalize p = c_sha3_finalize p 512 foreign import ccall unsafe "crypton_sha3_init" c_sha3_init :: Ptr (Context a) -> Word32 -> IO ()
Crypto/Hash/SHA384.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.SHA384 -- License : BSD-style@@ -7,38 +12,33 @@ -- -- Module containing the binding functions to work with the -- SHA384 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.SHA384 ( SHA384 (..) ) where+module Crypto.Hash.SHA384 (SHA384 (..)) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | SHA384 cryptographic hash algorithm data SHA384 = SHA384- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm SHA384 where- type HashBlockSize SHA384 = 128- type HashDigestSize SHA384 = 48+ type HashBlockSize SHA384 = 128+ type HashDigestSize SHA384 = 48 type HashInternalContextSize SHA384 = 256- hashBlockSize _ = 128- hashDigestSize _ = 48+ hashBlockSize _ = 128+ hashDigestSize _ = 48 hashInternalContextSize _ = 256- hashInternalInit = c_sha384_init- hashInternalUpdate = c_sha384_update- hashInternalFinalize = c_sha384_finalize+ hashInternalInit = c_sha384_init+ hashInternalUpdate = c_sha384_update+ hashInternalFinalize = c_sha384_finalize instance HashAlgorithmPrefix SHA384 where hashInternalFinalizePrefix = c_sha384_finalize_prefix foreign import ccall unsafe "crypton_sha384_init"- c_sha384_init :: Ptr (Context a)-> IO ()+ c_sha384_init :: Ptr (Context a) -> IO () foreign import ccall "crypton_sha384_update" c_sha384_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()@@ -47,4 +47,5 @@ c_sha384_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () foreign import ccall "crypton_sha384_finalize_prefix"- c_sha384_finalize_prefix :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()+ c_sha384_finalize_prefix+ :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA512.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.SHA512 -- License : BSD-style@@ -7,38 +12,33 @@ -- -- Module containing the binding functions to work with the -- SHA512 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.SHA512 ( SHA512 (..) ) where+module Crypto.Hash.SHA512 (SHA512 (..)) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | SHA512 cryptographic hash algorithm data SHA512 = SHA512- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm SHA512 where- type HashBlockSize SHA512 = 128- type HashDigestSize SHA512 = 64+ type HashBlockSize SHA512 = 128+ type HashDigestSize SHA512 = 64 type HashInternalContextSize SHA512 = 256- hashBlockSize _ = 128- hashDigestSize _ = 64+ hashBlockSize _ = 128+ hashDigestSize _ = 64 hashInternalContextSize _ = 256- hashInternalInit = c_sha512_init- hashInternalUpdate = c_sha512_update- hashInternalFinalize = c_sha512_finalize+ hashInternalInit = c_sha512_init+ hashInternalUpdate = c_sha512_update+ hashInternalFinalize = c_sha512_finalize instance HashAlgorithmPrefix SHA512 where hashInternalFinalizePrefix = c_sha512_finalize_prefix foreign import ccall unsafe "crypton_sha512_init"- c_sha512_init :: Ptr (Context a)-> IO ()+ c_sha512_init :: Ptr (Context a) -> IO () foreign import ccall "crypton_sha512_update" c_sha512_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()@@ -47,4 +47,5 @@ c_sha512_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () foreign import ccall "crypton_sha512_finalize_prefix"- c_sha512_finalize_prefix :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()+ c_sha512_finalize_prefix+ :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA512t.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.SHA512t -- License : BSD-style@@ -7,51 +12,45 @@ -- -- Module containing the binding functions to work with the -- SHA512t cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.SHA512t- ( SHA512t_224 (..), SHA512t_256 (..)- ) where--import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+module Crypto.Hash.SHA512t (+ SHA512t_224 (..),+ SHA512t_256 (..),+) where +import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | SHA512t (224 bits) cryptographic hash algorithm data SHA512t_224 = SHA512t_224- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm SHA512t_224 where- type HashBlockSize SHA512t_224 = 128- type HashDigestSize SHA512t_224 = 28+ type HashBlockSize SHA512t_224 = 128+ type HashDigestSize SHA512t_224 = 28 type HashInternalContextSize SHA512t_224 = 256- hashBlockSize _ = 128- hashDigestSize _ = 28+ hashBlockSize _ = 128+ hashDigestSize _ = 28 hashInternalContextSize _ = 256- hashInternalInit p = c_sha512t_init p 224- hashInternalUpdate = c_sha512t_update- hashInternalFinalize p = c_sha512t_finalize p 224+ hashInternalInit p = c_sha512t_init p 224+ hashInternalUpdate = c_sha512t_update+ hashInternalFinalize p = c_sha512t_finalize p 224 -- | SHA512t (256 bits) cryptographic hash algorithm data SHA512t_256 = SHA512t_256- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm SHA512t_256 where- type HashBlockSize SHA512t_256 = 128- type HashDigestSize SHA512t_256 = 32+ type HashBlockSize SHA512t_256 = 128+ type HashDigestSize SHA512t_256 = 32 type HashInternalContextSize SHA512t_256 = 256- hashBlockSize _ = 128- hashDigestSize _ = 32+ hashBlockSize _ = 128+ hashDigestSize _ = 32 hashInternalContextSize _ = 256- hashInternalInit p = c_sha512t_init p 256- hashInternalUpdate = c_sha512t_update- hashInternalFinalize p = c_sha512t_finalize p 256-+ hashInternalInit p = c_sha512t_init p 256+ hashInternalUpdate = c_sha512t_update+ hashInternalFinalize p = c_sha512t_finalize p 256 foreign import ccall unsafe "crypton_sha512t_init" c_sha512t_init :: Ptr (Context a) -> Word32 -> IO ()
Crypto/Hash/SHAKE.hs view
@@ -1,3 +1,12 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UndecidableInstances #-}+ -- | -- Module : Crypto.Hash.SHAKE -- License : BSD-style@@ -7,34 +16,28 @@ -- -- Module containing the binding functions to work with the -- SHA3 extendable output functions (SHAKE).----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE UndecidableInstances #-}-module Crypto.Hash.SHAKE- ( SHAKE128 (..), SHAKE256 (..), HashSHAKE (..)- ) where+module Crypto.Hash.SHAKE (+ SHAKE128 (..),+ SHAKE256 (..),+ HashSHAKE (..),+) where -import Control.Monad (when)-import Crypto.Hash.Types-import Foreign.Ptr (Ptr, castPtr)-import Foreign.Storable (Storable(..))-import Data.Bits-import Data.Data-import Data.Word (Word8, Word32)+import Control.Monad (when)+import Crypto.Hash.Types+import Data.Bits+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr, castPtr)+import Foreign.Storable (Storable (..)) -import GHC.TypeLits (Nat, KnownNat, type (+))-import Crypto.Internal.Nat+import Crypto.Internal.Nat+import GHC.TypeLits (KnownNat, Nat, type (+)) -- | Type class of SHAKE algorithms. class HashAlgorithm a => HashSHAKE a where -- | Alternate finalization needed for cSHAKE cshakeInternalFinalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()+ -- | Get the digest bit length cshakeOutputLength :: a -> Int @@ -48,15 +51,15 @@ deriving (Show, Data) instance KnownNat bitlen => HashAlgorithm (SHAKE128 bitlen) where- type HashBlockSize (SHAKE128 bitlen) = 168- type HashDigestSize (SHAKE128 bitlen) = Div8 (bitlen + 7)+ type HashBlockSize (SHAKE128 bitlen) = 168+ type HashDigestSize (SHAKE128 bitlen) = Div8 (bitlen + 7) type HashInternalContextSize (SHAKE128 bitlen) = 376- hashBlockSize _ = 168- hashDigestSize _ = byteLen (Proxy :: Proxy bitlen)+ hashBlockSize _ = 168+ hashDigestSize _ = byteLen (Proxy :: Proxy bitlen) hashInternalContextSize _ = 376- hashInternalInit p = c_sha3_init p 128- hashInternalUpdate = c_sha3_update- hashInternalFinalize = shakeFinalizeOutput (Proxy :: Proxy bitlen)+ hashInternalInit p = c_sha3_init p 128+ hashInternalUpdate = c_sha3_update+ hashInternalFinalize = shakeFinalizeOutput (Proxy :: Proxy bitlen) instance KnownNat bitlen => HashSHAKE (SHAKE128 bitlen) where cshakeInternalFinalize = cshakeFinalizeOutput (Proxy :: Proxy bitlen)@@ -72,35 +75,37 @@ deriving (Show, Data) instance KnownNat bitlen => HashAlgorithm (SHAKE256 bitlen) where- type HashBlockSize (SHAKE256 bitlen) = 136- type HashDigestSize (SHAKE256 bitlen) = Div8 (bitlen + 7)+ type HashBlockSize (SHAKE256 bitlen) = 136+ type HashDigestSize (SHAKE256 bitlen) = Div8 (bitlen + 7) type HashInternalContextSize (SHAKE256 bitlen) = 344- hashBlockSize _ = 136- hashDigestSize _ = byteLen (Proxy :: Proxy bitlen)+ hashBlockSize _ = 136+ hashDigestSize _ = byteLen (Proxy :: Proxy bitlen) hashInternalContextSize _ = 344- hashInternalInit p = c_sha3_init p 256- hashInternalUpdate = c_sha3_update- hashInternalFinalize = shakeFinalizeOutput (Proxy :: Proxy bitlen)+ hashInternalInit p = c_sha3_init p 256+ hashInternalUpdate = c_sha3_update+ hashInternalFinalize = shakeFinalizeOutput (Proxy :: Proxy bitlen) instance KnownNat bitlen => HashSHAKE (SHAKE256 bitlen) where cshakeInternalFinalize = cshakeFinalizeOutput (Proxy :: Proxy bitlen) cshakeOutputLength _ = integralNatVal (Proxy :: Proxy bitlen) -shakeFinalizeOutput :: KnownNat bitlen- => proxy bitlen- -> Ptr (Context a)- -> Ptr (Digest a)- -> IO ()+shakeFinalizeOutput+ :: KnownNat bitlen+ => proxy bitlen+ -> Ptr (Context a)+ -> Ptr (Digest a)+ -> IO () shakeFinalizeOutput d ctx dig = do c_sha3_finalize_shake ctx c_sha3_output ctx dig (byteLen d) shakeTruncate d (castPtr dig) -cshakeFinalizeOutput :: KnownNat bitlen- => proxy bitlen- -> Ptr (Context a)- -> Ptr (Digest a)- -> IO ()+cshakeFinalizeOutput+ :: KnownNat bitlen+ => proxy bitlen+ -> Ptr (Context a)+ -> Ptr (Digest a)+ -> IO () cshakeFinalizeOutput d ctx dig = do c_sha3_finalize_cshake ctx c_sha3_output ctx dig (byteLen d)
Crypto/Hash/Skein256.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.Skein256 -- License : BSD-style@@ -7,51 +12,45 @@ -- -- Module containing the binding functions to work with the -- Skein256 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.Skein256- ( Skein256_224 (..), Skein256_256 (..)- ) where--import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+module Crypto.Hash.Skein256 (+ Skein256_224 (..),+ Skein256_256 (..),+) where +import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | Skein256 (224 bits) cryptographic hash algorithm data Skein256_224 = Skein256_224- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Skein256_224 where- type HashBlockSize Skein256_224 = 32- type HashDigestSize Skein256_224 = 28+ type HashBlockSize Skein256_224 = 32+ type HashDigestSize Skein256_224 = 28 type HashInternalContextSize Skein256_224 = 96- hashBlockSize _ = 32- hashDigestSize _ = 28+ hashBlockSize _ = 32+ hashDigestSize _ = 28 hashInternalContextSize _ = 96- hashInternalInit p = c_skein256_init p 224- hashInternalUpdate = c_skein256_update- hashInternalFinalize p = c_skein256_finalize p 224+ hashInternalInit p = c_skein256_init p 224+ hashInternalUpdate = c_skein256_update+ hashInternalFinalize p = c_skein256_finalize p 224 -- | Skein256 (256 bits) cryptographic hash algorithm data Skein256_256 = Skein256_256- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Skein256_256 where- type HashBlockSize Skein256_256 = 32- type HashDigestSize Skein256_256 = 32+ type HashBlockSize Skein256_256 = 32+ type HashDigestSize Skein256_256 = 32 type HashInternalContextSize Skein256_256 = 96- hashBlockSize _ = 32- hashDigestSize _ = 32+ hashBlockSize _ = 32+ hashDigestSize _ = 32 hashInternalContextSize _ = 96- hashInternalInit p = c_skein256_init p 256- hashInternalUpdate = c_skein256_update- hashInternalFinalize p = c_skein256_finalize p 256-+ hashInternalInit p = c_skein256_init p 256+ hashInternalUpdate = c_skein256_update+ hashInternalFinalize p = c_skein256_finalize p 256 foreign import ccall unsafe "crypton_skein256_init" c_skein256_init :: Ptr (Context a) -> Word32 -> IO ()
Crypto/Hash/Skein512.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.Skein512 -- License : BSD-style@@ -7,81 +12,77 @@ -- -- Module containing the binding functions to work with the -- Skein512 cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.Skein512- ( Skein512_224 (..), Skein512_256 (..), Skein512_384 (..), Skein512_512 (..)- ) where--import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+module Crypto.Hash.Skein512 (+ Skein512_224 (..),+ Skein512_256 (..),+ Skein512_384 (..),+ Skein512_512 (..),+) where +import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | Skein512 (224 bits) cryptographic hash algorithm data Skein512_224 = Skein512_224- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Skein512_224 where- type HashBlockSize Skein512_224 = 64- type HashDigestSize Skein512_224 = 28+ type HashBlockSize Skein512_224 = 64+ type HashDigestSize Skein512_224 = 28 type HashInternalContextSize Skein512_224 = 160- hashBlockSize _ = 64- hashDigestSize _ = 28+ hashBlockSize _ = 64+ hashDigestSize _ = 28 hashInternalContextSize _ = 160- hashInternalInit p = c_skein512_init p 224- hashInternalUpdate = c_skein512_update- hashInternalFinalize p = c_skein512_finalize p 224+ hashInternalInit p = c_skein512_init p 224+ hashInternalUpdate = c_skein512_update+ hashInternalFinalize p = c_skein512_finalize p 224 -- | Skein512 (256 bits) cryptographic hash algorithm data Skein512_256 = Skein512_256- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Skein512_256 where- type HashBlockSize Skein512_256 = 64- type HashDigestSize Skein512_256 = 32+ type HashBlockSize Skein512_256 = 64+ type HashDigestSize Skein512_256 = 32 type HashInternalContextSize Skein512_256 = 160- hashBlockSize _ = 64- hashDigestSize _ = 32+ hashBlockSize _ = 64+ hashDigestSize _ = 32 hashInternalContextSize _ = 160- hashInternalInit p = c_skein512_init p 256- hashInternalUpdate = c_skein512_update- hashInternalFinalize p = c_skein512_finalize p 256+ hashInternalInit p = c_skein512_init p 256+ hashInternalUpdate = c_skein512_update+ hashInternalFinalize p = c_skein512_finalize p 256 -- | Skein512 (384 bits) cryptographic hash algorithm data Skein512_384 = Skein512_384- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Skein512_384 where- type HashBlockSize Skein512_384 = 64- type HashDigestSize Skein512_384 = 48+ type HashBlockSize Skein512_384 = 64+ type HashDigestSize Skein512_384 = 48 type HashInternalContextSize Skein512_384 = 160- hashBlockSize _ = 64- hashDigestSize _ = 48+ hashBlockSize _ = 64+ hashDigestSize _ = 48 hashInternalContextSize _ = 160- hashInternalInit p = c_skein512_init p 384- hashInternalUpdate = c_skein512_update- hashInternalFinalize p = c_skein512_finalize p 384+ hashInternalInit p = c_skein512_init p 384+ hashInternalUpdate = c_skein512_update+ hashInternalFinalize p = c_skein512_finalize p 384 -- | Skein512 (512 bits) cryptographic hash algorithm data Skein512_512 = Skein512_512- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Skein512_512 where- type HashBlockSize Skein512_512 = 64- type HashDigestSize Skein512_512 = 64+ type HashBlockSize Skein512_512 = 64+ type HashDigestSize Skein512_512 = 64 type HashInternalContextSize Skein512_512 = 160- hashBlockSize _ = 64- hashDigestSize _ = 64+ hashBlockSize _ = 64+ hashDigestSize _ = 64 hashInternalContextSize _ = 160- hashInternalInit p = c_skein512_init p 512- hashInternalUpdate = c_skein512_update- hashInternalFinalize p = c_skein512_finalize p 512-+ hashInternalInit p = c_skein512_init p 512+ hashInternalUpdate = c_skein512_update+ hashInternalFinalize p = c_skein512_finalize p 512 foreign import ccall unsafe "crypton_skein512_init" c_skein512_init :: Ptr (Context a) -> Word32 -> IO ()
Crypto/Hash/Tiger.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.Tiger -- License : BSD-style@@ -7,35 +12,30 @@ -- -- Module containing the binding functions to work with the -- Tiger cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.Tiger ( Tiger (..) ) where+module Crypto.Hash.Tiger (Tiger (..)) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | Tiger cryptographic hash algorithm data Tiger = Tiger- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Tiger where- type HashBlockSize Tiger = 64- type HashDigestSize Tiger = 24+ type HashBlockSize Tiger = 64+ type HashDigestSize Tiger = 24 type HashInternalContextSize Tiger = 96- hashBlockSize _ = 64- hashDigestSize _ = 24+ hashBlockSize _ = 64+ hashDigestSize _ = 24 hashInternalContextSize _ = 96- hashInternalInit = c_tiger_init- hashInternalUpdate = c_tiger_update- hashInternalFinalize = c_tiger_finalize+ hashInternalInit = c_tiger_init+ hashInternalUpdate = c_tiger_update+ hashInternalFinalize = c_tiger_finalize foreign import ccall unsafe "crypton_tiger_init"- c_tiger_init :: Ptr (Context a)-> IO ()+ c_tiger_init :: Ptr (Context a) -> IO () foreign import ccall "crypton_tiger_update" c_tiger_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
Crypto/Hash/Types.hs view
@@ -1,3 +1,10 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE RoleAnnotations #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.Types -- License : BSD-style@@ -6,32 +13,25 @@ -- Portability : unknown -- -- Crypto hash types definitions----{-# LANGUAGE DataKinds #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE RoleAnnotations #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.Types- ( HashAlgorithm(..)- , HashAlgorithmPrefix(..)- , Context(..)- , Digest(..)- ) where+module Crypto.Hash.Types (+ HashAlgorithm (..),+ HashAlgorithmPrefix (..),+ Context (..),+ Digest (..),+) where -import Crypto.Internal.Imports-import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes)+import Basement.Block (Block, unsafeFreeze)+import Basement.Block.Mutable (MutableBlock, new, unsafeWrite)+import Basement.NormalForm (deepseq)+import Basement.Types.OffsetSize (CountOf (..), Offset (..))+import Control.Monad.ST+import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes) import qualified Crypto.Internal.ByteArray as B-import Control.Monad.ST-import Data.Char (digitToInt, isHexDigit)-import Foreign.Ptr (Ptr)-import Basement.Block (Block, unsafeFreeze)-import Basement.Block.Mutable (MutableBlock, new, unsafeWrite)-import Basement.NormalForm (deepseq)-import Basement.Types.OffsetSize (CountOf(..), Offset(..))-import GHC.TypeLits (Nat)-import Data.Data (Data)+import Crypto.Internal.Imports+import Data.Char (digitToInt, isHexDigit)+import Data.Data (Data)+import Foreign.Ptr (Ptr)+import GHC.TypeLits (Nat) -- | Class representing hashing algorithms. --@@ -41,23 +41,30 @@ class HashAlgorithm a where -- | Associated type for the block size of the hash algorithm type HashBlockSize a :: Nat+ -- | Associated type for the digest size of the hash algorithm type HashDigestSize a :: Nat+ -- | Associated type for the internal context size of the hash algorithm type HashInternalContextSize a :: Nat -- | Get the block size of a hash algorithm- hashBlockSize :: a -> Int+ hashBlockSize :: a -> Int+ -- | Get the digest size of a hash algorithm- hashDigestSize :: a -> Int+ hashDigestSize :: a -> Int+ -- | Get the size of the context used for a hash algorithm hashInternalContextSize :: a -> Int- --hashAlgorithmFromProxy :: Proxy a -> a + -- hashAlgorithmFromProxy :: Proxy a -> a+ -- | Initialize a context pointer to the initial state of a hash algorithm- hashInternalInit :: Ptr (Context a) -> IO ()+ hashInternalInit :: Ptr (Context a) -> IO ()+ -- | Update the context with some raw data- hashInternalUpdate :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ hashInternalUpdate :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ -- | Finalize the context and set the digest raw memory to the right value hashInternalFinalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () @@ -66,11 +73,13 @@ -- | Update the context with the first N bytes of a buffer and finalize this -- context. The code path executed is independent from N and depends only -- on the complete buffer length.- hashInternalFinalizePrefix :: Ptr (Context a)- -> Ptr Word8 -> Word32- -> Word32- -> Ptr (Digest a)- -> IO ()+ hashInternalFinalizePrefix+ :: Ptr (Context a)+ -> Ptr Word8+ -> Word32+ -> Word32+ -> Ptr (Digest a)+ -> IO () {- hashContextGetAlgorithm :: HashAlgorithm a => Context a -> a@@ -84,7 +93,7 @@ -- and change in future versions. The bytearray should not be used as input to -- cryptographic algorithms. newtype Context a = Context Bytes- deriving (ByteArrayAccess,NFData)+ deriving (ByteArrayAccess, NFData) -- | Represent a digest for a given hash algorithm. --@@ -96,7 +105,7 @@ -- Creating a digest from a bytearray is also possible with function -- 'Crypto.Hash.digestFromByteString'. newtype Digest a = Digest (Block Word8)- deriving (Eq,Ord,ByteArrayAccess, Data)+ deriving (Eq, Ord, ByteArrayAccess, Data) type role Digest nominal @@ -104,23 +113,25 @@ rnf (Digest u) = u `deepseq` () instance Show (Digest a) where- show (Digest bs) = map (toEnum . fromIntegral)- $ B.unpack (B.convertToBase B.Base16 bs :: Bytes)+ show (Digest bs) =+ map (toEnum . fromIntegral) $+ B.unpack (B.convertToBase B.Base16 bs :: Bytes) instance HashAlgorithm a => Read (Digest a) where- readsPrec _ str = runST $ do mut <- new (CountOf len)- loop mut len str+ readsPrec _ str = runST $ do+ mut <- new (CountOf len)+ loop mut len str where len = hashDigestSize (undefined :: a) loop :: MutableBlock Word8 s -> Int -> String -> ST s [(Digest a, String)]- loop mut 0 cs = (\b -> [(Digest b, cs)]) <$> unsafeFreeze mut- loop _ _ [] = return []- loop _ _ [_] = return []- loop mut n (c:(d:ds))+ loop mut 0 cs = (\b -> [(Digest b, cs)]) <$> unsafeFreeze mut+ loop _ _ [] = return []+ loop _ _ [_] = return []+ loop mut n (c : (d : ds)) | not (isHexDigit c) = return [] | not (isHexDigit d) = return []- | otherwise = do+ | otherwise = do let w8 = fromIntegral $ digitToInt c * 16 + digitToInt d unsafeWrite mut (Offset $ len - n) w8 loop mut (n - 1) ds
Crypto/Hash/Whirlpool.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE TypeFamilies #-}+ -- | -- Module : Crypto.Hash.Whirlpool -- License : BSD-style@@ -7,35 +12,30 @@ -- -- Module containing the binding functions to work with the -- Whirlpool cryptographic hash.----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-module Crypto.Hash.Whirlpool ( Whirlpool (..) ) where+module Crypto.Hash.Whirlpool (Whirlpool (..)) where -import Crypto.Hash.Types-import Foreign.Ptr (Ptr)-import Data.Data-import Data.Word (Word8, Word32)+import Crypto.Hash.Types+import Data.Data+import Data.Word (Word32, Word8)+import Foreign.Ptr (Ptr) -- | Whirlpool cryptographic hash algorithm data Whirlpool = Whirlpool- deriving (Show,Data)+ deriving (Show, Data) instance HashAlgorithm Whirlpool where- type HashBlockSize Whirlpool = 64- type HashDigestSize Whirlpool = 64+ type HashBlockSize Whirlpool = 64+ type HashDigestSize Whirlpool = 64 type HashInternalContextSize Whirlpool = 168- hashBlockSize _ = 64- hashDigestSize _ = 64+ hashBlockSize _ = 64+ hashDigestSize _ = 64 hashInternalContextSize _ = 168- hashInternalInit = c_whirlpool_init- hashInternalUpdate = c_whirlpool_update- hashInternalFinalize = c_whirlpool_finalize+ hashInternalInit = c_whirlpool_init+ hashInternalUpdate = c_whirlpool_update+ hashInternalFinalize = c_whirlpool_finalize foreign import ccall unsafe "crypton_whirlpool_init"- c_whirlpool_init :: Ptr (Context a)-> IO ()+ c_whirlpool_init :: Ptr (Context a) -> IO () foreign import ccall "crypton_whirlpool_update" c_whirlpool_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
Crypto/Internal/Builder.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE BangPatterns #-}+ -- | -- Module : Crypto.Internal.Builder -- License : BSD-style@@ -8,31 +10,30 @@ -- Delaying and merging ByteArray allocations. This is similar to module -- "Data.ByteArray.Pack" except the total length is computed automatically based -- on what is appended.----{-# LANGUAGE BangPatterns #-}-module Crypto.Internal.Builder- ( Builder- , buildAndFreeze- , builderLength- , byte- , bytes- , zero- ) where+module Crypto.Internal.Builder (+ Builder,+ buildAndFreeze,+ builderLength,+ byte,+ bytes,+ zero,+) where -import Data.ByteArray (ByteArray, ByteArrayAccess)+import Data.ByteArray (ByteArray, ByteArrayAccess) import qualified Data.ByteArray as B-import Data.Memory.PtrMethods (memSet)+import Data.Memory.PtrMethods (memSet) -import Foreign.Ptr (Ptr, plusPtr)-import Foreign.Storable (poke)+import Foreign.Ptr (Ptr, plusPtr)+import Foreign.Storable (poke) -import Crypto.Internal.Imports hiding (empty)+import Crypto.Internal.Imports hiding (empty) -data Builder = Builder !Int (Ptr Word8 -> IO ()) -- size and initializer+data Builder = Builder !Int (Ptr Word8 -> IO ()) -- size and initializer instance Semigroup Builder where (Builder s1 f1) <> (Builder s2 f2) = Builder (s1 + s2) f- where f p = f1 p >> f2 (p `plusPtr` s1)+ where+ f p = f1 p >> f2 (p `plusPtr` s1) builderLength :: Builder -> Int builderLength (Builder s _) = s
Crypto/Internal/ByteArray.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE BangPatterns #-}+{-# OPTIONS_HADDOCK hide #-}+ -- | -- Module : Crypto.Internal.ByteArray -- License : BSD-style@@ -6,19 +9,16 @@ -- Portability : Good -- -- Simple and efficient byte array types----{-# LANGUAGE BangPatterns #-}-{-# OPTIONS_HADDOCK hide #-}-module Crypto.Internal.ByteArray- ( module Data.ByteArray- , module Data.ByteArray.Mapping- , module Data.ByteArray.Encoding- , constAllZero- ) where+module Crypto.Internal.ByteArray (+ module Data.ByteArray,+ module Data.ByteArray.Mapping,+ module Data.ByteArray.Encoding,+ constAllZero,+) where import Data.ByteArray-import Data.ByteArray.Mapping import Data.ByteArray.Encoding+import Data.ByteArray.Mapping import Data.Bits ((.|.)) import Data.Word (Word8)@@ -32,8 +32,8 @@ where loop :: Ptr b -> Int -> Word8 -> IO Bool loop p i !acc- | i == len = return $! acc == 0+ | i == len = return $! acc == 0 | otherwise = do e <- peekByteOff p i- loop p (i+1) (acc .|. e)+ loop p (i + 1) (acc .|. e) len = Data.ByteArray.length b
Crypto/Internal/Compat.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ -- | -- Module : Crypto.Internal.Compat -- License : BSD-style@@ -7,17 +9,15 @@ -- -- This module tries to keep all the difference between versions of base -- or other needed packages, so that modules don't need to use CPP.----{-# LANGUAGE CPP #-}-module Crypto.Internal.Compat- ( unsafeDoIO- , popCount- , byteSwap64- ) where+module Crypto.Internal.Compat (+ unsafeDoIO,+ popCount,+ byteSwap64,+) where -import System.IO.Unsafe-import Data.Word import Data.Bits+import Data.Word+import System.IO.Unsafe -- | Perform io for hashes that do allocation and FFI. -- 'unsafeDupablePerformIO' is used when possible as the
Crypto/Internal/CompatPrim.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE UnboxedTuples #-}+ -- | -- Module : Crypto.Internal.CompatPrim -- License : BSD-style@@ -10,18 +15,13 @@ -- -- Note that MagicHash and CPP conflicts in places, making it "more interesting" -- to write compat code for primitives.----{-# LANGUAGE CPP #-}-{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE UnboxedTuples #-}-module Crypto.Internal.CompatPrim- ( be32Prim- , le32Prim- , byteswap32Prim- , booleanPrim- , convert4To32- ) where+module Crypto.Internal.CompatPrim (+ be32Prim,+ le32Prim,+ byteswap32Prim,+ booleanPrim,+ convert4To32,+) where #if !defined(ARCH_IS_LITTLE_ENDIAN) && !defined(ARCH_IS_BIG_ENDIAN) import Data.Memory.Endian (getSystemEndianness, Endianness(..))@@ -68,8 +68,12 @@ #endif -- | Combine 4 word8 [a,b,c,d] to a word32 representing [a,b,c,d]-convert4To32 :: Word# -> Word# -> Word# -> Word#- -> Word#+convert4To32+ :: Word#+ -> Word#+ -> Word#+ -> Word#+ -> Word# convert4To32 a b c d = or# (or# c1 c2) (or# c3 c4) where #ifdef ARCH_IS_LITTLE_ENDIAN
Crypto/Internal/DeepSeq.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ -- | -- Module : Crypto.Internal.DeepSeq -- License : BSD-style@@ -8,11 +10,9 @@ -- Simple abstraction module to allow compilation without deepseq -- by defining our own NFData class if not compiling with deepseq -- support.----{-# LANGUAGE CPP #-}-module Crypto.Internal.DeepSeq- ( NFData(..)- ) where+module Crypto.Internal.DeepSeq (+ NFData (..),+) where #ifdef WITH_DEEPSEQ_SUPPORT import Control.DeepSeq
Crypto/Internal/Imports.hs view
@@ -1,20 +1,20 @@+{-# LANGUAGE CPP #-}+ -- | -- Module : Crypto.Internal.Imports -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : unknown----{-# LANGUAGE CPP #-}-module Crypto.Internal.Imports- ( module X- ) where+module Crypto.Internal.Imports (+ module X,+) where -import Data.Word as X+import Data.Word as X #if !(MIN_VERSION_base(4,11,0)) import Data.Semigroup as X (Semigroup(..)) #endif-import Control.Applicative as X-import Control.Monad as X (forM, forM_, void)-import Control.Arrow as X (first, second)+import Control.Applicative as X+import Control.Arrow as X (first, second)+import Control.Monad as X (forM, forM_, void) import Crypto.Internal.DeepSeq as X
Crypto/Internal/WordArray.hs view
@@ -1,3 +1,7 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE UnboxedTuples #-}+ -- | -- Module : Crypto.Internal.WordArray -- License : BSD-style@@ -9,35 +13,31 @@ -- with limited safety for internal use. -- -- The array produced should never be exposed to the user directly.----{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE UnboxedTuples #-}-module Crypto.Internal.WordArray- ( Array8- , Array32- , Array64- , MutableArray32- , array8- , array32- , array32FromAddrBE- , allocArray32AndFreeze- , mutableArray32- , array64- , arrayRead8- , arrayRead32- , arrayRead64- , mutableArrayRead32- , mutableArrayWrite32- , mutableArrayWriteXor32- , mutableArray32FromAddrBE- , mutableArray32Freeze- ) where+module Crypto.Internal.WordArray (+ Array8,+ Array32,+ Array64,+ MutableArray32,+ array8,+ array32,+ array32FromAddrBE,+ allocArray32AndFreeze,+ mutableArray32,+ array64,+ arrayRead8,+ arrayRead32,+ arrayRead64,+ mutableArrayRead32,+ mutableArrayWrite32,+ mutableArrayWriteXor32,+ mutableArray32FromAddrBE,+ mutableArray32Freeze,+) where -import Data.Word-import Data.Bits (xor) import Crypto.Internal.Compat import Crypto.Internal.CompatPrim+import Data.Bits (xor)+import Data.Word import GHC.Prim import GHC.Types import GHC.Word@@ -81,15 +81,15 @@ case newAlignedPinnedByteArray# (n *# 8#) 8# s of (# s', mbarr #) -> loop 0# s' mbarr l where- loop _ st mb [] = freezeArray mb st- loop i st mb ((W64# x):xs)- | booleanPrim (i ==# n) = freezeArray mb st- | otherwise =- let !st' = writeWord64Array# mb i x st- in loop (i +# 1#) st' mb xs- freezeArray mb st =- case unsafeFreezeByteArray# mb st of- (# st', b #) -> (# st', Array64 b #)+ loop _ st mb [] = freezeArray mb st+ loop i st mb ((W64# x) : xs)+ | booleanPrim (i ==# n) = freezeArray mb st+ | otherwise =+ let !st' = writeWord64Array# mb i x st+ in loop (i +# 1#) st' mb xs+ freezeArray mb st =+ case unsafeFreezeByteArray# mb st of+ (# st', b #) -> (# st', Array64 b #) {-# NOINLINE array64 #-} -- | Create a Mutable Array of Word32 of specific size from a list of Word32@@ -98,12 +98,12 @@ case newAlignedPinnedByteArray# (n *# 4#) 4# s of (# s', mbarr #) -> loop 0# s' mbarr l where- loop _ st mb [] = (# st, MutableArray32 mb #)- loop i st mb ((W32# x):xs)- | booleanPrim (i ==# n) = (# st, MutableArray32 mb #)- | otherwise =- let !st' = writeWord32Array# mb i x st- in loop (i +# 1#) st' mb xs+ loop _ st mb [] = (# st, MutableArray32 mb #)+ loop i st mb ((W32# x) : xs)+ | booleanPrim (i ==# n) = (# st, MutableArray32 mb #)+ | otherwise =+ let !st' = writeWord32Array# mb i x st+ in loop (i +# 1#) st' mb xs -- | Create a Mutable Array of BE Word32 aliasing an Addr mutableArray32FromAddrBE :: Int -> Addr# -> IO MutableArray32@@ -111,11 +111,11 @@ case newAlignedPinnedByteArray# (n *# 4#) 4# s of (# s', mbarr #) -> loop 0# s' mbarr where- loop i st mb- | booleanPrim (i ==# n) = (# st, MutableArray32 mb #)- | otherwise =- let !st' = writeWord32Array# mb i (be32Prim (indexWord32OffAddr# a i)) st- in loop (i +# 1#) st' mb+ loop i st mb+ | booleanPrim (i ==# n) = (# st, MutableArray32 mb #)+ | otherwise =+ let !st' = writeWord32Array# mb i (be32Prim (indexWord32OffAddr# a i)) st+ in loop (i +# 1#) st' mb -- | freeze a Mutable Array of Word32 into a immutable Array of Word32 mutableArray32Freeze :: MutableArray32 -> IO Array32
Crypto/Internal/Words.hs view
@@ -6,16 +6,15 @@ -- Portability : unknown -- -- Extra Word size----module Crypto.Internal.Words- ( Word128(..)- , w64to32- , w32to64- ) where+module Crypto.Internal.Words (+ Word128 (..),+ w64to32,+ w32to64,+) where -import Data.Word import Data.Bits import Data.Memory.ExtendedWords+import Data.Word -- | Split a 'Word64' into the highest and lowest 'Word32' w64to32 :: Word64 -> (Word32, Word32)
Crypto/KDF/Argon2.hs view
@@ -11,47 +11,49 @@ -- -- File started from Argon2.hs, from Oliver Charles -- at https://github.com/ocharles/argon2----module Crypto.KDF.Argon2- (- Options(..)- , TimeCost- , MemoryCost- , Parallelism- , Variant(..)- , Version(..)- , defaultOptions+module Crypto.KDF.Argon2 (+ Options (..),+ TimeCost,+ MemoryCost,+ Parallelism,+ Variant (..),+ Version (..),+ defaultOptions,+ -- * Hashing function- , hash- ) where+ hash,+) where -import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess)+import Control.Monad (when)+import Crypto.Error+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B-import Crypto.Error-import Control.Monad (when)-import Data.Word-import Foreign.C-import Foreign.Ptr+import Data.Word+import Foreign.C+import Foreign.Ptr -- | Which variant of Argon2 to use. You should choose the variant that is most -- applicable to your intention to hash inputs.-data Variant =- Argon2d -- ^ Argon2d is faster than Argon2i and uses data-depending memory access,- -- which makes it suitable for cryptocurrencies and applications with no- -- threats from side-channel timing attacks.- | Argon2i -- ^ Argon2i uses data-independent memory access, which is preferred- -- for password hashing and password-based key derivation. Argon2i- -- is slower as it makes more passes over the memory to protect from- -- tradeoff attacks.- | Argon2id -- ^ Argon2id is a hybrid of Argon2i and Argon2d, using a combination- -- of data-depending and data-independent memory accesses, which gives- -- some of Argon2i's resistance to side-channel cache timing attacks- -- and much of Argon2d's resistance to GPU cracking attacks- deriving (Eq,Ord,Read,Show,Enum,Bounded)+data Variant+ = -- | Argon2d is faster than Argon2i and uses data-depending memory access,+ -- which makes it suitable for cryptocurrencies and applications with no+ -- threats from side-channel timing attacks.+ Argon2d+ | -- | Argon2i uses data-independent memory access, which is preferred+ -- for password hashing and password-based key derivation. Argon2i+ -- is slower as it makes more passes over the memory to protect from+ -- tradeoff attacks.+ Argon2i+ | -- | Argon2id is a hybrid of Argon2i and Argon2d, using a combination+ -- of data-depending and data-independent memory accesses, which gives+ -- some of Argon2i's resistance to side-channel cache timing attacks+ -- and much of Argon2d's resistance to GPU cracking attacks+ Argon2id+ deriving (Eq, Ord, Read, Show, Enum, Bounded) -- | Which version of Argon2 to use data Version = Version10 | Version13- deriving (Eq,Ord,Read,Show,Enum,Bounded)+ deriving (Eq, Ord, Read, Show, Enum, Bounded) -- | The time cost, which defines the amount of computation realized and therefore the execution time, given in number of iterations. --@@ -71,13 +73,15 @@ -- | Parameters that can be adjusted to change the runtime performance of the -- hashing. data Options = Options- { iterations :: !TimeCost- , memory :: !MemoryCost+ { iterations :: !TimeCost+ , memory :: !MemoryCost , parallelism :: !Parallelism- , variant :: !Variant -- ^ Which variant of Argon2 to use.- , version :: !Version -- ^ Which version of Argon2 to use.+ , variant :: !Variant+ -- ^ Which variant of Argon2 to use.+ , version :: !Version+ -- ^ Which version of Argon2 to use. }- deriving (Eq,Ord,Read,Show)+ deriving (Eq, Ord, Read, Show) saltMinLength :: Int saltMinLength = 8@@ -92,37 +96,40 @@ defaultOptions :: Options defaultOptions =- Options { iterations = 1- , memory = 2 ^ (17 :: Int)- , parallelism = 4- , variant = Argon2i- , version = Version13- }+ Options+ { iterations = 1+ , memory = 2 ^ (17 :: Int)+ , parallelism = 4+ , variant = Argon2i+ , version = Version13+ } -hash :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray out)- => Options- -> password- -> salt- -> Int- -> CryptoFailable out+hash+ :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray out)+ => Options+ -> password+ -> salt+ -> Int+ -> CryptoFailable out hash options password salt outLen- | saltLen < saltMinLength = CryptoFailed CryptoError_SaltTooSmall+ | saltLen < saltMinLength = CryptoFailed CryptoError_SaltTooSmall | outLen < outputMinLength = CryptoFailed CryptoError_OutputLengthTooSmall | outLen > outputMaxLength = CryptoFailed CryptoError_OutputLengthTooBig- | otherwise = CryptoPassed $ B.allocAndFreeze outLen $ \out -> do+ | otherwise = CryptoPassed $ B.allocAndFreeze outLen $ \out -> do res <- B.withByteArray password $ \pPass ->- B.withByteArray salt $ \pSalt ->- argon2_hash (iterations options)- (memory options)- (parallelism options)- pPass- (csizeOfInt passwordLen)- pSalt- (csizeOfInt saltLen)- out- (csizeOfInt outLen)- (cOfVariant $ variant options)- (cOfVersion $ version options)+ B.withByteArray salt $ \pSalt ->+ argon2_hash+ (iterations options)+ (memory options)+ (parallelism options)+ pPass+ (csizeOfInt passwordLen)+ pSalt+ (csizeOfInt saltLen)+ out+ (csizeOfInt outLen)+ (cOfVariant $ variant options)+ (cOfVersion $ version options) when (res /= 0) $ error "argon2: hash: internal error" where saltLen = B.length salt@@ -140,18 +147,24 @@ cOfVersion Version13 = 0x13 cOfVariant :: Variant -> CVariant-cOfVariant Argon2d = 0-cOfVariant Argon2i = 1+cOfVariant Argon2d = 0+cOfVariant Argon2i = 1 cOfVariant Argon2id = 2 csizeOfInt :: Int -> CSize csizeOfInt = fromIntegral foreign import ccall unsafe "crypton_argon2_hash"- argon2_hash :: Word32 -> Word32 -> Word32- -> Ptr Pass -> CSize- -> Ptr Salt -> CSize- -> Ptr HashOut -> CSize- -> CVariant- -> CVersion- -> IO CInt+ argon2_hash+ :: Word32+ -> Word32+ -> Word32+ -> Ptr Pass+ -> CSize+ -> Ptr Salt+ -> CSize+ -> Ptr HashOut+ -> CSize+ -> CVariant+ -> CVersion+ -> IO CInt
Crypto/KDF/BCrypt.hs view
@@ -1,4 +1,3 @@- -- | Password encoding and validation using bcrypt. -- -- Example usage:@@ -43,27 +42,33 @@ -- depending on your hardware. Choose the highest value you can without having -- an unacceptable impact on your users. The cost parameter can also be varied -- depending on the account, since it is unique to an individual hash.--module Crypto.KDF.BCrypt- ( hashPassword- , validatePassword- , validatePasswordEither- , bcrypt- )+module Crypto.KDF.BCrypt (+ hashPassword,+ validatePassword,+ validatePasswordEither,+ bcrypt,+) where -import Control.Monad (forM_, unless, when)-import Crypto.Cipher.Blowfish.Primitive (Context, createKeySchedule,- encrypt, expandKey,- expandKeyWithSalt,- freezeKeySchedule)-import Crypto.Internal.Compat-import Crypto.Random (MonadRandom, getRandomBytes)-import Data.ByteArray (ByteArray, ByteArrayAccess,- Bytes)-import qualified Data.ByteArray as B-import Data.ByteArray.Encoding-import Data.Char+import Control.Monad (forM_, unless, when)+import Crypto.Cipher.Blowfish.Primitive (+ Context,+ createKeySchedule,+ encrypt,+ expandKey,+ expandKeyWithSalt,+ freezeKeySchedule,+ )+import Crypto.Internal.Compat+import Crypto.Random (MonadRandom, getRandomBytes)+import Data.ByteArray (+ ByteArray,+ ByteArrayAccess,+ Bytes,+ )+import qualified Data.ByteArray as B+import Data.ByteArray.Encoding+import Data.Char data BCryptHash = BCH Char Int Bytes Bytes @@ -73,14 +78,15 @@ -- -- Each increment of the cost approximately doubles the time taken. -- The 16 bytes of random salt will be generated internally.-hashPassword :: (MonadRandom m, ByteArray password, ByteArray hash)- => Int- -- ^ The cost parameter. Should be between 4 and 31 (inclusive).- -- Values which lie outside this range will be adjusted accordingly.- -> password- -- ^ The password. Should be the UTF-8 encoded bytes of the password text.- -> m hash- -- ^ The bcrypt hash in standard format.+hashPassword+ :: (MonadRandom m, ByteArray password, ByteArray hash)+ => Int+ -- ^ The cost parameter. Should be between 4 and 31 (inclusive).+ -- Values which lie outside this range will be adjusted accordingly.+ -> password+ -- ^ The password. Should be the UTF-8 encoded bytes of the password text.+ -> m hash+ -- ^ The bcrypt hash in standard format. hashPassword cost password = do salt <- getRandomBytes 16 return $ bcrypt cost (salt :: Bytes) password@@ -88,54 +94,63 @@ -- | Create a bcrypt hash for a password with a provided cost value and salt. -- -- Cost value under 4 will be automatically adjusted back to 10 for safety reason.-bcrypt :: (ByteArray salt, ByteArray password, ByteArray output)- => Int- -- ^ The cost parameter. Should be between 4 and 31 (inclusive).- -- Values which lie outside this range will be adjusted accordingly.- -> salt- -- ^ The salt. Must be 16 bytes in length or an error will be raised.- -> password- -- ^ The password. Should be the UTF-8 encoded bytes of the password text.- -> output- -- ^ The bcrypt hash in standard format.+bcrypt+ :: (ByteArray salt, ByteArray password, ByteArray output)+ => Int+ -- ^ The cost parameter. Should be between 4 and 31 (inclusive).+ -- Values which lie outside this range will be adjusted accordingly.+ -> salt+ -- ^ The salt. Must be 16 bytes in length or an error will be raised.+ -> password+ -- ^ The password. Should be the UTF-8 encoded bytes of the password text.+ -> output+ -- ^ The bcrypt hash in standard format. bcrypt cost salt password = B.concat [header, B.snoc costBytes dollar, b64 salt, b64 hash] where- hash = rawHash 'b' realCost salt password+ hash = rawHash 'b' realCost salt password header = B.pack [dollar, fromIntegral (ord '2'), fromIntegral (ord 'b'), dollar] dollar = fromIntegral (ord '$')- zero = fromIntegral (ord '0')- costBytes = B.pack [zero + fromIntegral (realCost `div` 10), zero + fromIntegral (realCost `mod` 10)]+ zero = fromIntegral (ord '0')+ costBytes =+ B.pack+ [ zero + fromIntegral (realCost `div` 10)+ , zero + fromIntegral (realCost `mod` 10)+ ] realCost- | cost < 4 = 10 -- 4 is virtually pointless so go for 10+ | cost < 4 = 10 -- 4 is virtually pointless so go for 10 | cost > 31 = 31 | otherwise = cost - b64 :: (ByteArray ba) => ba -> ba+ b64 :: ByteArray ba => ba -> ba b64 = convertToBase Base64OpenBSD -- | Check a password against a stored bcrypt hash when authenticating a user. -- -- Returns @False@ if the password doesn't match the hash, or if the hash is -- invalid or an unsupported version.-validatePassword :: (ByteArray password, ByteArray hash) => password -> hash -> Bool+validatePassword+ :: (ByteArray password, ByteArray hash) => password -> hash -> Bool validatePassword password bcHash = either (const False) id (validatePasswordEither password bcHash) -- | Check a password against a bcrypt hash -- -- As for @validatePassword@ but will provide error information if the hash is invalid or -- an unsupported version.-validatePasswordEither :: (ByteArray password, ByteArray hash) => password -> hash -> Either String Bool+validatePasswordEither+ :: (ByteArray password, ByteArray hash) => password -> hash -> Either String Bool validatePasswordEither password bcHash = do BCH version cost salt hash <- parseBCryptHash bcHash return $ (rawHash version cost salt password :: Bytes) `B.constEq` hash -rawHash :: (ByteArrayAccess salt, ByteArray password, ByteArray output) => Char -> Int -> salt -> password -> output+rawHash+ :: (ByteArrayAccess salt, ByteArray password, ByteArray output)+ => Char -> Int -> salt -> password -> output rawHash _ cost salt password = B.take 23 hash -- Another compatibility bug. Ignore last byte of hash where hash = loop (0 :: Int) orpheanBeholder loop i input- | i < 64 = loop (i+1) (encrypt ctx input)+ | i < 64 = loop (i + 1) (encrypt ctx input) | otherwise = input -- Truncate the password if necessary and append a null byte for C compatibility@@ -144,27 +159,58 @@ ctx = expensiveBlowfishContext key salt cost -- The BCrypt plaintext: "OrpheanBeholderScryDoubt"- orpheanBeholder = B.pack [79,114,112,104,101,97,110,66,101,104,111,108,100,101,114,83,99,114,121,68,111,117,98,116]+ orpheanBeholder =+ B.pack+ [ 79+ , 114+ , 112+ , 104+ , 101+ , 97+ , 110+ , 66+ , 101+ , 104+ , 111+ , 108+ , 100+ , 101+ , 114+ , 83+ , 99+ , 114+ , 121+ , 68+ , 111+ , 117+ , 98+ , 116+ ] -- "$2a$10$XajjQvNhvvRt5GSeFk1xFeyqRrsxkhBkUiQeg0dt.wU1qD4aFDcga"-parseBCryptHash :: (ByteArray ba) => ba -> Either String BCryptHash+parseBCryptHash :: ByteArray ba => ba -> Either String BCryptHash parseBCryptHash bc = do- unless (B.length bc == 60 &&- B.index bc 0 == dollar &&- B.index bc 1 == fromIntegral (ord '2') &&- B.index bc 3 == dollar &&- B.index bc 6 == dollar) (Left "Invalid hash format")- unless (version == 'b' || version == 'a' || version == 'y') (Left ("Unsupported minor version: " ++ [version]))- when (costTens > 3 || cost > 31 || cost < 4) (Left "Invalid bcrypt cost")+ unless+ ( B.length bc == 60+ && B.index bc 0 == dollar+ && B.index bc 1 == fromIntegral (ord '2')+ && B.index bc 3 == dollar+ && B.index bc 6 == dollar+ )+ (Left "Invalid hash format")+ unless+ (version == 'b' || version == 'a' || version == 'y')+ (Left ("Unsupported minor version: " ++ [version]))+ when (costTens > 3 || cost > 31 || cost < 4) (Left "Invalid bcrypt cost") (salt, hash) <- decodeSaltHash (B.drop 7 bc) return (BCH version cost salt hash) where- dollar = fromIntegral (ord '$')- zero = ord '0'- costTens = fromIntegral (B.index bc 4) - zero+ dollar = fromIntegral (ord '$')+ zero = ord '0'+ costTens = fromIntegral (B.index bc 4) - zero costUnits = fromIntegral (B.index bc 5) - zero- version = chr (fromIntegral (B.index bc 2))- cost = costUnits + 10*costTens :: Int+ version = chr (fromIntegral (B.index bc 2))+ cost = costUnits + 10 * costTens :: Int decodeSaltHash saltHash = do let (s, h) = B.splitAt 22 saltHash@@ -177,13 +223,14 @@ -- Salt must be a 128-bit byte array. -- Cost must be between 4 and 31 inclusive -- See <https://www.usenix.org/conference/1999-usenix-annual-technical-conference/future-adaptable-password-scheme>-expensiveBlowfishContext :: (ByteArrayAccess key, ByteArrayAccess salt) => key-> salt -> Int -> Context+expensiveBlowfishContext+ :: (ByteArrayAccess key, ByteArrayAccess salt) => key -> salt -> Int -> Context expensiveBlowfishContext keyBytes saltBytes cost- | B.length saltBytes /= 16 = error "bcrypt salt must be 16 bytes"- | otherwise = unsafeDoIO $ do+ | B.length saltBytes /= 16 = error "bcrypt salt must be 16 bytes"+ | otherwise = unsafeDoIO $ do ks <- createKeySchedule expandKeyWithSalt ks keyBytes saltBytes- forM_ [1..2^cost :: Int] $ \_ -> do+ forM_ [1 .. 2 ^ cost :: Int] $ \_ -> do expandKey ks keyBytes expandKey ks saltBytes freezeKeySchedule ks
Crypto/KDF/BCryptPBKDF.hs view
@@ -6,137 +6,146 @@ -- -- Port of the bcrypt_pbkdf key derivation function from OpenBSD -- as described at <http://man.openbsd.org/bcrypt_pbkdf.3>.-module Crypto.KDF.BCryptPBKDF- ( Parameters (..)- , generate- , hashInternal- )+module Crypto.KDF.BCryptPBKDF (+ Parameters (..),+ generate,+ hashInternal,+) where -import Basement.Block (MutableBlock)-import qualified Basement.Block as Block-import qualified Basement.Block.Mutable as Block-import Basement.Monad (PrimState)-import Basement.Types.OffsetSize (CountOf (..), Offset (..))-import Control.Exception (finally)-import Control.Monad (when)-import qualified Crypto.Cipher.Blowfish.Box as Blowfish+import Basement.Block (MutableBlock)+import qualified Basement.Block as Block+import qualified Basement.Block.Mutable as Block+import Basement.Monad (PrimState)+import Basement.Types.OffsetSize (CountOf (..), Offset (..))+import Control.Exception (finally)+import Control.Monad (when)+import qualified Crypto.Cipher.Blowfish.Box as Blowfish import qualified Crypto.Cipher.Blowfish.Primitive as Blowfish-import Crypto.Hash.Algorithms (SHA512 (..))-import Crypto.Hash.Types (Context,- hashDigestSize,- hashInternalContextSize,- hashInternalFinalize,- hashInternalInit,- hashInternalUpdate)-import Crypto.Internal.Compat (unsafeDoIO)-import Data.Bits-import qualified Data.ByteArray as B-import Data.Foldable (forM_)-import Data.Memory.PtrMethods (memCopy, memSet, memXor)-import Data.Word-import Foreign.Ptr (Ptr, castPtr)-import Foreign.Storable (peekByteOff, pokeByteOff)+import Crypto.Hash.Algorithms (SHA512 (..))+import Crypto.Hash.Types (+ Context,+ hashDigestSize,+ hashInternalContextSize,+ hashInternalFinalize,+ hashInternalInit,+ hashInternalUpdate,+ )+import Crypto.Internal.Compat (unsafeDoIO)+import Data.Bits+import qualified Data.ByteArray as B+import Data.Foldable (forM_)+import Data.Memory.PtrMethods (memCopy, memSet, memXor)+import Data.Word+import Foreign.Ptr (Ptr, castPtr)+import Foreign.Storable (peekByteOff, pokeByteOff) data Parameters = Parameters- { iterCounts :: Int -- ^ The number of user-defined iterations for the algorithm- -- (must be > 0)- , outputLength :: Int -- ^ The number of bytes to generate out of BCryptPBKDF- -- (must be in 1..1024)- } deriving (Eq, Ord, Show)+ { iterCounts :: Int+ -- ^ The number of user-defined iterations for the algorithm+ -- (must be > 0)+ , outputLength :: Int+ -- ^ The number of bytes to generate out of BCryptPBKDF+ -- (must be in 1..1024)+ }+ deriving (Eq, Ord, Show) -- | Derive a key of specified length using the bcrypt_pbkdf algorithm.-generate :: (B.ByteArray pass, B.ByteArray salt, B.ByteArray output)- => Parameters- -> pass- -> salt- -> output+generate+ :: (B.ByteArray pass, B.ByteArray salt, B.ByteArray output)+ => Parameters+ -> pass+ -> salt+ -> output generate params pass salt- | iterCounts params < 1 = error "BCryptPBKDF: iterCounts must be > 0"- | keyLen < 1 || keyLen > 1024 = error "BCryptPBKDF: outputLength must be in 1..1024"- | otherwise = B.unsafeCreate keyLen deriveKey+ | iterCounts params < 1 = error "BCryptPBKDF: iterCounts must be > 0"+ | keyLen < 1 || keyLen > 1024 =+ error "BCryptPBKDF: outputLength must be in 1..1024"+ | otherwise = B.unsafeCreate keyLen deriveKey where outLen, tmpLen, blkLen, keyLen, passLen, saltLen, ctxLen, hashLen, blocks :: Int- outLen = 32- tmpLen = 32- blkLen = 4+ outLen = 32+ tmpLen = 32+ blkLen = 4 passLen = B.length pass saltLen = B.length salt- keyLen = outputLength params- ctxLen = hashInternalContextSize SHA512+ keyLen = outputLength params+ ctxLen = hashInternalContextSize SHA512 hashLen = hashDigestSize SHA512 -- 64- blocks = (keyLen + outLen - 1) `div` outLen+ blocks = (keyLen + outLen - 1) `div` outLen deriveKey :: Ptr Word8 -> IO () deriveKey keyPtr = do -- Allocate all necessary memory. The algorihm shall not allocate -- any more dynamic memory after this point. Blocks need to be pinned -- as pointers to them are passed to the SHA512 implementation.- ksClean <- Blowfish.createKeySchedule- ksDirty <- Blowfish.createKeySchedule- ctxMBlock <- Block.newPinned (CountOf ctxLen :: CountOf Word8)- outMBlock <- Block.newPinned (CountOf outLen :: CountOf Word8)- tmpMBlock <- Block.newPinned (CountOf tmpLen :: CountOf Word8)- blkMBlock <- Block.newPinned (CountOf blkLen :: CountOf Word8)+ ksClean <- Blowfish.createKeySchedule+ ksDirty <- Blowfish.createKeySchedule+ ctxMBlock <- Block.newPinned (CountOf ctxLen :: CountOf Word8)+ outMBlock <- Block.newPinned (CountOf outLen :: CountOf Word8)+ tmpMBlock <- Block.newPinned (CountOf tmpLen :: CountOf Word8)+ blkMBlock <- Block.newPinned (CountOf blkLen :: CountOf Word8) passHashMBlock <- Block.newPinned (CountOf hashLen :: CountOf Word8) saltHashMBlock <- Block.newPinned (CountOf hashLen :: CountOf Word8) -- Finally erase all memory areas that contain information from -- which the derived key could be reconstructed. -- As all MutableBlocks are pinned it shall be guaranteed that -- no temporary trampoline buffers are allocated.- finallyErase outMBlock $ finallyErase passHashMBlock $- B.withByteArray pass $ \passPtr->- B.withByteArray salt $ \saltPtr->- Block.withMutablePtr ctxMBlock $ \ctxPtr->- Block.withMutablePtr outMBlock $ \outPtr->- Block.withMutablePtr tmpMBlock $ \tmpPtr->- Block.withMutablePtr blkMBlock $ \blkPtr->- Block.withMutablePtr passHashMBlock $ \passHashPtr->- Block.withMutablePtr saltHashMBlock $ \saltHashPtr-> do- -- Hash the password.- let shaPtr = castPtr ctxPtr :: Ptr (Context SHA512)- hashInternalInit shaPtr- hashInternalUpdate shaPtr passPtr (fromIntegral passLen)- hashInternalFinalize shaPtr (castPtr passHashPtr)- passHashBlock <- Block.unsafeFreeze passHashMBlock- forM_ [1..blocks] $ \block-> do- -- Poke the increased block counter.- Block.unsafeWrite blkMBlock 0 (fromIntegral $ block `shiftR` 24)- Block.unsafeWrite blkMBlock 1 (fromIntegral $ block `shiftR` 16)- Block.unsafeWrite blkMBlock 2 (fromIntegral $ block `shiftR` 8)- Block.unsafeWrite blkMBlock 3 (fromIntegral $ block `shiftR` 0)- -- First round (slightly different).- hashInternalInit shaPtr- hashInternalUpdate shaPtr saltPtr (fromIntegral saltLen)- hashInternalUpdate shaPtr blkPtr (fromIntegral blkLen)- hashInternalFinalize shaPtr (castPtr saltHashPtr)- Block.unsafeFreeze saltHashMBlock >>= \x-> do- Blowfish.copyKeySchedule ksDirty ksClean- hashInternalMutable ksDirty passHashBlock x tmpMBlock- memCopy outPtr tmpPtr outLen- -- Remaining rounds.- forM_ [2..iterCounts params] $ const $ do- hashInternalInit shaPtr- hashInternalUpdate shaPtr tmpPtr (fromIntegral tmpLen)- hashInternalFinalize shaPtr (castPtr saltHashPtr)- Block.unsafeFreeze saltHashMBlock >>= \x-> do- Blowfish.copyKeySchedule ksDirty ksClean- hashInternalMutable ksDirty passHashBlock x tmpMBlock- memXor outPtr outPtr tmpPtr outLen- -- Spread the current out buffer evenly over the key buffer.- -- After both loops have run every byte of the key buffer- -- will have been written to exactly once and every byte- -- of the output will have been used.- forM_ [0..outLen - 1] $ \outIdx-> do- let keyIdx = outIdx * blocks + block - 1- when (keyIdx < keyLen) $ do- w8 <- peekByteOff outPtr outIdx :: IO Word8- pokeByteOff keyPtr keyIdx w8+ finallyErase outMBlock $+ finallyErase passHashMBlock $+ B.withByteArray pass $ \passPtr ->+ B.withByteArray salt $ \saltPtr ->+ Block.withMutablePtr ctxMBlock $ \ctxPtr ->+ Block.withMutablePtr outMBlock $ \outPtr ->+ Block.withMutablePtr tmpMBlock $ \tmpPtr ->+ Block.withMutablePtr blkMBlock $ \blkPtr ->+ Block.withMutablePtr passHashMBlock $ \passHashPtr ->+ Block.withMutablePtr saltHashMBlock $ \saltHashPtr -> do+ -- Hash the password.+ let shaPtr = castPtr ctxPtr :: Ptr (Context SHA512)+ hashInternalInit shaPtr+ hashInternalUpdate shaPtr passPtr (fromIntegral passLen)+ hashInternalFinalize shaPtr (castPtr passHashPtr)+ passHashBlock <- Block.unsafeFreeze passHashMBlock+ forM_ [1 .. blocks] $ \block -> do+ -- Poke the increased block counter.+ Block.unsafeWrite blkMBlock 0 (fromIntegral $ block `shiftR` 24)+ Block.unsafeWrite blkMBlock 1 (fromIntegral $ block `shiftR` 16)+ Block.unsafeWrite blkMBlock 2 (fromIntegral $ block `shiftR` 8)+ Block.unsafeWrite blkMBlock 3 (fromIntegral $ block `shiftR` 0)+ -- First round (slightly different).+ hashInternalInit shaPtr+ hashInternalUpdate shaPtr saltPtr (fromIntegral saltLen)+ hashInternalUpdate shaPtr blkPtr (fromIntegral blkLen)+ hashInternalFinalize shaPtr (castPtr saltHashPtr)+ Block.unsafeFreeze saltHashMBlock >>= \x -> do+ Blowfish.copyKeySchedule ksDirty ksClean+ hashInternalMutable ksDirty passHashBlock x tmpMBlock+ memCopy outPtr tmpPtr outLen+ -- Remaining rounds.+ forM_ [2 .. iterCounts params] $ const $ do+ hashInternalInit shaPtr+ hashInternalUpdate shaPtr tmpPtr (fromIntegral tmpLen)+ hashInternalFinalize shaPtr (castPtr saltHashPtr)+ Block.unsafeFreeze saltHashMBlock >>= \x -> do+ Blowfish.copyKeySchedule ksDirty ksClean+ hashInternalMutable ksDirty passHashBlock x tmpMBlock+ memXor outPtr outPtr tmpPtr outLen+ -- Spread the current out buffer evenly over the key buffer.+ -- After both loops have run every byte of the key buffer+ -- will have been written to exactly once and every byte+ -- of the output will have been used.+ forM_ [0 .. outLen - 1] $ \outIdx -> do+ let keyIdx = outIdx * blocks + block - 1+ when (keyIdx < keyLen) $ do+ w8 <- peekByteOff outPtr outIdx :: IO Word8+ pokeByteOff keyPtr keyIdx w8 -- | Internal hash function used by `generate`. -- -- Normal users should not need this.-hashInternal :: (B.ByteArrayAccess pass, B.ByteArrayAccess salt, B.ByteArray output)+hashInternal+ :: (B.ByteArrayAccess pass, B.ByteArrayAccess salt, B.ByteArray output) => pass -> salt -> output@@ -149,7 +158,8 @@ hashInternalMutable ks0 passHash saltHash outMBlock B.convert `fmap` Block.freeze outMBlock -hashInternalMutable :: (B.ByteArrayAccess pass, B.ByteArrayAccess salt)+hashInternalMutable+ :: (B.ByteArrayAccess pass, B.ByteArrayAccess salt) => Blowfish.KeySchedule -> pass -> salt@@ -157,31 +167,31 @@ -> IO () hashInternalMutable bfks passHash saltHash outMBlock = do Blowfish.expandKeyWithSalt bfks passHash saltHash- forM_ [0..63 :: Int] $ const $ do+ forM_ [0 .. 63 :: Int] $ const $ do Blowfish.expandKey bfks saltHash Blowfish.expandKey bfks passHash -- "OxychromaticBlowfishSwatDynamite" represented as 4 Word64 in big-endian.- store 0 =<< cipher 64 0x4f78796368726f6d- store 8 =<< cipher 64 0x61746963426c6f77+ store 0 =<< cipher 64 0x4f78796368726f6d+ store 8 =<< cipher 64 0x61746963426c6f77 store 16 =<< cipher 64 0x6669736853776174 store 24 =<< cipher 64 0x44796e616d697465- where- store :: Offset Word8 -> Word64 -> IO ()- store o w64 = do- Block.unsafeWrite outMBlock (o + 0) (fromIntegral $ w64 `shiftR` 32)- Block.unsafeWrite outMBlock (o + 1) (fromIntegral $ w64 `shiftR` 40)- Block.unsafeWrite outMBlock (o + 2) (fromIntegral $ w64 `shiftR` 48)- Block.unsafeWrite outMBlock (o + 3) (fromIntegral $ w64 `shiftR` 56)- Block.unsafeWrite outMBlock (o + 4) (fromIntegral $ w64 `shiftR` 0)- Block.unsafeWrite outMBlock (o + 5) (fromIntegral $ w64 `shiftR` 8)- Block.unsafeWrite outMBlock (o + 6) (fromIntegral $ w64 `shiftR` 16)- Block.unsafeWrite outMBlock (o + 7) (fromIntegral $ w64 `shiftR` 24)- cipher :: Int -> Word64 -> IO Word64- cipher 0 block = return block- cipher i block = Blowfish.cipherBlockMutable bfks block >>= cipher (i - 1)+ where+ store :: Offset Word8 -> Word64 -> IO ()+ store o w64 = do+ Block.unsafeWrite outMBlock (o + 0) (fromIntegral $ w64 `shiftR` 32)+ Block.unsafeWrite outMBlock (o + 1) (fromIntegral $ w64 `shiftR` 40)+ Block.unsafeWrite outMBlock (o + 2) (fromIntegral $ w64 `shiftR` 48)+ Block.unsafeWrite outMBlock (o + 3) (fromIntegral $ w64 `shiftR` 56)+ Block.unsafeWrite outMBlock (o + 4) (fromIntegral $ w64 `shiftR` 0)+ Block.unsafeWrite outMBlock (o + 5) (fromIntegral $ w64 `shiftR` 8)+ Block.unsafeWrite outMBlock (o + 6) (fromIntegral $ w64 `shiftR` 16)+ Block.unsafeWrite outMBlock (o + 7) (fromIntegral $ w64 `shiftR` 24)+ cipher :: Int -> Word64 -> IO Word64+ cipher 0 block = return block+ cipher i block = Blowfish.cipherBlockMutable bfks block >>= cipher (i - 1) finallyErase :: MutableBlock Word8 (PrimState IO) -> IO () -> IO () finallyErase mblock action =- action `finally` Block.withMutablePtr mblock (\ptr-> memSet ptr 0 len)- where- CountOf len = Block.mutableLengthBytes mblock+ action `finally` Block.withMutablePtr mblock (\ptr -> memSet ptr 0 len)+ where+ CountOf len = Block.mutableLengthBytes mblock
Crypto/KDF/HKDF.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE BangPatterns #-}+ -- | -- Module : Crypto.KDF.HKDF -- License : BSD-style@@ -8,77 +10,96 @@ -- Key Derivation Function based on HMAC -- -- See RFC5869----{-# LANGUAGE BangPatterns #-}-module Crypto.KDF.HKDF- ( PRK- , extract- , extractSkip- , expand- ) where+module Crypto.KDF.HKDF (+ PRK,+ extract,+ extractSkip,+ expand,+ toPRK,+) where -import Data.Word-import Crypto.Hash-import Crypto.MAC.HMAC-import Crypto.Internal.ByteArray (ScrubbedBytes, ByteArray, ByteArrayAccess)+import Crypto.Hash+import Crypto.Internal.ByteArray (+ ByteArray,+ ByteArrayAccess,+ ScrubbedBytes,+ ) import qualified Crypto.Internal.ByteArray as B+import Crypto.MAC.HMAC+import Data.Word -- | Pseudo Random Key data PRK a = PRK (HMAC a) | PRK_NoExpand ScrubbedBytes deriving (Eq) instance ByteArrayAccess (PRK a) where- length (PRK hm) = B.length hm+ length (PRK hm) = B.length hm length (PRK_NoExpand sb) = B.length sb- withByteArray (PRK hm) = B.withByteArray hm+ withByteArray (PRK hm) = B.withByteArray hm withByteArray (PRK_NoExpand sb) = B.withByteArray sb -- | Extract a Pseudo Random Key using the parameter and the underlaying hash mechanism-extract :: (HashAlgorithm a, ByteArrayAccess salt, ByteArrayAccess ikm)- => salt -- ^ Salt- -> ikm -- ^ Input Keying Material- -> PRK a -- ^ Pseudo random key+extract+ :: (HashAlgorithm a, ByteArrayAccess salt, ByteArrayAccess ikm)+ => salt+ -- ^ Salt+ -> ikm+ -- ^ Input Keying Material+ -> PRK a+ -- ^ Pseudo random key extract salt ikm = PRK $ hmac salt ikm -- | Create a PRK directly from the input key material. -- -- Only use when guaranteed to have a good quality and random data to use directly as key. -- This effectively skip a HMAC with key=salt and data=key.-extractSkip :: ByteArrayAccess ikm- => ikm- -> PRK a+extractSkip+ :: ByteArrayAccess ikm+ => ikm+ -> PRK a extractSkip ikm = PRK_NoExpand $ B.convert ikm -- | Expand key material of specific length out of the parameters-expand :: (HashAlgorithm a, ByteArrayAccess info, ByteArray out)- => PRK a -- ^ Pseudo Random Key- -> info -- ^ Optional context and application specific information- -> Int -- ^ Output length in bytes- -> out -- ^ Output data+expand+ :: (HashAlgorithm a, ByteArrayAccess info, ByteArray out)+ => PRK a+ -- ^ Pseudo Random Key+ -> info+ -- ^ Optional context and application specific information+ -> Int+ -- ^ Output length in bytes+ -> out+ -- ^ Output data expand prkAt infoAt outputLength = let hF = hFGet prkAt in B.concat $ loop hF B.empty outputLength 1 where hFGet :: (HashAlgorithm a, ByteArrayAccess b) => PRK a -> (b -> HMAC a) hFGet prk = case prk of- PRK hmacKey -> hmac hmacKey- PRK_NoExpand ikm -> hmac ikm+ PRK hmacKey -> hmac hmacKey+ PRK_NoExpand ikm -> hmac ikm info :: ScrubbedBytes info = B.convert infoAt - loop :: HashAlgorithm a- => (ScrubbedBytes -> HMAC a)- -> ScrubbedBytes- -> Int- -> Word8- -> [ScrubbedBytes]+ loop+ :: HashAlgorithm a+ => (ScrubbedBytes -> HMAC a)+ -> ScrubbedBytes+ -> Int+ -> Word8+ -> [ScrubbedBytes] loop hF tim1 n i- | n <= 0 = []+ | n <= 0 = [] | otherwise =- let input = B.concat [tim1,info,B.singleton i] :: ScrubbedBytes- ti = B.convert $ hF input+ let input = B.concat [tim1, info, B.singleton i] :: ScrubbedBytes+ ti = B.convert $ hF input hashLen = B.length ti- r = n - hashLen+ r = n - hashLen in (if n >= hashLen then ti else B.take n ti)- : loop hF ti r (i+1)+ : loop hF ti r (i + 1)++toPRK :: (HashAlgorithm a, ByteArrayAccess ba) => ba -> Maybe (PRK a)+toPRK bs = case digestFromByteString bs of+ Nothing -> Nothing+ Just digest -> Just $ PRK $ HMAC digest
Crypto/KDF/PBKDF2.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE ForeignFunctionInterface #-}+ -- | -- Module : Crypto.KDF.PBKDF2 -- License : BSD-style@@ -6,67 +9,71 @@ -- Portability : unknown -- -- Password Based Key Derivation Function 2----{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE ForeignFunctionInterface #-}--module Crypto.KDF.PBKDF2- ( PRF- , prfHMAC- , Parameters(..)- , generate- , fastPBKDF2_SHA1- , fastPBKDF2_SHA256- , fastPBKDF2_SHA512- ) where+module Crypto.KDF.PBKDF2 (+ PRF,+ prfHMAC,+ Parameters (..),+ generate,+ fastPBKDF2_SHA1,+ fastPBKDF2_SHA256,+ fastPBKDF2_SHA512,+) where -import Data.Word-import Data.Bits-import Foreign.Marshal.Alloc-import Foreign.Ptr (plusPtr, Ptr)-import Foreign.C.Types (CUInt(..), CSize(..))+import Data.Bits+import Data.Word+import Foreign.C.Types (CSize (..), CUInt (..))+import Foreign.Marshal.Alloc+import Foreign.Ptr (Ptr, plusPtr) -import Crypto.Hash (HashAlgorithm)+import Crypto.Hash (HashAlgorithm) import qualified Crypto.MAC.HMAC as HMAC -import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess, Bytes)+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess, Bytes) import qualified Crypto.Internal.ByteArray as B-import Data.Memory.PtrMethods+import Data.Memory.PtrMethods -- | The PRF used for PBKDF2 type PRF password =- password -- ^ the password parameters- -> Bytes -- ^ the content- -> Bytes -- ^ prf(password,content)+ password+ -- ^ the password parameters+ -> Bytes+ -- ^ the content+ -> Bytes+ -- ^ prf(password,content) -- | PRF for PBKDF2 using HMAC with the hash algorithm as parameter-prfHMAC :: (HashAlgorithm a, ByteArrayAccess password)- => a- -> PRF password+prfHMAC+ :: (HashAlgorithm a, ByteArrayAccess password)+ => a+ -> PRF password prfHMAC alg k = hmacIncr alg (HMAC.initialize k)- where hmacIncr :: HashAlgorithm a => a -> HMAC.Context a -> (Bytes -> Bytes)- hmacIncr _ !ctx = \b -> B.convert $ HMAC.finalize $ HMAC.update ctx b+ where+ hmacIncr :: HashAlgorithm a => a -> HMAC.Context a -> (Bytes -> Bytes)+ hmacIncr _ !ctx = \b -> B.convert $ HMAC.finalize $ HMAC.update ctx b -- | Parameters for PBKDF2 data Parameters = Parameters- { iterCounts :: Int -- ^ the number of user-defined iterations for the algorithms. e.g. WPA2 uses 4000.- , outputLength :: Int -- ^ the number of bytes to generate out of PBKDF2+ { iterCounts :: Int+ -- ^ the number of user-defined iterations for the algorithms. e.g. WPA2 uses 4000.+ , outputLength :: Int+ -- ^ the number of bytes to generate out of PBKDF2 } -- | generate the pbkdf2 key derivation function from the output-generate :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray ba)- => PRF password- -> Parameters- -> password- -> salt- -> ba+generate+ :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray ba)+ => PRF password+ -> Parameters+ -> password+ -> salt+ -> ba generate prf params password salt = B.allocAndFreeze (outputLength params) $ \p -> do memSet p 0 (outputLength params) loop 1 (outputLength params) p where !runPRF = prf password- !hLen = B.length $ runPRF B.empty+ !hLen = B.length $ runPRF B.empty -- run the following f function on each complete chunk. -- when having an incomplete chunk, we call partial.@@ -76,100 +83,124 @@ -- U1 = PRF(pass,salt || BE32(i)) -- Uc = PRF(pass,Uc-1) loop iterNb len p- | len == 0 = return ()+ | len == 0 = return () | len < hLen = partial iterNb len p- | otherwise = do- let applyMany 0 _ = return ()+ | otherwise = do+ let applyMany 0 _ = return () applyMany i uprev = do let uData = runPRF uprev B.withByteArray uData $ \u -> memXor p p u hLen- applyMany (i-1) uData+ applyMany (i - 1) uData applyMany (iterCounts params) (B.convert salt `B.append` toBS iterNb)- loop (iterNb+1) (len - hLen) (p `plusPtr` hLen)+ loop (iterNb + 1) (len - hLen) (p `plusPtr` hLen) partial iterNb len p = allocaBytesAligned hLen 8 $ \tmp -> do let applyMany :: Int -> Bytes -> IO ()- applyMany 0 _ = return ()+ applyMany 0 _ = return () applyMany i uprev = do let uData = runPRF uprev B.withByteArray uData $ \u -> memXor tmp tmp u hLen- applyMany (i-1) uData+ applyMany (i - 1) uData memSet tmp 0 hLen applyMany (iterCounts params) (B.convert salt `B.append` toBS iterNb) memCopy p tmp len -- big endian encoding of Word32 toBS :: ByteArray ba => Word32 -> ba- toBS w = B.pack [a,b,c,d]- where a = fromIntegral (w `shiftR` 24)- b = fromIntegral ((w `shiftR` 16) .&. 0xff)- c = fromIntegral ((w `shiftR` 8) .&. 0xff)- d = fromIntegral (w .&. 0xff)+ toBS w = B.pack [a, b, c, d]+ where+ a = fromIntegral (w `shiftR` 24)+ b = fromIntegral ((w `shiftR` 16) .&. 0xff)+ c = fromIntegral ((w `shiftR` 8) .&. 0xff)+ d = fromIntegral (w .&. 0xff) {-# NOINLINE generate #-} -fastPBKDF2_SHA1 :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray out)- => Parameters- -> password- -> salt- -> out+fastPBKDF2_SHA1+ :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray out)+ => Parameters+ -> password+ -> salt+ -> out fastPBKDF2_SHA1 params password salt = B.allocAndFreeze (outputLength params) $ \outPtr ->- B.withByteArray password $ \passPtr ->- B.withByteArray salt $ \saltPtr ->- c_crypton_fastpbkdf2_hmac_sha1- passPtr (fromIntegral $ B.length password)- saltPtr (fromIntegral $ B.length salt)- (fromIntegral $ iterCounts params)- outPtr (fromIntegral $ outputLength params)+ B.withByteArray password $ \passPtr ->+ B.withByteArray salt $ \saltPtr ->+ c_crypton_fastpbkdf2_hmac_sha1+ passPtr+ (fromIntegral $ B.length password)+ saltPtr+ (fromIntegral $ B.length salt)+ (fromIntegral $ iterCounts params)+ outPtr+ (fromIntegral $ outputLength params) -fastPBKDF2_SHA256 :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray out)- => Parameters- -> password- -> salt- -> out+fastPBKDF2_SHA256+ :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray out)+ => Parameters+ -> password+ -> salt+ -> out fastPBKDF2_SHA256 params password salt = B.allocAndFreeze (outputLength params) $ \outPtr ->- B.withByteArray password $ \passPtr ->- B.withByteArray salt $ \saltPtr ->- c_crypton_fastpbkdf2_hmac_sha256- passPtr (fromIntegral $ B.length password)- saltPtr (fromIntegral $ B.length salt)- (fromIntegral $ iterCounts params)- outPtr (fromIntegral $ outputLength params)+ B.withByteArray password $ \passPtr ->+ B.withByteArray salt $ \saltPtr ->+ c_crypton_fastpbkdf2_hmac_sha256+ passPtr+ (fromIntegral $ B.length password)+ saltPtr+ (fromIntegral $ B.length salt)+ (fromIntegral $ iterCounts params)+ outPtr+ (fromIntegral $ outputLength params) -fastPBKDF2_SHA512 :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray out)- => Parameters- -> password- -> salt- -> out+fastPBKDF2_SHA512+ :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray out)+ => Parameters+ -> password+ -> salt+ -> out fastPBKDF2_SHA512 params password salt = B.allocAndFreeze (outputLength params) $ \outPtr ->- B.withByteArray password $ \passPtr ->- B.withByteArray salt $ \saltPtr ->- c_crypton_fastpbkdf2_hmac_sha512- passPtr (fromIntegral $ B.length password)- saltPtr (fromIntegral $ B.length salt)- (fromIntegral $ iterCounts params)- outPtr (fromIntegral $ outputLength params)-+ B.withByteArray password $ \passPtr ->+ B.withByteArray salt $ \saltPtr ->+ c_crypton_fastpbkdf2_hmac_sha512+ passPtr+ (fromIntegral $ B.length password)+ saltPtr+ (fromIntegral $ B.length salt)+ (fromIntegral $ iterCounts params)+ outPtr+ (fromIntegral $ outputLength params) foreign import ccall unsafe "crypton_pbkdf2.h crypton_fastpbkdf2_hmac_sha1"- c_crypton_fastpbkdf2_hmac_sha1 :: Ptr Word8 -> CSize- -> Ptr Word8 -> CSize- -> CUInt- -> Ptr Word8 -> CSize- -> IO ()+ c_crypton_fastpbkdf2_hmac_sha1+ :: Ptr Word8+ -> CSize+ -> Ptr Word8+ -> CSize+ -> CUInt+ -> Ptr Word8+ -> CSize+ -> IO () foreign import ccall unsafe "crypton_pbkdf2.h crypton_fastpbkdf2_hmac_sha256"- c_crypton_fastpbkdf2_hmac_sha256 :: Ptr Word8 -> CSize- -> Ptr Word8 -> CSize- -> CUInt- -> Ptr Word8 -> CSize- -> IO ()+ c_crypton_fastpbkdf2_hmac_sha256+ :: Ptr Word8+ -> CSize+ -> Ptr Word8+ -> CSize+ -> CUInt+ -> Ptr Word8+ -> CSize+ -> IO () foreign import ccall unsafe "crypton_pbkdf2.h crypton_fastpbkdf2_hmac_sha512"- c_crypton_fastpbkdf2_hmac_sha512 :: Ptr Word8 -> CSize- -> Ptr Word8 -> CSize- -> CUInt- -> Ptr Word8 -> CSize- -> IO ()+ c_crypton_fastpbkdf2_hmac_sha512+ :: Ptr Word8+ -> CSize+ -> Ptr Word8+ -> CSize+ -> CUInt+ -> Ptr Word8+ -> CSize+ -> IO ()
Crypto/KDF/Scrypt.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE ForeignFunctionInterface #-}+ -- | -- Module : Crypto.KDF.Scrypt -- License : BSD-style@@ -8,42 +11,45 @@ -- Scrypt key derivation function as defined in Colin Percival's paper -- "Stronger Key Derivation via Sequential Memory-Hard Functions" -- <http://www.tarsnap.com/scrypt/scrypt.pdf>.----{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE ForeignFunctionInterface #-}-module Crypto.KDF.Scrypt- ( Parameters(..)- , generate- ) where+module Crypto.KDF.Scrypt (+ Parameters (..),+ generate,+) where -import Data.Word-import Foreign.Marshal.Alloc-import Foreign.Ptr (Ptr, plusPtr)-import Control.Monad (forM_)+import Control.Monad (forM_)+import Data.Word+import Foreign.Marshal.Alloc+import Foreign.Ptr (Ptr, plusPtr) -import Crypto.Hash (SHA256(..))-import qualified Crypto.KDF.PBKDF2 as PBKDF2-import Crypto.Internal.Compat (popCount, unsafeDoIO)-import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess)+import Crypto.Hash (SHA256 (..))+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B+import Crypto.Internal.Compat (popCount, unsafeDoIO)+import qualified Crypto.KDF.PBKDF2 as PBKDF2 -- | Parameters for Scrypt data Parameters = Parameters- { n :: Word64 -- ^ Cpu/Memory cost ratio. must be a power of 2 greater than 1. also known as N.- , r :: Int -- ^ Must satisfy r * p < 2^30- , p :: Int -- ^ Must satisfy r * p < 2^30- , outputLength :: Int -- ^ the number of bytes to generate out of Scrypt+ { n :: Word64+ -- ^ Cpu/Memory cost ratio. must be a power of 2 greater than 1. also known as N.+ , r :: Int+ -- ^ Must satisfy r * p < 2^30+ , p :: Int+ -- ^ Must satisfy r * p < 2^30+ , outputLength :: Int+ -- ^ the number of bytes to generate out of Scrypt } foreign import ccall "crypton_scrypt_smix"- ccrypton_scrypt_smix :: Ptr Word8 -> Word32 -> Word64 -> Ptr Word8 -> Ptr Word8 -> IO ()+ ccrypton_scrypt_smix+ :: Ptr Word8 -> Word32 -> Word64 -> Ptr Word8 -> Ptr Word8 -> IO () -- | Generate the scrypt key derivation data-generate :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray output)- => Parameters- -> password- -> salt- -> output+generate+ :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray output)+ => Parameters+ -> password+ -> salt+ -> output generate params password salt | r params * p params >= 0x40000000 = error "Scrypt: invalid parameters: r and p constraint"@@ -52,13 +58,23 @@ | otherwise = unsafeDoIO $ do let b = PBKDF2.generate prf (PBKDF2.Parameters 1 intLen) password salt :: B.Bytes newSalt <- B.copy b $ \bPtr ->- allocaBytesAligned (128*(fromIntegral $ n params)*(r params)) 8 $ \v ->- allocaBytesAligned (256*r params + 64) 8 $ \xy -> do- forM_ [0..(p params-1)] $ \i ->- ccrypton_scrypt_smix (bPtr `plusPtr` (i * 128 * (r params)))- (fromIntegral $ r params) (n params) v xy+ allocaBytesAligned (128 * (fromIntegral $ n params) * (r params)) 8 $ \v ->+ allocaBytesAligned (256 * r params + 64) 8 $ \xy -> do+ forM_ [0 .. (p params - 1)] $ \i ->+ ccrypton_scrypt_smix+ (bPtr `plusPtr` (i * 128 * (r params)))+ (fromIntegral $ r params)+ (n params)+ v+ xy - return $ PBKDF2.generate prf (PBKDF2.Parameters 1 (outputLength params)) password (newSalt :: B.Bytes)- where prf = PBKDF2.prfHMAC SHA256- intLen = p params * 128 * r params+ return $+ PBKDF2.generate+ prf+ (PBKDF2.Parameters 1 (outputLength params))+ password+ (newSalt :: B.Bytes)+ where+ prf = PBKDF2.prfHMAC SHA256+ intLen = p params * 128 * r params {-# NOINLINE generate #-}
Crypto/MAC/CMAC.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.MAC.CMAC -- License : BSD-style@@ -8,20 +10,18 @@ -- Provide the CMAC (Cipher based Message Authentification Code) base algorithm. -- <http://en.wikipedia.org/wiki/CMAC> -- <http://csrc.nist.gov/publications/nistpubs/800-38B/SP_800-38B.pdf>----{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.MAC.CMAC- ( cmac- , CMAC- , subKeys- ) where+module Crypto.MAC.CMAC (+ cmac,+ CMAC,+ subKeys,+) where -import Data.Word-import Data.Bits (setBit, testBit, shiftL)-import Data.List (foldl')+import Data.Bits (setBit, shiftL, testBit)+import Data.List (foldl')+import Data.Word -import Crypto.Cipher.Types-import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, Bytes)+import Crypto.Cipher.Types+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess, Bytes) import qualified Crypto.Internal.ByteArray as B -- | Authentication code@@ -29,13 +29,17 @@ deriving (ByteArrayAccess) instance Eq (CMAC a) where- CMAC b1 == CMAC b2 = B.constEq b1 b2+ CMAC b1 == CMAC b2 = B.constEq b1 b2 -- | compute a MAC using the supplied cipher-cmac :: (ByteArrayAccess bin, BlockCipher cipher)- => cipher -- ^ key to compute CMAC with- -> bin -- ^ input message- -> CMAC cipher -- ^ output tag+cmac+ :: (ByteArrayAccess bin, BlockCipher cipher)+ => cipher+ -- ^ key to compute CMAC with+ -> bin+ -- ^ input message+ -> CMAC cipher+ -- ^ output tag cmac k msg = CMAC $ foldl' (\c m -> ecbEncrypt k $ bxor c m) zeroV ms where@@ -45,54 +49,62 @@ ms = cmacChunks k k1 k2 $ B.convert msg cmacChunks :: (BlockCipher k, ByteArray ba) => k -> ba -> ba -> ba -> [ba]-cmacChunks k k1 k2 = rec' where+cmacChunks k k1 k2 = rec'+ where rec' msg- | B.null tl = if lack == 0- then [bxor k1 hd]- else [bxor k2 $ hd `B.append` B.pack (0x80 : replicate (lack - 1) 0)]- | otherwise = hd : rec' tl+ | B.null tl =+ if lack == 0+ then [bxor k1 hd]+ else [bxor k2 $ hd `B.append` B.pack (0x80 : replicate (lack - 1) 0)]+ | otherwise = hd : rec' tl where- bytes = blockSize k- (hd, tl) = B.splitAt bytes msg- lack = bytes - B.length hd+ bytes = blockSize k+ (hd, tl) = B.splitAt bytes msg+ lack = bytes - B.length hd -- | make sub-keys used in CMAC-subKeys :: (BlockCipher k, ByteArray ba)- => k -- ^ key to compute CMAC with- -> (ba, ba) -- ^ sub-keys to compute CMAC-subKeys k = (k1, k2) where+subKeys+ :: (BlockCipher k, ByteArray ba)+ => k+ -- ^ key to compute CMAC with+ -> (ba, ba)+ -- ^ sub-keys to compute CMAC+subKeys k = (k1, k2)+ where ipt = cipherIPT k k0 = ecbEncrypt k $ B.replicate (blockSize k) 0 k1 = subKey ipt k0 k2 = subKey ipt k1 -- polynomial multiply operation to culculate subkey-subKey :: (ByteArray ba) => [Word8] -> ba -> ba-subKey ipt ws = case B.unpack ws of- [] -> B.empty- w:_ | testBit w 7 -> B.pack ipt `bxor` shiftL1 ws- | otherwise -> shiftL1 ws+subKey :: ByteArray ba => [Word8] -> ba -> ba+subKey ipt ws = case B.unpack ws of+ [] -> B.empty+ w : _+ | testBit w 7 -> B.pack ipt `bxor` shiftL1 ws+ | otherwise -> shiftL1 ws -shiftL1 :: (ByteArray ba) => ba -> ba+shiftL1 :: ByteArray ba => ba -> ba shiftL1 = B.pack . shiftL1W . B.unpack shiftL1W :: [Word8] -> [Word8]-shiftL1W [] = []-shiftL1W ws@(_:ns) = rec' $ zip ws (ns ++ [0]) where- rec' [] = []- rec' ((x,y):ps) = w : rec' ps+shiftL1W [] = []+shiftL1W ws@(_ : ns) = rec' $ zip ws (ns ++ [0])+ where+ rec' [] = []+ rec' ((x, y) : ps) = w : rec' ps where- w | testBit y 7 = setBit sl1 0- | otherwise = sl1- where sl1 = shiftL x 1+ w+ | testBit y 7 = setBit sl1 0+ | otherwise = sl1+ where+ sl1 = shiftL x 1 bxor :: ByteArray ba => ba -> ba -> ba bxor = B.xor - ----- - cipherIPT :: BlockCipher k => k -> [Word8] cipherIPT = expandIPT . blockSize @@ -104,29 +116,44 @@ -- It represents that the smallest irreducible binary polynomial of degree 128 -- is x^128 + x^7 + x^2 + x^1 + 1. data IPolynomial- = Q Int Int Int+ = Q Int Int Int+ --- | T Int iPolynomial :: Int -> Maybe IPolynomial-iPolynomial = d where- d 64 = Just $ Q 4 3 1- d 128 = Just $ Q 7 2 1- d _ = Nothing+iPolynomial = d+ where+ d 64 = Just $ Q 4 3 1+ d 128 = Just $ Q 7 2 1+ d _ = Nothing -- Expand a tail bit pattern of irreducible binary polynomial expandIPT :: Int -> [Word8]-expandIPT bytes = expandIPT' bytes ipt where- ipt = maybe (error $ "Irreducible binary polynomial not defined against " ++ show nb ++ " bit") id- $ iPolynomial nb+expandIPT bytes = expandIPT' bytes ipt+ where+ ipt =+ maybe+ ( error $+ "Irreducible binary polynomial not defined against " ++ show nb ++ " bit"+ )+ id+ $ iPolynomial nb nb = bytes * 8 -- Expand a tail bit pattern of irreducible binary polynomial-expandIPT' :: Int -- ^ width in byte- -> IPolynomial -- ^ irreducible binary polynomial definition- -> [Word8] -- ^ result bit pattern+expandIPT'+ :: Int+ -- ^ width in byte+ -> IPolynomial+ -- ^ irreducible binary polynomial definition+ -> [Word8]+ -- ^ result bit pattern expandIPT' bytes (Q x y z) = reverse . setB x . setB y . setB z . setB 0 $ replicate bytes 0 where- setB i ws = hd ++ setBit (head tl) r : tail tl where+ setB i ws = case tl of+ (a : as) -> hd ++ setBit a r : as+ _ -> error "expandIPT'"+ where (q, r) = i `quotRem` 8 (hd, tl) = splitAt q ws
Crypto/MAC/HMAC.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.MAC.HMAC -- License : BSD-style@@ -7,52 +10,56 @@ -- -- Provide the HMAC (Hash based Message Authentification Code) base algorithm. -- <http://en.wikipedia.org/wiki/HMAC>----{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.MAC.HMAC- ( hmac- , hmacLazy- , HMAC(..)+module Crypto.MAC.HMAC (+ hmac,+ hmacLazy,+ HMAC (..),+ -- * Incremental- , Context(..)- , initialize- , update- , updates- , finalize- ) where+ Context (..),+ initialize,+ update,+ updates,+ finalize,+) where -import Crypto.Hash hiding (Context)+import Crypto.Hash hiding (Context) import qualified Crypto.Hash as Hash (Context)-import Crypto.Hash.IO-import Crypto.Internal.ByteArray (ScrubbedBytes, ByteArrayAccess)+import Crypto.Hash.IO+import Crypto.Internal.ByteArray (ByteArrayAccess, ScrubbedBytes) import qualified Crypto.Internal.ByteArray as B-import Data.Memory.PtrMethods-import Crypto.Internal.Compat+import Crypto.Internal.Compat import qualified Data.ByteString.Lazy as L+import Data.Memory.PtrMethods -- | Represent an HMAC that is a phantom type with the hash used to produce the mac. -- -- The Eq instance is constant time. No Show instance is provided, to avoid -- printing by mistake.-newtype HMAC a = HMAC { hmacGetDigest :: Digest a }+newtype HMAC a = HMAC {hmacGetDigest :: Digest a} deriving (ByteArrayAccess) instance Eq (HMAC a) where (HMAC b1) == (HMAC b2) = B.constEq b1 b2 -- | Compute a MAC using the supplied hashing function-hmac :: (ByteArrayAccess key, ByteArrayAccess message, HashAlgorithm a)- => key -- ^ Secret key- -> message -- ^ Message to MAC- -> HMAC a+hmac+ :: (ByteArrayAccess key, ByteArrayAccess message, HashAlgorithm a)+ => key+ -- ^ Secret key+ -> message+ -- ^ Message to MAC+ -> HMAC a hmac secret msg = finalize $ updates (initialize secret) [msg] -- | Compute a MAC using the supplied hashing function, for a lazy input-hmacLazy :: (ByteArrayAccess key, HashAlgorithm a)- => key -- ^ Secret key- -> L.ByteString -- ^ Message to MAC- -> HMAC a+hmacLazy+ :: (ByteArrayAccess key, HashAlgorithm a)+ => key+ -- ^ Secret key+ -> L.ByteString+ -- ^ Message to MAC+ -> HMAC a hmacLazy secret msg = finalize $ updates (initialize secret) (L.toChunks msg) -- | Represent an ongoing HMAC state, that can be appended with 'update'@@ -60,64 +67,79 @@ data Context hashalg = Context !(Hash.Context hashalg) !(Hash.Context hashalg) -- | Initialize a new incremental HMAC context-initialize :: (ByteArrayAccess key, HashAlgorithm a)- => key -- ^ Secret key- -> Context a+initialize+ :: (ByteArrayAccess key, HashAlgorithm a)+ => key+ -- ^ Secret key+ -> Context a initialize secret = unsafeDoIO (doHashAlg undefined) where- doHashAlg :: HashAlgorithm a => a -> IO (Context a)- doHashAlg alg = do- !withKey <- case B.length secret `compare` blockSize of- EQ -> return $ B.withByteArray secret- LT -> do key <- B.alloc blockSize $ \k -> do- memSet k 0 blockSize- B.withByteArray secret $ \s -> memCopy k s (B.length secret)- return $ B.withByteArray (key :: ScrubbedBytes)- GT -> do- -- hash the secret key- ctx <- hashMutableInitWith alg- hashMutableUpdate ctx secret- digest <- hashMutableFinalize ctx- hashMutableReset ctx- -- pad it if necessary- if digestSize < blockSize- then do- key <- B.alloc blockSize $ \k -> do- memSet k 0 blockSize- B.withByteArray digest $ \s -> memCopy k s (B.length digest)- return $ B.withByteArray (key :: ScrubbedBytes)- else- return $ B.withByteArray digest- (inner, outer) <- withKey $ \keyPtr ->- (,) <$> B.alloc blockSize (\p -> memXorWith p 0x36 keyPtr blockSize)- <*> B.alloc blockSize (\p -> memXorWith p 0x5c keyPtr blockSize)- return $ Context (hashUpdates initCtx [outer :: ScrubbedBytes])- (hashUpdates initCtx [inner :: ScrubbedBytes])- where - blockSize = hashBlockSize alg- digestSize = hashDigestSize alg- initCtx = hashInitWith alg+ doHashAlg :: HashAlgorithm a => a -> IO (Context a)+ doHashAlg alg = do+ !withKey <- case B.length secret `compare` blockSize of+ EQ -> return $ B.withByteArray secret+ LT -> do+ key <- B.alloc blockSize $ \k -> do+ memSet k 0 blockSize+ B.withByteArray secret $ \s -> memCopy k s (B.length secret)+ return $ B.withByteArray (key :: ScrubbedBytes)+ GT -> do+ -- hash the secret key+ ctx <- hashMutableInitWith alg+ hashMutableUpdate ctx secret+ digest <- hashMutableFinalize ctx+ hashMutableReset ctx+ -- pad it if necessary+ if digestSize < blockSize+ then do+ key <- B.alloc blockSize $ \k -> do+ memSet k 0 blockSize+ B.withByteArray digest $ \s -> memCopy k s (B.length digest)+ return $ B.withByteArray (key :: ScrubbedBytes)+ else+ return $ B.withByteArray digest+ (inner, outer) <- withKey $ \keyPtr ->+ (,)+ <$> B.alloc blockSize (\p -> memXorWith p 0x36 keyPtr blockSize)+ <*> B.alloc blockSize (\p -> memXorWith p 0x5c keyPtr blockSize)+ return $+ Context+ (hashUpdates initCtx [outer :: ScrubbedBytes])+ (hashUpdates initCtx [inner :: ScrubbedBytes])+ where+ blockSize = hashBlockSize alg+ digestSize = hashDigestSize alg+ initCtx = hashInitWith alg {-# NOINLINE initialize #-} -- | Incrementally update a HMAC context-update :: (ByteArrayAccess message, HashAlgorithm a)- => Context a -- ^ Current HMAC context- -> message -- ^ Message to append to the MAC- -> Context a -- ^ Updated HMAC context+update+ :: (ByteArrayAccess message, HashAlgorithm a)+ => Context a+ -- ^ Current HMAC context+ -> message+ -- ^ Message to append to the MAC+ -> Context a+ -- ^ Updated HMAC context update (Context octx ictx) msg = Context octx (hashUpdate ictx msg) -- | Increamentally update a HMAC context with multiple inputs-updates :: (ByteArrayAccess message, HashAlgorithm a)- => Context a -- ^ Current HMAC context- -> [message] -- ^ Messages to append to the MAC- -> Context a -- ^ Updated HMAC context+updates+ :: (ByteArrayAccess message, HashAlgorithm a)+ => Context a+ -- ^ Current HMAC context+ -> [message]+ -- ^ Messages to append to the MAC+ -> Context a+ -- ^ Updated HMAC context updates (Context octx ictx) msgs = Context octx (hashUpdates ictx msgs) -- | Finalize a HMAC context and return the HMAC.-finalize :: HashAlgorithm a- => Context a- -> HMAC a+finalize+ :: HashAlgorithm a+ => Context a+ -> HMAC a finalize (Context octx ictx) = HMAC $ hashFinalize $ hashUpdates octx [hashFinalize ictx]
Crypto/MAC/KMAC.hs view
@@ -1,3 +1,7 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE ScopedTypeVariables #-}+ -- | -- Module : Crypto.MAC.KMAC -- License : BSD-style@@ -7,38 +11,40 @@ -- -- Provide the KMAC (Keccak Message Authentication Code) algorithm, derived from -- the SHA-3 base algorithm Keccak and defined in NIST SP800-185.----{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE ScopedTypeVariables #-}-module Crypto.MAC.KMAC- ( HashSHAKE- , kmac- , KMAC(..)+module Crypto.MAC.KMAC (+ HashSHAKE,+ kmac,+ KMAC (..),+ -- * Incremental- , Context- , initialize- , update- , updates- , finalize- ) where+ Context,+ initialize,+ update,+ updates,+ finalize,+) where import qualified Crypto.Hash as H-import Crypto.Hash.SHAKE (HashSHAKE(..))-import Crypto.Hash.Types (HashAlgorithm(..), Digest(..))+import Crypto.Hash.SHAKE (HashSHAKE (..))+import Crypto.Hash.Types (Digest (..), HashAlgorithm (..)) import qualified Crypto.Hash.Types as H-import Crypto.Internal.Builder-import Crypto.Internal.Imports-import Foreign.Ptr (Ptr)-import Data.Bits (shiftR)-import Data.ByteArray (ByteArrayAccess)+import Crypto.Internal.Builder+import Crypto.Internal.Imports+import Data.Bits (shiftR)+import Data.ByteArray (ByteArrayAccess) import qualified Data.ByteArray as B-+import Foreign.Ptr (Ptr) -- cSHAKE -cshakeInit :: forall a name string prefix . (HashSHAKE a, ByteArrayAccess name, ByteArrayAccess string, ByteArrayAccess prefix)- => name -> string -> prefix -> H.Context a+cshakeInit+ :: forall a name string prefix+ . ( HashSHAKE a+ , ByteArrayAccess name+ , ByteArrayAccess string+ , ByteArrayAccess prefix+ )+ => name -> string -> prefix -> H.Context a cshakeInit n s p = H.Context $ B.allocAndFreeze c $ \(ptr :: Ptr (H.Context a)) -> do hashInternalInit ptr B.withByteArray b $ \d -> hashInternalUpdate ptr d (fromIntegral $ B.length b)@@ -49,16 +55,20 @@ x = encodeString n <> encodeString s b = buildAndFreeze (bytepad x w) :: B.Bytes -cshakeUpdate :: (HashSHAKE a, ByteArrayAccess ba)- => H.Context a -> ba -> H.Context a+cshakeUpdate+ :: (HashSHAKE a, ByteArrayAccess ba)+ => H.Context a -> ba -> H.Context a cshakeUpdate = H.hashUpdate -cshakeUpdates :: (HashSHAKE a, ByteArrayAccess ba)- => H.Context a -> [ba] -> H.Context a+cshakeUpdates+ :: (HashSHAKE a, ByteArrayAccess ba)+ => H.Context a -> [ba] -> H.Context a cshakeUpdates = H.hashUpdates -cshakeFinalize :: forall a suffix . (HashSHAKE a, ByteArrayAccess suffix)- => H.Context a -> suffix -> Digest a+cshakeFinalize+ :: forall a suffix+ . (HashSHAKE a, ByteArrayAccess suffix)+ => H.Context a -> suffix -> Digest a cshakeFinalize !c s = Digest $ B.allocAndFreeze (hashDigestSize (undefined :: a)) $ \dig -> do ((!_) :: B.Bytes) <- B.copy c $ \(ctx :: Ptr (H.Context a)) -> do@@ -67,7 +77,6 @@ cshakeInternalFinalize ctx dig return () - -- KMAC -- | Represent a KMAC that is a phantom type with the hash used to produce the@@ -75,15 +84,16 @@ -- -- The Eq instance is constant time. No Show instance is provided, to avoid -- printing by mistake.-newtype KMAC a = KMAC { kmacGetDigest :: Digest a }- deriving (ByteArrayAccess,NFData)+newtype KMAC a = KMAC {kmacGetDigest :: Digest a}+ deriving (ByteArrayAccess, NFData) instance Eq (KMAC a) where (KMAC b1) == (KMAC b2) = B.constEq b1 b2 -- | Compute a KMAC using the supplied customization string and key.-kmac :: (HashSHAKE a, ByteArrayAccess string, ByteArrayAccess key, ByteArrayAccess ba)- => string -> key -> ba -> KMAC a+kmac+ :: (HashSHAKE a, ByteArrayAccess string, ByteArrayAccess key, ByteArrayAccess ba)+ => string -> key -> ba -> KMAC a kmac str key msg = finalize $ updates (initialize str key) [msg] -- | Represent an ongoing KMAC state, that can be appended with 'update' and@@ -92,11 +102,13 @@ -- | Initialize a new incremental KMAC context with the supplied customization -- string and key.-initialize :: forall a string key . (HashSHAKE a, ByteArrayAccess string, ByteArrayAccess key)- => string -> key -> Context a+initialize+ :: forall a string key+ . (HashSHAKE a, ByteArrayAccess string, ByteArrayAccess key)+ => string -> key -> Context a initialize str key = Context $ cshakeInit n str p where- n = B.pack [75,77,65,67] :: B.Bytes -- "KMAC"+ n = B.pack [75, 77, 65, 67] :: B.Bytes -- "KMAC" w = hashBlockSize (undefined :: a) p = buildAndFreeze (bytepad (encodeString key) w) :: B.ScrubbedBytes @@ -109,13 +121,12 @@ updates (Context ctx) = Context . cshakeUpdates ctx -- | Finalize a KMAC context and return the KMAC.-finalize :: forall a . HashSHAKE a => Context a -> KMAC a+finalize :: forall a. HashSHAKE a => Context a -> KMAC a finalize (Context ctx) = KMAC $ cshakeFinalize ctx suffix where l = cshakeOutputLength (undefined :: a) suffix = buildAndFreeze (rightEncode l) :: B.Bytes - -- Utilities bytepad :: Builder -> Int -> Builder@@ -131,14 +142,15 @@ leftEncode x = byte len <> digits where digits = i2osp x- len = fromIntegral (builderLength digits)+ len = fromIntegral (builderLength digits) rightEncode :: Int -> Builder rightEncode x = digits <> byte len where digits = i2osp x- len = fromIntegral (builderLength digits)+ len = fromIntegral (builderLength digits) i2osp :: Int -> Builder-i2osp i | i >= 256 = i2osp (shiftR i 8) <> byte (fromIntegral i)- | otherwise = byte (fromIntegral i)+i2osp i+ | i >= 256 = i2osp (shiftR i 8) <> byte (fromIntegral i)+ | otherwise = byte (fromIntegral i)
Crypto/MAC/KeyedBlake2.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE ScopedTypeVariables #-}+ -- | -- Module : Crypto.MAC.KeyedBlake2 -- License : BSD-style@@ -7,33 +10,29 @@ -- -- Expose a MAC interface to the keyed Blake2 algorithms -- defined in RFC 7693.----{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE ScopedTypeVariables #-}+module Crypto.MAC.KeyedBlake2 (+ HashBlake2,+ KeyedBlake2 (..),+ keyedBlake2,+ keyedBlake2Lazy, -module Crypto.MAC.KeyedBlake2- ( HashBlake2- , KeyedBlake2(..)- , keyedBlake2- , keyedBlake2Lazy -- * Incremental- , Context- , initialize- , update- , updates- , finalize- ) where+ Context,+ initialize,+ update,+ updates,+ finalize,+) where import qualified Crypto.Hash as H+import Crypto.Hash.Blake2 import qualified Crypto.Hash.Types as H-import Crypto.Hash.Blake2-import Crypto.Internal.DeepSeq (NFData)+import Crypto.Internal.DeepSeq (NFData)+import Data.ByteArray (ByteArrayAccess) import qualified Data.ByteArray as B-import Data.ByteArray (ByteArrayAccess) import qualified Data.ByteString.Lazy as L -import Foreign.Ptr (Ptr)-+import Foreign.Ptr (Ptr) -- Keyed Blake2b @@ -42,8 +41,8 @@ -- -- The Eq instance is constant time. No Show instance is provided, to avoid -- printing by mistake.-newtype KeyedBlake2 a = KeyedBlake2 { keyedBlake2GetDigest :: H.Digest a }- deriving (ByteArrayAccess,NFData)+newtype KeyedBlake2 a = KeyedBlake2 {keyedBlake2GetDigest :: H.Digest a}+ deriving (ByteArrayAccess, NFData) instance Eq (KeyedBlake2 a) where KeyedBlake2 x == KeyedBlake2 y = B.constEq x y@@ -53,17 +52,20 @@ newtype Context a = Context (H.Context a) -- | Initialize a new incremental keyed Blake2 context with the supplied key.-initialize :: forall a key . (HashBlake2 a, ByteArrayAccess key)- => key -> Context a+initialize+ :: forall a key+ . (HashBlake2 a, ByteArrayAccess key)+ => key -> Context a initialize k = Context $ H.Context $ B.allocAndFreeze ctxSz performInit- where ctxSz = H.hashInternalContextSize (undefined :: a)- digestSz = H.hashDigestSize (undefined :: a)- -- cap the number of key bytes at digestSz,- -- since that's the maximal key size- keyByteLen = min (B.length k) digestSz- performInit :: Ptr (H.Context a) -> IO ()- performInit ptr = B.withByteArray k- $ \keyPtr -> blake2InternalKeyedInit ptr keyPtr (fromIntegral keyByteLen)+ where+ ctxSz = H.hashInternalContextSize (undefined :: a)+ digestSz = H.hashDigestSize (undefined :: a)+ -- cap the number of key bytes at digestSz,+ -- since that's the maximal key size+ keyByteLen = min (B.length k) digestSz+ performInit :: Ptr (H.Context a) -> IO ()+ performInit ptr = B.withByteArray k $+ \keyPtr -> blake2InternalKeyedInit ptr keyPtr (fromIntegral keyByteLen) -- | Incrementally update a keyed Blake2 context. update :: (HashBlake2 a, ByteArrayAccess ba) => Context a -> ba -> Context a@@ -78,11 +80,13 @@ finalize (Context ctx) = KeyedBlake2 $ H.hashFinalize ctx -- | Compute a Blake2 MAC using the supplied key.-keyedBlake2 :: (HashBlake2 a, ByteArrayAccess key, ByteArrayAccess ba)- => key -> ba -> KeyedBlake2 a+keyedBlake2+ :: (HashBlake2 a, ByteArrayAccess key, ByteArrayAccess ba)+ => key -> ba -> KeyedBlake2 a keyedBlake2 key msg = finalize $ update (initialize key) msg -- | Compute a Blake2 MAC using the supplied key, for a lazy input.-keyedBlake2Lazy :: (HashBlake2 a, ByteArrayAccess key)- => key -> L.ByteString -> KeyedBlake2 a+keyedBlake2Lazy+ :: (HashBlake2 a, ByteArrayAccess key)+ => key -> L.ByteString -> KeyedBlake2 a keyedBlake2Lazy key msg = finalize $ updates (initialize key) (L.toChunks msg)
Crypto/MAC/Poly1305.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-} -- | -- Module : Crypto.MAC.Poly1305@@ -7,30 +9,33 @@ -- Portability : unknown -- -- Poly1305 implementation----{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.MAC.Poly1305- ( Ctx- , State- , Auth(..)- , authTag+module Crypto.MAC.Poly1305 (+ Ctx,+ State,+ Auth (..),+ authTag,+ -- * Incremental MAC Functions- , initialize -- :: State- , update -- :: State -> ByteString -> State- , updates -- :: State -> [ByteString] -> State- , finalize -- :: State -> Auth+ initialize, -- :: State+ update, -- :: State -> ByteString -> State+ updates, -- :: State -> [ByteString] -> State+ finalize, -- :: State -> Auth+ -- * One-pass MAC function- , auth- ) where+ auth,+) where -import Foreign.Ptr-import Foreign.C.Types-import Data.Word-import Crypto.Internal.ByteArray (ByteArrayAccess, ScrubbedBytes, Bytes)+import Crypto.Error+import Crypto.Internal.ByteArray (+ ByteArrayAccess,+ Bytes,+ ScrubbedBytes,+ ) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.DeepSeq-import Crypto.Error+import Crypto.Internal.DeepSeq+import Data.Word+import Foreign.C.Types+import Foreign.Ptr -- | Poly1305 State --@@ -43,16 +48,17 @@ -- | Poly1305 State. use State instead of Ctx type Ctx = State+ {-# DEPRECATED Ctx "use Poly1305 State instead" #-} -- | Poly1305 Auth newtype Auth = Auth Bytes- deriving (ByteArrayAccess,NFData)+ deriving (ByteArrayAccess, NFData) authTag :: ByteArrayAccess b => b -> CryptoFailable Auth authTag b | B.length b /= 16 = CryptoFailed $ CryptoError_AuthenticationTagSizeInvalid- | otherwise = CryptoPassed $ Auth $ B.convert b+ | otherwise = CryptoPassed $ Auth $ B.convert b instance Eq Auth where (Auth a1) == (Auth a2) = B.constEq a1 a2@@ -67,12 +73,13 @@ c_poly1305_finalize :: Ptr Word8 -> Ptr State -> IO () -- | initialize a Poly1305 context-initialize :: ByteArrayAccess key- => key- -> CryptoFailable State+initialize+ :: ByteArrayAccess key+ => key+ -> CryptoFailable State initialize key | B.length key /= 32 = CryptoFailed $ CryptoError_MacKeyInvalid- | otherwise = CryptoPassed $ State $ B.allocAndFreeze 84 $ \ctxPtr ->+ | otherwise = CryptoPassed $ State $ B.allocAndFreeze 84 $ \ctxPtr -> B.withByteArray key $ \keyPtr -> c_poly1305_init (castPtr ctxPtr) keyPtr {-# NOINLINE initialize #-}@@ -87,16 +94,19 @@ -- | updates a context with multiples bytestring updates :: ByteArrayAccess ba => State -> [ba] -> State updates (State prevCtx) d = State $ B.copyAndFreeze prevCtx (loop d)- where loop [] _ = return ()- loop (x:xs) ctxPtr = do- B.withByteArray x $ \dataPtr -> c_poly1305_update ctxPtr dataPtr (fromIntegral $ B.length x)- loop xs ctxPtr+ where+ loop [] _ = return ()+ loop (x : xs) ctxPtr = do+ B.withByteArray x $ \dataPtr -> c_poly1305_update ctxPtr dataPtr (fromIntegral $ B.length x)+ loop xs ctxPtr {-# NOINLINE updates #-} -- | finalize the context into a digest bytestring finalize :: State -> Auth finalize (State prevCtx) = Auth $ B.allocAndFreeze 16 $ \dst -> do- _ <- B.copy prevCtx (\ctxPtr -> c_poly1305_finalize dst (castPtr ctxPtr)) :: IO ScrubbedBytes+ _ <-+ B.copy prevCtx (\ctxPtr -> c_poly1305_finalize dst (castPtr ctxPtr))+ :: IO ScrubbedBytes return () {-# NOINLINE finalize #-} @@ -104,13 +114,13 @@ auth :: (ByteArrayAccess key, ByteArrayAccess ba) => key -> ba -> Auth auth key d | B.length key /= 32 = error "Poly1305: key length expected 32 bytes"- | otherwise = Auth $ B.allocAndFreeze 16 $ \dst -> do+ | otherwise = Auth $ B.allocAndFreeze 16 $ \dst -> do _ <- B.alloc 84 (onCtx dst) :: IO ScrubbedBytes return () where- onCtx dst ctxPtr =- B.withByteArray key $ \keyPtr -> do- c_poly1305_init (castPtr ctxPtr) keyPtr- B.withByteArray d $ \dataPtr ->- c_poly1305_update (castPtr ctxPtr) dataPtr (fromIntegral $ B.length d)- c_poly1305_finalize dst (castPtr ctxPtr)+ onCtx dst ctxPtr =+ B.withByteArray key $ \keyPtr -> do+ c_poly1305_init (castPtr ctxPtr) keyPtr+ B.withByteArray d $ \dataPtr ->+ c_poly1305_update (castPtr ctxPtr) dataPtr (fromIntegral $ B.length d)+ c_poly1305_finalize dst (castPtr ctxPtr)
Crypto/Number/Basic.hs view
@@ -1,20 +1,20 @@+{-# LANGUAGE BangPatterns #-}+ -- | -- Module : Crypto.Number.Basic -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good--{-# LANGUAGE BangPatterns #-}-module Crypto.Number.Basic- ( sqrti- , gcde- , areEven- , log2- , numBits- , numBytes- , asPowerOf2AndOdd- ) where+module Crypto.Number.Basic (+ sqrti,+ gcde,+ areEven,+ log2,+ numBits,+ numBytes,+ asPowerOf2AndOdd,+) where import Data.Bits @@ -25,46 +25,48 @@ -- and use a dichotomy algorithm to compute the bound relatively efficiently. sqrti :: Integer -> (Integer, Integer) sqrti i- | i < 0 = error "cannot compute negative square root"- | i == 0 = (0,0)- | i == 1 = (1,1)- | i == 2 = (1,2)+ | i < 0 = error "cannot compute negative square root"+ | i == 0 = (0, 0)+ | i == 1 = (1, 1)+ | i == 2 = (1, 2) | otherwise = loop x0- where- nbdigits = length $ show i- x0n = (if even nbdigits then nbdigits - 2 else nbdigits - 1) `div` 2- x0 = if even nbdigits then 2 * 10 ^ x0n else 6 * 10 ^ x0n- loop x = case compare (sq x) i of- LT -> iterUp x- EQ -> (x, x)- GT -> iterDown x- iterUp lb = if sq ub >= i then iter lb ub else iterUp ub- where ub = lb * 2- iterDown ub = if sq lb >= i then iterDown lb else iter lb ub- where lb = ub `div` 2- iter lb ub- | lb == ub = (lb, ub)- | lb+1 == ub = (lb, ub)- | otherwise =- let d = (ub - lb) `div` 2 in- if sq (lb + d) >= i- then iter lb (ub-d)- else iter (lb+d) ub- sq a = a * a+ where+ nbdigits = length $ show i+ x0n = (if even nbdigits then nbdigits - 2 else nbdigits - 1) `div` 2+ x0 = if even nbdigits then 2 * 10 ^ x0n else 6 * 10 ^ x0n+ loop x = case compare (sq x) i of+ LT -> iterUp x+ EQ -> (x, x)+ GT -> iterDown x+ iterUp lb = if sq ub >= i then iter lb ub else iterUp ub+ where+ ub = lb * 2+ iterDown ub = if sq lb >= i then iterDown lb else iter lb ub+ where+ lb = ub `div` 2+ iter lb ub+ | lb == ub = (lb, ub)+ | lb + 1 == ub = (lb, ub)+ | otherwise =+ let d = (ub - lb) `div` 2+ in if sq (lb + d) >= i+ then iter lb (ub - d)+ else iter (lb + d) ub+ sq a = a * a -- | Get the extended GCD of two integer using integer divMod -- -- gcde 'a' 'b' find (x,y,gcd(a,b)) where ax + by = d--- gcde :: Integer -> Integer -> (Integer, Integer, Integer)-gcde a b = onGmpUnsupported (gmpGcde a b) $- if d < 0 then (-x,-y,-d) else (x,y,d)+gcde a b =+ onGmpUnsupported (gmpGcde a b) $+ if d < 0 then (-x, -y, -d) else (x, y, d) where- (d, x, y) = f (a,1,0) (b,0,1)- f t (0, _, _) = t+ (d, x, y) = f (a, 1, 0) (b, 0, 1)+ f t (0, _, _) = t f (a', sa, ta) t@(b', sb, tb) =- let (q, r) = a' `divMod` b' in- f t (r, sa - (q * sb), ta - (q * tb))+ let (q, r) = a' `divMod` b'+ in f t (r, sa - (q * sb), ta - (q * tb)) -- | Check if a list of integer are all even areEven :: [Integer] -> Bool@@ -75,7 +77,7 @@ log2 n = onGmpUnsupported (gmpLog2 n) $ imLog 2 n where -- http://www.haskell.org/pipermail/haskell-cafe/2008-February/039465.html- imLog b x = if x < b then 0 else (x `div` b^l) `doDiv` l+ imLog b x = if x < b then 0 else (x `div` b ^ l) `doDiv` l where l = 2 * imLog (b * b) x doDiv x' l' = if x' < b then l' else (x' `div` b) `doDiv` (l' + 1)@@ -84,19 +86,36 @@ -- | Compute the number of bits for an integer numBits :: Integer -> Int numBits n = gmpSizeInBits n `onGmpUnsupported` (if n == 0 then 1 else computeBits 0 n)- where computeBits !acc i- | q == 0 =- if r >= 0x80 then acc+8- else if r >= 0x40 then acc+7- else if r >= 0x20 then acc+6- else if r >= 0x10 then acc+5- else if r >= 0x08 then acc+4- else if r >= 0x04 then acc+3- else if r >= 0x02 then acc+2- else if r >= 0x01 then acc+1- else acc -- should be catch by previous loop- | otherwise = computeBits (acc+8) q- where (q,r) = i `divMod` 256+ where+ computeBits !acc i+ | q == 0 =+ if r >= 0x80+ then acc + 8+ else+ if r >= 0x40+ then acc + 7+ else+ if r >= 0x20+ then acc + 6+ else+ if r >= 0x10+ then acc + 5+ else+ if r >= 0x08+ then acc + 4+ else+ if r >= 0x04+ then acc + 3+ else+ if r >= 0x02+ then acc + 2+ else+ if r >= 0x01+ then acc + 1+ else acc -- should be catch by previous loop+ | otherwise = computeBits (acc + 8) q+ where+ (q, r) = i `divMod` 256 -- | Compute the number of bytes for an integer numBytes :: Integer -> Int@@ -105,12 +124,14 @@ -- | Express an integer as an odd number and a power of 2 asPowerOf2AndOdd :: Integer -> (Int, Integer) asPowerOf2AndOdd a- | a == 0 = (0, 0)- | odd a = (0, a)- | a < 0 = let (e, a1) = asPowerOf2AndOdd $ abs a in (e, -a1)+ | a == 0 = (0, 0)+ | odd a = (0, a)+ | a < 0 = let (e, a1) = asPowerOf2AndOdd $ abs a in (e, -a1) | isPowerOf2 a = (log2 a, 1)- | otherwise = loop a 0- where - isPowerOf2 n = (n /= 0) && ((n .&. (n - 1)) == 0)- loop n pw = if n `mod` 2 == 0 then loop (n `div` 2) (pw + 1)- else (pw, n)+ | otherwise = loop a 0+ where+ isPowerOf2 n = (n /= 0) && ((n .&. (n - 1)) == 0)+ loop n pw =+ if n `mod` 2 == 0+ then loop (n `div` 2) (pw + 1)+ else (pw, n)
Crypto/Number/Compat.hs view
@@ -1,31 +1,32 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE UnboxedTuples #-}+{-# OPTIONS_GHC -Wno-deprecations #-}+ -- | -- Module : Crypto.Number.Compat -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----{-# LANGUAGE CPP #-}-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE UnboxedTuples #-}-module Crypto.Number.Compat- ( GmpSupported(..)- , onGmpUnsupported- , gmpGcde- , gmpLog2- , gmpPowModSecInteger- , gmpPowModInteger- , gmpInverse- , gmpNextPrime- , gmpTestPrimeMillerRabin- , gmpSizeInBytes- , gmpSizeInBits- , gmpExportInteger- , gmpExportIntegerLE- , gmpImportInteger- , gmpImportIntegerLE- ) where+module Crypto.Number.Compat (+ GmpSupported (..),+ onGmpUnsupported,+ gmpGcde,+ gmpLog2,+ gmpPowModSecInteger,+ gmpPowModInteger,+ gmpInverse,+ gmpNextPrime,+ gmpTestPrimeMillerRabin,+ gmpSizeInBytes,+ gmpSizeInBits,+ gmpExportInteger,+ gmpExportIntegerLE,+ gmpImportInteger,+ gmpImportIntegerLE,+) where #ifndef MIN_VERSION_integer_gmp #define MIN_VERSION_integer_gmp(a,b,c) 0@@ -37,17 +38,18 @@ import GHC.Integer.Logarithms (integerLog2#) #endif import Data.Word-import GHC.Ptr (Ptr(..))+import GHC.Ptr (Ptr (..)) -- | GMP Supported / Unsupported-data GmpSupported a = GmpSupported a- | GmpUnsupported- deriving (Show,Eq)+data GmpSupported a+ = GmpSupported a+ | GmpUnsupported+ deriving (Show, Eq) -- | Simple combinator in case the operation is not supported through GMP onGmpUnsupported :: GmpSupported a -> a -> a onGmpUnsupported (GmpSupported a) _ = a-onGmpUnsupported GmpUnsupported f = f+onGmpUnsupported GmpUnsupported f = f -- | Compute the GCDE of a two integer through GMP gmpGcde :: Integer -> Integer -> GmpSupported (Integer, Integer, Integer)
Crypto/Number/F2m.hs view
@@ -9,31 +9,32 @@ -- not optimal and it doesn't provide protection against timing -- attacks. The 'm' parameter is implicitly derived from the irreducible -- polynomial where applicable.--module Crypto.Number.F2m- ( BinaryPolynomial- , addF2m- , mulF2m- , squareF2m'- , squareF2m- , powF2m- , modF2m- , sqrtF2m- , invF2m- , divF2m- ) where+module Crypto.Number.F2m (+ BinaryPolynomial,+ addF2m,+ mulF2m,+ squareF2m',+ squareF2m,+ powF2m,+ modF2m,+ sqrtF2m,+ invF2m,+ divF2m,+ quadraticF2m,+) where -import Data.Bits (xor, shift, testBit, setBit)-import Data.List import Crypto.Number.Basic+import Data.Bits (setBit, shift, testBit, unsafeShiftR, xor)+import Data.List (foldl') -- | Binary Polynomial represented by an integer type BinaryPolynomial = Integer -- | Addition over F₂m. This is just a synonym of 'xor'.-addF2m :: Integer- -> Integer- -> Integer+addF2m+ :: Integer+ -> Integer+ -> Integer addF2m = xor {-# INLINE addF2m #-} @@ -41,50 +42,62 @@ -- -- This function is undefined for negative arguments, because their bit -- representation is platform-dependent. Zero modulus is also prohibited.-modF2m :: BinaryPolynomial -- ^ Modulus- -> Integer- -> Integer+modF2m+ :: BinaryPolynomial+ -- ^ Modulus+ -> Integer+ -> Integer modF2m fx i- | fx < 0 || i < 0 = error "modF2m: negative number represent no binary polynomial"- | fx == 0 = error "modF2m: cannot divide by zero polynomial"- | fx == 1 = 0- | otherwise = go i+ | fx < 0 || i < 0 =+ error "modF2m: negative number represent no binary polynomial"+ | fx == 0 = error "modF2m: cannot divide by zero polynomial"+ | fx == 1 = 0+ | otherwise = go i+ where+ lfx = log2 fx+ go n+ | s == 0 = n `addF2m` fx+ | s < 0 = n+ | otherwise = go $ n `addF2m` shift fx s where- lfx = log2 fx- go n | s == 0 = n `addF2m` fx- | s < 0 = n- | otherwise = go $ n `addF2m` shift fx s- where s = log2 n - lfx+ s = log2 n - lfx {-# INLINE modF2m #-} -- | Multiplication over F₂m. -- -- This function is undefined for negative arguments, because their bit -- representation is platform-dependent. Zero modulus is also prohibited.-mulF2m :: BinaryPolynomial -- ^ Modulus- -> Integer- -> Integer- -> Integer+mulF2m+ :: BinaryPolynomial+ -- ^ Modulus+ -> Integer+ -> Integer+ -> Integer mulF2m fx n1 n2- | fx < 0- || n1 < 0- || n2 < 0 = error "mulF2m: negative number represent no binary polynomial"- | fx == 0 = error "mulF2m: cannot multiply modulo zero polynomial"+ | fx < 0+ || n1 < 0+ || n2 < 0 =+ error "mulF2m: negative number represent no binary polynomial"+ | fx == 0 = error "mulF2m: cannot multiply modulo zero polynomial" | otherwise = modF2m fx $ go (if n2 `mod` 2 == 1 then n1 else 0) (log2 n2)- where- go n s | s == 0 = n- | otherwise = if testBit n2 s- then go (n `addF2m` shift n1 s) (s - 1)- else go n (s - 1)-{-# INLINABLE mulF2m #-}+ where+ go n s+ | s == 0 = n+ | otherwise =+ if testBit n2 s+ then go (n `addF2m` shift n1 s) (s - 1)+ else go n (s - 1)+{-# INLINEABLE mulF2m #-} -- | Squaring over F₂m. -- -- This function is undefined for negative arguments, because their bit -- representation is platform-dependent. Zero modulus is also prohibited.-squareF2m :: BinaryPolynomial -- ^ Modulus- -> Integer- -> Integer+squareF2m+ :: BinaryPolynomial+ -- ^ Modulus+ -> Integer+ -> Integer squareF2m fx = modF2m fx . squareF2m' {-# INLINE squareF2m #-} @@ -95,75 +108,123 @@ -- -- This function is undefined for negative arguments, because their bit -- representation is platform-dependent.-squareF2m' :: Integer- -> Integer+squareF2m'+ :: Integer+ -> Integer squareF2m' n- | n < 0 = error "mulF2m: negative number represent no binary polynomial"- | otherwise = foldl' (\acc s -> if testBit n s then setBit acc (2 * s) else acc) 0 [0 .. log2 n]+ | n < 0 = error "mulF2m: negative number represent no binary polynomial"+ | otherwise =+ foldl'+ (\acc s -> if testBit n s then setBit acc (2 * s) else acc)+ 0+ [0 .. log2 n] {-# INLINE squareF2m' #-} -- | Exponentiation in F₂m by computing @a^b mod fx@. -- -- This implements an exponentiation by squaring based solution. It inherits the -- same restrictions as 'squareF2m'. Negative exponents are disallowed.-powF2m :: BinaryPolynomial -- ^Modulus- -> Integer -- ^a- -> Integer -- ^b- -> Integer+powF2m+ :: BinaryPolynomial+ -- ^ Modulus+ -> Integer+ -- ^ a+ -> Integer+ -- ^ b+ -> Integer powF2m fx a b- | b < 0 = error "powF2m: negative exponents disallowed"- | b == 0 = if fx > 1 then 1 else 0- | even b = squareF2m fx x- | otherwise = mulF2m fx a (squareF2m' x)- where x = powF2m fx a (b `div` 2)+ | b < 0 = error "powF2m: negative exponents disallowed"+ | b == 0 = if fx > 1 then 1 else 0+ | even b = squareF2m fx x+ | otherwise = mulF2m fx a (squareF2m' x)+ where+ x = powF2m fx a (b `div` 2) -- | Square rooot in F₂m. -- -- We exploit the fact that @a^(2^m) = a@, or in particular, @a^(2^m - 1) = 1@ -- from a classical result by Lagrange. Thus the square root is simply @a^(2^(m -- - 1))@.-sqrtF2m :: BinaryPolynomial -- ^Modulus- -> Integer -- ^a- -> Integer+sqrtF2m+ :: BinaryPolynomial+ -- ^ Modulus+ -> Integer+ -- ^ a+ -> Integer sqrtF2m fx a = go (log2 fx - 1) a- where go 0 x = x- go n x = go (n - 1) (squareF2m fx x)+ where+ go 0 x = x+ go n x = go (n - 1) (squareF2m fx x) -- | Extended GCD algorithm for polynomials. For @a@ and @b@ returns @(g, u, v)@ such that @a * u + b * v == g@. -- -- Reference: https://en.wikipedia.org/wiki/Polynomial_greatest_common_divisor#B.C3.A9zout.27s_identity_and_extended_GCD_algorithm-gcdF2m :: Integer- -> Integer- -> (Integer, Integer, Integer)+gcdF2m+ :: Integer+ -> Integer+ -> (Integer, Integer, Integer) gcdF2m a b = go (a, b, 1, 0, 0, 1) where- go (g, 0, u, _, v, _)- = (g, u, v)- go (r0, r1, s0, s1, t0, t1)- = go (r1, r0 `addF2m` shift r1 j, s1, s0 `addF2m` shift s1 j, t1, t0 `addF2m` shift t1 j)- where j = max 0 (log2 r0 - log2 r1)+ go (g, 0, u, _, v, _) =+ (g, u, v)+ go (r0, r1, s0, s1, t0, t1) =+ go+ ( r1+ , r0 `addF2m` shift r1 j+ , s1+ , s0 `addF2m` shift s1 j+ , t1+ , t0 `addF2m` shift t1 j+ )+ where+ j = max 0 (log2 r0 - log2 r1) -- | Modular inversion over F₂m. -- If @n@ doesn't have an inverse, 'Nothing' is returned. -- -- This function is undefined for negative arguments, because their bit -- representation is platform-dependent. Zero modulus is also prohibited.-invF2m :: BinaryPolynomial -- ^ Modulus- -> Integer- -> Maybe Integer+invF2m+ :: BinaryPolynomial+ -- ^ Modulus+ -> Integer+ -> Maybe Integer invF2m fx n = if g == 1 then Just (modF2m fx u) else Nothing where (g, u, _) = gcdF2m n fx-{-# INLINABLE invF2m #-}+{-# INLINEABLE invF2m #-} -- | Division over F₂m. If the dividend doesn't have an inverse it returns -- 'Nothing'. -- -- This function is undefined for negative arguments, because their bit -- representation is platform-dependent. Zero modulus is also prohibited.-divF2m :: BinaryPolynomial -- ^ Modulus- -> Integer -- ^ Dividend- -> Integer -- ^ Divisor- -> Maybe Integer -- ^ Quotient+divF2m+ :: BinaryPolynomial+ -- ^ Modulus+ -> Integer+ -- ^ Dividend+ -> Integer+ -- ^ Divisor+ -> Maybe Integer+ -- ^ Quotient divF2m fx n1 n2 = mulF2m fx n1 <$> invF2m fx n2 {-# INLINE divF2m #-}++traceF2m :: BinaryPolynomial -> Integer -> Integer+traceF2m fx = foldr addF2m 0 . take (log2 fx) . iterate (squareF2m fx)+{-# INLINE traceF2m #-}++halfTraceF2m :: BinaryPolynomial -> Integer -> Integer+halfTraceF2m fx =+ foldr addF2m 0+ . take (1 + log2 fx `unsafeShiftR` 1)+ . iterate (squareF2m fx . squareF2m fx)+{-# INLINE halfTraceF2m #-}++-- | Solve a quadratic equation of the form @x^2 + x = a@ in F₂m.+quadraticF2m :: BinaryPolynomial -> Integer -> Maybe Integer+quadraticF2m fx a+ | traceF2m fx a == 0 = Just $ halfTraceF2m fx a+ | otherwise = Nothing+{-# INLINEABLE quadraticF2m #-}
Crypto/Number/Generate.hs view
@@ -4,31 +4,32 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good--module Crypto.Number.Generate- ( GenTopPolicy(..)- , generateParams- , generateMax- , generateBetween- ) where+module Crypto.Number.Generate (+ GenTopPolicy (..),+ generateParams,+ generatePrefix,+ generateMax,+ generateBetween,+) where -import Crypto.Internal.Imports-import Crypto.Number.Basic-import Crypto.Number.Serialize-import Crypto.Random.Types-import Control.Monad (when)-import Foreign.Ptr-import Foreign.Storable-import Data.Bits ((.|.), (.&.), shiftL, complement, testBit)-import Crypto.Internal.ByteArray (ScrubbedBytes)+import Control.Monad (when)+import Crypto.Internal.ByteArray (ScrubbedBytes) import qualified Crypto.Internal.ByteArray as B-+import Crypto.Internal.Imports+import Crypto.Number.Basic+import Crypto.Number.Serialize+import Crypto.Random.Types+import Data.Bits (complement, shiftL, testBit, unsafeShiftR, (.&.), (.|.))+import Foreign.Ptr+import Foreign.Storable -- | Top bits policy when generating a number-data GenTopPolicy =- SetHighest -- ^ set the highest bit- | SetTwoHighest -- ^ set the two highest bit- deriving (Show,Eq)+data GenTopPolicy+ = -- | set the highest bit+ SetHighest+ | -- | set the two highest bit+ SetTwoHighest+ deriving (Show, Eq) -- | Generate a number for a specific size of bits, -- and optionaly set bottom and top bits@@ -38,27 +39,31 @@ -- -- If @generateOdd is set to 'True', then the number generated -- is guaranteed to be odd. Otherwise it will be whatever is generated----generateParams :: MonadRandom m- => Int -- ^ number of bits- -> Maybe GenTopPolicy -- ^ top bit policy- -> Bool -- ^ force the number to be odd- -> m Integer+generateParams+ :: MonadRandom m+ => Int+ -- ^ number of bits+ -> Maybe GenTopPolicy+ -- ^ top bit policy+ -> Bool+ -- ^ force the number to be odd+ -> m Integer generateParams bits genTopPolicy generateOdd | bits <= 0 = return 0 | otherwise = os2ip . tweak <$> getRandomBytes bytes where tweak :: ScrubbedBytes -> ScrubbedBytes tweak orig = B.copyAndFreeze orig $ \p0 -> do- let p1 = p0 `plusPtr` 1+ let p1 = p0 `plusPtr` 1 pEnd = p0 `plusPtr` (bytes - 1) case genTopPolicy of- Nothing -> return ()- Just SetHighest -> p0 |= (1 `shiftL` bit)+ Nothing -> return ()+ Just SetHighest -> p0 |= (1 `shiftL` bit) Just SetTwoHighest- | bit == 0 -> do p0 $= 0x1- p1 |= 0x80- | otherwise -> p0 |= (0x3 `shiftL` (bit - 1))+ | bit == 0 -> do+ p0 $= 0x1+ p1 |= 0x80+ | otherwise -> p0 |= (0x3 `shiftL` (bit - 1)) p0 &= (complement $ mask) when generateOdd (pEnd |= 0x1) @@ -71,52 +76,81 @@ (&=) :: Ptr Word8 -> Word8 -> IO () (&=) p w = peek p >>= \v -> poke p (v .&. w) - bytes = (bits + 7) `div` 8;- bit = (bits - 1) `mod` 8;- mask = 0xff `shiftL` (bit + 1);+ bytes = (bits + 7) `div` 8+ bit = (bits - 1) `mod` 8+ mask = 0xff `shiftL` (bit + 1) +-- | Generate a number for a specific size of bits.+--+-- * @'generateParams' n Nothing False@ generates bytes and uses the suffix of @n@ bits+-- * @'generatePrefix' n@ generates bytes and uses the prefix of @n@ bits+generatePrefix :: MonadRandom m => Int -> m Integer+generatePrefix bits+ | bits <= 0 = return 0+ | otherwise = do+ let (count, offset) = (bits + 7) `divMod` 8+ bytes <- getRandomBytes count+ return $ os2ip (bytes :: ScrubbedBytes) `unsafeShiftR` (7 - offset)+ -- | Generate a positive integer x, s.t. 0 <= x < range-generateMax :: MonadRandom m- => Integer -- ^ range- -> m Integer+generateMax+ :: MonadRandom m+ => Integer+ -- ^ range+ -> m Integer generateMax range- | range <= 1 = return 0- | range < 127 = generateSimple+ | range <= 1 = return 0+ | range < 127 = generateSimple | canOverGenerate = loopGenerateOver tries- | otherwise = loopGenerate tries+ | otherwise = loopGenerate tries where- -- this "generator" is mostly for quickcheck benefits. it'll be biased if- -- range is not a multiple of 2, but overall, no security should be- -- assumed for a number between 0 and 127.- generateSimple = flip mod range `fmap` generateParams bits Nothing False+ -- this "generator" is mostly for quickcheck benefits. it'll be biased if+ -- range is not a multiple of 2, but overall, no security should be+ -- assumed for a number between 0 and 127.+ generateSimple = flip mod range `fmap` generateParams bits Nothing False - loopGenerate count- | count == 0 = error $ "internal: generateMax(" ++ show range ++ " bits=" ++ show bits ++ ") (normal) doesn't seems to work properly"- | otherwise = do- r <- generateParams bits Nothing False- if isValid r then return r else loopGenerate (count-1)+ loopGenerate count+ | count == 0 =+ error $+ "internal: generateMax("+ ++ show range+ ++ " bits="+ ++ show bits+ ++ ") (normal) doesn't seems to work properly"+ | otherwise = do+ r <- generateParams bits Nothing False+ if isValid r then return r else loopGenerate (count - 1) - loopGenerateOver count- | count == 0 = error $ "internal: generateMax(" ++ show range ++ " bits=" ++ show bits ++ ") (over) doesn't seems to work properly"- | otherwise = do- r <- generateParams (bits+1) Nothing False- let r2 = r - range- r3 = r2 - range- if isValid r- then return r- else if isValid r2+ loopGenerateOver count+ | count == 0 =+ error $+ "internal: generateMax("+ ++ show range+ ++ " bits="+ ++ show bits+ ++ ") (over) doesn't seems to work properly"+ | otherwise = do+ r <- generateParams (bits + 1) Nothing False+ let r2 = r - range+ r3 = r2 - range+ if isValid r+ then return r+ else+ if isValid r2 then return r2- else if isValid r3- then return r3- else loopGenerateOver (count-1)+ else+ if isValid r3+ then return r3+ else loopGenerateOver (count - 1) - bits = numBits range- canOverGenerate = bits > 3 && not (range `testBit` (bits-2)) && not (range `testBit` (bits-3))+ bits = numBits range+ canOverGenerate =+ bits > 3 && not (range `testBit` (bits - 2)) && not (range `testBit` (bits - 3)) - isValid n = n < range+ isValid n = n < range - tries :: Int- tries = 100+ tries :: Int+ tries = 100 -- | generate a number between the inclusive bound [low,high]. generateBetween :: MonadRandom m => Integer -> Integer -> m Integer
Crypto/Number/ModArithmetic.hs view
@@ -1,26 +1,27 @@ {-# LANGUAGE BangPatterns #-}+ -- | -- Module : Crypto.Number.ModArithmetic -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good--module Crypto.Number.ModArithmetic- (+module Crypto.Number.ModArithmetic ( -- * Exponentiation- expSafe- , expFast+ expSafe,+ expFast,+ -- * Inverse computing- , inverse- , inverseCoprimes- , inverseFermat+ inverse,+ inverseCoprimes,+ inverseFermat,+ -- * Squares- , jacobi- , squareRoot- ) where+ jacobi,+ squareRoot,+) where -import Control.Exception (throw, Exception)+import Control.Exception (Exception, throw) import Crypto.Number.Basic import Crypto.Number.Compat @@ -42,16 +43,24 @@ -- -- Before GHC 8.4.2, powModSecInteger is missing from integer-gmp, -- so expSafe has the same security as expFast.-expSafe :: Integer -- ^ base- -> Integer -- ^ exponent- -> Integer -- ^ modulo- -> Integer -- ^ result+expSafe+ :: Integer+ -- ^ base+ -> Integer+ -- ^ exponent+ -> Integer+ -- ^ modulo+ -> Integer+ -- ^ result expSafe b e m- | odd m = gmpPowModSecInteger b e m `onGmpUnsupported`- (gmpPowModInteger b e m `onGmpUnsupported`- exponentiation b e m)- | otherwise = gmpPowModInteger b e m `onGmpUnsupported`- exponentiation b e m+ | odd m =+ gmpPowModSecInteger b e m+ `onGmpUnsupported` ( gmpPowModInteger b e m+ `onGmpUnsupported` exponentiation b e m+ )+ | otherwise =+ gmpPowModInteger b e m+ `onGmpUnsupported` exponentiation b e m -- | Compute the modular exponentiation of base^exponent using -- the fastest algorithm without any consideration for@@ -59,31 +68,37 @@ -- -- Use this function when all the parameters are public, -- otherwise 'expSafe' should be preferred.-expFast :: Integer -- ^ base- -> Integer -- ^ exponent- -> Integer -- ^ modulo- -> Integer -- ^ result+expFast+ :: Integer+ -- ^ base+ -> Integer+ -- ^ exponent+ -> Integer+ -- ^ modulo+ -> Integer+ -- ^ result expFast b e m = gmpPowModInteger b e m `onGmpUnsupported` exponentiation b e m -- | @exponentiation@ computes modular exponentiation as /b^e mod m/ -- using repetitive squaring. exponentiation :: Integer -> Integer -> Integer -> Integer exponentiation b e m- | b == 1 = b- | e == 0 = 1- | e == 1 = b `mod` m- | even e = let p = exponentiation b (e `div` 2) m `mod` m- in (p^(2::Integer)) `mod` m- | otherwise = (b * exponentiation b (e-1) m) `mod` m+ | b == 1 = b+ | e == 0 = 1+ | e == 1 = b `mod` m+ | even e =+ let p = exponentiation b (e `div` 2) m `mod` m+ in (p ^ (2 :: Integer)) `mod` m+ | otherwise = (b * exponentiation b (e - 1) m) `mod` m -- | @inverse@ computes the modular inverse as in /g^(-1) mod m/. inverse :: Integer -> Integer -> Maybe Integer inverse g m = gmpInverse g m `onGmpUnsupported` v where v- | d > 1 = Nothing+ | d > 1 = Nothing | otherwise = Just (x `mod` m)- (x,_,d) = gcde g m+ (x, _, d) = gcde g m -- | Compute the modular inverse of two coprime numbers. -- This is equivalent to inverse except that the result@@ -95,7 +110,7 @@ inverseCoprimes g m = case inverse g m of Nothing -> throw CoprimesAssertionError- Just i -> i+ Just i -> i -- | Computes the Jacobi symbol (a/n). -- 0 ≤ a < n; n ≥ 3 and odd.@@ -106,22 +121,23 @@ -- See algorithm 2.149 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al. jacobi :: Integer -> Integer -> Maybe Integer jacobi a n- | n < 3 || even n = Nothing+ | n < 3 || even n = Nothing | a == 0 || a == 1 = Just a- | n <= a = jacobi (a `mod` n) n- | a < 0 =- let b = if n `mod` 4 == 1 then 1 else -1- in fmap (*b) (jacobi (-a) n)- | otherwise =- let (e, a1) = asPowerOf2AndOdd a- nMod8 = n `mod` 8- nMod4 = n `mod` 4- a1Mod4 = a1 `mod` 4- s' = if even e || nMod8 == 1 || nMod8 == 7 then 1 else -1- s = if nMod4 == 3 && a1Mod4 == 3 then -s' else s'- n1 = n `mod` a1- in if a1 == 1 then Just s- else fmap (*s) (jacobi n1 a1)+ | n <= a = jacobi (a `mod` n) n+ | a < 0 =+ let b = if n `mod` 4 == 1 then 1 else -1+ in fmap (* b) (jacobi (-a) n)+ | otherwise =+ let (e, a1) = asPowerOf2AndOdd a+ nMod8 = n `mod` 8+ nMod4 = n `mod` 4+ a1Mod4 = a1 `mod` 4+ s' = if even e || nMod8 == 1 || nMod8 == 7 then 1 else -1+ s = if nMod4 == 3 && a1Mod4 == 3 then -s' else s'+ n1 = n `mod` a1+ in if a1 == 1+ then Just s+ else fmap (* s) (jacobi n1 a1) -- | Modular inverse using Fermat's little theorem. This works only when -- the modulus is prime but avoids side channels like in 'expSafe'.@@ -143,21 +159,21 @@ -- parameters only. squareRoot :: Integer -> Integer -> Maybe Integer squareRoot p- | p < 2 = throw ModulusAssertionError+ | p < 2 = throw ModulusAssertionError | otherwise = case p `divMod` 8 of- (v, 3) -> method1 (2 * v + 1)- (v, 7) -> method1 (2 * v + 2)- (u, 5) -> method2 u- (_, 1) -> tonelliShanks p- (0, 2) -> \a -> Just (if even a then 0 else 1)- _ -> throw ModulusAssertionError-+ (v, 3) -> method1 (2 * v + 1)+ (v, 7) -> method1 (2 * v + 2)+ (u, 5) -> method2 u+ (_, 1) -> tonelliShanks p+ (0, 2) -> \a -> Just (if even a then 0 else 1)+ _ -> throw ModulusAssertionError where x `eqMod` y = (x - y) `mod` p == 0 - validate g y | (y * y) `eqMod` g = Just y- | otherwise = Nothing+ validate g y+ | (y * y) `eqMod` g = Just y+ | otherwise = Nothing -- p == 4u + 3 and u' == u + 1 method1 u' g =@@ -174,20 +190,24 @@ tonelliShanks :: Integer -> Integer -> Maybe Integer tonelliShanks p a- | aa == 0 = Just 0+ | aa == 0 = Just 0 | otherwise = case expFast aa p2 p of- b | b == p1 -> Nothing- | b == 1 -> Just $ go (expFast aa ((s + 1) `div` 2) p)- (expFast aa s p)- (expFast n s p)- e- | otherwise -> throw ModulusAssertionError+ b+ | b == p1 -> Nothing+ | b == 1 ->+ Just $+ go+ (expFast aa ((s + 1) `div` 2) p)+ (expFast aa s p)+ (expFast n s p)+ e+ | otherwise -> throw ModulusAssertionError where aa = a `mod` p p1 = p - 1 p2 = p1 `div` 2- n = findN 2+ n = findN 2 x `mul` y = (x * y) `mod` p @@ -199,15 +219,15 @@ -- find a quadratic non-residue findN i | expFast i p2 p == p1 = i- | otherwise = findN (i + 1)+ | otherwise = findN (i + 1) -- find m such that b^(2^m) == 1 (mod p) findM b i- | b == 1 = i+ | b == 1 = i | otherwise = findM (b `mul` b) (i + 1) go !x b g !r- | b == 1 = x+ | b == 1 = x | otherwise = let r' = findM b 0 z = pow2m (r - r' - 1) g
Crypto/Number/Nat.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE TypeOperators #-}+ -- | -- Module : Crypto.Number.Nat -- License : BSD-style@@ -26,38 +29,39 @@ -- -- Function @withDivisibleBy8@ above returns 'Nothing' when the argument @len@ -- is negative or not divisible by 8.-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeOperators #-}-module Crypto.Number.Nat- ( type IsDivisibleBy8- , type IsAtMost, type IsAtLeast- , isDivisibleBy8- , isAtMost- , isAtLeast- ) where+module Crypto.Number.Nat (+ type IsDivisibleBy8,+ type IsAtMost,+ type IsAtLeast,+ isDivisibleBy8,+ isAtMost,+ isAtLeast,+) where -import Data.Type.Equality-import GHC.TypeLits-import Unsafe.Coerce (unsafeCoerce)+import Data.Type.Equality+import GHC.TypeLits+import Unsafe.Coerce (unsafeCoerce) -import Crypto.Internal.Nat+import Crypto.Internal.Nat -- | get a runtime proof that the constraint @'IsDivisibleBy8' n@ is satified isDivisibleBy8 :: KnownNat n => proxy n -> Maybe (IsDiv8 n n :~: 'True) isDivisibleBy8 n | mod (natVal n) 8 == 0 = Just (unsafeCoerce Refl)- | otherwise = Nothing+ | otherwise = Nothing -- | get a runtime proof that the constraint @'IsAtMost' value bound@ is -- satified-isAtMost :: (KnownNat value, KnownNat bound)- => proxy value -> proxy' bound -> Maybe ((value <=? bound) :~: 'True)+isAtMost+ :: (KnownNat value, KnownNat bound)+ => proxy value -> proxy' bound -> Maybe ((value <=? bound) :~: 'True) isAtMost x y- | natVal x <= natVal y = Just (unsafeCoerce Refl)- | otherwise = Nothing+ | natVal x <= natVal y = Just (unsafeCoerce Refl)+ | otherwise = Nothing -- | get a runtime proof that the constraint @'IsAtLeast' value bound@ is -- satified-isAtLeast :: (KnownNat value, KnownNat bound)- => proxy value -> proxy' bound -> Maybe ((bound <=? value) :~: 'True)+isAtLeast+ :: (KnownNat value, KnownNat bound)+ => proxy value -> proxy' bound -> Maybe ((bound <=? value) :~: 'True) isAtLeast = flip isAtMost
Crypto/Number/Prime.hs view
@@ -1,31 +1,30 @@+{-# LANGUAGE BangPatterns #-}+ -- | -- Module : Crypto.Number.Prime -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good--{-# LANGUAGE BangPatterns #-}-module Crypto.Number.Prime- (- generatePrime- , generateSafePrime- , isProbablyPrime- , findPrimeFrom- , findPrimeFromWith- , primalityTestMillerRabin- , primalityTestNaive- , primalityTestFermat- , isCoprime- ) where+module Crypto.Number.Prime (+ generatePrime,+ generateSafePrime,+ isProbablyPrime,+ findPrimeFrom,+ findPrimeFromWith,+ primalityTestMillerRabin,+ primalityTestNaive,+ primalityTestFermat,+ isCoprime,+) where +import Crypto.Error+import Crypto.Number.Basic (gcde, sqrti) import Crypto.Number.Compat import Crypto.Number.Generate-import Crypto.Number.Basic (sqrti, gcde) import Crypto.Number.ModArithmetic (expSafe)-import Crypto.Random.Types import Crypto.Random.Probabilistic-import Crypto.Error+import Crypto.Random.Types import Data.Bits @@ -36,9 +35,10 @@ isProbablyPrime :: Integer -> Bool isProbablyPrime !n | any (\p -> p `divides` n) (filter (< n) firstPrimes) = False- | n >= 2 && n <= 2903 = True- | primalityTestFermat 50 (n `div` 2) n = primalityTestMillerRabin 30 n- | otherwise = False+ | n >= 2 && n <= 2903 = True+ | primalityTestFermat 50 (n `div` 2) n =+ primalityTestMillerRabin 30 n+ | otherwise = False -- | Generate a prime number of the required bitsize (i.e. in the range -- [2^(b-1)+2^(b-2), 2^b)).@@ -50,14 +50,16 @@ -- the proper size. generatePrime :: MonadRandom m => Int -> m Integer generatePrime bits = do- if bits < 5 then- throwCryptoError $ CryptoFailed $ CryptoError_PrimeSizeInvalid- else do- sp <- generateParams bits (Just SetTwoHighest) True- let prime = findPrimeFrom sp- if prime < 1 `shiftL` bits then- return $ prime- else generatePrime bits+ if bits < 5+ then+ throwCryptoError $ CryptoFailed $ CryptoError_PrimeSizeInvalid+ else do+ sp <- generateParams bits (Just SetTwoHighest) True+ let prime = findPrimeFrom sp+ if prime < 1 `shiftL` bits+ then+ return $ prime+ else generatePrime bits -- | Generate a prime number of the form 2p+1 where p is also prime. -- it is also knowed as a Sophie Germaine prime or safe prime.@@ -69,27 +71,29 @@ -- 6 bits, as the smallest safe prime with the two highest bits set is 59. generateSafePrime :: MonadRandom m => Int -> m Integer generateSafePrime bits = do- if bits < 6 then- throwCryptoError $ CryptoFailed $ CryptoError_PrimeSizeInvalid- else do- sp <- generateParams bits (Just SetTwoHighest) True- let p = findPrimeFromWith (\i -> isProbablyPrime (2*i+1)) (sp `div` 2)- let val = 2 * p + 1- if val < 1 `shiftL` bits then- return $ val- else generateSafePrime bits+ if bits < 6+ then+ throwCryptoError $ CryptoFailed $ CryptoError_PrimeSizeInvalid+ else do+ sp <- generateParams bits (Just SetTwoHighest) True+ let p = findPrimeFromWith (\i -> isProbablyPrime (2 * i + 1)) (sp `div` 2)+ let val = 2 * p + 1+ if val < 1 `shiftL` bits+ then+ return $ val+ else generateSafePrime bits -- | Find a prime from a starting point where the property hold. findPrimeFromWith :: (Integer -> Bool) -> Integer -> Integer findPrimeFromWith prop !n- | even n = findPrimeFromWith prop (n+1)- | otherwise =+ | even n = findPrimeFromWith prop (n + 1)+ | otherwise = if not (isProbablyPrime n)- then findPrimeFromWith prop (n+2)+ then findPrimeFromWith prop (n + 2) else if prop n then n- else findPrimeFromWith prop (n+2)+ else findPrimeFromWith prop (n + 2) -- | Find a prime from a starting point with no specific property. findPrimeFrom :: Integer -> Integer@@ -107,41 +111,42 @@ GmpUnsupported -> probabilistic run where run- | n <= 3 = error "Miller-Rabin requires tested value to be > 3"- | even n = return False+ | n <= 3 = error "Miller-Rabin requires tested value to be > 3"+ | even n = return False | tries <= 0 = error "Miller-Rabin tries need to be > 0"- | otherwise = loop <$> generateTries tries+ | otherwise = loop <$> generateTries tries - !nm1 = n-1- !nm2 = n-2+ !nm1 = n - 1+ !nm2 = n - 2 - (!s,!d) = (factorise 0 nm1)+ (!s, !d) = (factorise 0 nm1) generateTries 0 = return [] generateTries t = do- v <- generateBetween 2 nm2- vs <- generateTries (t-1)- return (v:vs)+ v <- generateBetween 2 nm2+ vs <- generateTries (t - 1)+ return (v : vs) -- factorise n-1 into the form 2^s*d factorise :: Integer -> Integer -> (Integer, Integer) factorise !si !vi | vi `testBit` 0 = (si, vi)- | otherwise = factorise (si+1) (vi `shiftR` 1) -- probably faster to not shift v continuously, but just once.+ | otherwise = factorise (si + 1) (vi `shiftR` 1) -- probably faster to not shift v continuously, but just once. expmod = expSafe -- when iteration reach zero, we have a probable prime- loop [] = True- loop (w:ws) = let x = expmod w d n- in if x == (1 :: Integer) || x == nm1- then loop ws- else loop' ws ((x*x) `mod` n) 1+ loop [] = True+ loop (w : ws) =+ let x = expmod w d n+ in if x == (1 :: Integer) || x == nm1+ then loop ws+ else loop' ws ((x * x) `mod` n) 1 -- loop from 1 to s-1. if we reach the end then it's composite loop' ws !x2 !r- | r == s = False- | x2 == 1 = False- | x2 /= nm1 = loop' ws ((x2*x2) `mod` n) (r+1)+ | r == s = False+ | x2 == 1 = False+ | x2 /= nm1 = loop' ws ((x2 * x2) `mod` n) (r + 1) | otherwise = loop ws {-@@ -157,77 +162,461 @@ -- | Probabilitic Test using Fermat primility test. -- Beware of Carmichael numbers that are Fermat liars, i.e. this test -- is useless for them. always combines with some other test.-primalityTestFermat :: Int -- ^ number of iterations of the algorithm- -> Integer -- ^ starting a- -> Integer -- ^ number to test for primality- -> Bool-primalityTestFermat n a p = and $ map expTest [a..(a+fromIntegral n)]- where !pm1 = p-1- expTest i = expSafe i pm1 p == 1+primalityTestFermat+ :: Int+ -- ^ number of iterations of the algorithm+ -> Integer+ -- ^ starting a+ -> Integer+ -- ^ number to test for primality+ -> Bool+primalityTestFermat n a p = and $ map expTest [a .. (a + fromIntegral n)]+ where+ !pm1 = p - 1+ expTest i = expSafe i pm1 p == 1 -- | Test naively is integer is prime. -- while naive, we skip even number and stop iteration at i > sqrt(n) primalityTestNaive :: Integer -> Bool primalityTestNaive n- | n <= 1 = False- | n == 2 = True- | even n = False+ | n <= 1 = False+ | n == 2 = True+ | even n = False | otherwise = search 3- where !ubound = snd $ sqrti n- search !i- | i > ubound = True- | i `divides` n = False- | otherwise = search (i+2)+ where+ !ubound = snd $ sqrti n+ search !i+ | i > ubound = True+ | i `divides` n = False+ | otherwise = search (i + 2) -- | Test is two integer are coprime to each other isCoprime :: Integer -> Integer -> Bool-isCoprime m n = case gcde m n of (_,_,d) -> d == 1+isCoprime m n = case gcde m n of (_, _, d) -> d == 1 -- | List of the first primes till 2903. firstPrimes :: [Integer] firstPrimes =- [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29- , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71- , 73 , 79 , 83 , 89 , 97 , 101 , 103 , 107 , 109 , 113- , 127 , 131 , 137 , 139 , 149 , 151 , 157 , 163 , 167 , 173- , 179 , 181 , 191 , 193 , 197 , 199 , 211 , 223 , 227 , 229- , 233 , 239 , 241 , 251 , 257 , 263 , 269 , 271 , 277 , 281- , 283 , 293 , 307 , 311 , 313 , 317 , 331 , 337 , 347 , 349- , 353 , 359 , 367 , 373 , 379 , 383 , 389 , 397 , 401 , 409- , 419 , 421 , 431 , 433 , 439 , 443 , 449 , 457 , 461 , 463- , 467 , 479 , 487 , 491 , 499 , 503 , 509 , 521 , 523 , 541- , 547 , 557 , 563 , 569 , 571 , 577 , 587 , 593 , 599 , 601- , 607 , 613 , 617 , 619 , 631 , 641 , 643 , 647 , 653 , 659- , 661 , 673 , 677 , 683 , 691 , 701 , 709 , 719 , 727 , 733- , 739 , 743 , 751 , 757 , 761 , 769 , 773 , 787 , 797 , 809- , 811 , 821 , 823 , 827 , 829 , 839 , 853 , 857 , 859 , 863- , 877 , 881 , 883 , 887 , 907 , 911 , 919 , 929 , 937 , 941- , 947 , 953 , 967 , 971 , 977 , 983 , 991 , 997 , 1009 , 1013- , 1019 , 1021 , 1031 , 1033 , 1039 , 1049 , 1051 , 1061 , 1063 , 1069- , 1087 , 1091 , 1093 , 1097 , 1103 , 1109 , 1117 , 1123 , 1129 , 1151- , 1153 , 1163 , 1171 , 1181 , 1187 , 1193 , 1201 , 1213 , 1217 , 1223- , 1229 , 1231 , 1237 , 1249 , 1259 , 1277 , 1279 , 1283 , 1289 , 1291- , 1297 , 1301 , 1303 , 1307 , 1319 , 1321 , 1327 , 1361 , 1367 , 1373- , 1381 , 1399 , 1409 , 1423 , 1427 , 1429 , 1433 , 1439 , 1447 , 1451- , 1453 , 1459 , 1471 , 1481 , 1483 , 1487 , 1489 , 1493 , 1499 , 1511- , 1523 , 1531 , 1543 , 1549 , 1553 , 1559 , 1567 , 1571 , 1579 , 1583- , 1597 , 1601 , 1607 , 1609 , 1613 , 1619 , 1621 , 1627 , 1637 , 1657- , 1663 , 1667 , 1669 , 1693 , 1697 , 1699 , 1709 , 1721 , 1723 , 1733- , 1741 , 1747 , 1753 , 1759 , 1777 , 1783 , 1787 , 1789 , 1801 , 1811- , 1823 , 1831 , 1847 , 1861 , 1867 , 1871 , 1873 , 1877 , 1879 , 1889- , 1901 , 1907 , 1913 , 1931 , 1933 , 1949 , 1951 , 1973 , 1979 , 1987- , 1993 , 1997 , 1999 , 2003 , 2011 , 2017 , 2027 , 2029 , 2039 , 2053- , 2063 , 2069 , 2081 , 2083 , 2087 , 2089 , 2099 , 2111 , 2113 , 2129- , 2131 , 2137 , 2141 , 2143 , 2153 , 2161 , 2179 , 2203 , 2207 , 2213- , 2221 , 2237 , 2239 , 2243 , 2251 , 2267 , 2269 , 2273 , 2281 , 2287- , 2293 , 2297 , 2309 , 2311 , 2333 , 2339 , 2341 , 2347 , 2351 , 2357- , 2371 , 2377 , 2381 , 2383 , 2389 , 2393 , 2399 , 2411 , 2417 , 2423- , 2437 , 2441 , 2447 , 2459 , 2467 , 2473 , 2477 , 2503 , 2521 , 2531- , 2539 , 2543 , 2549 , 2551 , 2557 , 2579 , 2591 , 2593 , 2609 , 2617- , 2621 , 2633 , 2647 , 2657 , 2659 , 2663 , 2671 , 2677 , 2683 , 2687- , 2689 , 2693 , 2699 , 2707 , 2711 , 2713 , 2719 , 2729 , 2731 , 2741- , 2749 , 2753 , 2767 , 2777 , 2789 , 2791 , 2797 , 2801 , 2803 , 2819- , 2833 , 2837 , 2843 , 2851 , 2857 , 2861 , 2879 , 2887 , 2897 , 2903+ [ 2+ , 3+ , 5+ , 7+ , 11+ , 13+ , 17+ , 19+ , 23+ , 29+ , 31+ , 37+ , 41+ , 43+ , 47+ , 53+ , 59+ , 61+ , 67+ , 71+ , 73+ , 79+ , 83+ , 89+ , 97+ , 101+ , 103+ , 107+ , 109+ , 113+ , 127+ , 131+ , 137+ , 139+ , 149+ , 151+ , 157+ , 163+ , 167+ , 173+ , 179+ , 181+ , 191+ , 193+ , 197+ , 199+ , 211+ , 223+ , 227+ , 229+ , 233+ , 239+ , 241+ , 251+ , 257+ , 263+ , 269+ , 271+ , 277+ , 281+ , 283+ , 293+ , 307+ , 311+ , 313+ , 317+ , 331+ , 337+ , 347+ , 349+ , 353+ , 359+ , 367+ , 373+ , 379+ , 383+ , 389+ , 397+ , 401+ , 409+ , 419+ , 421+ , 431+ , 433+ , 439+ , 443+ , 449+ , 457+ , 461+ , 463+ , 467+ , 479+ , 487+ , 491+ , 499+ , 503+ , 509+ , 521+ , 523+ , 541+ , 547+ , 557+ , 563+ , 569+ , 571+ , 577+ , 587+ , 593+ , 599+ , 601+ , 607+ , 613+ , 617+ , 619+ , 631+ , 641+ , 643+ , 647+ , 653+ , 659+ , 661+ , 673+ , 677+ , 683+ , 691+ , 701+ , 709+ , 719+ , 727+ , 733+ , 739+ , 743+ , 751+ , 757+ , 761+ , 769+ , 773+ , 787+ , 797+ , 809+ , 811+ , 821+ , 823+ , 827+ , 829+ , 839+ , 853+ , 857+ , 859+ , 863+ , 877+ , 881+ , 883+ , 887+ , 907+ , 911+ , 919+ , 929+ , 937+ , 941+ , 947+ , 953+ , 967+ , 971+ , 977+ , 983+ , 991+ , 997+ , 1009+ , 1013+ , 1019+ , 1021+ , 1031+ , 1033+ , 1039+ , 1049+ , 1051+ , 1061+ , 1063+ , 1069+ , 1087+ , 1091+ , 1093+ , 1097+ , 1103+ , 1109+ , 1117+ , 1123+ , 1129+ , 1151+ , 1153+ , 1163+ , 1171+ , 1181+ , 1187+ , 1193+ , 1201+ , 1213+ , 1217+ , 1223+ , 1229+ , 1231+ , 1237+ , 1249+ , 1259+ , 1277+ , 1279+ , 1283+ , 1289+ , 1291+ , 1297+ , 1301+ , 1303+ , 1307+ , 1319+ , 1321+ , 1327+ , 1361+ , 1367+ , 1373+ , 1381+ , 1399+ , 1409+ , 1423+ , 1427+ , 1429+ , 1433+ , 1439+ , 1447+ , 1451+ , 1453+ , 1459+ , 1471+ , 1481+ , 1483+ , 1487+ , 1489+ , 1493+ , 1499+ , 1511+ , 1523+ , 1531+ , 1543+ , 1549+ , 1553+ , 1559+ , 1567+ , 1571+ , 1579+ , 1583+ , 1597+ , 1601+ , 1607+ , 1609+ , 1613+ , 1619+ , 1621+ , 1627+ , 1637+ , 1657+ , 1663+ , 1667+ , 1669+ , 1693+ , 1697+ , 1699+ , 1709+ , 1721+ , 1723+ , 1733+ , 1741+ , 1747+ , 1753+ , 1759+ , 1777+ , 1783+ , 1787+ , 1789+ , 1801+ , 1811+ , 1823+ , 1831+ , 1847+ , 1861+ , 1867+ , 1871+ , 1873+ , 1877+ , 1879+ , 1889+ , 1901+ , 1907+ , 1913+ , 1931+ , 1933+ , 1949+ , 1951+ , 1973+ , 1979+ , 1987+ , 1993+ , 1997+ , 1999+ , 2003+ , 2011+ , 2017+ , 2027+ , 2029+ , 2039+ , 2053+ , 2063+ , 2069+ , 2081+ , 2083+ , 2087+ , 2089+ , 2099+ , 2111+ , 2113+ , 2129+ , 2131+ , 2137+ , 2141+ , 2143+ , 2153+ , 2161+ , 2179+ , 2203+ , 2207+ , 2213+ , 2221+ , 2237+ , 2239+ , 2243+ , 2251+ , 2267+ , 2269+ , 2273+ , 2281+ , 2287+ , 2293+ , 2297+ , 2309+ , 2311+ , 2333+ , 2339+ , 2341+ , 2347+ , 2351+ , 2357+ , 2371+ , 2377+ , 2381+ , 2383+ , 2389+ , 2393+ , 2399+ , 2411+ , 2417+ , 2423+ , 2437+ , 2441+ , 2447+ , 2459+ , 2467+ , 2473+ , 2477+ , 2503+ , 2521+ , 2531+ , 2539+ , 2543+ , 2549+ , 2551+ , 2557+ , 2579+ , 2591+ , 2593+ , 2609+ , 2617+ , 2621+ , 2633+ , 2647+ , 2657+ , 2659+ , 2663+ , 2671+ , 2677+ , 2683+ , 2687+ , 2689+ , 2693+ , 2699+ , 2707+ , 2711+ , 2713+ , 2719+ , 2729+ , 2731+ , 2741+ , 2749+ , 2753+ , 2767+ , 2777+ , 2789+ , 2791+ , 2797+ , 2801+ , 2803+ , 2819+ , 2833+ , 2837+ , 2843+ , 2851+ , 2857+ , 2861+ , 2879+ , 2887+ , 2897+ , 2903 ] {-# INLINE divides #-}
Crypto/Number/Serialize.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE BangPatterns #-}+ -- | -- Module : Crypto.Number.Serialize -- License : BSD-style@@ -6,17 +8,16 @@ -- Portability : Good -- -- Fast serialization primitives for integer-{-# LANGUAGE BangPatterns #-}-module Crypto.Number.Serialize- ( i2osp- , os2ip- , i2ospOf- , i2ospOf_- ) where+module Crypto.Number.Serialize (+ i2osp,+ os2ip,+ i2ospOf,+ i2ospOf_,+) where -import Crypto.Number.Basic-import Crypto.Internal.Compat (unsafeDoIO) import qualified Crypto.Internal.ByteArray as B+import Crypto.Internal.Compat (unsafeDoIO)+import Crypto.Number.Basic import qualified Crypto.Number.Serialize.Internal as Internal -- | @os2ip@ converts a byte string into a positive integer.@@ -27,23 +28,24 @@ -- -- The first byte is MSB (most significant byte); the last byte is the LSB (least significant byte) i2osp :: B.ByteArray ba => Integer -> ba-i2osp 0 = B.allocAndFreeze 1 (\p -> Internal.i2osp 0 p 1 >> return ())+i2osp 0 = B.allocAndFreeze 1 (\p -> Internal.i2osp 0 p 1 >> return ()) i2osp m = B.allocAndFreeze sz (\p -> Internal.i2osp m p sz >> return ()) where- !sz = numBytes m+ !sz = numBytes m -- | Just like 'i2osp', but takes an extra parameter for size. -- If the number is too big to fit in @len@ bytes, 'Nothing' is returned -- otherwise the number is padded with 0 to fit the @len@ required.-{-# INLINABLE i2ospOf #-}+{-# INLINEABLE i2ospOf #-} i2ospOf :: B.ByteArray ba => Int -> Integer -> Maybe ba i2ospOf len m- | len <= 0 = Nothing- | m < 0 = Nothing- | sz > len = Nothing- | otherwise = Just $ B.unsafeCreate len (\p -> Internal.i2ospOf m p len >> return ())+ | len <= 0 = Nothing+ | m < 0 = Nothing+ | sz > len = Nothing+ | otherwise =+ Just $ B.unsafeCreate len (\p -> Internal.i2ospOf m p len >> return ()) where- !sz = numBytes m+ !sz = numBytes m -- | Just like 'i2ospOf' except that it doesn't expect a failure: i.e. -- an integer larger than the number of output bytes requested.
Crypto/Number/Serialize/Internal.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE BangPatterns #-}+ -- | -- Module : Crypto.Number.Serialize.Internal -- License : BSD-style@@ -6,20 +8,19 @@ -- Portability : Good -- -- Fast serialization primitives for integer using raw pointers-{-# LANGUAGE BangPatterns #-}-module Crypto.Number.Serialize.Internal- ( i2osp- , i2ospOf- , os2ip- ) where+module Crypto.Number.Serialize.Internal (+ i2osp,+ i2ospOf,+ os2ip,+) where -import Crypto.Number.Compat-import Crypto.Number.Basic-import Data.Bits-import Data.Memory.PtrMethods-import Data.Word (Word8)-import Foreign.Ptr-import Foreign.Storable+import Crypto.Number.Basic+import Crypto.Number.Compat+import Data.Bits+import Data.Memory.PtrMethods+import Data.Word (Word8)+import Foreign.Ptr+import Foreign.Storable -- | Fill a pointer with the big endian binary representation of an integer --@@ -30,47 +31,47 @@ i2osp :: Integer -> Ptr Word8 -> Int -> IO Int i2osp m ptr ptrSz | ptrSz <= 0 = return 0- | m < 0 = return 0- | m == 0 = pokeByteOff ptr 0 (0 :: Word8) >> return 1+ | m < 0 = return 0+ | m == 0 = pokeByteOff ptr 0 (0 :: Word8) >> return 1 | ptrSz < sz = return 0- | otherwise = fillPtr ptr sz m >> return sz+ | otherwise = fillPtr ptr sz m >> return sz where- !sz = numBytes m+ !sz = numBytes m -- | Similar to 'i2osp', except it will pad any remaining space with zero. i2ospOf :: Integer -> Ptr Word8 -> Int -> IO Int i2ospOf m ptr ptrSz | ptrSz <= 0 = return 0- | m < 0 = return 0+ | m < 0 = return 0 | ptrSz < sz = return 0- | otherwise = do+ | otherwise = do memSet ptr 0 ptrSz fillPtr (ptr `plusPtr` padSz) sz m return ptrSz where- !sz = numBytes m+ !sz = numBytes m !padSz = ptrSz - sz fillPtr :: Ptr Word8 -> Int -> Integer -> IO ()-fillPtr p sz m = gmpExportInteger m p `onGmpUnsupported` export (sz-1) m+fillPtr p sz m = gmpExportInteger m p `onGmpUnsupported` export (sz - 1) m where export ofs i- | ofs == 0 = pokeByteOff p ofs (fromIntegral i :: Word8)+ | ofs == 0 = pokeByteOff p ofs (fromIntegral i :: Word8) | otherwise = do let (i', b) = i `divMod` 256 pokeByteOff p ofs (fromIntegral b :: Word8)- export (ofs-1) i'+ export (ofs - 1) i' -- | Transform a big endian binary integer representation pointed by a pointer and a size -- into an integer os2ip :: Ptr Word8 -> Int -> IO Integer os2ip ptr ptrSz | ptrSz <= 0 = return 0- | otherwise = gmpImportInteger ptrSz ptr `onGmpUnsupported` loop 0 0 ptr+ | otherwise = gmpImportInteger ptrSz ptr `onGmpUnsupported` loop 0 0 ptr where loop :: Integer -> Int -> Ptr Word8 -> IO Integer loop !acc i !p | i == ptrSz = return acc- | otherwise = do+ | otherwise = do w <- peekByteOff p i :: IO Word8- loop ((acc `shiftL` 8) .|. fromIntegral w) (i+1) p+ loop ((acc `shiftL` 8) .|. fromIntegral w) (i + 1) p
Crypto/Number/Serialize/Internal/LE.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE BangPatterns #-}+ -- | -- Module : Crypto.Number.Serialize.Internal.LE -- License : BSD-style@@ -6,20 +8,19 @@ -- Portability : Good -- -- Fast serialization primitives for integer using raw pointers (little endian)-{-# LANGUAGE BangPatterns #-}-module Crypto.Number.Serialize.Internal.LE- ( i2osp- , i2ospOf- , os2ip- ) where+module Crypto.Number.Serialize.Internal.LE (+ i2osp,+ i2ospOf,+ os2ip,+) where -import Crypto.Number.Compat-import Crypto.Number.Basic-import Data.Bits-import Data.Memory.PtrMethods-import Data.Word (Word8)-import Foreign.Ptr-import Foreign.Storable+import Crypto.Number.Basic+import Crypto.Number.Compat+import Data.Bits+import Data.Memory.PtrMethods+import Data.Word (Word8)+import Foreign.Ptr+import Foreign.Storable -- | Fill a pointer with the little endian binary representation of an integer --@@ -30,25 +31,25 @@ i2osp :: Integer -> Ptr Word8 -> Int -> IO Int i2osp m ptr ptrSz | ptrSz <= 0 = return 0- | m < 0 = return 0- | m == 0 = pokeByteOff ptr 0 (0 :: Word8) >> return 1+ | m < 0 = return 0+ | m == 0 = pokeByteOff ptr 0 (0 :: Word8) >> return 1 | ptrSz < sz = return 0- | otherwise = fillPtr ptr sz m >> return sz+ | otherwise = fillPtr ptr sz m >> return sz where- !sz = numBytes m+ !sz = numBytes m -- | Similar to 'i2osp', except it will pad any remaining space with zero. i2ospOf :: Integer -> Ptr Word8 -> Int -> IO Int i2ospOf m ptr ptrSz | ptrSz <= 0 = return 0- | m < 0 = return 0+ | m < 0 = return 0 | ptrSz < sz = return 0- | otherwise = do+ | otherwise = do memSet ptr 0 ptrSz fillPtr ptr sz m return ptrSz where- !sz = numBytes m+ !sz = numBytes m fillPtr :: Ptr Word8 -> Int -> Integer -> IO () fillPtr p sz m = gmpExportIntegerLE m p `onGmpUnsupported` export 0 m@@ -58,18 +59,19 @@ | otherwise = do let (i', b) = i `divMod` 256 pokeByteOff p ofs (fromIntegral b :: Word8)- export (ofs+1) i'+ export (ofs + 1) i' -- | Transform a little endian binary integer representation pointed by a -- pointer and a size into an integer os2ip :: Ptr Word8 -> Int -> IO Integer os2ip ptr ptrSz | ptrSz <= 0 = return 0- | otherwise = gmpImportIntegerLE ptrSz ptr `onGmpUnsupported` loop 0 (ptrSz-1) ptr+ | otherwise =+ gmpImportIntegerLE ptrSz ptr `onGmpUnsupported` loop 0 (ptrSz - 1) ptr where loop :: Integer -> Int -> Ptr Word8 -> IO Integer loop !acc i !p- | i < 0 = return acc- | otherwise = do+ | i < 0 = return acc+ | otherwise = do w <- peekByteOff p i :: IO Word8- loop ((acc `shiftL` 8) .|. fromIntegral w) (i-1) p+ loop ((acc `shiftL` 8) .|. fromIntegral w) (i - 1) p
Crypto/Number/Serialize/LE.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE BangPatterns #-}+ -- | -- Module : Crypto.Number.Serialize.LE -- License : BSD-style@@ -6,17 +8,16 @@ -- Portability : Good -- -- Fast serialization primitives for integer (little endian)-{-# LANGUAGE BangPatterns #-}-module Crypto.Number.Serialize.LE- ( i2osp- , os2ip- , i2ospOf- , i2ospOf_- ) where+module Crypto.Number.Serialize.LE (+ i2osp,+ os2ip,+ i2ospOf,+ i2ospOf_,+) where -import Crypto.Number.Basic-import Crypto.Internal.Compat (unsafeDoIO) import qualified Crypto.Internal.ByteArray as B+import Crypto.Internal.Compat (unsafeDoIO)+import Crypto.Number.Basic import qualified Crypto.Number.Serialize.Internal.LE as Internal -- | @os2ip@ converts a byte string into a positive integer.@@ -27,23 +28,24 @@ -- -- The first byte is LSB (least significant byte); the last byte is the MSB (most significant byte) i2osp :: B.ByteArray ba => Integer -> ba-i2osp 0 = B.allocAndFreeze 1 (\p -> Internal.i2osp 0 p 1 >> return ())+i2osp 0 = B.allocAndFreeze 1 (\p -> Internal.i2osp 0 p 1 >> return ()) i2osp m = B.allocAndFreeze sz (\p -> Internal.i2osp m p sz >> return ()) where- !sz = numBytes m+ !sz = numBytes m -- | Just like 'i2osp', but takes an extra parameter for size. -- If the number is too big to fit in @len@ bytes, 'Nothing' is returned -- otherwise the number is padded with 0 to fit the @len@ required.-{-# INLINABLE i2ospOf #-}+{-# INLINEABLE i2ospOf #-} i2ospOf :: B.ByteArray ba => Int -> Integer -> Maybe ba i2ospOf len m- | len <= 0 = Nothing- | m < 0 = Nothing- | sz > len = Nothing- | otherwise = Just $ B.unsafeCreate len (\p -> Internal.i2ospOf m p len >> return ())+ | len <= 0 = Nothing+ | m < 0 = Nothing+ | sz > len = Nothing+ | otherwise =+ Just $ B.unsafeCreate len (\p -> Internal.i2ospOf m p len >> return ()) where- !sz = numBytes m+ !sz = numBytes m -- | Just like 'i2ospOf' except that it doesn't expect a failure: i.e. -- an integer larger than the number of output bytes requested.
Crypto/OTP.hs view
@@ -25,33 +25,30 @@ -- >>> import Data.Time.Clock.POSIX -- >>> -- >>> let getOTPTime = getPOSIXTime >>= \t -> return (floor t :: OTPTime)-----module Crypto.OTP- ( OTP- , OTPDigits (..)- , OTPTime- , hotp- , resynchronize- , totp- , totpVerify- , TOTPParams- , ClockSkew (..)- , defaultTOTPParams- , mkTOTPParams- )+module Crypto.OTP (+ OTP,+ OTPDigits (..),+ OTPTime,+ hotp,+ resynchronize,+ totp,+ totpVerify,+ TOTPParams,+ ClockSkew (..),+ defaultTOTPParams,+ mkTOTPParams,+) where -import Data.Bits (shiftL, (.&.), (.|.))-import Data.ByteArray.Mapping (fromW64BE)-import Data.List (elemIndex)-import Data.Word-import Control.Monad (unless)-import Crypto.Hash (HashAlgorithm, SHA1(..))-import Crypto.MAC.HMAC-import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes)+import Control.Monad (unless)+import Crypto.Hash (HashAlgorithm, SHA1 (..))+import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes) import qualified Crypto.Internal.ByteArray as B-+import Crypto.MAC.HMAC+import Data.Bits (shiftL, (.&.), (.|.))+import Data.ByteArray.Mapping (fromW64BE)+import Data.List (elemIndex)+import Data.Word -- | A one-time password which is a sequence of 4 to 9 digits. type OTP = Word32@@ -63,7 +60,9 @@ -- | An integral time value in seconds. type OTPTime = Word64 -hotp :: forall hash key. (HashAlgorithm hash, ByteArrayAccess key)+hotp+ :: forall hash key+ . (HashAlgorithm hash, ByteArrayAccess key) => hash -> OTPDigits -- ^ Number of digits in the HOTP value extracted from the calculated HMAC@@ -77,14 +76,16 @@ where mac = hmac k (fromW64BE c :: Bytes) :: HMAC hash offset = fromIntegral (B.index mac (B.length mac - 1) .&. 0xf)- dt = (fromIntegral (B.index mac offset .&. 0x7f) `shiftL` 24) .|.- (fromIntegral (B.index mac (offset + 1) .&. 0xff) `shiftL` 16) .|.- (fromIntegral (B.index mac (offset + 2) .&. 0xff) `shiftL` 8) .|.- fromIntegral (B.index mac (offset + 3) .&. 0xff)+ dt =+ (fromIntegral (B.index mac offset .&. 0x7f) `shiftL` 24)+ .|. (fromIntegral (B.index mac (offset + 1) .&. 0xff) `shiftL` 16)+ .|. (fromIntegral (B.index mac (offset + 2) .&. 0xff) `shiftL` 8)+ .|. fromIntegral (B.index mac (offset + 3) .&. 0xff) -- | Attempt to resynchronize the server's counter value -- with the client, given a sequence of HOTP values.-resynchronize :: (HashAlgorithm hash, ByteArrayAccess key)+resynchronize+ :: (HashAlgorithm hash, ByteArrayAccess key) => hash -> OTPDigits -> Word16@@ -105,11 +106,11 @@ checkExtraOtps (c + offBy + 1) extras where checkExtraOtps ctr [] = Just ctr- checkExtraOtps ctr (p:ps)+ checkExtraOtps ctr (p : ps) | hotp h d k ctr /= p = Nothing- | otherwise = checkExtraOtps (ctr + 1) ps+ | otherwise = checkExtraOtps (ctr + 1) ps - range = map (hotp h d k)[c..c + fromIntegral s]+ range = map (hotp h d k) [c .. c + fromIntegral s] digitsPower :: OTPDigits -> Word32 digitsPower OTP4 = 10000@@ -119,17 +120,18 @@ digitsPower OTP8 = 100000000 digitsPower OTP9 = 1000000000 - data TOTPParams h = TP !h !OTPTime !Word16 !OTPDigits !ClockSkew deriving (Show) -data ClockSkew = NoSkew | OneStep | TwoSteps | ThreeSteps | FourSteps deriving (Enum, Show)+data ClockSkew = NoSkew | OneStep | TwoSteps | ThreeSteps | FourSteps+ deriving (Enum, Show) -- | The default TOTP configuration. defaultTOTPParams :: TOTPParams SHA1 defaultTOTPParams = TP SHA1 0 30 OTP6 TwoSteps -- | Create a TOTP configuration with customized parameters.-mkTOTPParams :: (HashAlgorithm hash)+mkTOTPParams+ :: HashAlgorithm hash => hash -> OTPTime -- ^ The T0 parameter in seconds. This is the Unix time from which to start@@ -149,7 +151,8 @@ return (TP h t0 x d skew) -- | Calculate a totp value for the given time.-totp :: (HashAlgorithm hash, ByteArrayAccess key)+totp+ :: (HashAlgorithm hash, ByteArrayAccess key) => TOTPParams hash -> key -- ^ The shared secret@@ -161,7 +164,8 @@ -- | Check a supplied TOTP value is valid for the given time, -- within the window defined by the skew parameter.-totpVerify :: (HashAlgorithm hash, ByteArrayAccess key)+totpVerify+ :: (HashAlgorithm hash, ByteArrayAccess key) => TOTPParams hash -> key -> OTPTime@@ -172,7 +176,7 @@ t = timeToCounter now t0 x window = fromIntegral (fromEnum skew) range 0 acc = t : acc- range n acc = range (n-1) ((t-n) : (t+n) : acc)+ range n acc = range (n - 1) ((t - n) : (t + n) : acc) timeToCounter :: Word64 -> Word64 -> Word16 -> Word64 timeToCounter now t0 x = (now - t0) `div` fromIntegral x
Crypto/PubKey/Curve25519.hs view
@@ -1,3 +1,7 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE ScopedTypeVariables #-}+ -- | -- Module : Crypto.PubKey.Curve25519 -- License : BSD-style@@ -6,55 +10,59 @@ -- Portability : unknown -- -- Curve25519 support----{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE ScopedTypeVariables #-}-module Crypto.PubKey.Curve25519- ( SecretKey- , PublicKey- , DhSecret+module Crypto.PubKey.Curve25519 (+ SecretKey,+ PublicKey,+ DhSecret,+ -- * Smart constructors- , dhSecret- , publicKey- , secretKey+ dhSecret,+ publicKey,+ secretKey,+ -- * Methods- , dh- , toPublic- , generateSecretKey- ) where+ dh,+ toPublic,+ generateSecretKey,+) where -import Data.Bits-import Data.Word-import Foreign.Ptr-import Foreign.Storable-import GHC.Ptr+import Data.Bits+import Data.Word+import Foreign.Ptr+import Foreign.Storable+import GHC.Ptr -import Crypto.Error-import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Crypto.Internal.ByteArray (ByteArrayAccess, ScrubbedBytes, Bytes, withByteArray)+import Crypto.Error+import Crypto.Internal.ByteArray (+ ByteArrayAccess,+ Bytes,+ ScrubbedBytes,+ withByteArray,+ ) import qualified Crypto.Internal.ByteArray as B-import Crypto.Random+import Crypto.Internal.Compat+import Crypto.Internal.Imports+import Crypto.Random -- | A Curve25519 Secret key newtype SecretKey = SecretKey ScrubbedBytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | A Curve25519 public key newtype PublicKey = PublicKey Bytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | A Curve25519 Diffie Hellman secret related to a -- public key and a secret key. newtype DhSecret = DhSecret ScrubbedBytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | Try to build a public key from a bytearray publicKey :: ByteArrayAccess bs => bs -> CryptoFailable PublicKey publicKey bs- | B.length bs == 32 = CryptoPassed $ PublicKey $ B.copyAndFreeze bs (\_ -> return ())- | otherwise = CryptoFailed CryptoError_PublicKeySizeInvalid+ | B.length bs == 32 =+ CryptoPassed $ PublicKey $ B.copyAndFreeze bs (\_ -> return ())+ | otherwise = CryptoFailed CryptoError_PublicKeySizeInvalid -- | Try to build a secret key from a bytearray secretKey :: ByteArrayAccess bs => bs -> CryptoFailable SecretKey@@ -67,14 +75,14 @@ else return $ CryptoFailed CryptoError_SecretKeyStructureInvalid | otherwise = CryptoFailed CryptoError_SecretKeySizeInvalid where- -- e[0] &= 0xf8;- -- e[31] &= 0x7f;- -- e[31] |= 40;- isValidPtr :: Ptr Word8 -> IO Bool- isValidPtr _ = do- --b0 <- peekElemOff inp 0- --b31 <- peekElemOff inp 31- return True+ -- e[0] &= 0xf8;+ -- e[31] &= 0x7f;+ -- e[31] |= 40;+ isValidPtr :: Ptr Word8 -> IO Bool+ isValidPtr _ = do+ -- b0 <- peekElemOff inp 0+ -- b31 <- peekElemOff inp 31+ return True {- return $ and [ testBit b0 0 == False , testBit b0 1 == False@@ -88,29 +96,34 @@ -- | Create a DhSecret from a bytearray object dhSecret :: ByteArrayAccess b => b -> CryptoFailable DhSecret dhSecret bs- | B.length bs == 32 = CryptoPassed $ DhSecret $ B.copyAndFreeze bs (\_ -> return ())- | otherwise = CryptoFailed CryptoError_SharedSecretSizeInvalid+ | B.length bs == 32 =+ CryptoPassed $ DhSecret $ B.copyAndFreeze bs (\_ -> return ())+ | otherwise = CryptoFailed CryptoError_SharedSecretSizeInvalid -- | Compute the Diffie Hellman secret from a public key and a secret key. -- -- This implementation may return an all-zero value as it does not check for -- the condition. dh :: PublicKey -> SecretKey -> DhSecret-dh (PublicKey pub) (SecretKey sec) = DhSecret <$>- B.allocAndFreeze 32 $ \result ->- withByteArray sec $ \psec ->- withByteArray pub $ \ppub ->- ccrypton_curve25519 result psec ppub+dh (PublicKey pub) (SecretKey sec) = DhSecret+ <$> B.allocAndFreeze 32+ $ \result ->+ withByteArray sec $ \psec ->+ withByteArray pub $ \ppub ->+ ccrypton_curve25519 result psec ppub {-# NOINLINE dh #-} -- | Create a public key from a secret key toPublic :: SecretKey -> PublicKey-toPublic (SecretKey sec) = PublicKey <$>- B.allocAndFreeze 32 $ \result ->- withByteArray sec $ \psec ->- ccrypton_curve25519 result psec basePoint+toPublic (SecretKey sec) = PublicKey+ <$> B.allocAndFreeze 32+ $ \result ->+ withByteArray sec $ \psec ->+ ccrypton_curve25519 result psec basePoint where- basePoint = Ptr "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#+ basePoint =+ Ptr+ "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"# {-# NOINLINE toPublic #-} -- | Generate a secret key.@@ -126,7 +139,11 @@ modifyByte p n f = peekByteOff p n >>= pokeByteOff p n . f foreign import ccall "crypton_curve25519_donna"- ccrypton_curve25519 :: Ptr Word8 -- ^ public- -> Ptr Word8 -- ^ secret- -> Ptr Word8 -- ^ basepoint- -> IO ()+ ccrypton_curve25519+ :: Ptr Word8+ -- ^ public+ -> Ptr Word8+ -- ^ secret+ -> Ptr Word8+ -- ^ basepoint+ -> IO ()
Crypto/PubKey/Curve448.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.PubKey.Curve448 -- License : BSD-style@@ -10,50 +12,56 @@ -- Internally uses Decaf point compression to omit the cofactor -- and implementation by Mike Hamburg. Externally API and -- data types are compatible with the encoding specified in RFC 7748.----{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.PubKey.Curve448- ( SecretKey- , PublicKey- , DhSecret+module Crypto.PubKey.Curve448 (+ SecretKey,+ PublicKey,+ DhSecret,+ -- * Smart constructors- , dhSecret- , publicKey- , secretKey+ dhSecret,+ publicKey,+ secretKey,+ -- * Methods- , dh- , toPublic- , generateSecretKey- ) where+ dh,+ toPublic,+ generateSecretKey,+) where -import Data.Word-import Foreign.Ptr+import Data.Word+import Foreign.Ptr -import Crypto.Error-import Crypto.Random-import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Crypto.Internal.ByteArray (ByteArrayAccess, ScrubbedBytes, Bytes, withByteArray)+import Crypto.Error+import Crypto.Internal.ByteArray (+ ByteArrayAccess,+ Bytes,+ ScrubbedBytes,+ withByteArray,+ ) import qualified Crypto.Internal.ByteArray as B+import Crypto.Internal.Compat+import Crypto.Internal.Imports+import Crypto.Random -- | A Curve448 Secret key newtype SecretKey = SecretKey ScrubbedBytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | A Curve448 public key newtype PublicKey = PublicKey Bytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | A Curve448 Diffie Hellman secret related to a -- public key and a secret key. newtype DhSecret = DhSecret ScrubbedBytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | Try to build a public key from a bytearray publicKey :: ByteArrayAccess bs => bs -> CryptoFailable PublicKey publicKey bs- | B.length bs == x448_bytes = CryptoPassed $ PublicKey $ B.copyAndFreeze bs (\_ -> return ())- | otherwise = CryptoFailed CryptoError_PublicKeySizeInvalid+ | B.length bs == x448_bytes =+ CryptoPassed $ PublicKey $ B.copyAndFreeze bs (\_ -> return ())+ | otherwise = CryptoFailed CryptoError_PublicKeySizeInvalid -- | Try to build a secret key from a bytearray secretKey :: ByteArrayAccess bs => bs -> CryptoFailable SecretKey@@ -66,35 +74,38 @@ else return $ CryptoFailed CryptoError_SecretKeyStructureInvalid | otherwise = CryptoFailed CryptoError_SecretKeySizeInvalid where- isValidPtr :: Ptr Word8 -> IO Bool- isValidPtr _ =- return True+ isValidPtr :: Ptr Word8 -> IO Bool+ isValidPtr _ =+ return True {-# NOINLINE secretKey #-} -- | Create a DhSecret from a bytearray object dhSecret :: ByteArrayAccess b => b -> CryptoFailable DhSecret dhSecret bs- | B.length bs == x448_bytes = CryptoPassed $ DhSecret $ B.copyAndFreeze bs (\_ -> return ())- | otherwise = CryptoFailed CryptoError_SharedSecretSizeInvalid+ | B.length bs == x448_bytes =+ CryptoPassed $ DhSecret $ B.copyAndFreeze bs (\_ -> return ())+ | otherwise = CryptoFailed CryptoError_SharedSecretSizeInvalid -- | Compute the Diffie Hellman secret from a public key and a secret key. -- -- This implementation may return an all-zero value as it does not check for -- the condition. dh :: PublicKey -> SecretKey -> DhSecret-dh (PublicKey pub) (SecretKey sec) = DhSecret <$>- B.allocAndFreeze x448_bytes $ \result ->- withByteArray sec $ \psec ->- withByteArray pub $ \ppub ->- decaf_x448 result ppub psec+dh (PublicKey pub) (SecretKey sec) = DhSecret+ <$> B.allocAndFreeze x448_bytes+ $ \result ->+ withByteArray sec $ \psec ->+ withByteArray pub $ \ppub ->+ decaf_x448 result ppub psec {-# NOINLINE dh #-} -- | Create a public key from a secret key toPublic :: SecretKey -> PublicKey-toPublic (SecretKey sec) = PublicKey <$>- B.allocAndFreeze x448_bytes $ \result ->- withByteArray sec $ \psec ->- decaf_x448_derive_public_key result psec+toPublic (SecretKey sec) = PublicKey+ <$> B.allocAndFreeze x448_bytes+ $ \result ->+ withByteArray sec $ \psec ->+ decaf_x448_derive_public_key result psec {-# NOINLINE toPublic #-} -- | Generate a secret key.@@ -105,12 +116,19 @@ x448_bytes = 448 `quot` 8 foreign import ccall "crypton_decaf_x448"- decaf_x448 :: Ptr Word8 -- ^ public- -> Ptr Word8 -- ^ basepoint- -> Ptr Word8 -- ^ secret- -> IO ()+ decaf_x448+ :: Ptr Word8+ -- ^ public+ -> Ptr Word8+ -- ^ basepoint+ -> Ptr Word8+ -- ^ secret+ -> IO () foreign import ccall "crypton_decaf_x448_derive_public_key"- decaf_x448_derive_public_key :: Ptr Word8 -- ^ public- -> Ptr Word8 -- ^ secret- -> IO ()+ decaf_x448_derive_public_key+ :: Ptr Word8+ -- ^ public+ -> Ptr Word8+ -- ^ secret+ -> IO ()
Crypto/PubKey/DH.hs view
@@ -1,28 +1,28 @@+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.PubKey.DH -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.PubKey.DH- ( Params(..)- , PublicNumber(..)- , PrivateNumber(..)- , SharedKey(..)- , generateParams- , generatePrivate- , calculatePublic- , generatePublic- , getShared- ) where+module Crypto.PubKey.DH (+ Params (..),+ PublicNumber (..),+ PrivateNumber (..),+ SharedKey (..),+ generateParams,+ generatePrivate,+ calculatePublic,+ generatePublic,+ getShared,+) where import Crypto.Internal.Imports+import Crypto.Number.Generate (generateMax) import Crypto.Number.ModArithmetic (expSafe) import Crypto.Number.Prime (generateSafePrime)-import Crypto.Number.Generate (generateMax) import Crypto.Number.Serialize (i2ospOf_) import Crypto.Random.Types import Data.ByteArray (ByteArrayAccess, ScrubbedBytes)@@ -33,29 +33,33 @@ { params_p :: Integer , params_g :: Integer , params_bits :: Int- } deriving (Show,Read,Eq,Data)+ }+ deriving (Show, Read, Eq, Data) instance NFData Params where rnf (Params p g bits) = rnf p `seq` rnf g `seq` bits `seq` () -- | Represent Diffie Hellman public number Y. newtype PublicNumber = PublicNumber Integer- deriving (Show,Read,Eq,Enum,Real,Num,Ord,NFData)+ deriving (Show, Read, Eq, Enum, Real, Num, Ord, NFData) -- | Represent Diffie Hellman private number X. newtype PrivateNumber = PrivateNumber Integer- deriving (Show,Read,Eq,Enum,Real,Num,Ord,NFData)+ deriving (Show, Read, Eq, Enum, Real, Num, Ord, NFData) -- | Represent Diffie Hellman shared secret. newtype SharedKey = SharedKey ScrubbedBytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | generate params from a specific generator (2 or 5 are common values) -- we generate a safe prime (a prime number of the form 2p+1 where p is also prime)-generateParams :: MonadRandom m =>- Int -- ^ number of bits- -> Integer -- ^ generator- -> m Params+generateParams+ :: MonadRandom m+ => Int+ -- ^ number of bits+ -> Integer+ -- ^ generator+ -> m Params generateParams bits generator = (\p -> Params p generator bits) <$> generateSafePrime bits @@ -75,6 +79,7 @@ -- DEPRECATED use calculatePublic generatePublic :: Params -> PrivateNumber -> PublicNumber generatePublic = calculatePublic+ -- commented until 0.3 {-# DEPRECATED generatePublic "use calculatePublic" #-} -- | generate a shared key using our private number and the other party public number
Crypto/PubKey/DSA.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE DeriveDataTypeable #-}+ -- | -- Module : Crypto.PubKey.DSA -- License : BSD-style@@ -6,37 +8,39 @@ -- Portability : Good -- -- An implementation of the Digital Signature Algorithm (DSA)-{-# LANGUAGE DeriveDataTypeable #-}-module Crypto.PubKey.DSA- ( Params(..)- , Signature(..)- , PublicKey(..)- , PrivateKey(..)- , PublicNumber- , PrivateNumber+module Crypto.PubKey.DSA (+ Params (..),+ Signature (..),+ PublicKey (..),+ PrivateKey (..),+ PublicNumber,+ PrivateNumber,+ -- * Generation- , generatePrivate- , calculatePublic+ generatePrivate,+ calculatePublic,+ -- * Signature primitive- , sign- , signWith+ sign,+ signWith,+ -- * Verification primitive- , verify- -- * Key pair- , KeyPair(..)- , toPublicKey- , toPrivateKey- ) where+ verify, + -- * Key pair+ KeyPair (..),+ toPublicKey,+ toPrivateKey,+) where import Data.Data import Data.Maybe -import Crypto.Number.ModArithmetic (expFast, expSafe, inverse)-import Crypto.Number.Generate+import Crypto.Hash import Crypto.Internal.ByteArray (ByteArrayAccess) import Crypto.Internal.Imports-import Crypto.Hash+import Crypto.Number.Generate+import Crypto.Number.ModArithmetic (expFast, expSafe, inverse) import Crypto.PubKey.Internal (dsaTruncHash) import Crypto.Random.Types @@ -48,28 +52,38 @@ -- | Represent DSA parameters namely P, G, and Q. data Params = Params- { params_p :: Integer -- ^ DSA p- , params_g :: Integer -- ^ DSA g- , params_q :: Integer -- ^ DSA q- } deriving (Show,Read,Eq,Data)+ { params_p :: Integer+ -- ^ DSA p+ , params_g :: Integer+ -- ^ DSA g+ , params_q :: Integer+ -- ^ DSA q+ }+ deriving (Show, Read, Eq, Data) instance NFData Params where rnf (Params p g q) = p `seq` g `seq` q `seq` () -- | Represent a DSA signature namely R and S. data Signature = Signature- { sign_r :: Integer -- ^ DSA r- , sign_s :: Integer -- ^ DSA s- } deriving (Show,Read,Eq,Data)+ { sign_r :: Integer+ -- ^ DSA r+ , sign_s :: Integer+ -- ^ DSA s+ }+ deriving (Show, Read, Eq, Data) instance NFData Signature where rnf (Signature r s) = r `seq` s `seq` () -- | Represent a DSA public key. data PublicKey = PublicKey- { public_params :: Params -- ^ DSA parameters- , public_y :: PublicNumber -- ^ DSA public Y- } deriving (Show,Read,Eq,Data)+ { public_params :: Params+ -- ^ DSA parameters+ , public_y :: PublicNumber+ -- ^ DSA public Y+ }+ deriving (Show, Read, Eq, Data) instance NFData PublicKey where rnf (PublicKey params y) = y `seq` params `seq` ()@@ -79,16 +93,19 @@ -- Only x need to be secret. -- the DSA parameters are publicly shared with the other side. data PrivateKey = PrivateKey- { private_params :: Params -- ^ DSA parameters- , private_x :: PrivateNumber -- ^ DSA private X- } deriving (Show,Read,Eq,Data)+ { private_params :: Params+ -- ^ DSA parameters+ , private_x :: PrivateNumber+ -- ^ DSA private X+ }+ deriving (Show, Read, Eq, Data) instance NFData PrivateKey where rnf (PrivateKey params x) = x `seq` params `seq` () -- | Represent a DSA key pair data KeyPair = KeyPair Params PublicNumber PrivateNumber- deriving (Show,Read,Eq,Data)+ deriving (Show, Read, Eq, Data) instance NFData KeyPair where rnf (KeyPair params y x) = x `seq` y `seq` params `seq` ()@@ -111,44 +128,55 @@ calculatePublic (Params p g _) x = expSafe g x p -- | sign message using the private key and an explicit k number.-signWith :: (ByteArrayAccess msg, HashAlgorithm hash)- => Integer -- ^ k random number- -> PrivateKey -- ^ private key- -> hash -- ^ hash function- -> msg -- ^ message to sign- -> Maybe Signature+signWith+ :: (ByteArrayAccess msg, HashAlgorithm hash)+ => Integer+ -- ^ k random number+ -> PrivateKey+ -- ^ private key+ -> hash+ -- ^ hash function+ -> msg+ -- ^ message to sign+ -> Maybe Signature signWith k pk hashAlg msg- | r == 0 || s == 0 = Nothing- | otherwise = Just $ Signature r s- where -- parameters- (Params p g q) = private_params pk- x = private_x pk- -- compute r,s- kInv = fromJust $ inverse k q- hm = dsaTruncHash hashAlg msg q- r = expSafe g k p `mod` q- s = (kInv * (hm + x * r)) `mod` q+ | r == 0 || s == 0 = Nothing+ | otherwise = Just $ Signature r s+ where+ -- parameters+ (Params p g q) = private_params pk+ x = private_x pk+ -- compute r,s+ kInv = fromJust $ inverse k q+ hm = dsaTruncHash hashAlg msg q+ r = expSafe g k p `mod` q+ s = (kInv * (hm + x * r)) `mod` q -- | sign message using the private key.-sign :: (ByteArrayAccess msg, HashAlgorithm hash, MonadRandom m) => PrivateKey -> hash -> msg -> m Signature+sign+ :: (ByteArrayAccess msg, HashAlgorithm hash, MonadRandom m)+ => PrivateKey -> hash -> msg -> m Signature sign pk hashAlg msg = do k <- generateMax q case signWith k pk hashAlg msg of- Nothing -> sign pk hashAlg msg+ Nothing -> sign pk hashAlg msg Just sig -> return sig where (Params _ _ q) = private_params pk -- | verify a bytestring using the public key.-verify :: (ByteArrayAccess msg, HashAlgorithm hash) => hash -> PublicKey -> Signature -> msg -> Bool+verify+ :: (ByteArrayAccess msg, HashAlgorithm hash)+ => hash -> PublicKey -> Signature -> msg -> Bool verify hashAlg pk (Signature r s) m -- Reject the signature if either 0 < r < q or 0 < s < q is not satisfied. | r <= 0 || r >= q || s <= 0 || s >= q = False- | otherwise = v == r- where (Params p g q) = public_params pk- y = public_y pk- hm = dsaTruncHash hashAlg m q- w = fromJust $ inverse s q- u1 = (hm*w) `mod` q- u2 = (r*w) `mod` q- v = ((expFast g u1 p) * (expFast y u2 p)) `mod` p `mod` q+ | otherwise = v == r+ where+ (Params p g q) = public_params pk+ y = public_y pk+ hm = dsaTruncHash hashAlg m q+ w = fromJust $ inverse s q+ u1 = (hm * w) `mod` q+ u2 = (r * w) `mod` q+ v = ((expFast g u1 p) * (expFast y u2 p)) `mod` p `mod` q
Crypto/PubKey/ECC/DH.hs view
@@ -6,25 +6,31 @@ -- Portability : unknown -- -- Elliptic curve Diffie Hellman----module Crypto.PubKey.ECC.DH- (- Curve- , PublicPoint- , PrivateNumber- , SharedKey(..)- , generatePrivate- , calculatePublic- , getShared- ) where+module Crypto.PubKey.ECC.DH (+ Curve,+ PublicPoint,+ PrivateNumber,+ SharedKey (..),+ generatePrivate,+ calculatePublic,+ getShared,+) where import Crypto.Number.Generate (generateMax) import Crypto.Number.Serialize (i2ospOf_)+import Crypto.PubKey.DH (SharedKey (..)) import Crypto.PubKey.ECC.Prim (pointMul)+import Crypto.PubKey.ECC.Types (+ Curve,+ Point (..),+ PrivateNumber,+ PublicPoint,+ common_curve,+ curveSizeBits,+ ecc_g,+ ecc_n,+ ) import Crypto.Random.Types-import Crypto.PubKey.DH (SharedKey(..))-import Crypto.PubKey.ECC.Types (PublicPoint, PrivateNumber, Curve, Point(..), curveSizeBits)-import Crypto.PubKey.ECC.Types (ecc_n, ecc_g, common_curve) -- | Generating a private number d. generatePrivate :: MonadRandom m => Curve -> m PrivateNumber@@ -44,5 +50,7 @@ getShared :: Curve -> PrivateNumber -> PublicPoint -> SharedKey getShared curve db qa = SharedKey $ i2ospOf_ ((nbBits + 7) `div` 8) x where- Point x _ = pointMul curve db qa- nbBits = curveSizeBits curve+ x = case pointMul curve db qa of+ Point x' _ -> x'+ _ -> error "getShared"+ nbBits = curveSizeBits curve
Crypto/PubKey/ECC/ECDSA.hs view
@@ -1,56 +1,83 @@+{-# LANGUAGE DeriveDataTypeable #-}+ -- | /WARNING:/ Signature operations may leak the private key. Signature verification -- should be safe.-{-# LANGUAGE DeriveDataTypeable #-}-module Crypto.PubKey.ECC.ECDSA- ( Signature(..)- , PublicPoint- , PublicKey(..)- , PrivateNumber- , PrivateKey(..)- , KeyPair(..)- , toPublicKey- , toPrivateKey- , signWith- , signDigestWith- , sign- , signDigest- , verify- , verifyDigest- ) where+module Crypto.PubKey.ECC.ECDSA (+ Signature (..),+ ExtendedSignature (..),+ PublicPoint,+ PublicKey (..),+ PrivateNumber,+ PrivateKey (..),+ KeyPair (..),+ toPublicKey,+ toPrivateKey,+ signWith,+ signDigestWith,+ signExtendedDigestWith,+ sign,+ signDigest,+ signExtendedDigest,+ verify,+ verifyDigest,+ recover,+ recoverDigest,+ deterministicNonce,+) where import Control.Monad+import Data.Bits+import Data.ByteArray (ByteArrayAccess, ScrubbedBytes) import Data.Data import Crypto.Hash-import Crypto.Internal.ByteArray (ByteArrayAccess)-import Crypto.Number.ModArithmetic (inverse)+import Crypto.Number.Basic import Crypto.Number.Generate-import Crypto.PubKey.ECC.Types+import Crypto.Number.ModArithmetic (inverse)+import Crypto.Number.Serialize import Crypto.PubKey.ECC.Prim+import Crypto.PubKey.ECC.Types import Crypto.PubKey.Internal (dsaTruncHashDigest)+import Crypto.Random.HmacDRG import Crypto.Random.Types -- | Represent a ECDSA signature namely R and S. data Signature = Signature- { sign_r :: Integer -- ^ ECDSA r- , sign_s :: Integer -- ^ ECDSA s- } deriving (Show,Read,Eq,Data)+ { sign_r :: Integer+ -- ^ ECDSA r+ , sign_s :: Integer+ -- ^ ECDSA s+ }+ deriving (Show, Read, Eq, Data) +-- | ECDSA signature with public key recovery information.+data ExtendedSignature = ExtendedSignature+ { index :: Integer+ -- ^ Index of the X coordinate+ , parity :: Bool+ -- ^ Parity of the Y coordinate+ , signature :: Signature+ -- ^ Inner signature+ }+ deriving (Show, Read, Eq, Data)+ -- | ECDSA Private Key. data PrivateKey = PrivateKey { private_curve :: Curve- , private_d :: PrivateNumber- } deriving (Show,Read,Eq,Data)+ , private_d :: PrivateNumber+ }+ deriving (Show, Read, Eq, Data) -- | ECDSA Public Key. data PublicKey = PublicKey { public_curve :: Curve- , public_q :: PublicPoint- } deriving (Show,Read,Eq,Data)+ , public_q :: PublicPoint+ }+ deriving (Show, Read, Eq, Data) -- | ECDSA Key Pair. data KeyPair = KeyPair Curve PublicPoint PrivateNumber- deriving (Show,Read,Eq,Data)+ deriving (Show, Read, Eq, Data) -- | Public key of a ECDSA Key pair. toPublicKey :: KeyPair -> PublicKey@@ -63,71 +90,144 @@ -- | Sign digest using the private key and an explicit k number. -- -- /WARNING:/ Vulnerable to timing attacks.-signDigestWith :: HashAlgorithm hash- => Integer -- ^ k random number- -> PrivateKey -- ^ private key- -> Digest hash -- ^ digest to sign- -> Maybe Signature-signDigestWith k (PrivateKey curve d) digest = do+signExtendedDigestWith+ :: HashAlgorithm hash+ => Integer+ -- ^ k random number+ -> PrivateKey+ -- ^ private key+ -> Digest hash+ -- ^ digest to sign+ -> Maybe ExtendedSignature+signExtendedDigestWith k (PrivateKey curve d) digest = do let z = dsaTruncHashDigest digest n CurveCommon _ _ g n _ = common_curve curve- let point = pointMul curve k g- r <- case point of- PointO -> Nothing- Point x _ -> return $ x `mod` n+ (i, r, p) <- pointDecompose curve $ pointMul curve k g kInv <- inverse k n let s = kInv * (z + r * d) `mod` n when (r == 0 || s == 0) Nothing- return $ Signature r s+ return $+ if s <= n `unsafeShiftR` 1+ then ExtendedSignature i p $ Signature r s+ else ExtendedSignature i (not p) $ Signature r (n - s) +-- | Sign digest using the private key and an explicit k number.+--+-- /WARNING:/ Vulnerable to timing attacks.+signDigestWith+ :: HashAlgorithm hash+ => Integer+ -- ^ k random number+ -> PrivateKey+ -- ^ private key+ -> Digest hash+ -- ^ digest to sign+ -> Maybe Signature+signDigestWith k pk digest = signature <$> signExtendedDigestWith k pk digest+ -- | Sign message using the private key and an explicit k number. -- -- /WARNING:/ Vulnerable to timing attacks.-signWith :: (ByteArrayAccess msg, HashAlgorithm hash)- => Integer -- ^ k random number- -> PrivateKey -- ^ private key- -> hash -- ^ hash function- -> msg -- ^ message to sign- -> Maybe Signature+signWith+ :: (ByteArrayAccess msg, HashAlgorithm hash)+ => Integer+ -- ^ k random number+ -> PrivateKey+ -- ^ private key+ -> hash+ -- ^ hash function+ -> msg+ -- ^ message to sign+ -> Maybe Signature signWith k pk hashAlg msg = signDigestWith k pk (hashWith hashAlg msg) -- | Sign digest using the private key. -- -- /WARNING:/ Vulnerable to timing attacks.-signDigest :: (HashAlgorithm hash, MonadRandom m)- => PrivateKey -> Digest hash -> m Signature-signDigest pk digest = do+signExtendedDigest+ :: (HashAlgorithm hash, MonadRandom m)+ => PrivateKey -> Digest hash -> m ExtendedSignature+signExtendedDigest pk digest = do k <- generateBetween 1 (n - 1)- case signDigestWith k pk digest of- Nothing -> signDigest pk digest- Just sig -> return sig- where n = ecc_n . common_curve $ private_curve pk+ case signExtendedDigestWith k pk digest of+ Nothing -> signExtendedDigest pk digest+ Just sig -> return sig+ where+ n = ecc_n . common_curve $ private_curve pk +-- | Sign digest using the private key.+--+-- /WARNING:/ Vulnerable to timing attacks.+signDigest+ :: (HashAlgorithm hash, MonadRandom m)+ => PrivateKey -> Digest hash -> m Signature+signDigest pk digest = signature <$> signExtendedDigest pk digest+ -- | Sign message using the private key. -- -- /WARNING:/ Vulnerable to timing attacks.-sign :: (ByteArrayAccess msg, HashAlgorithm hash, MonadRandom m)- => PrivateKey -> hash -> msg -> m Signature+sign+ :: (ByteArrayAccess msg, HashAlgorithm hash, MonadRandom m)+ => PrivateKey -> hash -> msg -> m Signature sign pk hashAlg msg = signDigest pk (hashWith hashAlg msg) -- | Verify a digest using the public key.-verifyDigest :: HashAlgorithm hash => PublicKey -> Signature -> Digest hash -> Bool+verifyDigest+ :: HashAlgorithm hash => PublicKey -> Signature -> Digest hash -> Bool verifyDigest (PublicKey _ PointO) _ _ = False verifyDigest pk@(PublicKey curve q) (Signature r s) digest | r < 1 || r >= n || s < 1 || s >= n = False | otherwise = maybe False (r ==) $ do w <- inverse s n- let z = dsaTruncHashDigest digest n+ let z = dsaTruncHashDigest digest n u1 = z * w `mod` n u2 = r * w `mod` n- x = pointAddTwoMuls curve u1 g u2 q+ x = pointAddTwoMuls curve u1 g u2 q case x of- PointO -> Nothing- Point x1 _ -> return $ x1 `mod` n- where n = ecc_n cc- g = ecc_g cc- cc = common_curve $ public_curve pk+ PointO -> Nothing+ Point x1 _ -> return $ x1 `mod` n+ where+ n = ecc_n cc+ g = ecc_g cc+ cc = common_curve $ public_curve pk -- | Verify a bytestring using the public key.-verify :: (ByteArrayAccess msg, HashAlgorithm hash) => hash -> PublicKey -> Signature -> msg -> Bool+verify+ :: (ByteArrayAccess msg, HashAlgorithm hash)+ => hash -> PublicKey -> Signature -> msg -> Bool verify hashAlg pk sig msg = verifyDigest pk sig (hashWith hashAlg msg)++-- | Recover the public key from an extended signature and a digest.+recoverDigest+ :: HashAlgorithm hash+ => Curve -> ExtendedSignature -> Digest hash -> Maybe PublicKey+recoverDigest curve (ExtendedSignature i p (Signature r s)) digest = do+ let CurveCommon _ _ g n _ = common_curve curve+ let z = dsaTruncHashDigest digest n+ w <- inverse r n+ c <- pointCompose curve i r p+ pure $ PublicKey curve $ pointAddTwoMuls curve (s * w) c (negate $ z * w) g++-- | Recover the public key from an extended signature and a message.+recover+ :: (ByteArrayAccess msg, HashAlgorithm hash)+ => hash -> Curve -> ExtendedSignature -> msg -> Maybe PublicKey+recover hashAlg curve sig msg = recoverDigest curve sig $ hashWith hashAlg msg++-- | Deterministic nonce generation according to RFC 6979.+-- Allows using different hash algorithms for the HMAC-based DRG and the message digest.+deterministicNonce+ :: (HashAlgorithm hashDRG, HashAlgorithm hashDigest)+ => hashDRG -> PrivateKey -> Digest hashDigest -> (Integer -> Maybe a) -> a+deterministicNonce alg (PrivateKey curve key) digest go = fst $ withDRG state run+ where+ state = update seed $ initial alg+ where+ seed = i2ospOf_ bytes key <> i2ospOf_ bytes message :: ScrubbedBytes+ message = dsaTruncHashDigest digest n `mod` n+ run = do+ k <- generatePrefix bits+ if 0 < k && k < n then maybe run pure $ go k else run+ bytes = (bits + 7) `unsafeShiftR` 3+ bits = numBits n+ n = ecc_n $ common_curve curve
Crypto/PubKey/ECC/Generate.hs view
@@ -1,30 +1,34 @@ -- | Signature generation. module Crypto.PubKey.ECC.Generate where -import Crypto.Random.Types-import Crypto.PubKey.ECC.Types-import Crypto.PubKey.ECC.ECDSA import Crypto.Number.Generate+import Crypto.PubKey.ECC.ECDSA import Crypto.PubKey.ECC.Prim+import Crypto.PubKey.ECC.Types+import Crypto.Random.Types -- | Generate Q given d. -- -- /WARNING:/ Vulnerable to timing attacks.-generateQ :: Curve- -> Integer- -> Point+generateQ+ :: Curve+ -> Integer+ -> Point generateQ curve d = pointMul curve d g- where g = ecc_g $ common_curve curve+ where+ g = ecc_g $ common_curve curve -- | Generate a pair of (private, public) key. -- -- /WARNING:/ Vulnerable to timing attacks.-generate :: MonadRandom m- => Curve -- ^ Elliptic Curve- -> m (PublicKey, PrivateKey)+generate+ :: MonadRandom m+ => Curve+ -- ^ Elliptic Curve+ -> m (PublicKey, PrivateKey) generate curve = do d <- generateBetween 1 (n - 1) let q = generateQ curve d return (PublicKey curve q, PrivateKey curve d) where- n = ecc_n $ common_curve curve+ n = ecc_n $ common_curve curve
Crypto/PubKey/ECC/P256.hs view
@@ -1,3 +1,7 @@+{-# LANGUAGE EmptyDataDecls #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# OPTIONS_GHC -fno-warn-unused-binds #-}+ -- | -- Module : Crypto.PubKey.ECC.P256 -- License : BSD-style@@ -6,67 +10,65 @@ -- Portability : unknown -- -- P256 support----{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE EmptyDataDecls #-}-{-# OPTIONS_GHC -fno-warn-unused-binds #-}-module Crypto.PubKey.ECC.P256- ( Scalar- , Point+module Crypto.PubKey.ECC.P256 (+ Scalar,+ Point,+ -- * Point arithmetic- , pointBase- , pointAdd- , pointNegate- , pointMul- , pointDh- , pointsMulVarTime- , pointIsValid- , pointIsAtInfinity- , toPoint- , pointX- , pointToIntegers- , pointFromIntegers- , pointToBinary- , pointFromBinary- , unsafePointFromBinary+ pointBase,+ pointAdd,+ pointNegate,+ pointMul,+ pointDh,+ pointsMulVarTime,+ pointIsValid,+ pointIsAtInfinity,+ toPoint,+ pointX,+ pointToIntegers,+ pointFromIntegers,+ pointToBinary,+ pointFromBinary,+ unsafePointFromBinary,+ -- * Scalar arithmetic- , scalarGenerate- , scalarZero- , scalarN- , scalarIsZero- , scalarAdd- , scalarSub- , scalarMul- , scalarInv- , scalarInvSafe- , scalarCmp- , scalarFromBinary- , scalarToBinary- , scalarFromInteger- , scalarToInteger- ) where+ scalarGenerate,+ scalarZero,+ scalarN,+ scalarIsZero,+ scalarAdd,+ scalarSub,+ scalarMul,+ scalarInv,+ scalarInvSafe,+ scalarCmp,+ scalarFromBinary,+ scalarToBinary,+ scalarFromInteger,+ scalarToInteger,+) where -import Data.Word-import Foreign.Ptr-import Foreign.C.Types+import Data.Word+import Foreign.C.Types+import Foreign.Ptr -import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Crypto.Internal.ByteArray+import Crypto.Error+import Crypto.Internal.ByteArray import qualified Crypto.Internal.ByteArray as B-import Data.Memory.PtrMethods (memSet)-import Crypto.Error-import Crypto.Random-import Crypto.Number.Serialize.Internal (os2ip, i2ospOf)-import qualified Crypto.Number.Serialize as S (os2ip, i2ospOf)+import Crypto.Internal.Compat+import Crypto.Internal.Imports+import qualified Crypto.Number.Serialize as S (i2ospOf, os2ip)+import Crypto.Number.Serialize.Internal (i2ospOf, os2ip)+import Crypto.Random+import Data.Memory.PtrMethods (memSet) -- | A P256 scalar newtype Scalar = Scalar ScrubbedBytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | A P256 point newtype Point = Point Bytes- deriving (Show,Eq,NFData)+ deriving (Show, Eq, NFData) scalarSize :: Int scalarSize = 32@@ -74,7 +76,7 @@ pointSize :: Int pointSize = 64 -type P256Digit = Word32+type P256Digit = Word32 data P256Scalar data P256Y@@ -91,7 +93,7 @@ pointBase :: Point pointBase = case scalarFromInteger 1 of- CryptoPassed s -> toPoint s+ CryptoPassed s -> toPoint s CryptoFailed _ -> error "pointBase: assumption failed" -- | Lift to curve a scalar@@ -99,11 +101,10 @@ -- Using the curve generator as base point compute: -- -- > scalar * G--- toPoint :: Scalar -> Point toPoint s | scalarIsZero s = error "cannot create point from zero"- | otherwise =+ | otherwise = withNewPoint $ \px py -> withScalar s $ \p -> ccrypton_p256_basepoint_mul p px py @@ -160,10 +161,10 @@ pointX :: Point -> Maybe Scalar pointX p | pointIsAtInfinity p = Nothing- | otherwise = Just $- withNewScalarFreeze $ \d ->- withPoint p $ \px _ ->- ccrypton_p256_mod ccrypton_SECP256r1_n (castPtr px) (castPtr d)+ | otherwise = Just $+ withNewScalarFreeze $ \d ->+ withPoint p $ \px _ ->+ ccrypton_p256_mod ccrypton_SECP256r1_n (castPtr px) (castPtr d) -- | Convert a point to (x,y) Integers pointToIntegers :: Point -> (Integer, Integer)@@ -175,12 +176,14 @@ x <- os2ip temp scalarSize ccrypton_p256_to_bin py temp y <- os2ip temp scalarSize- return (x,y)+ return (x, y) -- | Convert from (x,y) Integers to a point pointFromIntegers :: (Integer, Integer) -> Point-pointFromIntegers (x,y) = withNewPoint $ \dx dy ->- allocTemp scalarSize (\temp -> fill temp (castPtr dx) x >> fill temp (castPtr dy) y)+pointFromIntegers (x, y) = withNewPoint $ \dx dy ->+ allocTemp+ scalarSize+ (\temp -> fill temp (castPtr dx) x >> fill temp (castPtr dy) y) where -- put @n to @temp in big endian format, then from @temp to @dest in p256 scalar format fill :: Ptr Word8 -> Ptr P256Scalar -> Integer -> IO ()@@ -207,15 +210,15 @@ validatePoint :: Point -> CryptoFailable Point validatePoint p | pointIsValid p = CryptoPassed p- | otherwise = CryptoFailed CryptoError_PointCoordinatesInvalid+ | otherwise = CryptoFailed CryptoError_PointCoordinatesInvalid -- | Convert from binary to a point, possibly invalid unsafePointFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Point unsafePointFromBinary ba | B.length ba /= pointSize = CryptoFailed CryptoError_PublicKeySizeInvalid- | otherwise =+ | otherwise = CryptoPassed $ withNewPoint $ \px py -> B.withByteArray ba $ \src -> do- ccrypton_p256_from_bin src (castPtr px)+ ccrypton_p256_from_bin src (castPtr px) ccrypton_p256_from_bin (src `plusPtr` scalarSize) (castPtr py) ------------------------------------------------------------------------@@ -267,7 +270,7 @@ scalarMul :: Scalar -> Scalar -> Scalar scalarMul a b = withNewScalarFreeze $ \d -> withScalar a $ \pa -> withScalar b $ \pb ->- ccrypton_p256_modmul ccrypton_SECP256r1_n pa 0 pb d+ ccrypton_p256_modmul ccrypton_SECP256r1_n pa 0 pb d -- | Give the inverse of the scalar --@@ -298,7 +301,7 @@ scalarFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Scalar scalarFromBinary ba | B.length ba /= scalarSize = CryptoFailed CryptoError_SecretKeySizeInvalid- | otherwise =+ | otherwise = CryptoPassed $ withNewScalarFreeze $ \p -> B.withByteArray ba $ \b -> ccrypton_p256_from_bin b p {-# NOINLINE scalarFromBinary #-}@@ -312,7 +315,10 @@ -- | Convert from an Integer to a P256 Scalar scalarFromInteger :: Integer -> CryptoFailable Scalar scalarFromInteger i =- maybe (CryptoFailed CryptoError_SecretKeySizeInvalid) scalarFromBinary (S.i2ospOf 32 i :: Maybe Bytes)+ maybe+ (CryptoFailed CryptoError_SecretKeySizeInvalid)+ scalarFromBinary+ (S.i2ospOf 32 i :: Maybe Bytes) -- | Convert from a P256 Scalar to an Integer scalarToInteger :: Scalar -> Integer@@ -370,53 +376,78 @@ foreign import ccall "crypton_p256_clear" ccrypton_p256_clear :: Ptr P256Scalar -> IO () foreign import ccall "crypton_p256e_modadd"- ccrypton_p256e_modadd :: Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> IO ()+ ccrypton_p256e_modadd+ :: Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> IO () foreign import ccall "crypton_p256_add_d" ccrypton_p256_add_d :: Ptr P256Scalar -> P256Digit -> Ptr P256Scalar -> IO CInt foreign import ccall "crypton_p256e_modsub"- ccrypton_p256e_modsub :: Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> IO ()+ ccrypton_p256e_modsub+ :: Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> IO () foreign import ccall "crypton_p256_cmp" ccrypton_p256_cmp :: Ptr P256Scalar -> Ptr P256Scalar -> IO CInt foreign import ccall "crypton_p256_mod" ccrypton_p256_mod :: Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> IO () foreign import ccall "crypton_p256_modmul"- ccrypton_p256_modmul :: Ptr P256Scalar -> Ptr P256Scalar -> P256Digit -> Ptr P256Scalar -> Ptr P256Scalar -> IO ()+ ccrypton_p256_modmul+ :: Ptr P256Scalar+ -> Ptr P256Scalar+ -> P256Digit+ -> Ptr P256Scalar+ -> Ptr P256Scalar+ -> IO () foreign import ccall "crypton_p256e_scalar_invert" ccrypton_p256e_scalar_invert :: Ptr P256Scalar -> Ptr P256Scalar -> IO ()---foreign import ccall "crypton_p256_modinv"++-- foreign import ccall "crypton_p256_modinv" -- ccrypton_p256_modinv :: Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> IO () foreign import ccall "crypton_p256_modinv_vartime"- ccrypton_p256_modinv_vartime :: Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> IO ()+ ccrypton_p256_modinv_vartime+ :: Ptr P256Scalar -> Ptr P256Scalar -> Ptr P256Scalar -> IO () foreign import ccall "crypton_p256_base_point_mul"- ccrypton_p256_basepoint_mul :: Ptr P256Scalar- -> Ptr P256X -> Ptr P256Y- -> IO ()+ ccrypton_p256_basepoint_mul+ :: Ptr P256Scalar+ -> Ptr P256X+ -> Ptr P256Y+ -> IO () foreign import ccall "crypton_p256e_point_add"- ccrypton_p256e_point_add :: Ptr P256X -> Ptr P256Y- -> Ptr P256X -> Ptr P256Y- -> Ptr P256X -> Ptr P256Y- -> IO ()+ ccrypton_p256e_point_add+ :: Ptr P256X+ -> Ptr P256Y+ -> Ptr P256X+ -> Ptr P256Y+ -> Ptr P256X+ -> Ptr P256Y+ -> IO () foreign import ccall "crypton_p256e_point_negate"- ccrypton_p256e_point_negate :: Ptr P256X -> Ptr P256Y- -> Ptr P256X -> Ptr P256Y- -> IO ()+ ccrypton_p256e_point_negate+ :: Ptr P256X+ -> Ptr P256Y+ -> Ptr P256X+ -> Ptr P256Y+ -> IO () -- compute (out_x,out_y) = n * (in_x,in_y) foreign import ccall "crypton_p256e_point_mul"- ccrypton_p256e_point_mul :: Ptr P256Scalar -- n- -> Ptr P256X -> Ptr P256Y -- in_{x,y}- -> Ptr P256X -> Ptr P256Y -- out_{x,y}- -> IO ()+ ccrypton_p256e_point_mul+ :: Ptr P256Scalar -- n+ -> Ptr P256X+ -> Ptr P256Y -- in_{x,y}+ -> Ptr P256X+ -> Ptr P256Y -- out_{x,y}+ -> IO () -- compute (out_x,out,y) = n1 * G + n2 * (in_x,in_y) foreign import ccall "crypton_p256_points_mul_vartime"- ccrypton_p256_points_mul_vartime :: Ptr P256Scalar -- n1- -> Ptr P256Scalar -- n2- -> Ptr P256X -> Ptr P256Y -- in_{x,y}- -> Ptr P256X -> Ptr P256Y -- out_{x,y}- -> IO ()+ ccrypton_p256_points_mul_vartime+ :: Ptr P256Scalar -- n1+ -> Ptr P256Scalar -- n2+ -> Ptr P256X+ -> Ptr P256Y -- in_{x,y}+ -> Ptr P256X+ -> Ptr P256Y -- out_{x,y}+ -> IO () foreign import ccall "crypton_p256_is_valid_point" ccrypton_p256_is_valid_point :: Ptr P256X -> Ptr P256Y -> IO CInt
Crypto/PubKey/ECC/Prim.hs view
@@ -1,39 +1,41 @@ -- | Elliptic Curve Arithmetic. -- -- /WARNING:/ These functions are vulnerable to timing attacks.-module Crypto.PubKey.ECC.Prim- ( scalarGenerate- , pointAdd- , pointNegate- , pointDouble- , pointBaseMul- , pointMul- , pointAddTwoMuls- , isPointAtInfinity- , isPointValid- ) where+module Crypto.PubKey.ECC.Prim (+ scalarGenerate,+ pointAdd,+ pointNegate,+ pointDouble,+ pointBaseMul,+ pointMul,+ pointAddTwoMuls,+ pointDecompose,+ pointCompose,+ isPointAtInfinity,+ isPointValid,+) where -import Data.Maybe-import Crypto.Number.ModArithmetic import Crypto.Number.F2m import Crypto.Number.Generate (generateBetween)+import Crypto.Number.ModArithmetic import Crypto.PubKey.ECC.Types import Crypto.Random+import Data.Maybe -- | Generate a valid scalar for a specific Curve scalarGenerate :: MonadRandom randomly => Curve -> randomly PrivateNumber scalarGenerate curve = generateBetween 1 (n - 1) where- n = ecc_n $ common_curve curve+ n = ecc_n $ common_curve curve ---TODO: Extract helper function for `fromMaybe PointO...`+-- TODO: Extract helper function for `fromMaybe PointO...` -- | Elliptic Curve point negation: -- @pointNegate c p@ returns point @q@ such that @pointAdd c p q == PointO@. pointNegate :: Curve -> Point -> Point-pointNegate _ PointO = PointO+pointNegate _ PointO = PointO pointNegate (CurveFP c) (Point x y) = Point x (ecc_p c - y)-pointNegate CurveF2m{} (Point x y) = Point x (x `addF2m` y)+pointNegate CurveF2m{} (Point x y) = Point x (x `addF2m` y) -- | Elliptic Curve point addition. --@@ -43,21 +45,22 @@ pointAdd _ PointO q = q pointAdd _ p PointO = p pointAdd c p q- | p == q = pointDouble c p- | p == pointNegate c q = PointO-pointAdd (CurveFP (CurvePrime pr _)) (Point xp yp) (Point xq yq)- = fromMaybe PointO $ do+ | p == q = pointDouble c p+ | p == pointNegate c q = PointO+pointAdd (CurveFP (CurvePrime pr _)) (Point xp yp) (Point xq yq) =+ fromMaybe PointO $ do s <- divmod (yp - yq) (xp - xq) pr- let xr = (s ^ (2::Int) - xp - xq) `mod` pr+ let xr = (s ^ (2 :: Int) - xp - xq) `mod` pr yr = (s * (xp - xr) - yp) `mod` pr return $ Point xr yr-pointAdd (CurveF2m (CurveBinary fx cc)) (Point xp yp) (Point xq yq)- = fromMaybe PointO $ do+pointAdd (CurveF2m (CurveBinary fx cc)) (Point xp yp) (Point xq yq) =+ fromMaybe PointO $ do s <- divF2m fx (yp `addF2m` yq) (xp `addF2m` xq) let xr = mulF2m fx s s `addF2m` s `addF2m` xp `addF2m` xq `addF2m` a yr = mulF2m fx s (xp `addF2m` xr) `addF2m` xr `addF2m` yp return $ Point xr yr- where a = ecc_a cc+ where+ a = ecc_a cc -- | Elliptic Curve point doubling. --@@ -74,23 +77,24 @@ -- > s = xp + (yp / xp) -- > xr = s ^ 2 + s + a -- > yr = xp ^ 2 + (s+1) * xr--- pointDouble :: Curve -> Point -> Point pointDouble _ PointO = PointO pointDouble (CurveFP (CurvePrime pr cc)) (Point xp yp) = fromMaybe PointO $ do- lambda <- divmod (3 * xp ^ (2::Int) + a) (2 * yp) pr- let xr = (lambda ^ (2::Int) - 2 * xp) `mod` pr+ lambda <- divmod (3 * xp ^ (2 :: Int) + a) (2 * yp) pr+ let xr = (lambda ^ (2 :: Int) - 2 * xp) `mod` pr yr = (lambda * (xp - xr) - yp) `mod` pr return $ Point xr yr- where a = ecc_a cc+ where+ a = ecc_a cc pointDouble (CurveF2m (CurveBinary fx cc)) (Point xp yp)- | xp == 0 = PointO+ | xp == 0 = PointO | otherwise = fromMaybe PointO $ do s <- return . addF2m xp =<< divF2m fx yp xp let xr = mulF2m fx s s `addF2m` s `addF2m` a yr = mulF2m fx xp xp `addF2m` mulF2m fx xr (s `addF2m` 1) return $ Point xr yr- where a = ecc_a cc+ where+ a = ecc_a cc -- | Elliptic curve point multiplication using the base --@@ -104,7 +108,7 @@ pointMul :: Curve -> Integer -> Point -> Point pointMul _ _ PointO = PointO pointMul c n p- | n < 0 = pointMul c (-n) (pointNegate c p)+ | n < 0 = pointMul c (-n) (pointNegate c p) | n == 0 = PointO | n == 1 = p | odd n = pointAdd c p (pointMul c (n - 1) p)@@ -117,30 +121,61 @@ -- -- /WARNING:/ Vulnerable to timing attacks. pointAddTwoMuls :: Curve -> Integer -> Point -> Integer -> Point -> Point-pointAddTwoMuls _ _ PointO _ PointO = PointO-pointAddTwoMuls c _ PointO n2 p2 = pointMul c n2 p2-pointAddTwoMuls c n1 p1 _ PointO = pointMul c n1 p1-pointAddTwoMuls c n1 p1 n2 p2- | n1 < 0 = pointAddTwoMuls c (-n1) (pointNegate c p1) n2 p2- | n2 < 0 = pointAddTwoMuls c n1 p1 (-n2) (pointNegate c p2)+pointAddTwoMuls _ _ PointO _ PointO = PointO+pointAddTwoMuls c _ PointO n2 p2 = pointMul c n2 p2+pointAddTwoMuls c n1 p1 _ PointO = pointMul c n1 p1+pointAddTwoMuls c n1 p1 n2 p2+ | n1 < 0 = pointAddTwoMuls c (-n1) (pointNegate c p1) n2 p2+ | n2 < 0 = pointAddTwoMuls c n1 p1 (-n2) (pointNegate c p2) | otherwise = go (n1, n2)- where p0 = pointAdd c p1 p2 - go (0, 0 ) = PointO+ go (0, 0) = PointO go (k1, k2) = let q = pointDouble c $ go (k1 `div` 2, k2 `div` 2)- in case (odd k1, odd k2) of- (True , True ) -> pointAdd c p0 q- (True , False ) -> pointAdd c p1 q- (False , True ) -> pointAdd c p2 q- (False , False ) -> q+ in case (odd k1, odd k2) of+ (True, True) -> pointAdd c p0 q+ (True, False) -> pointAdd c p1 q+ (False, True) -> pointAdd c p2 q+ (False, False) -> q +-- | Decompose a point into index, residue, and parity.+--+-- Adapted from SEC 1: Elliptic Curve Cryptography, Version 2.0, section 2.3.3.+pointDecompose :: Curve -> Point -> Maybe (Integer, Integer, Bool)+pointDecompose _ PointO = Nothing+pointDecompose curve (Point x y) = do+ let CurveCommon _ _ _ n _ = common_curve curve+ let (index, residue) = x `divMod` n+ parity <- case curve of+ CurveFP _ -> pure $ odd y+ CurveF2m _ | x == 0 -> pure False+ CurveF2m (CurveBinary fx _) -> odd <$> divF2m fx y x+ pure (index, residue, parity)++-- | Compose a point from index, residue, and parity.+--+-- Adapted from SEC 1: Elliptic Curve Cryptography, Version 2.0, section 2.3.4.+pointCompose :: Curve -> Integer -> Integer -> Bool -> Maybe Point+pointCompose curve index residue parity = do+ let CurveCommon a b _ n _ = common_curve curve+ let x = residue + index * n+ y <- case curve of+ CurveFP (CurvePrime p _) -> do+ z <- squareRoot p $ x ^ (3 :: Int) + a * x + b+ pure $ if odd z == parity then z else p - z+ CurveF2m (CurveBinary fx _) | x == 0 -> pure $ sqrtF2m fx b+ CurveF2m (CurveBinary fx _) -> do+ c <- divF2m fx b $ squareF2m fx x+ z <- quadraticF2m fx $ addF2m x $ addF2m a c+ pure $ mulF2m fx x $ if odd z == parity then z else addF2m 1 z+ pure $ Point x y+ -- | Check if a point is the point at infinity. isPointAtInfinity :: Point -> Bool isPointAtInfinity PointO = True-isPointAtInfinity _ = False+isPointAtInfinity _ = False -- | check if a point is on specific curve --@@ -150,23 +185,26 @@ -- * y is not out of range -- * the equation @y^2 = x^3 + a*x + b (mod p)@ holds isPointValid :: Curve -> Point -> Bool-isPointValid _ PointO = True+isPointValid _ PointO = True isPointValid (CurveFP (CurvePrime p cc)) (Point x y) = isValid x && isValid y && (y ^ (2 :: Int)) `eqModP` (x ^ (3 :: Int) + a * x + b)- where a = ecc_a cc- b = ecc_b cc- eqModP z1 z2 = (z1 `mod` p) == (z2 `mod` p)- isValid e = e >= 0 && e < p+ where+ a = ecc_a cc+ b = ecc_b cc+ eqModP z1 z2 = (z1 `mod` p) == (z2 `mod` p)+ isValid e = e >= 0 && e < p isPointValid (CurveF2m (CurveBinary fx cc)) (Point x y) =- and [ isValid x+ and+ [ isValid x , isValid y , ((((x `add` a) `mul` x `add` y) `mul` x) `add` b `add` (squareF2m fx y)) == 0 ]- where a = ecc_a cc- b = ecc_b cc- add = addF2m- mul = mulF2m fx- isValid e = modF2m fx e == e+ where+ a = ecc_a cc+ b = ecc_b cc+ add = addF2m+ mul = mulF2m fx+ isValid e = modF2m fx e == e -- | div and mod divmod :: Integer -> Integer -> Integer -> Maybe Integer
Crypto/PubKey/ECC/Types.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveDataTypeable #-}+ -- | -- Module : Crypto.PubKey.ECC.Types -- License : BSD-style@@ -8,32 +9,35 @@ -- -- References: -- <https://tools.ietf.org/html/rfc5915>----module Crypto.PubKey.ECC.Types- ( Curve(..)- , Point(..)- , PublicPoint- , PrivateNumber- , CurveBinary(..)- , CurvePrime(..)- , common_curve- , curveSizeBits- , ecc_fx- , ecc_p- , CurveCommon(..)+module Crypto.PubKey.ECC.Types (+ Curve (..),+ Point (..),+ PublicPoint,+ PrivateNumber,+ CurveBinary (..),+ CurvePrime (..),+ common_curve,+ curveSizeBits,+ ecc_fx,+ ecc_p,+ CurveCommon (..),+ -- * Recommended curves definition- , CurveName(..)- , getCurveByName- ) where+ CurveName (..),+ getCurveByName,+) where -import Data.Data-import Crypto.Internal.Imports-import Crypto.Number.Basic (numBits)+import Crypto.Internal.Imports+import Crypto.Number.Basic (numBits)+import Data.Data -- | Define either a binary curve or a prime curve.-data Curve = CurveF2m CurveBinary -- ^ 𝔽(2^m)- | CurveFP CurvePrime -- ^ 𝔽p- deriving (Show,Read,Eq,Data)+data Curve+ = -- | 𝔽(2^m)+ CurveF2m CurveBinary+ | -- | 𝔽p+ CurveFP CurvePrime+ deriving (Show, Read, Eq, Data) -- | ECC Public Point type PublicPoint = Point@@ -42,9 +46,11 @@ type PrivateNumber = Integer -- | Define a point on a curve.-data Point = Point Integer Integer- | PointO -- ^ Point at Infinity- deriving (Show,Read,Eq,Data)+data Point+ = Point Integer Integer+ | -- | Point at Infinity+ PointO+ deriving (Show, Read, Eq, Data) instance NFData Point where rnf (Point x y) = x `seq` y `seq` ()@@ -53,7 +59,7 @@ -- | Define an elliptic curve in 𝔽(2^m). -- The firt parameter is the Integer representatioin of the irreducible polynomial f(x). data CurveBinary = CurveBinary Integer CurveCommon- deriving (Show,Read,Eq,Data)+ deriving (Show, Read, Eq, Data) instance NFData CurveBinary where rnf (CurveBinary i cc) = i `seq` cc `seq` ()@@ -61,12 +67,12 @@ -- | Define an elliptic curve in 𝔽p. -- The first parameter is the Prime Number. data CurvePrime = CurvePrime Integer CurveCommon- deriving (Show,Read,Eq,Data)+ deriving (Show, Read, Eq, Data) -- | Parameters in common between binary and prime curves. common_curve :: Curve -> CurveCommon common_curve (CurveF2m (CurveBinary _ cc)) = cc-common_curve (CurveFP (CurvePrime _ cc)) = cc+common_curve (CurveFP (CurvePrime _ cc)) = cc -- | Irreducible polynomial representing the characteristic of a CurveBinary. ecc_fx :: CurveBinary -> Integer@@ -79,16 +85,22 @@ -- | Define common parameters in a curve definition -- of the form: y^2 = x^3 + ax + b. data CurveCommon = CurveCommon- { ecc_a :: Integer -- ^ curve parameter a- , ecc_b :: Integer -- ^ curve parameter b- , ecc_g :: Point -- ^ base point- , ecc_n :: Integer -- ^ order of G- , ecc_h :: Integer -- ^ cofactor- } deriving (Show,Read,Eq,Data)+ { ecc_a :: Integer+ -- ^ curve parameter a+ , ecc_b :: Integer+ -- ^ curve parameter b+ , ecc_g :: Point+ -- ^ base point+ , ecc_n :: Integer+ -- ^ order of G+ , ecc_h :: Integer+ -- ^ cofactor+ }+ deriving (Show, Read, Eq, Data) -- | Define names for known recommended curves.-data CurveName =- SEC_p112r1+data CurveName+ = SEC_p112r1 | SEC_p112r2 | SEC_p128r1 | SEC_p128r2@@ -121,7 +133,7 @@ | SEC_t409r1 | SEC_t571k1 | SEC_t571r1- deriving (Show,Read,Eq,Ord,Enum,Bounded,Data)+ deriving (Show, Read, Eq, Ord, Enum, Bounded, Data) {- curvesOIDs :: [ (CurveName, [Integer]) ]@@ -164,338 +176,527 @@ -- | get the size of the curve in bits curveSizeBits :: Curve -> Int-curveSizeBits (CurveFP c) = numBits (ecc_p c)+curveSizeBits (CurveFP c) = numBits (ecc_p c) curveSizeBits (CurveF2m c) = numBits (ecc_fx c) - 1 -- | Get the curve definition associated with a recommended known curve name. getCurveByName :: CurveName -> Curve-getCurveByName SEC_p112r1 = CurveFP $ CurvePrime- 0xdb7c2abf62e35e668076bead208b- (CurveCommon- { ecc_a = 0xdb7c2abf62e35e668076bead2088- , ecc_b = 0x659ef8ba043916eede8911702b22- , ecc_g = Point 0x09487239995a5ee76b55f9c2f098+getCurveByName SEC_p112r1 =+ CurveFP $+ CurvePrime+ 0xdb7c2abf62e35e668076bead208b+ ( CurveCommon+ { ecc_a = 0xdb7c2abf62e35e668076bead2088+ , ecc_b = 0x659ef8ba043916eede8911702b22+ , ecc_g =+ Point+ 0x09487239995a5ee76b55f9c2f098 0xa89ce5af8724c0a23e0e0ff77500- , ecc_n = 0xdb7c2abf62e35e7628dfac6561c5- , ecc_h = 1- })-getCurveByName SEC_p112r2 = CurveFP $ CurvePrime- 0xdb7c2abf62e35e668076bead208b- (CurveCommon- { ecc_a = 0x6127c24c05f38a0aaaf65c0ef02c- , ecc_b = 0x51def1815db5ed74fcc34c85d709- , ecc_g = Point 0x4ba30ab5e892b4e1649dd0928643+ , ecc_n = 0xdb7c2abf62e35e7628dfac6561c5+ , ecc_h = 1+ }+ )+getCurveByName SEC_p112r2 =+ CurveFP $+ CurvePrime+ 0xdb7c2abf62e35e668076bead208b+ ( CurveCommon+ { ecc_a = 0x6127c24c05f38a0aaaf65c0ef02c+ , ecc_b = 0x51def1815db5ed74fcc34c85d709+ , ecc_g =+ Point+ 0x4ba30ab5e892b4e1649dd0928643 0xadcd46f5882e3747def36e956e97- , ecc_n = 0x36df0aafd8b8d7597ca10520d04b- , ecc_h = 4- })-getCurveByName SEC_p128r1 = CurveFP $ CurvePrime- 0xfffffffdffffffffffffffffffffffff- (CurveCommon- { ecc_a = 0xfffffffdfffffffffffffffffffffffc- , ecc_b = 0xe87579c11079f43dd824993c2cee5ed3- , ecc_g = Point 0x161ff7528b899b2d0c28607ca52c5b86+ , ecc_n = 0x36df0aafd8b8d7597ca10520d04b+ , ecc_h = 4+ }+ )+getCurveByName SEC_p128r1 =+ CurveFP $+ CurvePrime+ 0xfffffffdffffffffffffffffffffffff+ ( CurveCommon+ { ecc_a = 0xfffffffdfffffffffffffffffffffffc+ , ecc_b = 0xe87579c11079f43dd824993c2cee5ed3+ , ecc_g =+ Point+ 0x161ff7528b899b2d0c28607ca52c5b86 0xcf5ac8395bafeb13c02da292dded7a83- , ecc_n = 0xfffffffe0000000075a30d1b9038a115- , ecc_h = 1- })-getCurveByName SEC_p128r2 = CurveFP $ CurvePrime- 0xfffffffdffffffffffffffffffffffff- (CurveCommon- { ecc_a = 0xd6031998d1b3bbfebf59cc9bbff9aee1- , ecc_b = 0x5eeefca380d02919dc2c6558bb6d8a5d- , ecc_g = Point 0x7b6aa5d85e572983e6fb32a7cdebc140+ , ecc_n = 0xfffffffe0000000075a30d1b9038a115+ , ecc_h = 1+ }+ )+getCurveByName SEC_p128r2 =+ CurveFP $+ CurvePrime+ 0xfffffffdffffffffffffffffffffffff+ ( CurveCommon+ { ecc_a = 0xd6031998d1b3bbfebf59cc9bbff9aee1+ , ecc_b = 0x5eeefca380d02919dc2c6558bb6d8a5d+ , ecc_g =+ Point+ 0x7b6aa5d85e572983e6fb32a7cdebc140 0x27b6916a894d3aee7106fe805fc34b44- , ecc_n = 0x3fffffff7fffffffbe0024720613b5a3- , ecc_h = 4- })-getCurveByName SEC_p160k1 = CurveFP $ CurvePrime- 0x00fffffffffffffffffffffffffffffffeffffac73- (CurveCommon- { ecc_a = 0x000000000000000000000000000000000000000000- , ecc_b = 0x000000000000000000000000000000000000000007- , ecc_g = Point 0x003b4c382ce37aa192a4019e763036f4f5dd4d7ebb+ , ecc_n = 0x3fffffff7fffffffbe0024720613b5a3+ , ecc_h = 4+ }+ )+getCurveByName SEC_p160k1 =+ CurveFP $+ CurvePrime+ 0x00fffffffffffffffffffffffffffffffeffffac73+ ( CurveCommon+ { ecc_a = 0x000000000000000000000000000000000000000000+ , ecc_b = 0x000000000000000000000000000000000000000007+ , ecc_g =+ Point+ 0x003b4c382ce37aa192a4019e763036f4f5dd4d7ebb 0x00938cf935318fdced6bc28286531733c3f03c4fee- , ecc_n = 0x0100000000000000000001b8fa16dfab9aca16b6b3- , ecc_h = 1- })-getCurveByName SEC_p160r1 = CurveFP $ CurvePrime- 0x00ffffffffffffffffffffffffffffffff7fffffff- (CurveCommon- { ecc_a = 0x00ffffffffffffffffffffffffffffffff7ffffffc- , ecc_b = 0x001c97befc54bd7a8b65acf89f81d4d4adc565fa45- , ecc_g = Point 0x004a96b5688ef573284664698968c38bb913cbfc82+ , ecc_n = 0x0100000000000000000001b8fa16dfab9aca16b6b3+ , ecc_h = 1+ }+ )+getCurveByName SEC_p160r1 =+ CurveFP $+ CurvePrime+ 0x00ffffffffffffffffffffffffffffffff7fffffff+ ( CurveCommon+ { ecc_a = 0x00ffffffffffffffffffffffffffffffff7ffffffc+ , ecc_b = 0x001c97befc54bd7a8b65acf89f81d4d4adc565fa45+ , ecc_g =+ Point+ 0x004a96b5688ef573284664698968c38bb913cbfc82 0x0023a628553168947d59dcc912042351377ac5fb32- , ecc_n = 0x0100000000000000000001f4c8f927aed3ca752257- , ecc_h = 1- })-getCurveByName SEC_p160r2 = CurveFP $ CurvePrime- 0x00fffffffffffffffffffffffffffffffeffffac73- (CurveCommon- { ecc_a = 0x00fffffffffffffffffffffffffffffffeffffac70- , ecc_b = 0x00b4e134d3fb59eb8bab57274904664d5af50388ba- , ecc_g = Point 0x0052dcb034293a117e1f4ff11b30f7199d3144ce6d+ , ecc_n = 0x0100000000000000000001f4c8f927aed3ca752257+ , ecc_h = 1+ }+ )+getCurveByName SEC_p160r2 =+ CurveFP $+ CurvePrime+ 0x00fffffffffffffffffffffffffffffffeffffac73+ ( CurveCommon+ { ecc_a = 0x00fffffffffffffffffffffffffffffffeffffac70+ , ecc_b = 0x00b4e134d3fb59eb8bab57274904664d5af50388ba+ , ecc_g =+ Point+ 0x0052dcb034293a117e1f4ff11b30f7199d3144ce6d 0x00feaffef2e331f296e071fa0df9982cfea7d43f2e- , ecc_n = 0x0100000000000000000000351ee786a818f3a1a16b- , ecc_h = 1- })-getCurveByName SEC_p192k1 = CurveFP $ CurvePrime- 0xfffffffffffffffffffffffffffffffffffffffeffffee37- (CurveCommon- { ecc_a = 0x000000000000000000000000000000000000000000000000- , ecc_b = 0x000000000000000000000000000000000000000000000003- , ecc_g = Point 0xdb4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d+ , ecc_n = 0x0100000000000000000000351ee786a818f3a1a16b+ , ecc_h = 1+ }+ )+getCurveByName SEC_p192k1 =+ CurveFP $+ CurvePrime+ 0xfffffffffffffffffffffffffffffffffffffffeffffee37+ ( CurveCommon+ { ecc_a = 0x000000000000000000000000000000000000000000000000+ , ecc_b = 0x000000000000000000000000000000000000000000000003+ , ecc_g =+ Point+ 0xdb4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d 0x9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d- , ecc_n = 0xfffffffffffffffffffffffe26f2fc170f69466a74defd8d- , ecc_h = 1- })-getCurveByName SEC_p192r1 = CurveFP $ CurvePrime- 0xfffffffffffffffffffffffffffffffeffffffffffffffff- (CurveCommon- { ecc_a = 0xfffffffffffffffffffffffffffffffefffffffffffffffc- , ecc_b = 0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1- , ecc_g = Point 0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012+ , ecc_n = 0xfffffffffffffffffffffffe26f2fc170f69466a74defd8d+ , ecc_h = 1+ }+ )+getCurveByName SEC_p192r1 =+ CurveFP $+ CurvePrime+ 0xfffffffffffffffffffffffffffffffeffffffffffffffff+ ( CurveCommon+ { ecc_a = 0xfffffffffffffffffffffffffffffffefffffffffffffffc+ , ecc_b = 0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1+ , ecc_g =+ Point+ 0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012 0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811- , ecc_n = 0xffffffffffffffffffffffff99def836146bc9b1b4d22831- , ecc_h = 1- })-getCurveByName SEC_p224k1 = CurveFP $ CurvePrime- 0x00fffffffffffffffffffffffffffffffffffffffffffffffeffffe56d- (CurveCommon- { ecc_a = 0x0000000000000000000000000000000000000000000000000000000000- , ecc_b = 0x0000000000000000000000000000000000000000000000000000000005- , ecc_g = Point 0x00a1455b334df099df30fc28a169a467e9e47075a90f7e650eb6b7a45c+ , ecc_n = 0xffffffffffffffffffffffff99def836146bc9b1b4d22831+ , ecc_h = 1+ }+ )+getCurveByName SEC_p224k1 =+ CurveFP $+ CurvePrime+ 0x00fffffffffffffffffffffffffffffffffffffffffffffffeffffe56d+ ( CurveCommon+ { ecc_a = 0x0000000000000000000000000000000000000000000000000000000000+ , ecc_b = 0x0000000000000000000000000000000000000000000000000000000005+ , ecc_g =+ Point+ 0x00a1455b334df099df30fc28a169a467e9e47075a90f7e650eb6b7a45c 0x007e089fed7fba344282cafbd6f7e319f7c0b0bd59e2ca4bdb556d61a5- , ecc_n = 0x010000000000000000000000000001dce8d2ec6184caf0a971769fb1f7- , ecc_h = 1- })-getCurveByName SEC_p224r1 = CurveFP $ CurvePrime- 0xffffffffffffffffffffffffffffffff000000000000000000000001- (CurveCommon- { ecc_a = 0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe- , ecc_b = 0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4- , ecc_g = Point 0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21+ , ecc_n = 0x010000000000000000000000000001dce8d2ec6184caf0a971769fb1f7+ , ecc_h = 1+ }+ )+getCurveByName SEC_p224r1 =+ CurveFP $+ CurvePrime+ 0xffffffffffffffffffffffffffffffff000000000000000000000001+ ( CurveCommon+ { ecc_a = 0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe+ , ecc_b = 0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4+ , ecc_g =+ Point+ 0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21 0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34- , ecc_n = 0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d- , ecc_h = 1- })-getCurveByName SEC_p256k1 = CurveFP $ CurvePrime- 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f- (CurveCommon- { ecc_a = 0x0000000000000000000000000000000000000000000000000000000000000000- , ecc_b = 0x0000000000000000000000000000000000000000000000000000000000000007- , ecc_g = Point 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798+ , ecc_n = 0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d+ , ecc_h = 1+ }+ )+getCurveByName SEC_p256k1 =+ CurveFP $+ CurvePrime+ 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f+ ( CurveCommon+ { ecc_a = 0x0000000000000000000000000000000000000000000000000000000000000000+ , ecc_b = 0x0000000000000000000000000000000000000000000000000000000000000007+ , ecc_g =+ Point+ 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8- , ecc_n = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141- , ecc_h = 1- })-getCurveByName SEC_p256r1 = CurveFP $ CurvePrime- 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff- (CurveCommon- { ecc_a = 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc- , ecc_b = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b- , ecc_g = Point 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296+ , ecc_n = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141+ , ecc_h = 1+ }+ )+getCurveByName SEC_p256r1 =+ CurveFP $+ CurvePrime+ 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff+ ( CurveCommon+ { ecc_a = 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc+ , ecc_b = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b+ , ecc_g =+ Point+ 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5- , ecc_n = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551- , ecc_h = 1- })-getCurveByName SEC_p384r1 = CurveFP $ CurvePrime- 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff- (CurveCommon- { ecc_a = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc- , ecc_b = 0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef- , ecc_g = Point 0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7+ , ecc_n = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551+ , ecc_h = 1+ }+ )+getCurveByName SEC_p384r1 =+ CurveFP $+ CurvePrime+ 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff+ ( CurveCommon+ { ecc_a =+ 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc+ , ecc_b =+ 0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef+ , ecc_g =+ Point+ 0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7 0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f- , ecc_n = 0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973- , ecc_h = 1- })-getCurveByName SEC_p521r1 = CurveFP $ CurvePrime- 0x01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff- (CurveCommon- { ecc_a = 0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc- , ecc_b = 0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00- , ecc_g = Point 0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66+ , ecc_n =+ 0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973+ , ecc_h = 1+ }+ )+getCurveByName SEC_p521r1 =+ CurveFP $+ CurvePrime+ 0x01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff+ ( CurveCommon+ { ecc_a =+ 0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc+ , ecc_b =+ 0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00+ , ecc_g =+ Point+ 0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66 0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650- , ecc_n = 0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409- , ecc_h = 1- })-getCurveByName SEC_t113r1 = CurveF2m $ CurveBinary- 0x020000000000000000000000000201- (CurveCommon- { ecc_a = 0x003088250ca6e7c7fe649ce85820f7- , ecc_b = 0x00e8bee4d3e2260744188be0e9c723- , ecc_g = Point 0x009d73616f35f4ab1407d73562c10f+ , ecc_n =+ 0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409+ , ecc_h = 1+ }+ )+getCurveByName SEC_t113r1 =+ CurveF2m $+ CurveBinary+ 0x020000000000000000000000000201+ ( CurveCommon+ { ecc_a = 0x003088250ca6e7c7fe649ce85820f7+ , ecc_b = 0x00e8bee4d3e2260744188be0e9c723+ , ecc_g =+ Point+ 0x009d73616f35f4ab1407d73562c10f 0x00a52830277958ee84d1315ed31886- , ecc_n = 0x0100000000000000d9ccec8a39e56f- , ecc_h = 2- })-getCurveByName SEC_t113r2 = CurveF2m $ CurveBinary- 0x020000000000000000000000000201- (CurveCommon- { ecc_a = 0x00689918dbec7e5a0dd6dfc0aa55c7- , ecc_b = 0x0095e9a9ec9b297bd4bf36e059184f- , ecc_g = Point 0x01a57a6a7b26ca5ef52fcdb8164797+ , ecc_n = 0x0100000000000000d9ccec8a39e56f+ , ecc_h = 2+ }+ )+getCurveByName SEC_t113r2 =+ CurveF2m $+ CurveBinary+ 0x020000000000000000000000000201+ ( CurveCommon+ { ecc_a = 0x00689918dbec7e5a0dd6dfc0aa55c7+ , ecc_b = 0x0095e9a9ec9b297bd4bf36e059184f+ , ecc_g =+ Point+ 0x01a57a6a7b26ca5ef52fcdb8164797 0x00b3adc94ed1fe674c06e695baba1d- , ecc_n = 0x010000000000000108789b2496af93- , ecc_h = 2- })-getCurveByName SEC_t131r1 = CurveF2m $ CurveBinary- 0x080000000000000000000000000000010d- (CurveCommon- { ecc_a = 0x07a11b09a76b562144418ff3ff8c2570b8- , ecc_b = 0x0217c05610884b63b9c6c7291678f9d341- , ecc_g = Point 0x0081baf91fdf9833c40f9c181343638399+ , ecc_n = 0x010000000000000108789b2496af93+ , ecc_h = 2+ }+ )+getCurveByName SEC_t131r1 =+ CurveF2m $+ CurveBinary+ 0x080000000000000000000000000000010d+ ( CurveCommon+ { ecc_a = 0x07a11b09a76b562144418ff3ff8c2570b8+ , ecc_b = 0x0217c05610884b63b9c6c7291678f9d341+ , ecc_g =+ Point+ 0x0081baf91fdf9833c40f9c181343638399 0x078c6e7ea38c001f73c8134b1b4ef9e150- , ecc_n = 0x0400000000000000023123953a9464b54d- , ecc_h = 2- })-getCurveByName SEC_t131r2 = CurveF2m $ CurveBinary- 0x080000000000000000000000000000010d- (CurveCommon- { ecc_a = 0x03e5a88919d7cafcbf415f07c2176573b2- , ecc_b = 0x04b8266a46c55657ac734ce38f018f2192- , ecc_g = Point 0x0356dcd8f2f95031ad652d23951bb366a8+ , ecc_n = 0x0400000000000000023123953a9464b54d+ , ecc_h = 2+ }+ )+getCurveByName SEC_t131r2 =+ CurveF2m $+ CurveBinary+ 0x080000000000000000000000000000010d+ ( CurveCommon+ { ecc_a = 0x03e5a88919d7cafcbf415f07c2176573b2+ , ecc_b = 0x04b8266a46c55657ac734ce38f018f2192+ , ecc_g =+ Point+ 0x0356dcd8f2f95031ad652d23951bb366a8 0x0648f06d867940a5366d9e265de9eb240f- , ecc_n = 0x0400000000000000016954a233049ba98f- , ecc_h = 2- })-getCurveByName SEC_t163k1 = CurveF2m $ CurveBinary- 0x0800000000000000000000000000000000000000c9- (CurveCommon- { ecc_a = 0x000000000000000000000000000000000000000001- , ecc_b = 0x000000000000000000000000000000000000000001- , ecc_g = Point 0x02fe13c0537bbc11acaa07d793de4e6d5e5c94eee8+ , ecc_n = 0x0400000000000000016954a233049ba98f+ , ecc_h = 2+ }+ )+getCurveByName SEC_t163k1 =+ CurveF2m $+ CurveBinary+ 0x0800000000000000000000000000000000000000c9+ ( CurveCommon+ { ecc_a = 0x000000000000000000000000000000000000000001+ , ecc_b = 0x000000000000000000000000000000000000000001+ , ecc_g =+ Point+ 0x02fe13c0537bbc11acaa07d793de4e6d5e5c94eee8 0x0289070fb05d38ff58321f2e800536d538ccdaa3d9- , ecc_n = 0x04000000000000000000020108a2e0cc0d99f8a5ef- , ecc_h = 2- })-getCurveByName SEC_t163r1 = CurveF2m $ CurveBinary- 0x0800000000000000000000000000000000000000c9- (CurveCommon- { ecc_a = 0x07b6882caaefa84f9554ff8428bd88e246d2782ae2- , ecc_b = 0x0713612dcddcb40aab946bda29ca91f73af958afd9- , ecc_g = Point 0x0369979697ab43897789566789567f787a7876a654+ , ecc_n = 0x04000000000000000000020108a2e0cc0d99f8a5ef+ , ecc_h = 2+ }+ )+getCurveByName SEC_t163r1 =+ CurveF2m $+ CurveBinary+ 0x0800000000000000000000000000000000000000c9+ ( CurveCommon+ { ecc_a = 0x07b6882caaefa84f9554ff8428bd88e246d2782ae2+ , ecc_b = 0x0713612dcddcb40aab946bda29ca91f73af958afd9+ , ecc_g =+ Point+ 0x0369979697ab43897789566789567f787a7876a654 0x00435edb42efafb2989d51fefce3c80988f41ff883- , ecc_n = 0x03ffffffffffffffffffff48aab689c29ca710279b- , ecc_h = 2- })-getCurveByName SEC_t163r2 = CurveF2m $ CurveBinary- 0x0800000000000000000000000000000000000000c9- (CurveCommon- { ecc_a = 0x000000000000000000000000000000000000000001- , ecc_b = 0x020a601907b8c953ca1481eb10512f78744a3205fd- , ecc_g = Point 0x03f0eba16286a2d57ea0991168d4994637e8343e36+ , ecc_n = 0x03ffffffffffffffffffff48aab689c29ca710279b+ , ecc_h = 2+ }+ )+getCurveByName SEC_t163r2 =+ CurveF2m $+ CurveBinary+ 0x0800000000000000000000000000000000000000c9+ ( CurveCommon+ { ecc_a = 0x000000000000000000000000000000000000000001+ , ecc_b = 0x020a601907b8c953ca1481eb10512f78744a3205fd+ , ecc_g =+ Point+ 0x03f0eba16286a2d57ea0991168d4994637e8343e36 0x00d51fbc6c71a0094fa2cdd545b11c5c0c797324f1- , ecc_n = 0x040000000000000000000292fe77e70c12a4234c33- , ecc_h = 2- })-getCurveByName SEC_t193r1 = CurveF2m $ CurveBinary- 0x02000000000000000000000000000000000000000000008001- (CurveCommon- { ecc_a = 0x0017858feb7a98975169e171f77b4087de098ac8a911df7b01- , ecc_b = 0x00fdfb49bfe6c3a89facadaa7a1e5bbc7cc1c2e5d831478814- , ecc_g = Point 0x01f481bc5f0ff84a74ad6cdf6fdef4bf6179625372d8c0c5e1+ , ecc_n = 0x040000000000000000000292fe77e70c12a4234c33+ , ecc_h = 2+ }+ )+getCurveByName SEC_t193r1 =+ CurveF2m $+ CurveBinary+ 0x02000000000000000000000000000000000000000000008001+ ( CurveCommon+ { ecc_a = 0x0017858feb7a98975169e171f77b4087de098ac8a911df7b01+ , ecc_b = 0x00fdfb49bfe6c3a89facadaa7a1e5bbc7cc1c2e5d831478814+ , ecc_g =+ Point+ 0x01f481bc5f0ff84a74ad6cdf6fdef4bf6179625372d8c0c5e1 0x0025e399f2903712ccf3ea9e3a1ad17fb0b3201b6af7ce1b05- , ecc_n = 0x01000000000000000000000000c7f34a778f443acc920eba49- , ecc_h = 2- })-getCurveByName SEC_t193r2 = CurveF2m $ CurveBinary- 0x02000000000000000000000000000000000000000000008001- (CurveCommon- { ecc_a = 0x0163f35a5137c2ce3ea6ed8667190b0bc43ecd69977702709b- , ecc_b = 0x00c9bb9e8927d4d64c377e2ab2856a5b16e3efb7f61d4316ae- , ecc_g = Point 0x00d9b67d192e0367c803f39e1a7e82ca14a651350aae617e8f+ , ecc_n = 0x01000000000000000000000000c7f34a778f443acc920eba49+ , ecc_h = 2+ }+ )+getCurveByName SEC_t193r2 =+ CurveF2m $+ CurveBinary+ 0x02000000000000000000000000000000000000000000008001+ ( CurveCommon+ { ecc_a = 0x0163f35a5137c2ce3ea6ed8667190b0bc43ecd69977702709b+ , ecc_b = 0x00c9bb9e8927d4d64c377e2ab2856a5b16e3efb7f61d4316ae+ , ecc_g =+ Point+ 0x00d9b67d192e0367c803f39e1a7e82ca14a651350aae617e8f 0x01ce94335607c304ac29e7defbd9ca01f596f927224cdecf6c- , ecc_n = 0x010000000000000000000000015aab561b005413ccd4ee99d5- , ecc_h = 2- })-getCurveByName SEC_t233k1 = CurveF2m $ CurveBinary- 0x020000000000000000000000000000000000000004000000000000000001- (CurveCommon- { ecc_a = 0x000000000000000000000000000000000000000000000000000000000000- , ecc_b = 0x000000000000000000000000000000000000000000000000000000000001- , ecc_g = Point 0x017232ba853a7e731af129f22ff4149563a419c26bf50a4c9d6eefad6126+ , ecc_n = 0x010000000000000000000000015aab561b005413ccd4ee99d5+ , ecc_h = 2+ }+ )+getCurveByName SEC_t233k1 =+ CurveF2m $+ CurveBinary+ 0x020000000000000000000000000000000000000004000000000000000001+ ( CurveCommon+ { ecc_a = 0x000000000000000000000000000000000000000000000000000000000000+ , ecc_b = 0x000000000000000000000000000000000000000000000000000000000001+ , ecc_g =+ Point+ 0x017232ba853a7e731af129f22ff4149563a419c26bf50a4c9d6eefad6126 0x01db537dece819b7f70f555a67c427a8cd9bf18aeb9b56e0c11056fae6a3- , ecc_n = 0x008000000000000000000000000000069d5bb915bcd46efb1ad5f173abdf- , ecc_h = 4- })-getCurveByName SEC_t233r1 = CurveF2m $ CurveBinary- 0x020000000000000000000000000000000000000004000000000000000001- (CurveCommon- { ecc_a = 0x000000000000000000000000000000000000000000000000000000000001- , ecc_b = 0x0066647ede6c332c7f8c0923bb58213b333b20e9ce4281fe115f7d8f90ad- , ecc_g = Point 0x00fac9dfcbac8313bb2139f1bb755fef65bc391f8b36f8f8eb7371fd558b+ , ecc_n = 0x008000000000000000000000000000069d5bb915bcd46efb1ad5f173abdf+ , ecc_h = 4+ }+ )+getCurveByName SEC_t233r1 =+ CurveF2m $+ CurveBinary+ 0x020000000000000000000000000000000000000004000000000000000001+ ( CurveCommon+ { ecc_a = 0x000000000000000000000000000000000000000000000000000000000001+ , ecc_b = 0x0066647ede6c332c7f8c0923bb58213b333b20e9ce4281fe115f7d8f90ad+ , ecc_g =+ Point+ 0x00fac9dfcbac8313bb2139f1bb755fef65bc391f8b36f8f8eb7371fd558b 0x01006a08a41903350678e58528bebf8a0beff867a7ca36716f7e01f81052- , ecc_n = 0x01000000000000000000000000000013e974e72f8a6922031d2603cfe0d7- , ecc_h = 2- })-getCurveByName SEC_t239k1 = CurveF2m $ CurveBinary- 0x800000000000000000004000000000000000000000000000000000000001- (CurveCommon- { ecc_a = 0x000000000000000000000000000000000000000000000000000000000000- , ecc_b = 0x000000000000000000000000000000000000000000000000000000000001- , ecc_g = Point 0x29a0b6a887a983e9730988a68727a8b2d126c44cc2cc7b2a6555193035dc+ , ecc_n = 0x01000000000000000000000000000013e974e72f8a6922031d2603cfe0d7+ , ecc_h = 2+ }+ )+getCurveByName SEC_t239k1 =+ CurveF2m $+ CurveBinary+ 0x800000000000000000004000000000000000000000000000000000000001+ ( CurveCommon+ { ecc_a = 0x000000000000000000000000000000000000000000000000000000000000+ , ecc_b = 0x000000000000000000000000000000000000000000000000000000000001+ , ecc_g =+ Point+ 0x29a0b6a887a983e9730988a68727a8b2d126c44cc2cc7b2a6555193035dc 0x76310804f12e549bdb011c103089e73510acb275fc312a5dc6b76553f0ca- , ecc_n = 0x2000000000000000000000000000005a79fec67cb6e91f1c1da800e478a5- , ecc_h = 4- })-getCurveByName SEC_t283k1 = CurveF2m $ CurveBinary- 0x0800000000000000000000000000000000000000000000000000000000000000000010a1- (CurveCommon- { ecc_a = 0x000000000000000000000000000000000000000000000000000000000000000000000000- , ecc_b = 0x000000000000000000000000000000000000000000000000000000000000000000000001- , ecc_g = Point 0x0503213f78ca44883f1a3b8162f188e553cd265f23c1567a16876913b0c2ac2458492836+ , ecc_n = 0x2000000000000000000000000000005a79fec67cb6e91f1c1da800e478a5+ , ecc_h = 4+ }+ )+getCurveByName SEC_t283k1 =+ CurveF2m $+ CurveBinary+ 0x0800000000000000000000000000000000000000000000000000000000000000000010a1+ ( CurveCommon+ { ecc_a =+ 0x000000000000000000000000000000000000000000000000000000000000000000000000+ , ecc_b =+ 0x000000000000000000000000000000000000000000000000000000000000000000000001+ , ecc_g =+ Point+ 0x0503213f78ca44883f1a3b8162f188e553cd265f23c1567a16876913b0c2ac2458492836 0x01ccda380f1c9e318d90f95d07e5426fe87e45c0e8184698e45962364e34116177dd2259- , ecc_n = 0x01ffffffffffffffffffffffffffffffffffe9ae2ed07577265dff7f94451e061e163c61- , ecc_h = 4- })-getCurveByName SEC_t283r1 = CurveF2m $ CurveBinary- 0x0800000000000000000000000000000000000000000000000000000000000000000010a1- (CurveCommon- { ecc_a = 0x000000000000000000000000000000000000000000000000000000000000000000000001- , ecc_b = 0x027b680ac8b8596da5a4af8a19a0303fca97fd7645309fa2a581485af6263e313b79a2f5- , ecc_g = Point 0x05f939258db7dd90e1934f8c70b0dfec2eed25b8557eac9c80e2e198f8cdbecd86b12053+ , ecc_n =+ 0x01ffffffffffffffffffffffffffffffffffe9ae2ed07577265dff7f94451e061e163c61+ , ecc_h = 4+ }+ )+getCurveByName SEC_t283r1 =+ CurveF2m $+ CurveBinary+ 0x0800000000000000000000000000000000000000000000000000000000000000000010a1+ ( CurveCommon+ { ecc_a =+ 0x000000000000000000000000000000000000000000000000000000000000000000000001+ , ecc_b =+ 0x027b680ac8b8596da5a4af8a19a0303fca97fd7645309fa2a581485af6263e313b79a2f5+ , ecc_g =+ Point+ 0x05f939258db7dd90e1934f8c70b0dfec2eed25b8557eac9c80e2e198f8cdbecd86b12053 0x03676854fe24141cb98fe6d4b20d02b4516ff702350eddb0826779c813f0df45be8112f4- , ecc_n = 0x03ffffffffffffffffffffffffffffffffffef90399660fc938a90165b042a7cefadb307- , ecc_h = 2- })-getCurveByName SEC_t409k1 = CurveF2m $ CurveBinary- 0x02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001- (CurveCommon- { ecc_a = 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000- , ecc_b = 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001- , ecc_g = Point 0x0060f05f658f49c1ad3ab1890f7184210efd0987e307c84c27accfb8f9f67cc2c460189eb5aaaa62ee222eb1b35540cfe9023746+ , ecc_n =+ 0x03ffffffffffffffffffffffffffffffffffef90399660fc938a90165b042a7cefadb307+ , ecc_h = 2+ }+ )+getCurveByName SEC_t409k1 =+ CurveF2m $+ CurveBinary+ 0x02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001+ ( CurveCommon+ { ecc_a =+ 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000+ , ecc_b =+ 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001+ , ecc_g =+ Point+ 0x0060f05f658f49c1ad3ab1890f7184210efd0987e307c84c27accfb8f9f67cc2c460189eb5aaaa62ee222eb1b35540cfe9023746 0x01e369050b7c4e42acba1dacbf04299c3460782f918ea427e6325165e9ea10e3da5f6c42e9c55215aa9ca27a5863ec48d8e0286b- , ecc_n = 0x007ffffffffffffffffffffffffffffffffffffffffffffffffffe5f83b2d4ea20400ec4557d5ed3e3e7ca5b4b5c83b8e01e5fcf- , ecc_h = 4- })-getCurveByName SEC_t409r1 = CurveF2m $ CurveBinary- 0x02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001- (CurveCommon- { ecc_a = 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001- , ecc_b = 0x0021a5c2c8ee9feb5c4b9a753b7b476b7fd6422ef1f3dd674761fa99d6ac27c8a9a197b272822f6cd57a55aa4f50ae317b13545f- , ecc_g = Point 0x015d4860d088ddb3496b0c6064756260441cde4af1771d4db01ffe5b34e59703dc255a868a1180515603aeab60794e54bb7996a7+ , ecc_n =+ 0x007ffffffffffffffffffffffffffffffffffffffffffffffffffe5f83b2d4ea20400ec4557d5ed3e3e7ca5b4b5c83b8e01e5fcf+ , ecc_h = 4+ }+ )+getCurveByName SEC_t409r1 =+ CurveF2m $+ CurveBinary+ 0x02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001+ ( CurveCommon+ { ecc_a =+ 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001+ , ecc_b =+ 0x0021a5c2c8ee9feb5c4b9a753b7b476b7fd6422ef1f3dd674761fa99d6ac27c8a9a197b272822f6cd57a55aa4f50ae317b13545f+ , ecc_g =+ Point+ 0x015d4860d088ddb3496b0c6064756260441cde4af1771d4db01ffe5b34e59703dc255a868a1180515603aeab60794e54bb7996a7 0x0061b1cfab6be5f32bbfa78324ed106a7636b9c5a7bd198d0158aa4f5488d08f38514f1fdf4b4f40d2181b3681c364ba0273c706- , ecc_n = 0x010000000000000000000000000000000000000000000000000001e2aad6a612f33307be5fa47c3c9e052f838164cd37d9a21173- , ecc_h = 2- })-getCurveByName SEC_t571k1 = CurveF2m $ CurveBinary- 0x080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425- (CurveCommon- { ecc_a = 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000- , ecc_b = 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001- , ecc_g = Point 0x026eb7a859923fbc82189631f8103fe4ac9ca2970012d5d46024804801841ca44370958493b205e647da304db4ceb08cbbd1ba39494776fb988b47174dca88c7e2945283a01c8972+ , ecc_n =+ 0x010000000000000000000000000000000000000000000000000001e2aad6a612f33307be5fa47c3c9e052f838164cd37d9a21173+ , ecc_h = 2+ }+ )+getCurveByName SEC_t571k1 =+ CurveF2m $+ CurveBinary+ 0x080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425+ ( CurveCommon+ { ecc_a =+ 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000+ , ecc_b =+ 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001+ , ecc_g =+ Point+ 0x026eb7a859923fbc82189631f8103fe4ac9ca2970012d5d46024804801841ca44370958493b205e647da304db4ceb08cbbd1ba39494776fb988b47174dca88c7e2945283a01c8972 0x0349dc807f4fbf374f4aeade3bca95314dd58cec9f307a54ffc61efc006d8a2c9d4979c0ac44aea74fbebbb9f772aedcb620b01a7ba7af1b320430c8591984f601cd4c143ef1c7a3- , ecc_n = 0x020000000000000000000000000000000000000000000000000000000000000000000000131850e1f19a63e4b391a8db917f4138b630d84be5d639381e91deb45cfe778f637c1001- , ecc_h = 4- })-getCurveByName SEC_t571r1 = CurveF2m $ CurveBinary- 0x080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425- (CurveCommon- { ecc_a = 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001- , ecc_b = 0x02f40e7e2221f295de297117b7f3d62f5c6a97ffcb8ceff1cd6ba8ce4a9a18ad84ffabbd8efa59332be7ad6756a66e294afd185a78ff12aa520e4de739baca0c7ffeff7f2955727a- , ecc_g = Point 0x0303001d34b856296c16c0d40d3cd7750a93d1d2955fa80aa5f40fc8db7b2abdbde53950f4c0d293cdd711a35b67fb1499ae60038614f1394abfa3b4c850d927e1e7769c8eec2d19+ , ecc_n =+ 0x020000000000000000000000000000000000000000000000000000000000000000000000131850e1f19a63e4b391a8db917f4138b630d84be5d639381e91deb45cfe778f637c1001+ , ecc_h = 4+ }+ )+getCurveByName SEC_t571r1 =+ CurveF2m $+ CurveBinary+ 0x080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425+ ( CurveCommon+ { ecc_a =+ 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001+ , ecc_b =+ 0x02f40e7e2221f295de297117b7f3d62f5c6a97ffcb8ceff1cd6ba8ce4a9a18ad84ffabbd8efa59332be7ad6756a66e294afd185a78ff12aa520e4de739baca0c7ffeff7f2955727a+ , ecc_g =+ Point+ 0x0303001d34b856296c16c0d40d3cd7750a93d1d2955fa80aa5f40fc8db7b2abdbde53950f4c0d293cdd711a35b67fb1499ae60038614f1394abfa3b4c850d927e1e7769c8eec2d19 0x037bf27342da639b6dccfffeb73d69d78c6c27a6009cbbca1980f8533921e8a684423e43bab08a576291af8f461bb2a8b3531d2f0485c19b16e2f1516e23dd3c1a4827af1b8ac15b- , ecc_n = 0x03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47- , ecc_h = 2- })+ , ecc_n =+ 0x03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47+ , ecc_h = 2+ }+ )
Crypto/PubKey/ECDSA.hs view
@@ -1,3 +1,10 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE StandaloneDeriving #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-}+ -- | -- Module : Crypto.PubKey.ECDSA -- License : BSD-style@@ -15,60 +22,60 @@ -- Signature operations with P-384 and P-521 may leak the private key. -- -- Signature verification should be safe for all curves.-{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE StandaloneDeriving #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE UndecidableInstances #-}-module Crypto.PubKey.ECDSA- ( EllipticCurveECDSA (..)+module Crypto.PubKey.ECDSA (+ EllipticCurveECDSA (..),+ -- * Public keys- , PublicKey- , encodePublic- , decodePublic- , toPublic+ PublicKey,+ encodePublic,+ decodePublic,+ toPublic,+ -- * Private keys- , PrivateKey- , encodePrivate- , decodePrivate+ PrivateKey,+ encodePrivate,+ decodePrivate,+ -- * Signatures- , Signature(..)- , signatureFromIntegers- , signatureToIntegers+ Signature (..),+ signatureFromIntegers,+ signatureToIntegers,+ -- * Generation and verification- , signWith- , signDigestWith- , sign- , signDigest- , verify- , verifyDigest- ) where+ signWith,+ signDigestWith,+ sign,+ signDigest,+ verify,+ verifyDigest,+) where -import Control.Monad+import Control.Monad -import Crypto.ECC+import Crypto.ECC import qualified Crypto.ECC.Simple.Types as Simple-import Crypto.Error-import Crypto.Hash-import Crypto.Hash.Types-import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess)-import Crypto.Internal.Imports-import Crypto.Number.ModArithmetic (inverseFermat)+import Crypto.Error+import Crypto.Hash+import Crypto.Hash.Types+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess)+import Crypto.Internal.Imports+import Crypto.Number.ModArithmetic (inverseFermat) import qualified Crypto.PubKey.ECC.P256 as P256-import Crypto.Random.Types+import Crypto.Random.Types -import Data.Bits+import Data.Bits import qualified Data.ByteArray as B-import Data.Data+import Data.Data -import Foreign.Ptr (Ptr)-import Foreign.Storable (peekByteOff, pokeByteOff)+import Foreign.Ptr (Ptr)+import Foreign.Storable (peekByteOff, pokeByteOff) -- | Represent a ECDSA signature namely R and S. data Signature curve = Signature- { sign_r :: Scalar curve -- ^ ECDSA r- , sign_s :: Scalar curve -- ^ ECDSA s+ { sign_r :: Scalar curve+ -- ^ ECDSA r+ , sign_s :: Scalar curve+ -- ^ ECDSA s } deriving instance Eq (Scalar curve) => Eq (Signature curve)@@ -99,15 +106,17 @@ pointX :: proxy curve -> Point curve -> Maybe (Scalar curve) instance EllipticCurveECDSA Curve_P256R1 where- scalarIsValid _ s = not (P256.scalarIsZero s)- && P256.scalarCmp s P256.scalarN == LT+ scalarIsValid _ s =+ not (P256.scalarIsZero s)+ && P256.scalarCmp s P256.scalarN == LT scalarIsZero _ = P256.scalarIsZero - scalarInv _ s = let inv = P256.scalarInvSafe s- in if P256.scalarIsZero inv then Nothing else Just inv+ scalarInv _ s =+ let inv = P256.scalarInvSafe s+ in if P256.scalarIsZero inv then Nothing else Just inv - pointX _ = P256.pointX+ pointX _ = P256.pointX instance EllipticCurveECDSA Curve_P384R1 where scalarIsValid _ = ecScalarIsValid (Proxy :: Proxy Simple.SEC_p384r1)@@ -116,7 +125,7 @@ scalarInv _ = ecScalarInv (Proxy :: Proxy Simple.SEC_p384r1) - pointX _ = ecPointX (Proxy :: Proxy Simple.SEC_p384r1)+ pointX _ = ecPointX (Proxy :: Proxy Simple.SEC_p384r1) instance EllipticCurveECDSA Curve_P521R1 where scalarIsValid _ = ecScalarIsValid (Proxy :: Proxy Simple.SEC_p521r1)@@ -125,12 +134,12 @@ scalarInv _ = ecScalarInv (Proxy :: Proxy Simple.SEC_p521r1) - pointX _ = ecPointX (Proxy :: Proxy Simple.SEC_p521r1)-+ pointX _ = ecPointX (Proxy :: Proxy Simple.SEC_p521r1) -- | Create a signature from integers (R, S).-signatureFromIntegers :: EllipticCurveECDSA curve- => proxy curve -> (Integer, Integer) -> CryptoFailable (Signature curve)+signatureFromIntegers+ :: EllipticCurveECDSA curve+ => proxy curve -> (Integer, Integer) -> CryptoFailable (Signature curve) signatureFromIntegers prx (r, s) = liftA2 Signature (scalarFromInteger prx r) (scalarFromInteger prx s) @@ -138,41 +147,52 @@ -- -- The values can then be used to encode the signature to binary with -- ASN.1.-signatureToIntegers :: EllipticCurveECDSA curve- => proxy curve -> Signature curve -> (Integer, Integer)+signatureToIntegers+ :: EllipticCurveECDSA curve+ => proxy curve -> Signature curve -> (Integer, Integer) signatureToIntegers prx sig = (scalarToInteger prx $ sign_r sig, scalarToInteger prx $ sign_s sig) -- | Encode a public key into binary form, i.e. the uncompressed encoding -- referenced from <https://tools.ietf.org/html/rfc5480 RFC 5480> section 2.2.-encodePublic :: (EllipticCurve curve, ByteArray bs)- => proxy curve -> PublicKey curve -> bs+encodePublic+ :: (EllipticCurve curve, ByteArray bs)+ => proxy curve -> PublicKey curve -> bs encodePublic = encodePoint -- | Try to decode the binary form of a public key.-decodePublic :: (EllipticCurve curve, ByteArray bs)- => proxy curve -> bs -> CryptoFailable (PublicKey curve)+decodePublic+ :: (EllipticCurve curve, ByteArray bs)+ => proxy curve -> bs -> CryptoFailable (PublicKey curve) decodePublic = decodePoint -- | Encode a private key into binary form, i.e. the @privateKey@ field -- described in <https://tools.ietf.org/html/rfc5915 RFC 5915>.-encodePrivate :: (EllipticCurveECDSA curve, ByteArray bs)- => proxy curve -> PrivateKey curve -> bs+encodePrivate+ :: (EllipticCurveECDSA curve, ByteArray bs)+ => proxy curve -> PrivateKey curve -> bs encodePrivate = encodeScalar -- | Try to decode the binary form of a private key.-decodePrivate :: (EllipticCurveECDSA curve, ByteArray bs)- => proxy curve -> bs -> CryptoFailable (PrivateKey curve)+decodePrivate+ :: (EllipticCurveECDSA curve, ByteArray bs)+ => proxy curve -> bs -> CryptoFailable (PrivateKey curve) decodePrivate = decodeScalar -- | Create a public key from a private key.-toPublic :: EllipticCurveECDSA curve- => proxy curve -> PrivateKey curve -> PublicKey curve+toPublic+ :: EllipticCurveECDSA curve+ => proxy curve -> PrivateKey curve -> PublicKey curve toPublic = pointBaseSmul -- | Sign digest using the private key and an explicit k scalar.-signDigestWith :: (EllipticCurveECDSA curve, HashAlgorithm hash)- => proxy curve -> Scalar curve -> PrivateKey curve -> Digest hash -> Maybe (Signature curve)+signDigestWith+ :: (EllipticCurveECDSA curve, HashAlgorithm hash)+ => proxy curve+ -> Scalar curve+ -> PrivateKey curve+ -> Digest hash+ -> Maybe (Signature curve) signDigestWith prx k d digest = do let z = tHashDigest prx digest point = pointBaseSmul prx k@@ -183,90 +203,113 @@ return $ Signature r s -- | Sign message using the private key and an explicit k scalar.-signWith :: (EllipticCurveECDSA curve, ByteArrayAccess msg, HashAlgorithm hash)- => proxy curve -> Scalar curve -> PrivateKey curve -> hash -> msg -> Maybe (Signature curve)+signWith+ :: (EllipticCurveECDSA curve, ByteArrayAccess msg, HashAlgorithm hash)+ => proxy curve+ -> Scalar curve+ -> PrivateKey curve+ -> hash+ -> msg+ -> Maybe (Signature curve) signWith prx k d hashAlg msg = signDigestWith prx k d (hashWith hashAlg msg) -- | Sign a digest using hash and private key.-signDigest :: (EllipticCurveECDSA curve, MonadRandom m, HashAlgorithm hash)- => proxy curve -> PrivateKey curve -> Digest hash -> m (Signature curve)+signDigest+ :: (EllipticCurveECDSA curve, MonadRandom m, HashAlgorithm hash)+ => proxy curve -> PrivateKey curve -> Digest hash -> m (Signature curve) signDigest prx pk digest = do k <- curveGenerateScalar prx case signDigestWith prx k pk digest of- Nothing -> signDigest prx pk digest+ Nothing -> signDigest prx pk digest Just sig -> return sig -- | Sign a message using hash and private key.-sign :: (EllipticCurveECDSA curve, MonadRandom m, ByteArrayAccess msg, HashAlgorithm hash)- => proxy curve -> PrivateKey curve -> hash -> msg -> m (Signature curve)+sign+ :: ( EllipticCurveECDSA curve+ , MonadRandom m+ , ByteArrayAccess msg+ , HashAlgorithm hash+ )+ => proxy curve -> PrivateKey curve -> hash -> msg -> m (Signature curve) sign prx pk hashAlg msg = signDigest prx pk (hashWith hashAlg msg) -- | Verify a digest using hash and public key.-verifyDigest :: (EllipticCurveECDSA curve, HashAlgorithm hash)- => proxy curve -> PublicKey curve -> Signature curve -> Digest hash -> Bool+verifyDigest+ :: (EllipticCurveECDSA curve, HashAlgorithm hash)+ => proxy curve -> PublicKey curve -> Signature curve -> Digest hash -> Bool verifyDigest prx q (Signature r s) digest | not (scalarIsValid prx r) = False | not (scalarIsValid prx s) = False | otherwise = maybe False (r ==) $ do w <- scalarInv prx s- let z = tHashDigest prx digest+ let z = tHashDigest prx digest u1 = scalarMul prx z w u2 = scalarMul prx r w- x = pointsSmulVarTime prx u1 u2 q+ x = pointsSmulVarTime prx u1 u2 q pointX prx x- -- Note: precondition q /= PointO is not tested because we assume- -- point decoding never decodes point at infinity. +-- Note: precondition q /= PointO is not tested because we assume+-- point decoding never decodes point at infinity.+ -- | Verify a signature using hash and public key.-verify :: (EllipticCurveECDSA curve, ByteArrayAccess msg, HashAlgorithm hash)- => proxy curve -> hash -> PublicKey curve -> Signature curve -> msg -> Bool+verify+ :: (EllipticCurveECDSA curve, ByteArrayAccess msg, HashAlgorithm hash)+ => proxy curve -> hash -> PublicKey curve -> Signature curve -> msg -> Bool verify prx hashAlg q sig msg = verifyDigest prx q sig (hashWith hashAlg msg) -- | Truncate a digest based on curve order size.-tHashDigest :: (EllipticCurveECDSA curve, HashAlgorithm hash)- => proxy curve -> Digest hash -> Scalar curve+tHashDigest+ :: (EllipticCurveECDSA curve, HashAlgorithm hash)+ => proxy curve -> Digest hash -> Scalar curve tHashDigest prx (Digest digest) = throwCryptoError $ decodeScalar prx encoded- where m = curveOrderBits prx- d = m - B.length digest * 8- (n, r) = m `divMod` 8- n' = if r > 0 then succ n else n-- encoded- | d > 0 = B.zero (n' - B.length digest) `B.append` digest- | d == 0 = digest- | r == 0 = B.take n digest- | otherwise = shiftBytes digest+ where+ m = curveOrderBits prx+ d = m - B.length digest * 8+ (n, r) = m `divMod` 8+ n' = if r > 0 then succ n else n - shiftBytes bs = B.allocAndFreeze n' $ \dst ->- B.withByteArray bs $ \src -> go dst src 0 0+ encoded+ | d > 0 = B.zero (n' - B.length digest) `B.append` digest+ | d == 0 = digest+ | r == 0 = B.take n digest+ | otherwise = shiftBytes digest - go :: Ptr Word8 -> Ptr Word8 -> Word8 -> Int -> IO ()- go dst src !a i- | i >= n' = return ()- | otherwise = do- b <- peekByteOff src i- pokeByteOff dst i (unsafeShiftR b (8 - r) .|. unsafeShiftL a r)- go dst src b (succ i)+ shiftBytes bs = B.allocAndFreeze n' $ \dst ->+ B.withByteArray bs $ \src -> go dst src 0 0 + go :: Ptr Word8 -> Ptr Word8 -> Word8 -> Int -> IO ()+ go dst src !a i+ | i >= n' = return ()+ | otherwise = do+ b <- peekByteOff src i+ pokeByteOff dst i (unsafeShiftR b (8 - r) .|. unsafeShiftL a r)+ go dst src b (succ i) ecScalarIsValid :: Simple.Curve c => proxy c -> Simple.Scalar c -> Bool ecScalarIsValid prx (Simple.Scalar s) = s > 0 && s < n- where n = Simple.curveEccN $ Simple.curveParameters prx+ where+ n = Simple.curveEccN $ Simple.curveParameters prx -ecScalarIsZero :: forall curve . Simple.Curve curve- => Simple.Scalar curve -> Bool+ecScalarIsZero+ :: forall curve+ . Simple.Curve curve+ => Simple.Scalar curve -> Bool ecScalarIsZero (Simple.Scalar a) = a == 0 -ecScalarInv :: Simple.Curve c- => proxy c -> Simple.Scalar c -> Maybe (Simple.Scalar c)+ecScalarInv+ :: Simple.Curve c+ => proxy c -> Simple.Scalar c -> Maybe (Simple.Scalar c) ecScalarInv prx (Simple.Scalar s)- | i == 0 = Nothing+ | i == 0 = Nothing | otherwise = Just $ Simple.Scalar i- where n = Simple.curveEccN $ Simple.curveParameters prx- i = inverseFermat s n+ where+ n = Simple.curveEccN $ Simple.curveParameters prx+ i = inverseFermat s n -ecPointX :: Simple.Curve c- => proxy c -> Simple.Point c -> Maybe (Simple.Scalar c)-ecPointX _ Simple.PointO = Nothing+ecPointX+ :: Simple.Curve c+ => proxy c -> Simple.Point c -> Maybe (Simple.Scalar c)+ecPointX _ Simple.PointO = Nothing ecPointX prx (Simple.Point x _) = Just (Simple.Scalar $ x `mod` n)- where n = Simple.curveEccN $ Simple.curveParameters prx+ where+ n = Simple.curveEccN $ Simple.curveParameters prx
Crypto/PubKey/ECIES.hs view
@@ -18,31 +18,37 @@ -- This module doesn't provide any symmetric data encryption capability or any mean to derive -- cryptographic key material for a symmetric key from the shared secret. -- this is left to the user for now.----module Crypto.PubKey.ECIES- ( deriveEncrypt- , deriveDecrypt- ) where+module Crypto.PubKey.ECIES (+ deriveEncrypt,+ deriveDecrypt,+) where -import Crypto.ECC-import Crypto.Error-import Crypto.Random+import Crypto.ECC+import Crypto.Error+import Crypto.Random -- | Generate random a new Shared secret and the associated point -- to do a ECIES style encryption-deriveEncrypt :: (MonadRandom randomly, EllipticCurveDH curve)- => proxy curve -- ^ representation of the curve- -> Point curve -- ^ the public key of the receiver- -> randomly (CryptoFailable (Point curve, SharedSecret))+deriveEncrypt+ :: (MonadRandom randomly, EllipticCurveDH curve)+ => proxy curve+ -- ^ representation of the curve+ -> Point curve+ -- ^ the public key of the receiver+ -> randomly (CryptoFailable (Point curve, SharedSecret)) deriveEncrypt proxy pub = do (KeyPair rPoint rScalar) <- curveGenerateKeyPair proxy return $ (\s -> (rPoint, s)) `fmap` ecdh proxy rScalar pub -- | Derive the shared secret with the receiver key -- and the R point of the scheme.-deriveDecrypt :: EllipticCurveDH curve- => proxy curve -- ^ representation of the curve- -> Point curve -- ^ The received R (supposedly, randomly generated on the encrypt side)- -> Scalar curve -- ^ The secret key of the receiver- -> CryptoFailable SharedSecret+deriveDecrypt+ :: EllipticCurveDH curve+ => proxy curve+ -- ^ representation of the curve+ -> Point curve+ -- ^ The received R (supposedly, randomly generated on the encrypt side)+ -> Scalar curve+ -- ^ The secret key of the receiver+ -> CryptoFailable SharedSecret deriveDecrypt proxy point secret = ecdh proxy secret point
Crypto/PubKey/Ed25519.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.PubKey.Ed25519 -- License : BSD-style@@ -6,51 +9,55 @@ -- Portability : unknown -- -- Ed25519 support----{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.PubKey.Ed25519- ( SecretKey- , PublicKey- , Signature+module Crypto.PubKey.Ed25519 (+ SecretKey,+ PublicKey,+ Signature,+ -- * Size constants- , publicKeySize- , secretKeySize- , signatureSize+ publicKeySize,+ secretKeySize,+ signatureSize,+ -- * Smart constructors- , signature- , publicKey- , secretKey+ signature,+ publicKey,+ secretKey,+ -- * Methods- , toPublic- , sign- , verify- , generateSecretKey- ) where+ toPublic,+ sign,+ verify,+ generateSecretKey,+) where -import Data.Word-import Foreign.C.Types-import Foreign.Ptr+import Data.Word+import Foreign.C.Types+import Foreign.Ptr -import Crypto.Error-import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes,- ScrubbedBytes, withByteArray)+import Crypto.Error+import Crypto.Internal.ByteArray (+ ByteArrayAccess,+ Bytes,+ ScrubbedBytes,+ withByteArray,+ ) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Crypto.Random+import Crypto.Internal.Compat+import Crypto.Internal.Imports+import Crypto.Random -- | An Ed25519 Secret key newtype SecretKey = SecretKey ScrubbedBytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | An Ed25519 public key newtype PublicKey = PublicKey Bytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | An Ed25519 signature newtype Signature = Signature Bytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | Try to build a public key from a bytearray publicKey :: ByteArrayAccess ba => ba -> CryptoFailable PublicKey@@ -64,15 +71,16 @@ secretKey :: ByteArrayAccess ba => ba -> CryptoFailable SecretKey secretKey bs | B.length bs == secretKeySize = unsafeDoIO $ withByteArray bs initialize- | otherwise = CryptoFailed CryptoError_SecretKeyStructureInvalid+ | otherwise =+ CryptoFailed CryptoError_SecretKeyStructureInvalid where- initialize inp = do- valid <- isValidPtr inp- if valid- then (CryptoPassed . SecretKey) <$> B.copy bs (\_ -> return ())- else return $ CryptoFailed CryptoError_SecretKeyStructureInvalid- isValidPtr _ =- return True+ initialize inp = do+ valid <- isValidPtr inp+ if valid+ then (CryptoPassed . SecretKey) <$> B.copy bs (\_ -> return ())+ else return $ CryptoFailed CryptoError_SecretKeyStructureInvalid+ isValidPtr _ =+ return True {-# NOINLINE secretKey #-} -- | Try to build a signature from a bytearray@@ -85,20 +93,21 @@ -- | Create a public key from a secret key toPublic :: SecretKey -> PublicKey-toPublic (SecretKey sec) = PublicKey <$>- B.allocAndFreeze publicKeySize $ \result ->- withByteArray sec $ \psec ->- ccrypton_ed25519_publickey psec result+toPublic (SecretKey sec) = PublicKey+ <$> B.allocAndFreeze publicKeySize+ $ \result ->+ withByteArray sec $ \psec ->+ ccrypton_ed25519_publickey psec result {-# NOINLINE toPublic #-} -- | Sign a message using the key pair sign :: ByteArrayAccess ba => SecretKey -> PublicKey -> ba -> Signature sign secret public message = Signature $ B.allocAndFreeze signatureSize $ \sig ->- withByteArray secret $ \sec ->- withByteArray public $ \pub ->- withByteArray message $ \msg ->- ccrypton_ed25519_sign msg (fromIntegral msgLen) sec pub sig+ withByteArray secret $ \sec ->+ withByteArray public $ \pub ->+ withByteArray message $ \msg ->+ ccrypton_ed25519_sign msg (fromIntegral msgLen) sec pub sig where !msgLen = B.length message @@ -106,10 +115,10 @@ verify :: ByteArrayAccess ba => PublicKey -> ba -> Signature -> Bool verify public message signatureVal = unsafeDoIO $ withByteArray signatureVal $ \sig ->- withByteArray public $ \pub ->- withByteArray message $ \msg -> do- r <- ccrypton_ed25519_sign_open msg (fromIntegral msgLen) pub sig- return (r == 0)+ withByteArray public $ \pub ->+ withByteArray message $ \msg -> do+ r <- ccrypton_ed25519_sign_open msg (fromIntegral msgLen) pub sig+ return (r == 0) where !msgLen = B.length message @@ -130,21 +139,24 @@ signatureSize = 64 foreign import ccall "crypton_ed25519_publickey"- ccrypton_ed25519_publickey :: Ptr SecretKey -- secret key- -> Ptr PublicKey -- public key- -> IO ()+ ccrypton_ed25519_publickey+ :: Ptr SecretKey -- secret key+ -> Ptr PublicKey -- public key+ -> IO () foreign import ccall "crypton_ed25519_sign_open"- ccrypton_ed25519_sign_open :: Ptr Word8 -- message- -> CSize -- message len- -> Ptr PublicKey -- public- -> Ptr Signature -- signature- -> IO CInt+ ccrypton_ed25519_sign_open+ :: Ptr Word8 -- message+ -> CSize -- message len+ -> Ptr PublicKey -- public+ -> Ptr Signature -- signature+ -> IO CInt foreign import ccall "crypton_ed25519_sign"- ccrypton_ed25519_sign :: Ptr Word8 -- message- -> CSize -- message len- -> Ptr SecretKey -- secret- -> Ptr PublicKey -- public- -> Ptr Signature -- signature- -> IO ()+ ccrypton_ed25519_sign+ :: Ptr Word8 -- message+ -> CSize -- message len+ -> Ptr SecretKey -- secret+ -> Ptr PublicKey -- public+ -> Ptr Signature -- signature+ -> IO ()
Crypto/PubKey/Ed448.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.PubKey.Ed448 -- License : BSD-style@@ -10,51 +13,55 @@ -- Internally uses Decaf point compression to omit the cofactor -- and implementation by Mike Hamburg. Externally API and -- data types are compatible with the encoding specified in RFC 8032.----{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.PubKey.Ed448- ( SecretKey- , PublicKey- , Signature+module Crypto.PubKey.Ed448 (+ SecretKey,+ PublicKey,+ Signature,+ -- * Size constants- , publicKeySize- , secretKeySize- , signatureSize+ publicKeySize,+ secretKeySize,+ signatureSize,+ -- * Smart constructors- , signature- , publicKey- , secretKey+ signature,+ publicKey,+ secretKey,+ -- * Methods- , toPublic- , sign- , verify- , generateSecretKey- ) where+ toPublic,+ sign,+ verify,+ generateSecretKey,+) where -import Data.Word-import Foreign.C.Types-import Foreign.Ptr+import Data.Word+import Foreign.C.Types+import Foreign.Ptr -import Crypto.Error-import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes,- ScrubbedBytes, withByteArray)+import Crypto.Error+import Crypto.Internal.ByteArray (+ ByteArrayAccess,+ Bytes,+ ScrubbedBytes,+ withByteArray,+ ) import qualified Crypto.Internal.ByteArray as B-import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Crypto.Random+import Crypto.Internal.Compat+import Crypto.Internal.Imports+import Crypto.Random -- | An Ed448 Secret key newtype SecretKey = SecretKey ScrubbedBytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | An Ed448 public key newtype PublicKey = PublicKey Bytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | An Ed448 signature newtype Signature = Signature Bytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | Try to build a public key from a bytearray publicKey :: ByteArrayAccess ba => ba -> CryptoFailable PublicKey@@ -68,15 +75,16 @@ secretKey :: ByteArrayAccess ba => ba -> CryptoFailable SecretKey secretKey bs | B.length bs == secretKeySize = unsafeDoIO $ withByteArray bs initialize- | otherwise = CryptoFailed CryptoError_SecretKeyStructureInvalid+ | otherwise =+ CryptoFailed CryptoError_SecretKeyStructureInvalid where- initialize inp = do- valid <- isValidPtr inp- if valid- then (CryptoPassed . SecretKey) <$> B.copy bs (\_ -> return ())- else return $ CryptoFailed CryptoError_SecretKeyStructureInvalid- isValidPtr _ =- return True+ initialize inp = do+ valid <- isValidPtr inp+ if valid+ then (CryptoPassed . SecretKey) <$> B.copy bs (\_ -> return ())+ else return $ CryptoFailed CryptoError_SecretKeyStructureInvalid+ isValidPtr _ =+ return True {-# NOINLINE secretKey #-} -- | Try to build a signature from a bytearray@@ -89,20 +97,21 @@ -- | Create a public key from a secret key toPublic :: SecretKey -> PublicKey-toPublic (SecretKey sec) = PublicKey <$>- B.allocAndFreeze publicKeySize $ \result ->- withByteArray sec $ \psec ->- decaf_ed448_derive_public_key result psec+toPublic (SecretKey sec) = PublicKey+ <$> B.allocAndFreeze publicKeySize+ $ \result ->+ withByteArray sec $ \psec ->+ decaf_ed448_derive_public_key result psec {-# NOINLINE toPublic #-} -- | Sign a message using the key pair sign :: ByteArrayAccess ba => SecretKey -> PublicKey -> ba -> Signature sign secret public message = Signature $ B.allocAndFreeze signatureSize $ \sig ->- withByteArray secret $ \sec ->- withByteArray public $ \pub ->- withByteArray message $ \msg ->- decaf_ed448_sign sig sec pub msg (fromIntegral msgLen) 0 no_context 0+ withByteArray secret $ \sec ->+ withByteArray public $ \pub ->+ withByteArray message $ \msg ->+ decaf_ed448_sign sig sec pub msg (fromIntegral msgLen) 0 no_context 0 where !msgLen = B.length message @@ -110,10 +119,10 @@ verify :: ByteArrayAccess ba => PublicKey -> ba -> Signature -> Bool verify public message signatureVal = unsafeDoIO $ withByteArray signatureVal $ \sig ->- withByteArray public $ \pub ->- withByteArray message $ \msg -> do- r <- decaf_ed448_verify sig pub msg (fromIntegral msgLen) 0 no_context 0- return (r /= 0)+ withByteArray public $ \pub ->+ withByteArray message $ \msg -> do+ r <- decaf_ed448_verify sig pub msg (fromIntegral msgLen) 0 no_context 0+ return (r /= 0) where !msgLen = B.length message @@ -137,27 +146,30 @@ no_context = nullPtr -- not supported yet foreign import ccall "crypton_decaf_ed448_derive_public_key"- decaf_ed448_derive_public_key :: Ptr PublicKey -- public key- -> Ptr SecretKey -- secret key- -> IO ()+ decaf_ed448_derive_public_key+ :: Ptr PublicKey -- public key+ -> Ptr SecretKey -- secret key+ -> IO () foreign import ccall "crypton_decaf_ed448_sign"- decaf_ed448_sign :: Ptr Signature -- signature- -> Ptr SecretKey -- secret- -> Ptr PublicKey -- public- -> Ptr Word8 -- message- -> CSize -- message len- -> Word8 -- prehashed- -> Ptr Word8 -- context- -> Word8 -- context len- -> IO ()+ decaf_ed448_sign+ :: Ptr Signature -- signature+ -> Ptr SecretKey -- secret+ -> Ptr PublicKey -- public+ -> Ptr Word8 -- message+ -> CSize -- message len+ -> Word8 -- prehashed+ -> Ptr Word8 -- context+ -> Word8 -- context len+ -> IO () foreign import ccall "crypton_decaf_ed448_verify"- decaf_ed448_verify :: Ptr Signature -- signature- -> Ptr PublicKey -- public- -> Ptr Word8 -- message- -> CSize -- message len- -> Word8 -- prehashed- -> Ptr Word8 -- context- -> Word8 -- context len- -> IO CInt+ decaf_ed448_verify+ :: Ptr Signature -- signature+ -> Ptr PublicKey -- public+ -> Ptr Word8 -- message+ -> CSize -- message len+ -> Word8 -- prehashed+ -> Ptr Word8 -- context+ -> Word8 -- context len+ -> IO CInt
Crypto/PubKey/EdDSA.hs view
@@ -1,3 +1,12 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+ -- | -- Module : Crypto.PubKey.EdDSA -- License : BSD-style@@ -15,81 +24,82 @@ -- This implementation is most useful when wanting to customize the hash -- algorithm. See module "Crypto.PubKey.Ed25519" for faster Ed25519 with -- SHA-512.----{-# LANGUAGE DataKinds #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeOperators #-}-module Crypto.PubKey.EdDSA- ( SecretKey- , PublicKey- , Signature+module Crypto.PubKey.EdDSA (+ SecretKey,+ PublicKey,+ Signature,+ -- * Curves with EdDSA implementation- , EllipticCurveEdDSA(CurveDigestSize)- , publicKeySize- , secretKeySize- , signatureSize+ EllipticCurveEdDSA (CurveDigestSize),+ publicKeySize,+ secretKeySize,+ signatureSize,+ -- * Smart constructors- , signature- , publicKey- , secretKey+ signature,+ publicKey,+ secretKey,+ -- * Methods- , toPublic- , sign- , signCtx- , signPh- , verify- , verifyCtx- , verifyPh- , generateSecretKey- ) where+ toPublic,+ sign,+ signCtx,+ signPh,+ verify,+ verifyCtx,+ verifyPh,+ generateSecretKey,+) where -import Data.Bits-import Data.ByteArray (ByteArray, ByteArrayAccess, Bytes, ScrubbedBytes, View)+import Data.Bits+import Data.ByteArray (+ ByteArray,+ ByteArrayAccess,+ Bytes,+ ScrubbedBytes,+ View,+ ) import qualified Data.ByteArray as B-import Data.ByteString (ByteString)-import Data.Proxy+import Data.ByteString (ByteString)+import Data.Proxy -import Crypto.ECC+import Crypto.ECC import qualified Crypto.ECC.Edwards25519 as Edwards25519-import Crypto.Error-import Crypto.Hash (Digest)-import Crypto.Hash.IO-import Crypto.Random--import GHC.TypeLits (KnownNat, Nat)+import Crypto.Error+import Crypto.Hash (Digest)+import Crypto.Hash.IO+import Crypto.Random -import Crypto.Internal.Builder-import Crypto.Internal.Compat-import Crypto.Internal.Imports-import Crypto.Internal.Nat (integralNatVal)+import GHC.TypeLits (KnownNat, Nat) -import Foreign.Storable+import Crypto.Internal.Builder+import Crypto.Internal.Compat+import Crypto.Internal.Imports+import Crypto.Internal.Nat (integralNatVal) +import Foreign.Storable -- API -- | An EdDSA Secret key newtype SecretKey curve = SecretKey ScrubbedBytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | An EdDSA public key newtype PublicKey curve hash = PublicKey Bytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | An EdDSA signature newtype Signature curve hash = Signature Bytes- deriving (Show,Eq,ByteArrayAccess,NFData)+ deriving (Show, Eq, ByteArrayAccess, NFData) -- | Elliptic curves with an implementation of EdDSA-class ( EllipticCurveBasepointArith curve- , KnownNat (CurveDigestSize curve)- ) => EllipticCurveEdDSA curve where-+class+ ( EllipticCurveBasepointArith curve+ , KnownNat (CurveDigestSize curve)+ ) =>+ EllipticCurveEdDSA curve+ where -- | Size of the digest for this curve (in bytes) type CurveDigestSize curve :: Nat @@ -97,43 +107,49 @@ secretKeySize :: proxy curve -> Int -- hash with specified parameters- hashWithDom :: (HashAlgorithm hash, ByteArrayAccess ctx, ByteArrayAccess msg)- => proxy curve -> hash -> Bool -> ctx -> Builder -> msg -> Bytes+ hashWithDom+ :: (HashAlgorithm hash, ByteArrayAccess ctx, ByteArrayAccess msg)+ => proxy curve -> hash -> Bool -> ctx -> Builder -> msg -> Bytes -- conversion between scalar, point and public key pointPublic :: proxy curve -> Point curve -> PublicKey curve hash- publicPoint :: proxy curve -> PublicKey curve hash -> CryptoFailable (Point curve)+ publicPoint+ :: proxy curve -> PublicKey curve hash -> CryptoFailable (Point curve) encodeScalarLE :: ByteArray bs => proxy curve -> Scalar curve -> bs- decodeScalarLE :: ByteArrayAccess bs => proxy curve -> bs -> CryptoFailable (Scalar curve)+ decodeScalarLE+ :: ByteArrayAccess bs => proxy curve -> bs -> CryptoFailable (Scalar curve) -- how to use bits in a secret key- scheduleSecret :: ( HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- )- => proxy curve- -> hash- -> SecretKey curve- -> (Scalar curve, View Bytes)+ scheduleSecret+ :: ( HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ )+ => proxy curve+ -> hash+ -> SecretKey curve+ -> (Scalar curve, View Bytes) -- | Size of public keys for this curve (in bytes) publicKeySize :: EllipticCurveEdDSA curve => proxy curve -> Int publicKeySize prx = signatureSize prx `div` 2 -- | Size of signatures for this curve (in bytes)-signatureSize :: forall proxy curve . EllipticCurveEdDSA curve- => proxy curve -> Int+signatureSize+ :: forall proxy curve+ . EllipticCurveEdDSA curve+ => proxy curve -> Int signatureSize _ = integralNatVal (Proxy :: Proxy (CurveDigestSize curve)) - -- Constructors -- | Try to build a public key from a bytearray-publicKey :: ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- , ByteArrayAccess ba- )- => proxy curve -> hash -> ba -> CryptoFailable (PublicKey curve hash)+publicKey+ :: ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ , ByteArrayAccess ba+ )+ => proxy curve -> hash -> ba -> CryptoFailable (PublicKey curve hash) publicKey prx _ bs | B.length bs == publicKeySize prx = CryptoPassed (PublicKey $ B.convert bs)@@ -141,181 +157,239 @@ CryptoFailed CryptoError_PublicKeySizeInvalid -- | Try to build a secret key from a bytearray-secretKey :: (EllipticCurveEdDSA curve, ByteArrayAccess ba)- => proxy curve -> ba -> CryptoFailable (SecretKey curve)+secretKey+ :: (EllipticCurveEdDSA curve, ByteArrayAccess ba)+ => proxy curve -> ba -> CryptoFailable (SecretKey curve) secretKey prx bs | B.length bs == secretKeySize prx = CryptoPassed (SecretKey $ B.convert bs)- | otherwise =+ | otherwise = CryptoFailed CryptoError_SecretKeyStructureInvalid -- | Try to build a signature from a bytearray-signature :: ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- , ByteArrayAccess ba- )- => proxy curve -> hash -> ba -> CryptoFailable (Signature curve hash)+signature+ :: ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ , ByteArrayAccess ba+ )+ => proxy curve -> hash -> ba -> CryptoFailable (Signature curve hash) signature prx _ bs | B.length bs == signatureSize prx = CryptoPassed (Signature $ B.convert bs) | otherwise = CryptoFailed CryptoError_SecretKeyStructureInvalid - -- Conversions -- | Generate a secret key-generateSecretKey :: (EllipticCurveEdDSA curve, MonadRandom m)- => proxy curve -> m (SecretKey curve)+generateSecretKey+ :: (EllipticCurveEdDSA curve, MonadRandom m)+ => proxy curve -> m (SecretKey curve) generateSecretKey prx = SecretKey <$> getRandomBytes (secretKeySize prx) -- | Create a public key from a secret key-toPublic :: ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- )- => proxy curve -> hash -> SecretKey curve -> PublicKey curve hash+toPublic+ :: ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ )+ => proxy curve -> hash -> SecretKey curve -> PublicKey curve hash toPublic prx alg priv = let p = pointBaseSmul prx (secretScalar prx alg priv) in pointPublic prx p -secretScalar :: ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- )- => proxy curve -> hash -> SecretKey curve -> Scalar curve+secretScalar+ :: ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ )+ => proxy curve -> hash -> SecretKey curve -> Scalar curve secretScalar prx alg priv = fst (scheduleSecret prx alg priv) - -- EdDSA signature generation & verification -- | Sign a message using the key pair-sign :: ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- , ByteArrayAccess msg- )- => proxy curve -> SecretKey curve -> PublicKey curve hash -> msg -> Signature curve hash+sign+ :: ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ , ByteArrayAccess msg+ )+ => proxy curve+ -> SecretKey curve+ -> PublicKey curve hash+ -> msg+ -> Signature curve hash sign prx = signCtx prx emptyCtx -- | Verify a message-verify :: ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- , ByteArrayAccess msg- )- => proxy curve -> PublicKey curve hash -> msg -> Signature curve hash -> Bool+verify+ :: ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ , ByteArrayAccess msg+ )+ => proxy curve -> PublicKey curve hash -> msg -> Signature curve hash -> Bool verify prx = verifyCtx prx emptyCtx -- | Sign a message using the key pair under context @ctx@-signCtx :: ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- , ByteArrayAccess ctx- , ByteArrayAccess msg- )- => proxy curve -> ctx -> SecretKey curve -> PublicKey curve hash -> msg -> Signature curve hash+signCtx+ :: ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ , ByteArrayAccess ctx+ , ByteArrayAccess msg+ )+ => proxy curve+ -> ctx+ -> SecretKey curve+ -> PublicKey curve hash+ -> msg+ -> Signature curve hash signCtx prx = signPhCtx prx False -- | Verify a message under context @ctx@-verifyCtx :: ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- , ByteArrayAccess ctx- , ByteArrayAccess msg- )- => proxy curve -> ctx -> PublicKey curve hash -> msg -> Signature curve hash -> Bool+verifyCtx+ :: ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ , ByteArrayAccess ctx+ , ByteArrayAccess msg+ )+ => proxy curve+ -> ctx+ -> PublicKey curve hash+ -> msg+ -> Signature curve hash+ -> Bool verifyCtx prx = verifyPhCtx prx False -- | Sign a prehashed message using the key pair under context @ctx@-signPh :: ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- , ByteArrayAccess ctx- )- => proxy curve -> ctx -> SecretKey curve -> PublicKey curve hash -> Digest prehash -> Signature curve hash+signPh+ :: ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ , ByteArrayAccess ctx+ )+ => proxy curve+ -> ctx+ -> SecretKey curve+ -> PublicKey curve hash+ -> Digest prehash+ -> Signature curve hash signPh prx = signPhCtx prx True -- | Verify a prehashed message under context @ctx@-verifyPh :: ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- , ByteArrayAccess ctx- )- => proxy curve -> ctx -> PublicKey curve hash -> Digest prehash -> Signature curve hash -> Bool+verifyPh+ :: ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ , ByteArrayAccess ctx+ )+ => proxy curve+ -> ctx+ -> PublicKey curve hash+ -> Digest prehash+ -> Signature curve hash+ -> Bool verifyPh prx = verifyPhCtx prx True -signPhCtx :: forall proxy curve hash ctx msg .- ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- , ByteArrayAccess ctx- , ByteArrayAccess msg- )- => proxy curve -> Bool -> ctx -> SecretKey curve -> PublicKey curve hash -> msg -> Signature curve hash+signPhCtx+ :: forall proxy curve hash ctx msg+ . ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ , ByteArrayAccess ctx+ , ByteArrayAccess msg+ )+ => proxy curve+ -> Bool+ -> ctx+ -> SecretKey curve+ -> PublicKey curve hash+ -> msg+ -> Signature curve hash signPhCtx prx ph ctx priv pub msg =- let alg = undefined :: hash+ let alg = undefined :: hash (s, prefix) = scheduleSecret prx alg priv digR = hashWithDom prx alg ph ctx (bytes prefix) msg- r = decodeScalarNoErr prx digR- pR = pointBaseSmul prx r- bsR = encodePoint prx pR- sK = getK prx ph ctx pub bsR msg- sS = scalarAdd prx r (scalarMul prx sK s)+ r = decodeScalarNoErr prx digR+ pR = pointBaseSmul prx r+ bsR = encodePoint prx pR+ sK = getK prx ph ctx pub bsR msg+ sS = scalarAdd prx r (scalarMul prx sK s) in encodeSignature prx (bsR, pR, sS) -verifyPhCtx :: ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- , ByteArrayAccess ctx- , ByteArrayAccess msg- )- => proxy curve -> Bool -> ctx -> PublicKey curve hash -> msg -> Signature curve hash -> Bool+verifyPhCtx+ :: ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ , ByteArrayAccess ctx+ , ByteArrayAccess msg+ )+ => proxy curve+ -> Bool+ -> ctx+ -> PublicKey curve hash+ -> msg+ -> Signature curve hash+ -> Bool verifyPhCtx prx ph ctx pub msg sig = case doVerify of CryptoPassed verified -> verified- CryptoFailed _ -> False+ CryptoFailed _ -> False where doVerify = do (bsR, pR, sS) <- decodeSignature prx sig nPub <- pointNegate prx `fmap` publicPoint prx pub- let sK = getK prx ph ctx pub bsR msg+ let sK = getK prx ph ctx pub bsR msg pR' = pointsSmulVarTime prx sS sK nPub return (pR == pR') emptyCtx :: Bytes emptyCtx = B.empty -getK :: forall proxy curve hash ctx msg .- ( EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ CurveDigestSize curve- , ByteArrayAccess ctx- , ByteArrayAccess msg- )- => proxy curve -> Bool -> ctx -> PublicKey curve hash -> Bytes -> msg -> Scalar curve+getK+ :: forall proxy curve hash ctx msg+ . ( EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ CurveDigestSize curve+ , ByteArrayAccess ctx+ , ByteArrayAccess msg+ )+ => proxy curve+ -> Bool+ -> ctx+ -> PublicKey curve hash+ -> Bytes+ -> msg+ -> Scalar curve getK prx ph ctx (PublicKey pub) bsR msg =- let alg = undefined :: hash+ let alg = undefined :: hash digK = hashWithDom prx alg ph ctx (bytes bsR <> bytes pub) msg in decodeScalarNoErr prx digK -encodeSignature :: EllipticCurveEdDSA curve- => proxy curve- -> (Bytes, Point curve, Scalar curve)- -> Signature curve hash-encodeSignature prx (bsR, _, sS) = Signature $ buildAndFreeze $- bytes bsR <> bytes bsS <> zero len0+encodeSignature+ :: EllipticCurveEdDSA curve+ => proxy curve+ -> (Bytes, Point curve, Scalar curve)+ -> Signature curve hash+encodeSignature prx (bsR, _, sS) =+ Signature $+ buildAndFreeze $+ bytes bsR <> bytes bsS <> zero len0 where- bsS = encodeScalarLE prx sS :: Bytes+ bsS = encodeScalarLE prx sS :: Bytes len0 = signatureSize prx - B.length bsR - B.length bsS -decodeSignature :: ( EllipticCurveEdDSA curve- , HashDigestSize hash ~ CurveDigestSize curve- )- => proxy curve- -> Signature curve hash- -> CryptoFailable (Bytes, Point curve, Scalar curve)+decodeSignature+ :: ( EllipticCurveEdDSA curve+ , HashDigestSize hash ~ CurveDigestSize curve+ )+ => proxy curve+ -> Signature curve hash+ -> CryptoFailable (Bytes, Point curve, Scalar curve) decodeSignature prx (Signature bs) = do let (bsR, bsS) = B.splitAt (publicKeySize prx) bs pR <- decodePoint prx bsR@@ -323,14 +397,14 @@ return (bsR, pR, sS) -- implementations are supposed to decode any scalar up to the size of the digest-decodeScalarNoErr :: (EllipticCurveEdDSA curve, ByteArrayAccess bs)- => proxy curve -> bs -> Scalar curve+decodeScalarNoErr+ :: (EllipticCurveEdDSA curve, ByteArrayAccess bs)+ => proxy curve -> bs -> Scalar curve decodeScalarNoErr prx = unwrap "decodeScalarNoErr" . decodeScalarLE prx unwrap :: String -> CryptoFailable a -> a unwrap name (CryptoFailed _) = error (name ++ ": assumption failed")-unwrap _ (CryptoPassed x) = x-+unwrap _ (CryptoPassed x) = x -- Ed25519 implementation @@ -340,11 +414,13 @@ hashWithDom _ alg ph ctx bss | not ph && B.null ctx = digestDomMsg alg bss- | otherwise = digestDomMsg alg (dom <> bss)- where dom = bytes ("SigEd25519 no Ed25519 collisions" :: ByteString) <>- byte (if ph then 1 else 0) <>- byte (fromIntegral $ B.length ctx) <>- bytes ctx+ | otherwise = digestDomMsg alg (dom <> bss)+ where+ dom =+ bytes ("SigEd25519 no Ed25519 collisions" :: ByteString)+ <> byte (if ph then 1 else 0)+ <> byte (fromIntegral $ B.length ctx)+ <> bytes ctx pointPublic _ = PublicKey . Edwards25519.pointEncode publicPoint _ = Edwards25519.pointDecode@@ -354,15 +430,14 @@ scheduleSecret prx alg priv = (decodeScalarNoErr prx clamped, B.dropView hashed 32) where- hashed = digest alg $ \update -> update priv+ hashed = digest alg $ \update -> update priv clamped :: Bytes clamped = B.copyAndFreeze (B.takeView hashed 32) $ \p -> do- b0 <- peekElemOff p 0 :: IO Word8- b31 <- peekElemOff p 31 :: IO Word8- pokeElemOff p 31 ((b31 .&. 0x7F) .|. 0x40)- pokeElemOff p 0 (b0 .&. 0xF8)-+ b0 <- peekElemOff p 0 :: IO Word8+ b31 <- peekElemOff p 31 :: IO Word8+ pokeElemOff p 31 ((b31 .&. 0x7F) .|. 0x40)+ pokeElemOff p 0 (b0 .&. 0xF8) {- Optimize hashing by limiting the number of roundtrips between Haskell and C.@@ -376,15 +451,17 @@ pinned trampoline. -} -digestDomMsg :: (HashAlgorithm alg, ByteArrayAccess msg)- => alg -> Builder -> msg -> Bytes+digestDomMsg+ :: (HashAlgorithm alg, ByteArrayAccess msg)+ => alg -> Builder -> msg -> Bytes digestDomMsg alg bss bs = digest alg $ \update -> update (buildAndFreeze bss :: Bytes) >> update bs -digest :: HashAlgorithm alg- => alg- -> ((forall bs . ByteArrayAccess bs => bs -> IO ()) -> IO ())- -> Bytes+digest+ :: HashAlgorithm alg+ => alg+ -> ((forall bs. ByteArrayAccess bs => bs -> IO ()) -> IO ())+ -> Bytes digest alg fn = B.convert $ unsafeDoIO $ do mc <- hashMutableInitWith alg fn (hashMutableUpdate mc)
Crypto/PubKey/ElGamal.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.PubKey.ElGamal -- License : BSD-style@@ -10,39 +12,46 @@ -- -- TODO: provide a mapping between integer and ciphertext -- generate numbers correctly----{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.PubKey.ElGamal- ( Params- , PublicNumber- , PrivateNumber- , EphemeralKey(..)- , SharedKey- , Signature+module Crypto.PubKey.ElGamal (+ Params,+ PublicNumber,+ PrivateNumber,+ EphemeralKey (..),+ SharedKey,+ Signature,+ -- * Generation- , generatePrivate- , generatePublic+ generatePrivate,+ generatePublic,+ -- * Encryption and decryption with no scheme- , encryptWith- , encrypt- , decrypt+ encryptWith,+ encrypt,+ decrypt,+ -- * Signature primitives- , signWith- , sign+ signWith,+ sign,+ -- * Verification primitives- , verify- ) where+ verify,+) where -import Data.Maybe (fromJust)-import Crypto.Internal.Imports+import Crypto.Hash import Crypto.Internal.ByteArray (ByteArrayAccess)-import Crypto.Number.ModArithmetic (expSafe, expFast, inverse)+import Crypto.Internal.Imports+import Crypto.Number.Basic (gcde) import Crypto.Number.Generate (generateMax)+import Crypto.Number.ModArithmetic (expFast, expSafe, inverse) import Crypto.Number.Serialize (os2ip)-import Crypto.Number.Basic (gcde)+import Crypto.PubKey.DH (+ Params (..),+ PrivateNumber (..),+ PublicNumber (..),+ SharedKey (..),+ ) import Crypto.Random.Types-import Crypto.PubKey.DH (PrivateNumber(..), PublicNumber(..), Params(..), SharedKey(..))-import Crypto.Hash+import Data.Maybe (fromJust) -- | ElGamal Signature data Signature = Signature (Integer, Integer)@@ -54,16 +63,15 @@ -- | generate a private number with no specific property -- this number is usually called a and need to be between -- 0 and q (order of the group G).--- generatePrivate :: MonadRandom m => Integer -> m PrivateNumber generatePrivate q = PrivateNumber <$> generateMax q -- | generate an ephemeral key which is a number with no specific property, -- and need to be between 0 and q (order of the group G).--- generateEphemeral :: MonadRandom m => Integer -> m EphemeralKey generateEphemeral q = toEphemeral <$> generatePrivate q- where toEphemeral (PrivateNumber n) = EphemeralKey n+ where+ toEphemeral (PrivateNumber n) = EphemeralKey n -- | generate a public number that is for the other party benefits. -- this number is usually called h=g^a@@ -72,23 +80,28 @@ -- | encrypt with a specified ephemeral key -- do not reuse ephemeral key.-encryptWith :: EphemeralKey -> Params -> PublicNumber -> Integer -> (Integer,Integer)-encryptWith (EphemeralKey b) (Params p g _) (PublicNumber h) m = (c1,c2)- where s = expSafe h b p- c1 = expSafe g b p- c2 = (s * m) `mod` p+encryptWith+ :: EphemeralKey -> Params -> PublicNumber -> Integer -> (Integer, Integer)+encryptWith (EphemeralKey b) (Params p g _) (PublicNumber h) m = (c1, c2)+ where+ s = expSafe h b p+ c1 = expSafe g b p+ c2 = (s * m) `mod` p -- | encrypt a message using params and public keys -- will generate b (called the ephemeral key)-encrypt :: MonadRandom m => Params -> PublicNumber -> Integer -> m (Integer,Integer)+encrypt+ :: MonadRandom m => Params -> PublicNumber -> Integer -> m (Integer, Integer) encrypt params@(Params p _ _) public m = (\b -> encryptWith b params public m) <$> generateEphemeral q- where q = p-1 -- p is prime, hence order of the group is p-1+ where+ q = p - 1 -- p is prime, hence order of the group is p-1 -- | decrypt message decrypt :: Params -> PrivateNumber -> (Integer, Integer) -> Integer-decrypt (Params p _ _) (PrivateNumber a) (c1,c2) = (c2 * sm1) `mod` p- where s = expSafe c1 a p- sm1 = fromJust $ inverse s p -- always inversible in Zp+decrypt (Params p _ _) (PrivateNumber a) (c1, c2) = (c2 * sm1) `mod` p+ where+ s = expSafe c1 a p+ sm1 = fromJust $ inverse s p -- always inversible in Zp -- | sign a message with an explicit k number --@@ -97,51 +110,64 @@ -- with some appropriate value of k, the signature generation can fail, -- and no signature is returned. User of this function need to retry -- with a different k value.-signWith :: (ByteArrayAccess msg, HashAlgorithm hash)- => Integer -- ^ random number k, between 0 and p-1 and gcd(k,p-1)=1- -> Params -- ^ DH params (p,g)- -> PrivateNumber -- ^ DH private key- -> hash -- ^ collision resistant hash algorithm- -> msg -- ^ message to sign- -> Maybe Signature+signWith+ :: (ByteArrayAccess msg, HashAlgorithm hash)+ => Integer+ -- ^ random number k, between 0 and p-1 and gcd(k,p-1)=1+ -> Params+ -- ^ DH params (p,g)+ -> PrivateNumber+ -- ^ DH private key+ -> hash+ -- ^ collision resistant hash algorithm+ -> msg+ -- ^ message to sign+ -> Maybe Signature signWith k (Params p g _) (PrivateNumber x) hashAlg msg- | k >= p-1 || d > 1 = Nothing -- gcd(k,p-1) is not 1- | s == 0 = Nothing- | otherwise = Just $ Signature (r,s)- where r = expSafe g k p- h = os2ip $ hashWith hashAlg msg- s = ((h - x*r) * kInv) `mod` (p-1)- (kInv,_,d) = gcde k (p-1)+ | k >= p - 1 || d > 1 = Nothing -- gcd(k,p-1) is not 1+ | s == 0 = Nothing+ | otherwise = Just $ Signature (r, s)+ where+ r = expSafe g k p+ h = os2ip $ hashWith hashAlg msg+ s = ((h - x * r) * kInv) `mod` (p - 1)+ (kInv, _, d) = gcde k (p - 1) -- | sign message -- -- This function will generate a random number, however -- as the signature might fail, the function will automatically retry -- until a proper signature has been created.----sign :: (ByteArrayAccess msg, HashAlgorithm hash, MonadRandom m)- => Params -- ^ DH params (p,g)- -> PrivateNumber -- ^ DH private key- -> hash -- ^ collision resistant hash algorithm- -> msg -- ^ message to sign- -> m Signature+sign+ :: (ByteArrayAccess msg, HashAlgorithm hash, MonadRandom m)+ => Params+ -- ^ DH params (p,g)+ -> PrivateNumber+ -- ^ DH private key+ -> hash+ -- ^ collision resistant hash algorithm+ -> msg+ -- ^ message to sign+ -> m Signature sign params@(Params p _ _) priv hashAlg msg = do- k <- generateMax (p-1)+ k <- generateMax (p - 1) case signWith k params priv hashAlg msg of- Nothing -> sign params priv hashAlg msg+ Nothing -> sign params priv hashAlg msg Just sig -> return sig -- | verify a signature-verify :: (ByteArrayAccess msg, HashAlgorithm hash)- => Params- -> PublicNumber- -> hash- -> msg- -> Signature- -> Bool-verify (Params p g _) (PublicNumber y) hashAlg msg (Signature (r,s))- | or [r <= 0,r >= p,s <= 0,s >= (p-1)] = False- | otherwise = lhs == rhs- where h = os2ip $ hashWith hashAlg msg- lhs = expFast g h p- rhs = (expFast y r p * expFast r s p) `mod` p+verify+ :: (ByteArrayAccess msg, HashAlgorithm hash)+ => Params+ -> PublicNumber+ -> hash+ -> msg+ -> Signature+ -> Bool+verify (Params p g _) (PublicNumber y) hashAlg msg (Signature (r, s))+ | or [r <= 0, r >= p, s <= 0, s >= (p - 1)] = False+ | otherwise = lhs == rhs+ where+ h = os2ip $ hashWith hashAlg msg+ lhs = expFast g h p+ rhs = (expFast y r p * expFast r s p) `mod` p
Crypto/PubKey/Internal.hs view
@@ -4,13 +4,12 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----module Crypto.PubKey.Internal- ( and'- , (&&!)- , dsaTruncHash- , dsaTruncHashDigest- ) where+module Crypto.PubKey.Internal (+ and',+ (&&!),+ dsaTruncHash,+ dsaTruncHashDigest,+) where import Data.Bits (shiftR) import Data.List (foldl')@@ -26,13 +25,14 @@ -- | This is a strict version of &&. (&&!) :: Bool -> Bool -> Bool-True &&! True = True-True &&! False = False-False &&! True = False+True &&! True = True+True &&! False = False+False &&! True = False False &&! False = False -- | Truncate and hash for DSA and ECDSA.-dsaTruncHash :: (ByteArrayAccess msg, HashAlgorithm hash) => hash -> msg -> Integer -> Integer+dsaTruncHash+ :: (ByteArrayAccess msg, HashAlgorithm hash) => hash -> msg -> Integer -> Integer dsaTruncHash hashAlg = dsaTruncHashDigest . hashWith hashAlg -- | Truncate a digest for DSA and ECDSA.@@ -40,8 +40,9 @@ dsaTruncHashDigest digest n | d > 0 = shiftR e d | otherwise = e- where e = os2ip digest- d = hashDigestSize (getHashAlg digest) * 8 - numBits n+ where+ e = os2ip digest+ d = hashDigestSize (getHashAlg digest) * 8 - numBits n getHashAlg :: Digest hash -> hash getHashAlg _ = undefined
Crypto/PubKey/MaskGenFunction.hs view
@@ -1,40 +1,45 @@+{-# LANGUAGE BangPatterns #-}+ -- | -- Module : Crypto.PubKey.MaskGenFunction -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----{-# LANGUAGE BangPatterns #-}-module Crypto.PubKey.MaskGenFunction- ( MaskGenAlgorithm- , mgf1- ) where+module Crypto.PubKey.MaskGenFunction (+ MaskGenAlgorithm,+ mgf1,+) where -import Crypto.Number.Serialize (i2ospOf_)-import Crypto.Hash-import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, Bytes)+import Crypto.Hash+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess, Bytes) import qualified Crypto.Internal.ByteArray as B+import Crypto.Number.Serialize (i2ospOf_) -- | Represent a mask generation algorithm type MaskGenAlgorithm seed output =- seed -- ^ seed- -> Int -- ^ length to generate+ seed+ -- ^ seed+ -> Int+ -- ^ length to generate -> output -- | Mask generation algorithm MGF1-mgf1 :: (ByteArrayAccess seed, ByteArray output, HashAlgorithm hashAlg)- => hashAlg- -> seed- -> Int- -> output+mgf1+ :: (ByteArrayAccess seed, ByteArray output, HashAlgorithm hashAlg)+ => hashAlg+ -> seed+ -> Int+ -> output mgf1 hashAlg seed len = let !seededCtx = hashUpdate (hashInitWith hashAlg) seed- in B.take len $ B.concat $ map (hashCounter seededCtx) [0..fromIntegral (maxCounter-1)]+ in B.take len $+ B.concat $+ map (hashCounter seededCtx) [0 .. fromIntegral (maxCounter - 1)] where- digestLen = hashDigestSize hashAlg- (chunks,left) = len `divMod` digestLen- maxCounter = if left > 0 then chunks + 1 else chunks+ digestLen = hashDigestSize hashAlg+ (chunks, left) = len `divMod` digestLen+ maxCounter = if left > 0 then chunks + 1 else chunks hashCounter :: HashAlgorithm a => Context a -> Integer -> Digest a hashCounter ctx counter = hashFinalize $ hashUpdate ctx (i2ospOf_ 4 counter :: Bytes)
Crypto/PubKey/RSA.hs view
@@ -4,23 +4,23 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----module Crypto.PubKey.RSA- ( Error(..)- , PublicKey(..)- , PrivateKey(..)- , Blinder(..)+module Crypto.PubKey.RSA (+ Error (..),+ PublicKey (..),+ PrivateKey (..),+ Blinder (..),+ -- * Generation function- , generateWith- , generate- , generateBlinder- ) where+ generateWith,+ generate,+ generateBlinder,+) where -import Crypto.Random.Types-import Crypto.Number.ModArithmetic (inverse, inverseCoprimes) import Crypto.Number.Generate (generateMax)+import Crypto.Number.ModArithmetic (inverse, inverseCoprimes) import Crypto.Number.Prime (generatePrime) import Crypto.PubKey.RSA.Types+import Crypto.Random.Types {- -- some bad implementation will not serialize ASN.1 integer properly, leading@@ -51,40 +51,52 @@ -- * e=0x10001 is a popular choice -- -- * e=3 is popular as well, but proven to not be as secure for some cases.----generateWith :: (Integer, Integer) -- ^ chosen distinct primes p and q- -> Int -- ^ size in bytes- -> Integer -- ^ RSA public exponent 'e'- -> Maybe (PublicKey, PrivateKey)-generateWith (p,q) size e =+generateWith+ :: (Integer, Integer)+ -- ^ chosen distinct primes p and q+ -> Int+ -- ^ size in bytes+ -> Integer+ -- ^ RSA public exponent 'e'+ -> Maybe (PublicKey, PrivateKey)+generateWith (p, q) size e = case inverse e phi of Nothing -> Nothing- Just d -> Just (pub,priv d)- where n = p*q- phi = (p-1)*(q-1)- -- q and p should be *distinct* *prime* numbers, hence always coprime- qinv = inverseCoprimes q p- pub = PublicKey { public_size = size- , public_n = n- , public_e = e- }- priv d = PrivateKey { private_pub = pub- , private_d = d- , private_p = p- , private_q = q- , private_dP = d `mod` (p-1)- , private_dQ = d `mod` (q-1)- , private_qinv = qinv- }+ Just d -> Just (pub, priv d)+ where+ n = p * q+ phi = (p - 1) * (q - 1)+ -- q and p should be *distinct* *prime* numbers, hence always coprime+ qinv = inverseCoprimes q p+ pub =+ PublicKey+ { public_size = size+ , public_n = n+ , public_e = e+ }+ priv d =+ PrivateKey+ { private_pub = pub+ , private_d = d+ , private_p = p+ , private_q = q+ , private_dP = d `mod` (p - 1)+ , private_dQ = d `mod` (q - 1)+ , private_qinv = qinv+ } -- | generate a pair of (private, public) key of size in bytes.-generate :: MonadRandom m- => Int -- ^ size in bytes- -> Integer -- ^ RSA public exponent 'e'- -> m (PublicKey, PrivateKey)+generate+ :: MonadRandom m+ => Int+ -- ^ size in bytes+ -> Integer+ -- ^ RSA public exponent 'e'+ -> m (PublicKey, PrivateKey) generate size e = loop where- loop = do -- loop until we find a valid key pair given e+ loop = do+ -- loop until we find a valid key pair given e pq <- generatePQ case generateWith pq size e of Nothing -> loop@@ -92,7 +104,7 @@ generatePQ = do p <- generatePrime (8 * (size `div` 2)) q <- generateQ p- return (p,q)+ return (p, q) generateQ p = do q <- generatePrime (8 * (size - (size `div` 2))) if p == q then generateQ p else return q@@ -101,8 +113,10 @@ -- -- the unique parameter apart from the random number generator is the -- public key value N.-generateBlinder :: MonadRandom m- => Integer -- ^ RSA public N parameter.- -> m Blinder+generateBlinder+ :: MonadRandom m+ => Integer+ -- ^ RSA public N parameter.+ -> m Blinder generateBlinder n = (\r -> Blinder r (inverseCoprimes r n)) <$> generateMax n
Crypto/PubKey/RSA/OAEP.hs view
@@ -7,121 +7,143 @@ -- -- RSA OAEP mode -- <http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding>----module Crypto.PubKey.RSA.OAEP- (- OAEPParams(..)- , defaultOAEPParams+module Crypto.PubKey.RSA.OAEP (+ OAEPParams (..),+ defaultOAEPParams,+ -- * OAEP encryption- , encryptWithSeed- , encrypt+ encryptWithSeed,+ encrypt,+ -- * OAEP decryption- , decrypt- , decryptSafer- ) where+ decrypt,+ decryptSafer,+) where -import Crypto.Hash-import Crypto.Random.Types-import Crypto.PubKey.RSA.Types-import Crypto.PubKey.MaskGenFunction-import Crypto.PubKey.RSA.Prim-import Crypto.PubKey.RSA (generateBlinder)-import Crypto.PubKey.Internal (and')-import Data.ByteString (ByteString)+import Crypto.Hash+import Crypto.PubKey.Internal (and')+import Crypto.PubKey.MaskGenFunction+import Crypto.PubKey.RSA (generateBlinder)+import Crypto.PubKey.RSA.Prim+import Crypto.PubKey.RSA.Types+import Crypto.Random.Types+import Data.Bits (xor)+import Data.ByteString (ByteString) import qualified Data.ByteString as B-import Data.Bits (xor) -import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray)+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B (convert) -- | Parameters for OAEP encryption/decryption data OAEPParams hash seed output = OAEPParams- { oaepHash :: hash -- ^ Hash function to use.- , oaepMaskGenAlg :: MaskGenAlgorithm seed output -- ^ Mask Gen algorithm to use.- , oaepLabel :: Maybe ByteString -- ^ Optional label prepended to message.+ { oaepHash :: hash+ -- ^ Hash function to use.+ , oaepMaskGenAlg :: MaskGenAlgorithm seed output+ -- ^ Mask Gen algorithm to use.+ , oaepLabel :: Maybe ByteString+ -- ^ Optional label prepended to message. } -- | Default Params with a specified hash function-defaultOAEPParams :: (ByteArrayAccess seed, ByteArray output, HashAlgorithm hash)- => hash- -> OAEPParams hash seed output+defaultOAEPParams+ :: (ByteArrayAccess seed, ByteArray output, HashAlgorithm hash)+ => hash+ -> OAEPParams hash seed output defaultOAEPParams hashAlg =- OAEPParams { oaepHash = hashAlg- , oaepMaskGenAlg = mgf1 hashAlg- , oaepLabel = Nothing- }+ OAEPParams+ { oaepHash = hashAlg+ , oaepMaskGenAlg = mgf1 hashAlg+ , oaepLabel = Nothing+ } -- | Encrypt a message using OAEP with a predefined seed.-encryptWithSeed :: HashAlgorithm hash- => ByteString -- ^ Seed- -> OAEPParams hash ByteString ByteString -- ^ OAEP params to use for encryption- -> PublicKey -- ^ Public key.- -> ByteString -- ^ Message to encrypt- -> Either Error ByteString+encryptWithSeed+ :: HashAlgorithm hash+ => ByteString+ -- ^ Seed+ -> OAEPParams hash ByteString ByteString+ -- ^ OAEP params to use for encryption+ -> PublicKey+ -- ^ Public key.+ -> ByteString+ -- ^ Message to encrypt+ -> Either Error ByteString encryptWithSeed seed oaep pk msg- | k < 2*hashLen+2 = Left InvalidParameters+ | k < 2 * hashLen + 2 = Left InvalidParameters | B.length seed /= hashLen = Left InvalidParameters- | mLen > k - 2*hashLen-2 = Left MessageTooLong- | otherwise = Right $ ep pk em- where -- parameters- k = public_size pk- mLen = B.length msg- mgf = oaepMaskGenAlg oaep- labelHash = hashWith (oaepHash oaep) (maybe B.empty id $ oaepLabel oaep)- hashLen = hashDigestSize (oaepHash oaep)+ | mLen > k - 2 * hashLen - 2 = Left MessageTooLong+ | otherwise = Right $ ep pk em+ where+ -- parameters+ k = public_size pk+ mLen = B.length msg+ mgf = oaepMaskGenAlg oaep+ labelHash = hashWith (oaepHash oaep) (maybe B.empty id $ oaepLabel oaep)+ hashLen = hashDigestSize (oaepHash oaep) - -- put fields- ps = B.replicate (k - mLen - 2*hashLen - 2) 0- db = B.concat [B.convert labelHash, ps, B.singleton 0x1, msg]- dbmask = mgf seed (k - hashLen - 1)- maskedDB = B.pack $ B.zipWith xor db dbmask- seedMask = mgf maskedDB hashLen- maskedSeed = B.pack $ B.zipWith xor seed seedMask- em = B.concat [B.singleton 0x0,maskedSeed,maskedDB]+ -- put fields+ ps = B.replicate (k - mLen - 2 * hashLen - 2) 0+ db = B.concat [B.convert labelHash, ps, B.singleton 0x1, msg]+ dbmask = mgf seed (k - hashLen - 1)+ maskedDB = B.pack $ B.zipWith xor db dbmask+ seedMask = mgf maskedDB hashLen+ maskedSeed = B.pack $ B.zipWith xor seed seedMask+ em = B.concat [B.singleton 0x0, maskedSeed, maskedDB] -- | Encrypt a message using OAEP-encrypt :: (HashAlgorithm hash, MonadRandom m)- => OAEPParams hash ByteString ByteString -- ^ OAEP params to use for encryption.- -> PublicKey -- ^ Public key.- -> ByteString -- ^ Message to encrypt- -> m (Either Error ByteString)+encrypt+ :: (HashAlgorithm hash, MonadRandom m)+ => OAEPParams hash ByteString ByteString+ -- ^ OAEP params to use for encryption.+ -> PublicKey+ -- ^ Public key.+ -> ByteString+ -- ^ Message to encrypt+ -> m (Either Error ByteString) encrypt oaep pk msg = do seed <- getRandomBytes hashLen return (encryptWithSeed seed oaep pk msg) where- hashLen = hashDigestSize (oaepHash oaep)+ hashLen = hashDigestSize (oaepHash oaep) -- | un-pad a OAEP encoded message. -- -- It doesn't apply the RSA decryption primitive-unpad :: HashAlgorithm hash- => OAEPParams hash ByteString ByteString -- ^ OAEP params to use- -> Int -- ^ size of the key in bytes- -> ByteString -- ^ encoded message (not encrypted)- -> Either Error ByteString+unpad+ :: HashAlgorithm hash+ => OAEPParams hash ByteString ByteString+ -- ^ OAEP params to use+ -> Int+ -- ^ size of the key in bytes+ -> ByteString+ -- ^ encoded message (not encrypted)+ -> Either Error ByteString unpad oaep k em | paddingSuccess = Right msg- | otherwise = Left MessageNotRecognized- where -- parameters- mgf = oaepMaskGenAlg oaep- labelHash = B.convert $ hashWith (oaepHash oaep) (maybe B.empty id $ oaepLabel oaep)- hashLen = hashDigestSize (oaepHash oaep)- -- getting em's fields- (pb, em0) = B.splitAt 1 em- (maskedSeed,maskedDB) = B.splitAt hashLen em0- seedMask = mgf maskedDB hashLen- seed = B.pack $ B.zipWith xor maskedSeed seedMask- dbmask = mgf seed (k - hashLen - 1)- db = B.pack $ B.zipWith xor maskedDB dbmask- -- getting db's fields- (labelHash',db1) = B.splitAt hashLen db- (_,db2) = B.break (/= 0) db1- (ps1,msg) = B.splitAt 1 db2+ | otherwise = Left MessageNotRecognized+ where+ -- parameters+ mgf = oaepMaskGenAlg oaep+ labelHash = B.convert $ hashWith (oaepHash oaep) (maybe B.empty id $ oaepLabel oaep)+ hashLen = hashDigestSize (oaepHash oaep)+ -- getting em's fields+ (pb, em0) = B.splitAt 1 em+ (maskedSeed, maskedDB) = B.splitAt hashLen em0+ seedMask = mgf maskedDB hashLen+ seed = B.pack $ B.zipWith xor maskedSeed seedMask+ dbmask = mgf seed (k - hashLen - 1)+ db = B.pack $ B.zipWith xor maskedDB dbmask+ -- getting db's fields+ (labelHash', db1) = B.splitAt hashLen db+ (_, db2) = B.break (/= 0) db1+ (ps1, msg) = B.splitAt 1 db2 - paddingSuccess = and' [ labelHash' == labelHash -- no need for constant eq- , ps1 == B.replicate 1 0x1- , pb == B.replicate 1 0x0- ]+ paddingSuccess =+ and'+ [ labelHash' == labelHash -- no need for constant eq+ , ps1 == B.replicate 1 0x1+ , pb == B.replicate 1 0x0+ ] -- | Decrypt a ciphertext using OAEP --@@ -129,26 +151,36 @@ -- information from the timing of the operation, the blinder can be set to None. -- -- If unsure always set a blinder or use decryptSafer-decrypt :: HashAlgorithm hash- => Maybe Blinder -- ^ Optional blinder- -> OAEPParams hash ByteString ByteString -- ^ OAEP params to use for decryption- -> PrivateKey -- ^ Private key- -> ByteString -- ^ Cipher text- -> Either Error ByteString+decrypt+ :: HashAlgorithm hash+ => Maybe Blinder+ -- ^ Optional blinder+ -> OAEPParams hash ByteString ByteString+ -- ^ OAEP params to use for decryption+ -> PrivateKey+ -- ^ Private key+ -> ByteString+ -- ^ Cipher text+ -> Either Error ByteString decrypt blinder oaep pk cipher | B.length cipher /= k = Left MessageSizeIncorrect- | k < 2*hashLen+2 = Left InvalidParameters- | otherwise = unpad oaep (private_size pk) $ dp blinder pk cipher- where -- parameters- k = private_size pk- hashLen = hashDigestSize (oaepHash oaep)+ | k < 2 * hashLen + 2 = Left InvalidParameters+ | otherwise = unpad oaep (private_size pk) $ dp blinder pk cipher+ where+ -- parameters+ k = private_size pk+ hashLen = hashDigestSize (oaepHash oaep) -- | Decrypt a ciphertext using OAEP and by automatically generating a blinder.-decryptSafer :: (HashAlgorithm hash, MonadRandom m)- => OAEPParams hash ByteString ByteString -- ^ OAEP params to use for decryption- -> PrivateKey -- ^ Private key- -> ByteString -- ^ Cipher text- -> m (Either Error ByteString)+decryptSafer+ :: (HashAlgorithm hash, MonadRandom m)+ => OAEPParams hash ByteString ByteString+ -- ^ OAEP params to use for decryption+ -> PrivateKey+ -- ^ Private key+ -> ByteString+ -- ^ Cipher text+ -> m (Either Error ByteString) decryptSafer oaep pk cipher = do blinder <- generateBlinder (private_n pk) return (decrypt (Just blinder) oaep pk cipher)
Crypto/PubKey/RSA/PKCS15.hs view
@@ -4,36 +4,37 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----module Crypto.PubKey.RSA.PKCS15- (+module Crypto.PubKey.RSA.PKCS15 ( -- * Padding and unpadding- pad- , padSignature- , unpad+ pad,+ padSignature,+ unpad,+ -- * Private key operations- , decrypt- , decryptSafer- , sign- , signSafer+ decrypt,+ decryptSafer,+ sign,+ signSafer,+ -- * Public key operations- , encrypt- , verify+ encrypt,+ verify,+ -- * Hash ASN1 description- , HashAlgorithmASN1- ) where+ HashAlgorithmASN1,+) where -import Crypto.Random.Types-import Crypto.PubKey.Internal (and')-import Crypto.PubKey.RSA.Types-import Crypto.PubKey.RSA.Prim-import Crypto.PubKey.RSA (generateBlinder)-import Crypto.Hash+import Crypto.Hash+import Crypto.PubKey.Internal (and')+import Crypto.PubKey.RSA (generateBlinder)+import Crypto.PubKey.RSA.Prim+import Crypto.PubKey.RSA.Types+import Crypto.Random.Types -import Data.ByteString (ByteString)-import Data.Word+import Data.ByteString (ByteString)+import Data.Word -import Crypto.Internal.ByteArray (ByteArray, Bytes)+import Crypto.Internal.ByteArray (ByteArray, Bytes) import qualified Crypto.Internal.ByteArray as B -- | A specialized class for hash algorithm that can product@@ -46,28 +47,230 @@ -- http://uk.emc.com/emc-plus/rsa-labs/pkcs/files/h11300-wp-pkcs-1v2-2-rsa-cryptography-standard.pdf -- EMSA-PKCS1-v1_5 instance HashAlgorithmASN1 MD2 where- hashDigestASN1 = addDigestPrefix [0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x02,0x05,0x00,0x04,0x10]+ hashDigestASN1 =+ addDigestPrefix+ [ 0x30+ , 0x20+ , 0x30+ , 0x0c+ , 0x06+ , 0x08+ , 0x2a+ , 0x86+ , 0x48+ , 0x86+ , 0xf7+ , 0x0d+ , 0x02+ , 0x02+ , 0x05+ , 0x00+ , 0x04+ , 0x10+ ] instance HashAlgorithmASN1 MD5 where- hashDigestASN1 = addDigestPrefix [0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x04,0x10]+ hashDigestASN1 =+ addDigestPrefix+ [ 0x30+ , 0x20+ , 0x30+ , 0x0c+ , 0x06+ , 0x08+ , 0x2a+ , 0x86+ , 0x48+ , 0x86+ , 0xf7+ , 0x0d+ , 0x02+ , 0x05+ , 0x05+ , 0x00+ , 0x04+ , 0x10+ ] instance HashAlgorithmASN1 SHA1 where- hashDigestASN1 = addDigestPrefix [0x30,0x21,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1a,0x05,0x00,0x04,0x14]+ hashDigestASN1 =+ addDigestPrefix+ [ 0x30+ , 0x21+ , 0x30+ , 0x09+ , 0x06+ , 0x05+ , 0x2b+ , 0x0e+ , 0x03+ , 0x02+ , 0x1a+ , 0x05+ , 0x00+ , 0x04+ , 0x14+ ] instance HashAlgorithmASN1 SHA224 where- hashDigestASN1 = addDigestPrefix [0x30,0x2d,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x04,0x05,0x00,0x04,0x1c]+ hashDigestASN1 =+ addDigestPrefix+ [ 0x30+ , 0x2d+ , 0x30+ , 0x0d+ , 0x06+ , 0x09+ , 0x60+ , 0x86+ , 0x48+ , 0x01+ , 0x65+ , 0x03+ , 0x04+ , 0x02+ , 0x04+ , 0x05+ , 0x00+ , 0x04+ , 0x1c+ ] instance HashAlgorithmASN1 SHA256 where- hashDigestASN1 = addDigestPrefix [0x30,0x31,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01,0x05,0x00,0x04,0x20]+ hashDigestASN1 =+ addDigestPrefix+ [ 0x30+ , 0x31+ , 0x30+ , 0x0d+ , 0x06+ , 0x09+ , 0x60+ , 0x86+ , 0x48+ , 0x01+ , 0x65+ , 0x03+ , 0x04+ , 0x02+ , 0x01+ , 0x05+ , 0x00+ , 0x04+ , 0x20+ ] instance HashAlgorithmASN1 SHA384 where- hashDigestASN1 = addDigestPrefix [0x30,0x41,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x02,0x05,0x00,0x04,0x30]+ hashDigestASN1 =+ addDigestPrefix+ [ 0x30+ , 0x41+ , 0x30+ , 0x0d+ , 0x06+ , 0x09+ , 0x60+ , 0x86+ , 0x48+ , 0x01+ , 0x65+ , 0x03+ , 0x04+ , 0x02+ , 0x02+ , 0x05+ , 0x00+ , 0x04+ , 0x30+ ] instance HashAlgorithmASN1 SHA512 where- hashDigestASN1 = addDigestPrefix [0x30,0x51,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x03,0x05,0x00,0x04,0x40]+ hashDigestASN1 =+ addDigestPrefix+ [ 0x30+ , 0x51+ , 0x30+ , 0x0d+ , 0x06+ , 0x09+ , 0x60+ , 0x86+ , 0x48+ , 0x01+ , 0x65+ , 0x03+ , 0x04+ , 0x02+ , 0x03+ , 0x05+ , 0x00+ , 0x04+ , 0x40+ ] instance HashAlgorithmASN1 SHA512t_224 where- hashDigestASN1 = addDigestPrefix [0x30,0x2d,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x05,0x05,0x00,0x04,0x1c]+ hashDigestASN1 =+ addDigestPrefix+ [ 0x30+ , 0x2d+ , 0x30+ , 0x0d+ , 0x06+ , 0x09+ , 0x60+ , 0x86+ , 0x48+ , 0x01+ , 0x65+ , 0x03+ , 0x04+ , 0x02+ , 0x05+ , 0x05+ , 0x00+ , 0x04+ , 0x1c+ ] instance HashAlgorithmASN1 SHA512t_256 where- hashDigestASN1 = addDigestPrefix [0x30,0x31,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x06,0x05,0x00,0x04,0x20]+ hashDigestASN1 =+ addDigestPrefix+ [ 0x30+ , 0x31+ , 0x30+ , 0x0d+ , 0x06+ , 0x09+ , 0x60+ , 0x86+ , 0x48+ , 0x01+ , 0x65+ , 0x03+ , 0x04+ , 0x02+ , 0x06+ , 0x05+ , 0x00+ , 0x04+ , 0x20+ ] instance HashAlgorithmASN1 RIPEMD160 where- hashDigestASN1 = addDigestPrefix [0x30,0x21,0x30,0x09,0x06,0x05,0x2b,0x24,0x03,0x02,0x01,0x05,0x00,0x04,0x14]+ hashDigestASN1 =+ addDigestPrefix+ [ 0x30+ , 0x21+ , 0x30+ , 0x09+ , 0x06+ , 0x05+ , 0x2b+ , 0x24+ , 0x03+ , 0x02+ , 0x01+ , 0x05+ , 0x00+ , 0x04+ , 0x14+ ] --+ -- ** Hack **+ -- -- this happens to not need a real ASN1 encoder, because -- thanks to the digest being a specific size AND@@ -89,47 +292,51 @@ B.pack prefix `B.append` B.convert digest -- | This produce a standard PKCS1.5 padding for encryption-pad :: (MonadRandom m, ByteArray message) => Int -> message -> m (Either Error message)+pad+ :: (MonadRandom m, ByteArray message) => Int -> message -> m (Either Error message) pad len m | B.length m > len - 11 = return (Left MessageTooLong)- | otherwise = do+ | otherwise = do padding <- getNonNullRandom (len - B.length m - 3)- return $ Right $ B.concat [ B.pack [0,2], padding, B.pack [0], m ]-+ return $ Right $ B.concat [B.pack [0, 2], padding, B.pack [0], m] where -- get random non-null bytes getNonNullRandom :: (ByteArray bytearray, MonadRandom m) => Int -> m bytearray getNonNullRandom n = do bs0 <- getRandomBytes n let bytes = B.pack $ filter (/= 0) $ B.unpack (bs0 :: Bytes)- left = n - B.length bytes+ left = n - B.length bytes if left == 0 then return bytes- else do bend <- getNonNullRandom left- return (bytes `B.append` bend)+ else do+ bend <- getNonNullRandom left+ return (bytes `B.append` bend) -- | Produce a standard PKCS1.5 padding for signature-padSignature :: ByteArray signature => Int -> signature -> Either Error signature+padSignature+ :: ByteArray signature => Int -> signature -> Either Error signature padSignature klen signature | klen < siglen + 11 = Left SignatureTooLong- | otherwise = Right (B.pack padding `B.append` signature)+ | otherwise = Right (B.pack padding `B.append` signature) where- siglen = B.length signature- padding = 0 : 1 : (replicate (klen - siglen - 3) 0xff ++ [0])+ siglen = B.length signature+ padding = 0 : 1 : (replicate (klen - siglen - 3) 0xff ++ [0]) -- | Try to remove a standard PKCS1.5 encryption padding. unpad :: ByteArray bytearray => bytearray -> Either Error bytearray unpad packed | paddingSuccess = Right m- | otherwise = Left MessageNotRecognized+ | otherwise = Left MessageNotRecognized where- (zt, ps0m) = B.splitAt 2 packed- (ps, zm) = B.span (/= 0) ps0m- (z, m) = B.splitAt 1 zm- paddingSuccess = and' [ zt `B.constEq` (B.pack [0,2] :: Bytes)- , z == B.zero 1- , B.length ps >= 8- ]+ (zt, ps0m) = B.splitAt 2 packed+ (ps, zm) = B.span (/= 0) ps0m+ (z, m) = B.splitAt 1 zm+ paddingSuccess =+ and'+ [ zt `B.constEq` (B.pack [0, 2] :: Bytes)+ , z == B.zero 1+ , B.length ps >= 8+ ] -- | decrypt message using the private key. --@@ -139,19 +346,26 @@ -- If unsure always set a blinder or use decryptSafer -- -- The message is returned un-padded.-decrypt :: Maybe Blinder -- ^ optional blinder- -> PrivateKey -- ^ RSA private key- -> ByteString -- ^ cipher text- -> Either Error ByteString+decrypt+ :: Maybe Blinder+ -- ^ optional blinder+ -> PrivateKey+ -- ^ RSA private key+ -> ByteString+ -- ^ cipher text+ -> Either Error ByteString decrypt blinder pk c | B.length c /= (private_size pk) = Left MessageSizeIncorrect- | otherwise = unpad $ dp blinder pk c+ | otherwise = unpad $ dp blinder pk c -- | decrypt message using the private key and by automatically generating a blinder.-decryptSafer :: MonadRandom m- => PrivateKey -- ^ RSA private key- -> ByteString -- ^ cipher text- -> m (Either Error ByteString)+decryptSafer+ :: MonadRandom m+ => PrivateKey+ -- ^ RSA private key+ -> ByteString+ -- ^ cipher text+ -> m (Either Error ByteString) decryptSafer pk b = do blinder <- generateBlinder (private_n pk) return (decrypt (Just blinder) pk b)@@ -160,7 +374,8 @@ -- -- The message needs to be smaller than the key size - 11. -- The message should not be padded.-encrypt :: MonadRandom m => PublicKey -> ByteString -> m (Either Error ByteString)+encrypt+ :: MonadRandom m => PublicKey -> ByteString -> m (Either Error ByteString) encrypt pk m = do r <- pad (public_size pk) m case r of@@ -173,41 +388,53 @@ -- information from the timing of the operation, the blinder can be set to None. -- -- If unsure always set a blinder or use signSafer-sign :: HashAlgorithmASN1 hashAlg- => Maybe Blinder -- ^ optional blinder- -> Maybe hashAlg -- ^ hash algorithm- -> PrivateKey -- ^ private key- -> ByteString -- ^ message to sign- -> Either Error ByteString+sign+ :: HashAlgorithmASN1 hashAlg+ => Maybe Blinder+ -- ^ optional blinder+ -> Maybe hashAlg+ -- ^ hash algorithm+ -> PrivateKey+ -- ^ private key+ -> ByteString+ -- ^ message to sign+ -> Either Error ByteString sign blinder hashDescr pk m = dp blinder pk `fmap` makeSignature hashDescr (private_size pk) m -- | sign message using the private key and by automatically generating a blinder.-signSafer :: (HashAlgorithmASN1 hashAlg, MonadRandom m)- => Maybe hashAlg -- ^ Hash algorithm- -> PrivateKey -- ^ private key- -> ByteString -- ^ message to sign- -> m (Either Error ByteString)+signSafer+ :: (HashAlgorithmASN1 hashAlg, MonadRandom m)+ => Maybe hashAlg+ -- ^ Hash algorithm+ -> PrivateKey+ -- ^ private key+ -> ByteString+ -- ^ message to sign+ -> m (Either Error ByteString) signSafer hashAlg pk m = do blinder <- generateBlinder (private_n pk) return (sign (Just blinder) hashAlg pk m) -- | verify message with the signed message-verify :: HashAlgorithmASN1 hashAlg- => Maybe hashAlg- -> PublicKey- -> ByteString- -> ByteString- -> Bool+verify+ :: HashAlgorithmASN1 hashAlg+ => Maybe hashAlg+ -> PublicKey+ -> ByteString+ -> ByteString+ -> Bool verify hashAlg pk m sm = case makeSignature hashAlg (public_size pk) m of- Left _ -> False+ Left _ -> False Right s -> s == (ep pk sm) -- | make signature digest, used in 'sign' and 'verify'-makeSignature :: HashAlgorithmASN1 hashAlg- => Maybe hashAlg -- ^ optional hashing algorithm- -> Int- -> ByteString- -> Either Error ByteString-makeSignature Nothing klen m = padSignature klen m+makeSignature+ :: HashAlgorithmASN1 hashAlg+ => Maybe hashAlg+ -- ^ optional hashing algorithm+ -> Int+ -> ByteString+ -> Either Error ByteString+makeSignature Nothing klen m = padSignature klen m makeSignature (Just hashAlg) klen m = padSignature klen (hashDigestASN1 $ hashWith hashAlg m)
Crypto/PubKey/RSA/PSS.hs view
@@ -4,56 +4,62 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----module Crypto.PubKey.RSA.PSS- ( PSSParams(..)- , defaultPSSParams- , defaultPSSParamsSHA1+module Crypto.PubKey.RSA.PSS (+ PSSParams (..),+ defaultPSSParams,+ defaultPSSParamsSHA1,+ -- * Sign and verify functions- , signWithSalt- , signDigestWithSalt- , sign- , signDigest- , signSafer- , signDigestSafer- , verify- , verifyDigest- ) where+ signWithSalt,+ signDigestWithSalt,+ sign,+ signDigest,+ signSafer,+ signDigestSafer,+ verify,+ verifyDigest,+) where -import Crypto.Random.Types-import Crypto.PubKey.RSA.Types-import Crypto.PubKey.RSA.Prim-import Crypto.PubKey.RSA (generateBlinder)-import Crypto.PubKey.MaskGenFunction-import Crypto.Hash-import Crypto.Number.Basic (numBits)-import Data.Bits (xor, shiftR, (.&.))-import Data.Word+import Crypto.Hash+import Crypto.Number.Basic (numBits)+import Crypto.PubKey.MaskGenFunction+import Crypto.PubKey.RSA (generateBlinder)+import Crypto.PubKey.RSA.Prim+import Crypto.PubKey.RSA.Types+import Crypto.Random.Types+import Data.Bits (shiftR, xor, (.&.))+import Data.Word -import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray)+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B (convert, eq) -import Data.ByteString (ByteString)+import Data.ByteString (ByteString) import qualified Data.ByteString as B -- | Parameters for PSS signature/verification. data PSSParams hash seed output = PSSParams- { pssHash :: hash -- ^ Hash function to use- , pssMaskGenAlg :: MaskGenAlgorithm seed output -- ^ Mask Gen algorithm to use- , pssSaltLength :: Int -- ^ Length of salt. need to be <= to hLen.- , pssTrailerField :: Word8 -- ^ Trailer field, usually 0xbc+ { pssHash :: hash+ -- ^ Hash function to use+ , pssMaskGenAlg :: MaskGenAlgorithm seed output+ -- ^ Mask Gen algorithm to use+ , pssSaltLength :: Int+ -- ^ Length of salt. need to be <= to hLen.+ , pssTrailerField :: Word8+ -- ^ Trailer field, usually 0xbc } -- | Default Params with a specified hash function-defaultPSSParams :: (ByteArrayAccess seed, ByteArray output, HashAlgorithm hash)- => hash- -> PSSParams hash seed output+defaultPSSParams+ :: (ByteArrayAccess seed, ByteArray output, HashAlgorithm hash)+ => hash+ -> PSSParams hash seed output defaultPSSParams hashAlg =- PSSParams { pssHash = hashAlg- , pssMaskGenAlg = mgf1 hashAlg- , pssSaltLength = hashDigestSize hashAlg- , pssTrailerField = 0xbc- }+ PSSParams+ { pssHash = hashAlg+ , pssMaskGenAlg = mgf1 hashAlg+ , pssSaltLength = hashDigestSize hashAlg+ , pssTrailerField = 0xbc+ } -- | Default Params using SHA1 algorithm. defaultPSSParamsSHA1 :: PSSParams SHA1 ByteString ByteString@@ -62,138 +68,181 @@ -- | Sign using the PSS parameters and the salt explicitely passed as parameters. -- -- the function ignore SaltLength from the PSS Parameters-signDigestWithSalt :: HashAlgorithm hash- => ByteString -- ^ Salt to use- -> Maybe Blinder -- ^ optional blinder to use- -> PSSParams hash ByteString ByteString -- ^ PSS Parameters to use- -> PrivateKey -- ^ RSA Private Key- -> Digest hash -- ^ Message digest- -> Either Error ByteString+signDigestWithSalt+ :: HashAlgorithm hash+ => ByteString+ -- ^ Salt to use+ -> Maybe Blinder+ -- ^ optional blinder to use+ -> PSSParams hash ByteString ByteString+ -- ^ PSS Parameters to use+ -> PrivateKey+ -- ^ RSA Private Key+ -> Digest hash+ -- ^ Message digest+ -> Either Error ByteString signDigestWithSalt salt blinder params pk digest | emLen < hashLen + saltLen + 2 = Left InvalidParameters- | otherwise = Right $ dp blinder pk em- where k = private_size pk- emLen = if emTruncate pubBits then k - 1 else k- mHash = B.convert digest- dbLen = emLen - hashLen - 1- saltLen = B.length salt- hashLen = hashDigestSize (pssHash params)- pubBits = numBits (private_n pk)- m' = B.concat [B.replicate 8 0,mHash,salt]- h = B.convert $ hashWith (pssHash params) m'- db = B.concat [B.replicate (dbLen - saltLen - 1) 0,B.singleton 1,salt]- dbmask = pssMaskGenAlg params h dbLen- maskedDB = B.pack $ normalizeToKeySize pubBits $ B.zipWith xor db dbmask- em = B.concat [maskedDB, h, B.singleton (pssTrailerField params)]+ | otherwise = Right $ dp blinder pk em+ where+ k = private_size pk+ emLen = if emTruncate pubBits then k - 1 else k+ mHash = B.convert digest+ dbLen = emLen - hashLen - 1+ saltLen = B.length salt+ hashLen = hashDigestSize (pssHash params)+ pubBits = numBits (private_n pk)+ m' = B.concat [B.replicate 8 0, mHash, salt]+ h = B.convert $ hashWith (pssHash params) m'+ db = B.concat [B.replicate (dbLen - saltLen - 1) 0, B.singleton 1, salt]+ dbmask = pssMaskGenAlg params h dbLen+ maskedDB = B.pack $ normalizeToKeySize pubBits $ B.zipWith xor db dbmask+ em = B.concat [maskedDB, h, B.singleton (pssTrailerField params)] -- | Sign using the PSS parameters and the salt explicitely passed as parameters. -- -- the function ignore SaltLength from the PSS Parameters-signWithSalt :: HashAlgorithm hash- => ByteString -- ^ Salt to use- -> Maybe Blinder -- ^ optional blinder to use- -> PSSParams hash ByteString ByteString -- ^ PSS Parameters to use- -> PrivateKey -- ^ RSA Private Key- -> ByteString -- ^ Message to sign- -> Either Error ByteString+signWithSalt+ :: HashAlgorithm hash+ => ByteString+ -- ^ Salt to use+ -> Maybe Blinder+ -- ^ optional blinder to use+ -> PSSParams hash ByteString ByteString+ -- ^ PSS Parameters to use+ -> PrivateKey+ -- ^ RSA Private Key+ -> ByteString+ -- ^ Message to sign+ -> Either Error ByteString signWithSalt salt blinder params pk m = signDigestWithSalt salt blinder params pk mHash- where mHash = hashWith (pssHash params) m+ where+ mHash = hashWith (pssHash params) m -- | Sign using the PSS Parameters-sign :: (HashAlgorithm hash, MonadRandom m)- => Maybe Blinder -- ^ optional blinder to use- -> PSSParams hash ByteString ByteString -- ^ PSS Parameters to use- -> PrivateKey -- ^ RSA Private Key- -> ByteString -- ^ Message to sign- -> m (Either Error ByteString)+sign+ :: (HashAlgorithm hash, MonadRandom m)+ => Maybe Blinder+ -- ^ optional blinder to use+ -> PSSParams hash ByteString ByteString+ -- ^ PSS Parameters to use+ -> PrivateKey+ -- ^ RSA Private Key+ -> ByteString+ -- ^ Message to sign+ -> m (Either Error ByteString) sign blinder params pk m = do salt <- getRandomBytes (pssSaltLength params) return (signWithSalt salt blinder params pk m) -- | Sign using the PSS Parameters-signDigest :: (HashAlgorithm hash, MonadRandom m)- => Maybe Blinder -- ^ optional blinder to use- -> PSSParams hash ByteString ByteString -- ^ PSS Parameters to use- -> PrivateKey -- ^ RSA Private Key- -> Digest hash -- ^ Message digest- -> m (Either Error ByteString)+signDigest+ :: (HashAlgorithm hash, MonadRandom m)+ => Maybe Blinder+ -- ^ optional blinder to use+ -> PSSParams hash ByteString ByteString+ -- ^ PSS Parameters to use+ -> PrivateKey+ -- ^ RSA Private Key+ -> Digest hash+ -- ^ Message digest+ -> m (Either Error ByteString) signDigest blinder params pk digest = do salt <- getRandomBytes (pssSaltLength params) return (signDigestWithSalt salt blinder params pk digest) -- | Sign using the PSS Parameters and an automatically generated blinder.-signSafer :: (HashAlgorithm hash, MonadRandom m)- => PSSParams hash ByteString ByteString -- ^ PSS Parameters to use- -> PrivateKey -- ^ private key- -> ByteString -- ^ message to sign- -> m (Either Error ByteString)+signSafer+ :: (HashAlgorithm hash, MonadRandom m)+ => PSSParams hash ByteString ByteString+ -- ^ PSS Parameters to use+ -> PrivateKey+ -- ^ private key+ -> ByteString+ -- ^ message to sign+ -> m (Either Error ByteString) signSafer params pk m = do blinder <- generateBlinder (private_n pk) sign (Just blinder) params pk m -- | Sign using the PSS Parameters and an automatically generated blinder.-signDigestSafer :: (HashAlgorithm hash, MonadRandom m)- => PSSParams hash ByteString ByteString -- ^ PSS Parameters to use- -> PrivateKey -- ^ private key- -> Digest hash -- ^ message digst- -> m (Either Error ByteString)+signDigestSafer+ :: (HashAlgorithm hash, MonadRandom m)+ => PSSParams hash ByteString ByteString+ -- ^ PSS Parameters to use+ -> PrivateKey+ -- ^ private key+ -> Digest hash+ -- ^ message digst+ -> m (Either Error ByteString) signDigestSafer params pk digest = do blinder <- generateBlinder (private_n pk) signDigest (Just blinder) params pk digest -- | Verify a signature using the PSS Parameters-verify :: HashAlgorithm hash- => PSSParams hash ByteString ByteString- -- ^ PSS Parameters to use to verify,- -- this need to be identical to the parameters when signing- -> PublicKey -- ^ RSA Public Key- -> ByteString -- ^ Message to verify- -> ByteString -- ^ Signature- -> Bool+verify+ :: HashAlgorithm hash+ => PSSParams hash ByteString ByteString+ -- ^ PSS Parameters to use to verify,+ -- this need to be identical to the parameters when signing+ -> PublicKey+ -- ^ RSA Public Key+ -> ByteString+ -- ^ Message to verify+ -> ByteString+ -- ^ Signature+ -> Bool verify params pk m = verifyDigest params pk mHash- where mHash = hashWith (pssHash params) m+ where+ mHash = hashWith (pssHash params) m -- | Verify a signature using the PSS Parameters-verifyDigest :: HashAlgorithm hash- => PSSParams hash ByteString ByteString- -- ^ PSS Parameters to use to verify,- -- this need to be identical to the parameters when signing- -> PublicKey -- ^ RSA Public Key- -> Digest hash -- ^ Digest to verify- -> ByteString -- ^ Signature- -> Bool+verifyDigest+ :: HashAlgorithm hash+ => PSSParams hash ByteString ByteString+ -- ^ PSS Parameters to use to verify,+ -- this need to be identical to the parameters when signing+ -> PublicKey+ -- ^ RSA Public Key+ -> Digest hash+ -- ^ Digest to verify+ -> ByteString+ -- ^ Signature+ -> Bool verifyDigest params pk digest s- | B.length s /= k = False- | B.any (/= 0) pre = False+ | B.length s /= k = False+ | B.any (/= 0) pre = False | B.last em /= pssTrailerField params = False- | B.any (/= 0) ps0 = False- | b1 /= B.singleton 1 = False- | otherwise = B.eq h h'- where -- parameters- hashLen = hashDigestSize (pssHash params)- mHash = B.convert digest- k = public_size pk- emLen = if emTruncate pubBits then k - 1 else k- dbLen = emLen - hashLen - 1- pubBits = numBits (public_n pk)- -- unmarshall fields- (pre, em) = B.splitAt (k - emLen) (ep pk s) -- drop 0..1 byte- maskedDB = B.take dbLen em- h = B.take hashLen $ B.drop (B.length maskedDB) em- dbmask = pssMaskGenAlg params h dbLen- db = B.pack $ normalizeToKeySize pubBits $ B.zipWith xor maskedDB dbmask- (ps0,z) = B.break (== 1) db- (b1,salt) = B.splitAt 1 z- m' = B.concat [B.replicate 8 0,mHash,salt]- h' = hashWith (pssHash params) m'+ | B.any (/= 0) ps0 = False+ | b1 /= B.singleton 1 = False+ | pssSaltLength params /= B.length salt = False+ | otherwise = B.eq h h'+ where+ -- parameters+ hashLen = hashDigestSize (pssHash params)+ mHash = B.convert digest+ k = public_size pk+ emLen = if emTruncate pubBits then k - 1 else k+ dbLen = emLen - hashLen - 1+ pubBits = numBits (public_n pk)+ -- unmarshall fields+ (pre, em) = B.splitAt (k - emLen) (ep pk s) -- drop 0..1 byte+ maskedDB = B.take dbLen em+ h = B.take hashLen $ B.drop (B.length maskedDB) em+ dbmask = pssMaskGenAlg params h dbLen+ db = B.pack $ normalizeToKeySize pubBits $ B.zipWith xor maskedDB dbmask+ (ps0, z) = B.break (== 1) db+ (b1, salt) = B.splitAt 1 z+ m' = B.concat [B.replicate 8 0, mHash, salt]+ h' = hashWith (pssHash params) m' -- When the modulus has bit length 1 modulo 8 we drop the first byte. emTruncate :: Int -> Bool-emTruncate bits = ((bits-1) .&. 0x7) == 0+emTruncate bits = ((bits - 1) .&. 0x7) == 0 normalizeToKeySize :: Int -> [Word8] -> [Word8]-normalizeToKeySize _ [] = [] -- very unlikely-normalizeToKeySize bits (x:xs) = x .&. mask : xs- where mask = if sh > 0 then 0xff `shiftR` (8-sh) else 0xff- sh = (bits-1) .&. 0x7-+normalizeToKeySize _ [] = [] -- very unlikely+normalizeToKeySize bits (x : xs) = x .&. mask : xs+ where+ mask = if sh > 0 then 0xff `shiftR` (8 - sh) else 0xff+ sh = (bits - 1) .&. 0x7
Crypto/PubKey/RSA/Prim.hs view
@@ -4,19 +4,18 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----module Crypto.PubKey.RSA.Prim- (+module Crypto.PubKey.RSA.Prim ( -- * Decrypt primitive- dp+ dp,+ -- * Encrypt primitive- , ep- ) where+ ep,+) where -import Crypto.PubKey.RSA.Types-import Crypto.Number.ModArithmetic (expFast, expSafe)-import Crypto.Number.Serialize (os2ip, i2ospOf_)-import Crypto.Internal.ByteArray (ByteArray)+import Crypto.Internal.ByteArray (ByteArray)+import Crypto.Number.ModArithmetic (expFast, expSafe)+import Crypto.Number.Serialize (i2ospOf_, os2ip)+import Crypto.PubKey.RSA.Types {- dpSlow computes the decrypted message not using any precomputed cache value. only n and d need to valid. -}@@ -28,28 +27,32 @@ to compute than mod pq -} dpFast :: ByteArray ba => Blinder -> PrivateKey -> ba -> ba dpFast (Blinder r rm1) pk c =- i2ospOf_ (private_size pk) (multiplication rm1 (m2 + h * (private_q pk)) (private_n pk))- where- re = expFast r (public_e $ private_pub pk) (private_n pk)- iC = multiplication re (os2ip c) (private_n pk)- m1 = expSafe iC (private_dP pk) (private_p pk)- m2 = expSafe iC (private_dQ pk) (private_q pk)- h = ((private_qinv pk) * (m1 - m2)) `mod` (private_p pk)+ i2ospOf_+ (private_size pk)+ (multiplication rm1 (m2 + h * (private_q pk)) (private_n pk))+ where+ re = expFast r (public_e $ private_pub pk) (private_n pk)+ iC = multiplication re (os2ip c) (private_n pk)+ m1 = expSafe iC (private_dP pk) (private_p pk)+ m2 = expSafe iC (private_dQ pk) (private_q pk)+ h = ((private_qinv pk) * (m1 - m2)) `mod` (private_p pk) dpFastNoBlinder :: ByteArray ba => PrivateKey -> ba -> ba dpFastNoBlinder pk c = i2ospOf_ (private_size pk) (m2 + h * (private_q pk))- where iC = os2ip c- m1 = expSafe iC (private_dP pk) (private_p pk)- m2 = expSafe iC (private_dQ pk) (private_q pk)- h = ((private_qinv pk) * (m1 - m2)) `mod` (private_p pk)+ where+ iC = os2ip c+ m1 = expSafe iC (private_dP pk) (private_p pk)+ m2 = expSafe iC (private_dQ pk) (private_q pk)+ h = ((private_qinv pk) * (m1 - m2)) `mod` (private_p pk) -- | Compute the RSA decrypt primitive. -- if the p and q numbers are available, then dpFast is used -- otherwise, we use dpSlow which only need d and n. dp :: ByteArray ba => Maybe Blinder -> PrivateKey -> ba -> ba dp blinder pk- | private_p pk /= 0 && private_q pk /= 0 = maybe dpFastNoBlinder dpFast blinder $ pk- | otherwise = dpSlow pk+ | private_p pk /= 0 && private_q pk /= 0 =+ maybe dpFastNoBlinder dpFast blinder $ pk+ | otherwise = dpSlow pk -- | Compute the RSA encrypt primitive ep :: ByteArray ba => PublicKey -> ba -> ba
Crypto/PubKey/RSA/Types.hs view
@@ -1,54 +1,63 @@+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.PubKey.RSA.Types -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.PubKey.RSA.Types- ( Error(..)- , Blinder(..)- , PublicKey(..)- , PrivateKey(..)- , KeyPair(..)- , toPublicKey- , toPrivateKey- , private_size- , private_n- , private_e- ) where+module Crypto.PubKey.RSA.Types (+ Error (..),+ Blinder (..),+ PublicKey (..),+ PrivateKey (..),+ KeyPair (..),+ toPublicKey,+ toPrivateKey,+ private_size,+ private_n,+ private_e,+) where -import Data.Data-import Crypto.Internal.Imports+import Crypto.Internal.Imports+import Data.Data -- | Blinder which is used to obfuscate the timing -- of the decryption primitive (used by decryption and signing). data Blinder = Blinder !Integer !Integer- deriving (Show,Eq)+ deriving (Show, Eq) -- | error possible during encryption, decryption or signing.-data Error =- MessageSizeIncorrect -- ^ the message to decrypt is not of the correct size (need to be == private_size)- | MessageTooLong -- ^ the message to encrypt is too long- | MessageNotRecognized -- ^ the message decrypted doesn't have a PKCS15 structure (0 2 .. 0 msg)- | SignatureTooLong -- ^ the message's digest is too long- | InvalidParameters -- ^ some parameters lead to breaking assumptions.- deriving (Show,Eq)+data Error+ = -- | the message to decrypt is not of the correct size (need to be == private_size)+ MessageSizeIncorrect+ | -- | the message to encrypt is too long+ MessageTooLong+ | -- | the message decrypted doesn't have a PKCS15 structure (0 2 .. 0 msg)+ MessageNotRecognized+ | -- | the message's digest is too long+ SignatureTooLong+ | -- | some parameters lead to breaking assumptions.+ InvalidParameters+ deriving (Show, Eq) -- | Represent a RSA public key data PublicKey = PublicKey- { public_size :: Int -- ^ size of key in bytes- , public_n :: Integer -- ^ public p*q- , public_e :: Integer -- ^ public exponent e- } deriving (Show,Read,Eq,Data)+ { public_size :: Int+ -- ^ size of key in bytes+ , public_n :: Integer+ -- ^ public p*q+ , public_e :: Integer+ -- ^ public exponent e+ }+ deriving (Show, Read, Eq, Data) instance NFData PublicKey where rnf (PublicKey sz n e) = rnf n `seq` rnf e `seq` sz `seq` () -- | Represent a RSA private key.--- +-- -- Only the pub, d fields are mandatory to fill. -- -- p, q, dP, dQ, qinv are by-product during RSA generation,@@ -56,20 +65,34 @@ -- the decrypt and sign operation. -- -- implementations can leave optional fields to 0.--- data PrivateKey = PrivateKey- { private_pub :: PublicKey -- ^ public part of a private key (size, n and e)- , private_d :: Integer -- ^ private exponent d- , private_p :: Integer -- ^ p prime number- , private_q :: Integer -- ^ q prime number- , private_dP :: Integer -- ^ d mod (p-1)- , private_dQ :: Integer -- ^ d mod (q-1)- , private_qinv :: Integer -- ^ q^(-1) mod p- } deriving (Show,Read,Eq,Data)+ { private_pub :: PublicKey+ -- ^ public part of a private key (size, n and e)+ , private_d :: Integer+ -- ^ private exponent d+ , private_p :: Integer+ -- ^ p prime number+ , private_q :: Integer+ -- ^ q prime number+ , private_dP :: Integer+ -- ^ d mod (p-1)+ , private_dQ :: Integer+ -- ^ d mod (q-1)+ , private_qinv :: Integer+ -- ^ q^(-1) mod p+ }+ deriving (Show, Read, Eq, Data) instance NFData PrivateKey where rnf (PrivateKey pub d p q dp dq qinv) =- rnf pub `seq` rnf d `seq` rnf p `seq` rnf q `seq` rnf dp `seq` rnf dq `seq` qinv `seq` ()+ rnf pub `seq`+ rnf d `seq`+ rnf p `seq`+ rnf q `seq`+ rnf dp `seq`+ rnf dq `seq`+ qinv `seq`+ () -- | get the size in bytes from a private key private_size :: PrivateKey -> Int@@ -87,7 +110,7 @@ -- -- note the RSA private key contains already an instance of public key for efficiency newtype KeyPair = KeyPair PrivateKey- deriving (Show,Read,Eq,Data,NFData)+ deriving (Show, Read, Eq, Data, NFData) -- | Public key of a RSA KeyPair toPublicKey :: KeyPair -> PublicKey
Crypto/PubKey/Rabin/Basic.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE DeriveDataTypeable #-}+ -- | -- Module : Crypto.PubKey.Rabin.Basic -- License : BSD-style@@ -6,48 +8,52 @@ -- Portability : unknown -- -- Rabin cryptosystem for public-key cryptography and digital signature.----{-# LANGUAGE DeriveDataTypeable #-}-module Crypto.PubKey.Rabin.Basic- ( PublicKey(..)- , PrivateKey(..)- , Signature(..)- , generate- , encrypt- , encryptWithSeed- , decrypt- , sign- , signWith- , verify- ) where+module Crypto.PubKey.Rabin.Basic (+ PublicKey (..),+ PrivateKey (..),+ Signature (..),+ generate,+ encrypt,+ encryptWithSeed,+ decrypt,+ sign,+ signWith,+ verify,+) where -import Data.ByteString (ByteString)+import Data.ByteString (ByteString) import qualified Data.ByteString as B-import Data.Data-import Data.Either (rights)+import Data.Data+import Data.Either (rights) -import Crypto.Hash-import Crypto.Number.Basic (gcde, numBytes)-import Crypto.Number.ModArithmetic (expSafe, jacobi)-import Crypto.Number.Serialize (i2osp, i2ospOf_, os2ip)-import Crypto.PubKey.Rabin.OAEP -import Crypto.PubKey.Rabin.Types-import Crypto.Random (MonadRandom, getRandomBytes)+import Crypto.Hash+import Crypto.Number.Basic (gcde, numBytes)+import Crypto.Number.ModArithmetic (expSafe, jacobi)+import Crypto.Number.Serialize (i2osp, i2ospOf_, os2ip)+import Crypto.PubKey.Rabin.OAEP+import Crypto.PubKey.Rabin.Types+import Crypto.Random (MonadRandom, getRandomBytes) -- | Represent a Rabin public key. data PublicKey = PublicKey- { public_size :: Int -- ^ size of key in bytes- , public_n :: Integer -- ^ public p*q- } deriving (Show, Read, Eq, Data)+ { public_size :: Int+ -- ^ size of key in bytes+ , public_n :: Integer+ -- ^ public p*q+ }+ deriving (Show, Read, Eq, Data) -- | Represent a Rabin private key. data PrivateKey = PrivateKey { private_pub :: PublicKey- , private_p :: Integer -- ^ p prime number- , private_q :: Integer -- ^ q prime number- , private_a :: Integer- , private_b :: Integer- } deriving (Show, Read, Eq, Data)+ , private_p :: Integer+ -- ^ p prime number+ , private_q :: Integer+ -- ^ q prime number+ , private_a :: Integer+ , private_b :: Integer+ }+ deriving (Show, Read, Eq, Data) -- | Rabin Signature. data Signature = Signature (Integer, Integer) deriving (Show, Read, Eq, Data)@@ -56,85 +62,112 @@ -- Primes p and q are both congruent 3 mod 4. -- -- See algorithm 8.11 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.-generate :: MonadRandom m- => Int- -> m (PublicKey, PrivateKey)+generate+ :: MonadRandom m+ => Int+ -> m (PublicKey, PrivateKey) generate size = do (p, q) <- generatePrimes size (\p -> p `mod` 4 == 3) (\q -> q `mod` 4 == 3) return $ generateKeys p q- where + where generateKeys p q =- let n = p*q- (a, b, _) = gcde p q - publicKey = PublicKey { public_size = size- , public_n = n }- privateKey = PrivateKey { private_pub = publicKey- , private_p = p- , private_q = q- , private_a = a- , private_b = b }- in (publicKey, privateKey)+ let n = p * q+ (a, b, _) = gcde p q+ publicKey =+ PublicKey+ { public_size = size+ , public_n = n+ }+ privateKey =+ PrivateKey+ { private_pub = publicKey+ , private_p = p+ , private_q = q+ , private_a = a+ , private_b = b+ }+ in (publicKey, privateKey) -- | Encrypt plaintext using public key an a predefined OAEP seed. -- -- See algorithm 8.11 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.-encryptWithSeed :: HashAlgorithm hash- => ByteString -- ^ Seed- -> OAEPParams hash ByteString ByteString -- ^ OAEP padding- -> PublicKey -- ^ public key- -> ByteString -- ^ plaintext- -> Either Error ByteString+encryptWithSeed+ :: HashAlgorithm hash+ => ByteString+ -- ^ Seed+ -> OAEPParams hash ByteString ByteString+ -- ^ OAEP padding+ -> PublicKey+ -- ^ public key+ -> ByteString+ -- ^ plaintext+ -> Either Error ByteString encryptWithSeed seed oaep pk m =- let n = public_n pk- k = numBytes n+ let n = public_n pk+ k = numBytes n in do- m' <- pad seed oaep k m- let m'' = os2ip m'- return $ i2osp $ expSafe m'' 2 n+ m' <- pad seed oaep k m+ let m'' = os2ip m'+ return $ i2osp $ expSafe m'' 2 n -- | Encrypt plaintext using public key.-encrypt :: (HashAlgorithm hash, MonadRandom m)- => OAEPParams hash ByteString ByteString -- ^ OAEP padding parameters- -> PublicKey -- ^ public key- -> ByteString -- ^ plaintext - -> m (Either Error ByteString)+encrypt+ :: (HashAlgorithm hash, MonadRandom m)+ => OAEPParams hash ByteString ByteString+ -- ^ OAEP padding parameters+ -> PublicKey+ -- ^ public key+ -> ByteString+ -- ^ plaintext+ -> m (Either Error ByteString) encrypt oaep pk m = do seed <- getRandomBytes hashLen return $ encryptWithSeed seed oaep pk m where- hashLen = hashDigestSize (oaepHash oaep) + hashLen = hashDigestSize (oaepHash oaep) -- | Decrypt ciphertext using private key. -- -- See algorithm 8.12 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.-decrypt :: HashAlgorithm hash- => OAEPParams hash ByteString ByteString -- ^ OAEP padding parameters- -> PrivateKey -- ^ private key- -> ByteString -- ^ ciphertext- -> Maybe ByteString+decrypt+ :: HashAlgorithm hash+ => OAEPParams hash ByteString ByteString+ -- ^ OAEP padding parameters+ -> PrivateKey+ -- ^ private key+ -> ByteString+ -- ^ ciphertext+ -> Maybe ByteString decrypt oaep pk c =- let p = private_p pk - q = private_q pk - a = private_a pk - b = private_b pk- n = public_n $ private_pub pk- k = numBytes n+ let p = private_p pk+ q = private_q pk+ a = private_a pk+ b = private_b pk+ n = public_n $ private_pub pk+ k = numBytes n c' = os2ip c solutions = rights $ toList $ mapTuple (unpad oaep k . i2ospOf_ k) $ sqroot' c' p q a b n- in if length solutions /= 1 then Nothing- else Just $ head solutions- where toList (w, x, y, z) = w:x:y:z:[]- mapTuple f (w, x, y, z) = (f w, f x, f y, f z)+ in case solutions of+ [x] -> Just x+ _ -> Nothing+ where+ toList (w, x, y, z) = w : x : y : z : []+ mapTuple f (w, x, y, z) = (f w, f x, f y, f z) -- | Sign message using padding, hash algorithm and private key. -- -- See <https://en.wikipedia.org/wiki/Rabin_signature_algorithm>.-signWith :: HashAlgorithm hash- => ByteString -- ^ padding- -> PrivateKey -- ^ private key- -> hash -- ^ hash function- -> ByteString -- ^ message to sign- -> Either Error Signature+signWith+ :: HashAlgorithm hash+ => ByteString+ -- ^ padding+ -> PrivateKey+ -- ^ private key+ -> hash+ -- ^ hash function+ -> ByteString+ -- ^ message to sign+ -> Either Error Signature signWith padding pk hashAlg m = do h <- calculateHash padding pk hashAlg m signature <- calculateSignature h@@ -142,61 +175,77 @@ where calculateSignature h = let p = private_p pk- q = private_q pk - a = private_a pk + q = private_q pk+ a = private_a pk b = private_b pk n = public_n $ private_pub pk- in if h >= n then Left MessageTooLong- else let (r, _, _, _) = sqroot' h p q a b n- in Right $ Signature (os2ip padding, r)+ in if h >= n+ then Left MessageTooLong+ else+ let (r, _, _, _) = sqroot' h p q a b n+ in Right $ Signature (os2ip padding, r) -- | Sign message using hash algorithm and private key. -- -- See <https://en.wikipedia.org/wiki/Rabin_signature_algorithm>.-sign :: (MonadRandom m, HashAlgorithm hash)- => PrivateKey -- ^ private key- -> hash -- ^ hash function- -> ByteString -- ^ message to sign- -> m (Either Error Signature)+sign+ :: (MonadRandom m, HashAlgorithm hash)+ => PrivateKey+ -- ^ private key+ -> hash+ -- ^ hash function+ -> ByteString+ -- ^ message to sign+ -> m (Either Error Signature) sign pk hashAlg m = do padding <- findPadding return $ signWith padding pk hashAlg m- where + where findPadding = do padding <- getRandomBytes 8 case calculateHash padding pk hashAlg m of Right _ -> return padding- _ -> findPadding+ _ -> findPadding -- | Calculate hash of message and padding. -- If the padding is valid, then the result of the hash operation is returned, otherwise an error.-calculateHash :: HashAlgorithm hash- => ByteString -- ^ padding- -> PrivateKey -- ^ private key- -> hash -- ^ hash function- -> ByteString -- ^ message to sign- -> Either Error Integer-calculateHash padding pk hashAlg m = +calculateHash+ :: HashAlgorithm hash+ => ByteString+ -- ^ padding+ -> PrivateKey+ -- ^ private key+ -> hash+ -- ^ hash function+ -> ByteString+ -- ^ message to sign+ -> Either Error Integer+calculateHash padding pk hashAlg m = let p = private_p pk q = private_q pk h = os2ip $ hashWith hashAlg $ B.append padding m in case (jacobi (h `mod` p) p, jacobi (h `mod` q) q) of (Just 1, Just 1) -> Right h- _ -> Left InvalidParameters+ _ -> Left InvalidParameters -- | Verify signature using hash algorithm and public key. -- -- See <https://en.wikipedia.org/wiki/Rabin_signature_algorithm>.-verify :: HashAlgorithm hash- => PublicKey -- ^ private key- -> hash -- ^ hash function- -> ByteString -- ^ message- -> Signature -- ^ signature- -> Bool+verify+ :: HashAlgorithm hash+ => PublicKey+ -- ^ private key+ -> hash+ -- ^ hash function+ -> ByteString+ -- ^ message+ -> Signature+ -- ^ signature+ -> Bool verify pk hashAlg m (Signature (padding, s)) =- let n = public_n pk- p = i2osp padding- h = os2ip $ hashWith hashAlg $ B.append p m + let n = public_n pk+ p = i2osp padding+ h = os2ip $ hashWith hashAlg $ B.append p m h' = expSafe s 2 n in h' == h @@ -204,27 +253,35 @@ -- Value a must be a quadratic residue modulo p (i.e. jacobi symbol (a/n) = 1). -- -- See algorithm 3.36 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.-sqroot :: Integer- -> Integer -- ^ prime p- -> (Integer, Integer)+sqroot+ :: Integer+ -> Integer+ -- ^ prime p+ -> (Integer, Integer) sqroot a p = let r = expSafe a ((p + 1) `div` 4) p in (r, -r) -- | Square roots modulo n given its prime factors p and q (both congruent 3 mod 4) -- Value a must be a quadratic residue of both modulo p and modulo q (i.e. jacobi symbols (a/p) = (a/q) = 1).--- +-- -- See algorithm 3.44 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.-sqroot' :: Integer - -> Integer -- ^ prime p- -> Integer -- ^ prime q- -> Integer -- ^ c such that c*p + d*q = 1- -> Integer -- ^ d such that c*p + d*q = 1- -> Integer -- ^ n = p*q- -> (Integer, Integer, Integer, Integer)+sqroot'+ :: Integer+ -> Integer+ -- ^ prime p+ -> Integer+ -- ^ prime q+ -> Integer+ -- ^ c such that c*p + d*q = 1+ -> Integer+ -- ^ d such that c*p + d*q = 1+ -> Integer+ -- ^ n = p*q+ -> (Integer, Integer, Integer, Integer) sqroot' a p q c d n = let (r, _) = sqroot a p (s, _) = sqroot a q- x = (r*d*q + s*c*p) `mod` n- y = (r*d*q - s*c*p) `mod` n+ x = (r * d * q + s * c * p) `mod` n+ y = (r * d * q - s * c * p) `mod` n in (x, (-x) `mod` n, y, (-y) `mod` n)
Crypto/PubKey/Rabin/Modified.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE DeriveDataTypeable #-}+ -- | -- Module : Crypto.PubKey.Rabin.Modified -- License : BSD-style@@ -7,95 +9,118 @@ -- -- Modified-Rabin public-key digital signature algorithm. -- See algorithm 11.30 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.----{-# LANGUAGE DeriveDataTypeable #-}-module Crypto.PubKey.Rabin.Modified- ( PublicKey(..)- , PrivateKey(..)- , generate- , sign- , verify- ) where+module Crypto.PubKey.Rabin.Modified (+ PublicKey (..),+ PrivateKey (..),+ generate,+ sign,+ verify,+) where -import Data.ByteString-import Data.Data+import Data.ByteString+import Data.Data -import Crypto.Hash-import Crypto.Number.ModArithmetic (expSafe, jacobi)-import Crypto.Number.Serialize (os2ip)-import Crypto.PubKey.Rabin.Types-import Crypto.Random.Types+import Crypto.Hash+import Crypto.Number.ModArithmetic (expSafe, jacobi)+import Crypto.Number.Serialize (os2ip)+import Crypto.PubKey.Rabin.Types+import Crypto.Random.Types -- | Represent a Modified-Rabin public key. data PublicKey = PublicKey- { public_size :: Int -- ^ size of key in bytes- , public_n :: Integer -- ^ public p*q- } deriving (Show, Read, Eq, Data)+ { public_size :: Int+ -- ^ size of key in bytes+ , public_n :: Integer+ -- ^ public p*q+ }+ deriving (Show, Read, Eq, Data) -- | Represent a Modified-Rabin private key. data PrivateKey = PrivateKey { private_pub :: PublicKey- , private_p :: Integer -- ^ p prime number- , private_q :: Integer -- ^ q prime number- , private_d :: Integer- } deriving (Show, Read, Eq, Data)+ , private_p :: Integer+ -- ^ p prime number+ , private_q :: Integer+ -- ^ q prime number+ , private_d :: Integer+ }+ deriving (Show, Read, Eq, Data) -- | Generate a pair of (private, public) key of size in bytes. -- Prime p is congruent 3 mod 8 and prime q is congruent 7 mod 8.-generate :: MonadRandom m- => Int - -> m (PublicKey, PrivateKey)+generate+ :: MonadRandom m+ => Int+ -> m (PublicKey, PrivateKey) generate size = do (p, q) <- generatePrimes size (\p -> p `mod` 8 == 3) (\q -> q `mod` 8 == 7) return $ generateKeys p q- where + where generateKeys p q =- let n = p*q + let n = p * q d = (n - p - q + 5) `div` 8- publicKey = PublicKey { public_size = size- , public_n = n }- privateKey = PrivateKey { private_pub = publicKey- , private_p = p- , private_q = q- , private_d = d }- in (publicKey, privateKey)+ publicKey =+ PublicKey+ { public_size = size+ , public_n = n+ }+ privateKey =+ PrivateKey+ { private_pub = publicKey+ , private_p = p+ , private_q = q+ , private_d = d+ }+ in (publicKey, privateKey) -- | Sign message using hash algorithm and private key.-sign :: HashAlgorithm hash- => PrivateKey -- ^ private key- -> hash -- ^ hash function- -> ByteString -- ^ message to sign- -> Either Error Integer+sign+ :: HashAlgorithm hash+ => PrivateKey+ -- ^ private key+ -> hash+ -- ^ hash function+ -> ByteString+ -- ^ message to sign+ -> Either Error Integer sign pk hashAlg m = let d = private_d pk n = public_n $ private_pub pk h = os2ip $ hashWith hashAlg m limit = (n - 6) `div` 16- in if h > limit then Left MessageTooLong- else let h' = 16*h + 6- in case jacobi h' n of- Just 1 -> Right $ expSafe h' d n- Just (-1) -> Right $ expSafe (h' `div` 2) d n- _ -> Left InvalidParameters+ in if h > limit+ then Left MessageTooLong+ else+ let h' = 16 * h + 6+ in case jacobi h' n of+ Just 1 -> Right $ expSafe h' d n+ Just (-1) -> Right $ expSafe (h' `div` 2) d n+ _ -> Left InvalidParameters -- | Verify signature using hash algorithm and public key.-verify :: HashAlgorithm hash- => PublicKey -- ^ public key- -> hash -- ^ hash function- -> ByteString -- ^ message- -> Integer -- ^ signature- -> Bool+verify+ :: HashAlgorithm hash+ => PublicKey+ -- ^ public key+ -> hash+ -- ^ hash function+ -> ByteString+ -- ^ message+ -> Integer+ -- ^ signature+ -> Bool verify pk hashAlg m s =- let n = public_n pk- h = os2ip $ hashWith hashAlg m- s' = expSafe s 2 n+ let n = public_n pk+ h = os2ip $ hashWith hashAlg m+ s' = expSafe s 2 n s'' = case s' `mod` 8 of 6 -> s'- 3 -> 2*s'+ 3 -> 2 * s' 7 -> n - s'- 2 -> 2*(n - s')+ 2 -> 2 * (n - s') _ -> 0 in case s'' `mod` 16 of- 6 -> let h' = (s'' - 6) `div` 16- in h' == h + 6 ->+ let h' = (s'' - 6) `div` 16+ in h' == h _ -> False
Crypto/PubKey/Rabin/OAEP.hs view
@@ -7,94 +7,111 @@ -- -- OAEP padding scheme. -- See <http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding>.----module Crypto.PubKey.Rabin.OAEP- ( OAEPParams(..)- , defaultOAEPParams- , pad- , unpad- ) where- -import Data.ByteString (ByteString)+module Crypto.PubKey.Rabin.OAEP (+ OAEPParams (..),+ defaultOAEPParams,+ pad,+ unpad,+) where++import Data.Bits (xor)+import Data.ByteString (ByteString) import qualified Data.ByteString as B-import Data.Bits (xor) -import Crypto.Hash-import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray)+import Crypto.Hash+import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B (convert)-import Crypto.PubKey.MaskGenFunction-import Crypto.PubKey.Internal (and')-import Crypto.PubKey.Rabin.Types+import Crypto.PubKey.Internal (and')+import Crypto.PubKey.MaskGenFunction+import Crypto.PubKey.Rabin.Types -- | Parameters for OAEP padding. data OAEPParams hash seed output = OAEPParams- { oaepHash :: hash -- ^ hash function to use- , oaepMaskGenAlg :: MaskGenAlgorithm seed output -- ^ mask Gen algorithm to use- , oaepLabel :: Maybe ByteString -- ^ optional label prepended to message+ { oaepHash :: hash+ -- ^ hash function to use+ , oaepMaskGenAlg :: MaskGenAlgorithm seed output+ -- ^ mask Gen algorithm to use+ , oaepLabel :: Maybe ByteString+ -- ^ optional label prepended to message } -- | Default Params with a specified hash function.-defaultOAEPParams :: (ByteArrayAccess seed, ByteArray output, HashAlgorithm hash)- => hash- -> OAEPParams hash seed output+defaultOAEPParams+ :: (ByteArrayAccess seed, ByteArray output, HashAlgorithm hash)+ => hash+ -> OAEPParams hash seed output defaultOAEPParams hashAlg =- OAEPParams { oaepHash = hashAlg- , oaepMaskGenAlg = mgf1 hashAlg- , oaepLabel = Nothing- }+ OAEPParams+ { oaepHash = hashAlg+ , oaepMaskGenAlg = mgf1 hashAlg+ , oaepLabel = Nothing+ } -- | Pad a message using OAEP.-pad :: HashAlgorithm hash- => ByteString -- ^ Seed- -> OAEPParams hash ByteString ByteString -- ^ OAEP params to use- -> Int -- ^ size of public key in bytes- -> ByteString -- ^ Message pad+pad+ :: HashAlgorithm hash+ => ByteString+ -- ^ Seed+ -> OAEPParams hash ByteString ByteString+ -- ^ OAEP params to use+ -> Int+ -- ^ size of public key in bytes+ -> ByteString+ -- ^ Message pad -> Either Error ByteString pad seed oaep k msg- | k < 2*hashLen+2 = Left InvalidParameters+ | k < 2 * hashLen + 2 = Left InvalidParameters | B.length seed /= hashLen = Left InvalidParameters- | mLen > k - 2*hashLen-2 = Left MessageTooLong- | otherwise = Right em- where -- parameters- mLen = B.length msg- mgf = oaepMaskGenAlg oaep- labelHash = hashWith (oaepHash oaep) (maybe B.empty id $ oaepLabel oaep)- hashLen = hashDigestSize (oaepHash oaep)- -- put fields- ps = B.replicate (k - mLen - 2*hashLen - 2) 0- db = B.concat [B.convert labelHash, ps, B.singleton 0x1, msg]- dbmask = mgf seed (k - hashLen - 1)- maskedDB = B.pack $ B.zipWith xor db dbmask- seedMask = mgf maskedDB hashLen- maskedSeed = B.pack $ B.zipWith xor seed seedMask- em = B.concat [B.singleton 0x0, maskedSeed, maskedDB]+ | mLen > k - 2 * hashLen - 2 = Left MessageTooLong+ | otherwise = Right em+ where+ -- parameters+ mLen = B.length msg+ mgf = oaepMaskGenAlg oaep+ labelHash = hashWith (oaepHash oaep) (maybe B.empty id $ oaepLabel oaep)+ hashLen = hashDigestSize (oaepHash oaep)+ -- put fields+ ps = B.replicate (k - mLen - 2 * hashLen - 2) 0+ db = B.concat [B.convert labelHash, ps, B.singleton 0x1, msg]+ dbmask = mgf seed (k - hashLen - 1)+ maskedDB = B.pack $ B.zipWith xor db dbmask+ seedMask = mgf maskedDB hashLen+ maskedSeed = B.pack $ B.zipWith xor seed seedMask+ em = B.concat [B.singleton 0x0, maskedSeed, maskedDB] -- | Un-pad a OAEP encoded message.-unpad :: HashAlgorithm hash- => OAEPParams hash ByteString ByteString -- ^ OAEP params to use- -> Int -- ^ size of public key in bytes- -> ByteString -- ^ encoded message (not encrypted)- -> Either Error ByteString+unpad+ :: HashAlgorithm hash+ => OAEPParams hash ByteString ByteString+ -- ^ OAEP params to use+ -> Int+ -- ^ size of public key in bytes+ -> ByteString+ -- ^ encoded message (not encrypted)+ -> Either Error ByteString unpad oaep k em | paddingSuccess = Right msg- | otherwise = Left MessageNotRecognized- where -- parameters- mgf = oaepMaskGenAlg oaep- labelHash = B.convert $ hashWith (oaepHash oaep) (maybe B.empty id $ oaepLabel oaep)- hashLen = hashDigestSize (oaepHash oaep)- -- getting em's fields- (pb, em0) = B.splitAt 1 em- (maskedSeed, maskedDB) = B.splitAt hashLen em0- seedMask = mgf maskedDB hashLen- seed = B.pack $ B.zipWith xor maskedSeed seedMask- dbmask = mgf seed (k - hashLen - 1)- db = B.pack $ B.zipWith xor maskedDB dbmask- -- getting db's fields- (labelHash', db1) = B.splitAt hashLen db- (_, db2) = B.break (/= 0) db1- (ps1, msg) = B.splitAt 1 db2+ | otherwise = Left MessageNotRecognized+ where+ -- parameters+ mgf = oaepMaskGenAlg oaep+ labelHash = B.convert $ hashWith (oaepHash oaep) (maybe B.empty id $ oaepLabel oaep)+ hashLen = hashDigestSize (oaepHash oaep)+ -- getting em's fields+ (pb, em0) = B.splitAt 1 em+ (maskedSeed, maskedDB) = B.splitAt hashLen em0+ seedMask = mgf maskedDB hashLen+ seed = B.pack $ B.zipWith xor maskedSeed seedMask+ dbmask = mgf seed (k - hashLen - 1)+ db = B.pack $ B.zipWith xor maskedDB dbmask+ -- getting db's fields+ (labelHash', db1) = B.splitAt hashLen db+ (_, db2) = B.break (/= 0) db1+ (ps1, msg) = B.splitAt 1 db2 - paddingSuccess = and' [ labelHash' == labelHash -- no need for constant eq- , ps1 == B.replicate 1 0x1- , pb == B.replicate 1 0x0- ]+ paddingSuccess =+ and'+ [ labelHash' == labelHash -- no need for constant eq+ , ps1 == B.replicate 1 0x1+ , pb == B.replicate 1 0x0+ ]
Crypto/PubKey/Rabin/RW.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE DeriveDataTypeable #-}+ -- | -- Module : Crypto.PubKey.Rabin.RW -- License : BSD-style@@ -5,147 +7,180 @@ -- Stability : experimental -- Portability : unknown ----- Rabin-Williams cryptosystem for public-key encryption and digital signature. +-- Rabin-Williams cryptosystem for public-key encryption and digital signature. -- See pages 323 - 324 in "Computational Number Theory and Modern Cryptography" by Song Y. Yan. -- Also inspired by https://github.com/vanilala/vncrypt/blob/master/vncrypt/vnrw_gmp.c.--- -{-# LANGUAGE DeriveDataTypeable #-}-module Crypto.PubKey.Rabin.RW- ( PublicKey(..)- , PrivateKey(..)- , generate- , encrypt- , encryptWithSeed- , decrypt- , sign- , verify- ) where+module Crypto.PubKey.Rabin.RW (+ PublicKey (..),+ PrivateKey (..),+ generate,+ encrypt,+ encryptWithSeed,+ decrypt,+ sign,+ verify,+) where -import Data.ByteString-import Data.Data+import Data.ByteString+import Data.Data -import Crypto.Hash-import Crypto.Number.Basic (numBytes)-import Crypto.Number.ModArithmetic (expSafe, jacobi)-import Crypto.Number.Serialize (i2osp, i2ospOf_, os2ip)-import Crypto.PubKey.Rabin.OAEP-import Crypto.PubKey.Rabin.Types-import Crypto.Random.Types+import Crypto.Hash+import Crypto.Number.Basic (numBytes)+import Crypto.Number.ModArithmetic (expSafe, jacobi)+import Crypto.Number.Serialize (i2osp, i2ospOf_, os2ip)+import Crypto.PubKey.Rabin.OAEP+import Crypto.PubKey.Rabin.Types+import Crypto.Random.Types -- | Represent a Rabin-Williams public key. data PublicKey = PublicKey- { public_size :: Int -- ^ size of key in bytes- , public_n :: Integer -- ^ public p*q- } deriving (Show, Read, Eq, Data)+ { public_size :: Int+ -- ^ size of key in bytes+ , public_n :: Integer+ -- ^ public p*q+ }+ deriving (Show, Read, Eq, Data) -- | Represent a Rabin-Williams private key. data PrivateKey = PrivateKey { private_pub :: PublicKey- , private_p :: Integer -- ^ p prime number- , private_q :: Integer -- ^ q prime number- , private_d :: Integer- } deriving (Show, Read, Eq, Data)+ , private_p :: Integer+ -- ^ p prime number+ , private_q :: Integer+ -- ^ q prime number+ , private_d :: Integer+ }+ deriving (Show, Read, Eq, Data) -- | Generate a pair of (private, public) key of size in bytes. -- Prime p is congruent 3 mod 8 and prime q is congruent 7 mod 8.-generate :: MonadRandom m- => Int - -> m (PublicKey, PrivateKey)+generate+ :: MonadRandom m+ => Int+ -> m (PublicKey, PrivateKey) generate size = do- (p, q) <- generatePrimes size (\p -> p `mod` 8 == 3) (\q -> q `mod` 8 == 7) + (p, q) <- generatePrimes size (\p -> p `mod` 8 == 3) (\q -> q `mod` 8 == 7) return (generateKeys p q)- where + where generateKeys p q =- let n = p*q - d = ((p - 1)*(q - 1) `div` 4 + 1) `div` 2- publicKey = PublicKey { public_size = size- , public_n = n }- privateKey = PrivateKey { private_pub = publicKey- , private_p = p- , private_q = q- , private_d = d }- in (publicKey, privateKey)+ let n = p * q+ d = ((p - 1) * (q - 1) `div` 4 + 1) `div` 2+ publicKey =+ PublicKey+ { public_size = size+ , public_n = n+ }+ privateKey =+ PrivateKey+ { private_pub = publicKey+ , private_p = p+ , private_q = q+ , private_d = d+ }+ in (publicKey, privateKey) -- | Encrypt plaintext using public key an a predefined OAEP seed. -- -- See algorithm 8.11 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.-encryptWithSeed :: HashAlgorithm hash- => ByteString -- ^ Seed- -> OAEPParams hash ByteString ByteString -- ^ OAEP padding- -> PublicKey -- ^ public key- -> ByteString -- ^ plaintext- -> Either Error ByteString+encryptWithSeed+ :: HashAlgorithm hash+ => ByteString+ -- ^ Seed+ -> OAEPParams hash ByteString ByteString+ -- ^ OAEP padding+ -> PublicKey+ -- ^ public key+ -> ByteString+ -- ^ plaintext+ -> Either Error ByteString encryptWithSeed seed oaep pk m = let n = public_n pk k = numBytes n in do- m' <- pad seed oaep k m- m'' <- ep1 n $ os2ip m'- return $ i2osp $ ep2 n m''+ m' <- pad seed oaep k m+ m'' <- ep1 n $ os2ip m'+ return $ i2osp $ ep2 n m'' -- | Encrypt plaintext using public key.-encrypt :: (HashAlgorithm hash, MonadRandom m)- => OAEPParams hash ByteString ByteString -- ^ OAEP padding parameters- -> PublicKey -- ^ public key- -> ByteString -- ^ plaintext - -> m (Either Error ByteString)+encrypt+ :: (HashAlgorithm hash, MonadRandom m)+ => OAEPParams hash ByteString ByteString+ -- ^ OAEP padding parameters+ -> PublicKey+ -- ^ public key+ -> ByteString+ -- ^ plaintext+ -> m (Either Error ByteString) encrypt oaep pk m = do seed <- getRandomBytes hashLen return $ encryptWithSeed seed oaep pk m where- hashLen = hashDigestSize (oaepHash oaep) + hashLen = hashDigestSize (oaepHash oaep) -- | Decrypt ciphertext using private key.-decrypt :: HashAlgorithm hash- => OAEPParams hash ByteString ByteString -- ^ OAEP padding parameters- -> PrivateKey -- ^ private key- -> ByteString -- ^ ciphertext- -> Maybe ByteString+decrypt+ :: HashAlgorithm hash+ => OAEPParams hash ByteString ByteString+ -- ^ OAEP padding parameters+ -> PrivateKey+ -- ^ private key+ -> ByteString+ -- ^ ciphertext+ -> Maybe ByteString decrypt oaep pk c =- let d = private_d pk - n = public_n $ private_pub pk- k = numBytes n+ let d = private_d pk+ n = public_n $ private_pub pk+ k = numBytes n c' = i2ospOf_ k $ dp2 n $ dp1 d n $ os2ip c in case unpad oaep k c' of- Left _ -> Nothing- Right p -> Just p + Left _ -> Nothing+ Right p -> Just p -- | Sign message using hash algorithm and private key.-sign :: HashAlgorithm hash- => PrivateKey -- ^ private key- -> hash -- ^ hash function- -> ByteString -- ^ message to sign- -> Either Error Integer+sign+ :: HashAlgorithm hash+ => PrivateKey+ -- ^ private key+ -> hash+ -- ^ hash function+ -> ByteString+ -- ^ message to sign+ -> Either Error Integer sign pk hashAlg m = let d = private_d pk n = public_n $ private_pub pk in do- m' <- ep1 n $ os2ip $ hashWith hashAlg m- return $ dp1 d n m' + m' <- ep1 n $ os2ip $ hashWith hashAlg m+ return $ dp1 d n m' -- | Verify signature using hash algorithm and public key.-verify :: HashAlgorithm hash- => PublicKey -- ^ public key- -> hash -- ^ hash function- -> ByteString -- ^ message- -> Integer -- ^ signature- -> Bool+verify+ :: HashAlgorithm hash+ => PublicKey+ -- ^ public key+ -> hash+ -- ^ hash function+ -> ByteString+ -- ^ message+ -> Integer+ -- ^ signature+ -> Bool verify pk hashAlg m s =- let n = public_n pk- h = os2ip $ hashWith hashAlg m+ let n = public_n pk+ h = os2ip $ hashWith hashAlg m h' = dp2 n $ ep2 n s in h' == h -- | Encryption primitive 1 ep1 :: Integer -> Integer -> Either Error Integer ep1 n m =- let m' = 2*m + 1- m'' = 2*m'- m''' = 2*m''+ let m' = 2 * m + 1+ m'' = 2 * m'+ m''' = 2 * m'' in case jacobi m' n of Just (-1) | m'' < n -> Right m''- Just 1 | m''' < n -> Right m'''- _ -> Left InvalidParameters+ Just 1 | m''' < n -> Right m'''+ _ -> Left InvalidParameters -- | Encryption primitive 2 ep2 :: Integer -> Integer -> Integer@@ -157,10 +192,11 @@ -- | Decryption primitive 2 dp2 :: Integer -> Integer -> Integer-dp2 n c = let c' = c `div` 2- c'' = (n - c) `div` 2- in case c `mod` 4 of- 0 -> ((c' `div` 2 - 1) `div` 2)- 1 -> ((c'' `div` 2 - 1) `div` 2)- 2 -> ((c' - 1) `div` 2)- _ -> ((c'' - 1) `div` 2)+dp2 n c =+ let c' = c `div` 2+ c'' = (n - c) `div` 2+ in case c `mod` 4 of+ 0 -> ((c' `div` 2 - 1) `div` 2)+ 1 -> ((c'' `div` 2 - 1) `div` 2)+ 2 -> ((c' - 1) `div` 2)+ _ -> ((c'' - 1) `div` 2)
Crypto/PubKey/Rabin/Types.hs view
@@ -4,40 +4,49 @@ -- Maintainer : Carlos Rodriguez-Vega <crodveg@yahoo.es> -- Stability : experimental -- Portability : unknown----module Crypto.PubKey.Rabin.Types- ( Error(..)- , generatePrimes- ) where+module Crypto.PubKey.Rabin.Types (+ Error (..),+ generatePrimes,+) where import Crypto.Number.Basic (numBits)-import Crypto.Number.Prime (generatePrime, findPrimeFromWith)+import Crypto.Number.Prime (findPrimeFromWith, generatePrime) import Crypto.Random.Types type PrimeCondition = Integer -> Bool -- | Error possible during encryption, decryption or signing.-data Error = MessageTooLong -- ^ the message to encrypt is too long- | MessageNotRecognized -- ^ the message decrypted doesn't have a OAEP structure- | InvalidParameters -- ^ some parameters lead to breaking assumptions- deriving (Show, Eq)+data Error+ = -- | the message to encrypt is too long+ MessageTooLong+ | -- | the message decrypted doesn't have a OAEP structure+ MessageNotRecognized+ | -- | some parameters lead to breaking assumptions+ InvalidParameters+ deriving (Show, Eq) -- | Generate primes p & q-generatePrimes :: MonadRandom m - => Int -- ^ size in bytes - -> PrimeCondition -- ^ condition prime p must satisfy- -> PrimeCondition -- ^ condition prime q must satisfy- -> m (Integer, Integer) -- ^ chosen distinct primes p and q+generatePrimes+ :: MonadRandom m+ => Int+ -- ^ size in bytes+ -> PrimeCondition+ -- ^ condition prime p must satisfy+ -> PrimeCondition+ -- ^ condition prime q must satisfy+ -> m (Integer, Integer)+ -- ^ chosen distinct primes p and q generatePrimes size pCond qCond =- let pBits = (8*(size `div` 2))- qBits = (8*(size - (size `div` 2)))+ let pBits = (8 * (size `div` 2))+ qBits = (8 * (size - (size `div` 2))) in do- p <- generatePrime' pBits pCond- q <- generatePrime' qBits qCond- return (p, q)- where- generatePrime' bits cond = do- pr' <- generatePrime bits- let pr = findPrimeFromWith cond pr'- if numBits pr == bits then return pr+ p <- generatePrime' pBits pCond+ q <- generatePrime' qBits qCond+ return (p, q)+ where+ generatePrime' bits cond = do+ pr' <- generatePrime bits+ let pr = findPrimeFromWith cond pr'+ if numBits pr == bits+ then return pr else generatePrime' bits cond
Crypto/Random.hs view
@@ -1,43 +1,45 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.Random -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : stable -- Portability : good----{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.Random- (+module Crypto.Random ( -- * Deterministic instances- ChaChaDRG- , SystemDRG- , Seed+ ChaChaDRG,+ SystemDRG,+ Seed,+ -- * Seed- , seedNew- , seedFromInteger- , seedToInteger- , seedFromBinary+ seedNew,+ seedFromInteger,+ seedToInteger,+ seedFromBinary,+ -- * Deterministic Random class- , getSystemDRG- , drgNew- , drgNewSeed- , drgNewTest- , withDRG- , withRandomBytes- , DRG(..)+ getSystemDRG,+ drgNew,+ drgNewSeed,+ drgNewTest,+ withDRG,+ withRandomBytes,+ DRG (..),+ -- * Random abstraction- , MonadRandom(..)- , MonadPseudoRandom- ) where+ MonadRandom (..),+ MonadPseudoRandom,+) where import Crypto.Error-import Crypto.Random.Types+import Crypto.Hash (Digest, SHA512, hash)+import Crypto.Internal.Imports import Crypto.Random.ChaChaDRG import Crypto.Random.SystemDRG+import Crypto.Random.Types import Data.ByteArray (ByteArray, ByteArrayAccess, ScrubbedBytes) import qualified Data.ByteArray as B-import Crypto.Internal.Imports-import Crypto.Hash (Digest, SHA512, hash) import qualified Crypto.Number.Serialize as Serialize @@ -56,7 +58,9 @@ -- potentially comprisable sources. Hashing of entropy before using -- it as a seed is a common mitigation for attacks via RNG/entropy -- source.-seedNew = (Seed . B.take seedLength . B.convert . (hash :: ScrubbedBytes -> Digest SHA512)) `fmap` getRandomBytes 64+seedNew =+ (Seed . B.take seedLength . B.convert . (hash :: ScrubbedBytes -> Digest SHA512))+ `fmap` getRandomBytes 64 -- | Convert a Seed to an integer seedToInteger :: Seed -> Integer@@ -64,13 +68,13 @@ -- | Convert an integer to a Seed seedFromInteger :: Integer -> Seed-seedFromInteger i = Seed $ Serialize.i2ospOf_ seedLength (i `mod` 2^(seedLength * 8))+seedFromInteger i = Seed $ Serialize.i2ospOf_ seedLength (i `mod` 2 ^ (seedLength * 8)) -- | Convert a binary to a seed seedFromBinary :: ByteArrayAccess b => b -> CryptoFailable Seed seedFromBinary b | B.length b /= 40 = CryptoFailed (CryptoError_SeedSizeInvalid)- | otherwise = CryptoPassed $ Seed $ B.convert b+ | otherwise = CryptoPassed $ Seed $ B.convert b -- | Create a new DRG from system entropy drgNew :: MonadRandom randomly => randomly ChaChaDRG@@ -102,4 +106,5 @@ -- This is equivalent to use Control.Arrow 'first' with 'randomBytesGenerate' withRandomBytes :: (ByteArray ba, DRG g) => g -> Int -> (ba -> a) -> (a, g) withRandomBytes rng len f = (f bs, rng')- where (bs, rng') = randomBytesGenerate len rng+ where+ (bs, rng') = randomBytesGenerate len rng
Crypto/Random/ChaChaDRG.hs view
@@ -1,22 +1,26 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ -- | -- Module : Crypto.Random.ChaChaDRG -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : stable -- Portability : good----{-# LANGUAGE GeneralizedNewtypeDeriving #-}-module Crypto.Random.ChaChaDRG- ( ChaChaDRG- , initialize- , initializeWords- ) where+module Crypto.Random.ChaChaDRG (+ ChaChaDRG,+ initialize,+ initializeWords,+) where -import Crypto.Random.Types-import Crypto.Internal.Imports-import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess, ScrubbedBytes)+import Crypto.Internal.ByteArray (+ ByteArray,+ ByteArrayAccess,+ ScrubbedBytes,+ ) import qualified Crypto.Internal.ByteArray as B-import Foreign.Storable (pokeElemOff)+import Crypto.Internal.Imports+import Crypto.Random.Types+import Foreign.Storable (pokeElemOff) import qualified Crypto.Cipher.ChaCha as C @@ -29,18 +33,24 @@ -- | Initialize a new ChaCha context with the number of rounds, -- the key and the nonce associated.-initialize :: ByteArrayAccess seed- => seed -- ^ 40 bytes of seed- -> ChaChaDRG -- ^ the initial ChaCha state+initialize+ :: ByteArrayAccess seed+ => seed+ -- ^ 40 bytes of seed+ -> ChaChaDRG+ -- ^ the initial ChaCha state initialize seed = ChaChaDRG $ C.initializeSimple seed -- | Initialize a new ChaCha context from 5-tuple of words64. -- This interface is useful when creating a RNG out of tests generators (e.g. QuickCheck). initializeWords :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG-initializeWords (a,b,c,d,e) = initialize (B.allocAndFreeze 40 fill :: ScrubbedBytes)- where fill s = mapM_ (uncurry (pokeElemOff s)) [(0,a), (1,b), (2,c), (3,d), (4,e)]+initializeWords (a, b, c, d, e) = initialize (B.allocAndFreeze 40 fill :: ScrubbedBytes)+ where+ fill s = mapM_ (uncurry (pokeElemOff s)) [(0, a), (1, b), (2, c), (3, d), (4, e)] generate :: ByteArray output => Int -> ChaChaDRG -> (output, ChaChaDRG) generate nbBytes st@(ChaChaDRG prevSt) | nbBytes <= 0 = (B.empty, st)- | otherwise = let (output, newSt) = C.generateSimple prevSt nbBytes in (output, ChaChaDRG newSt)+ | otherwise =+ let (output, newSt) = C.generateSimple prevSt nbBytes+ in (output, ChaChaDRG newSt)
Crypto/Random/Entropy.hs view
@@ -4,16 +4,15 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----module Crypto.Random.Entropy- ( getEntropy- ) where+module Crypto.Random.Entropy (+ getEntropy,+) where -import Data.Maybe (catMaybes)-import Crypto.Internal.ByteArray (ByteArray)+import Crypto.Internal.ByteArray (ByteArray) import qualified Crypto.Internal.ByteArray as B+import Data.Maybe (catMaybes) -import Crypto.Random.Entropy.Unsafe+import Crypto.Random.Entropy.Unsafe -- | Get some entropy from the system source of entropy getEntropy :: ByteArray byteArray => Int -> IO byteArray
Crypto/Random/Entropy/RDRand.hs view
@@ -1,38 +1,39 @@+{-# LANGUAGE ForeignFunctionInterface #-}+ -- | -- Module : Crypto.Random.Entropy.RDRand -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----{-# LANGUAGE ForeignFunctionInterface #-}-module Crypto.Random.Entropy.RDRand- ( RDRand- ) where+module Crypto.Random.Entropy.RDRand (+ RDRand,+) where -import Foreign.Ptr-import Foreign.C.Types-import Data.Word (Word8) import Crypto.Random.Entropy.Source+import Data.Word (Word8)+import Foreign.C.Types+import Foreign.Ptr foreign import ccall unsafe "crypton_cpu_has_rdrand"- c_cpu_has_rdrand :: IO CInt+ c_cpu_has_rdrand :: IO CInt foreign import ccall unsafe "crypton_get_rand_bytes"- c_get_rand_bytes :: Ptr Word8 -> CInt -> IO CInt+ c_get_rand_bytes :: Ptr Word8 -> CInt -> IO CInt -- | Fake handle to Intel RDRand entropy CPU instruction data RDRand = RDRand instance EntropySource RDRand where- entropyOpen = rdrandGrab+ entropyOpen = rdrandGrab entropyGather _ = rdrandGetBytes- entropyClose _ = return ()+ entropyClose _ = return () rdrandGrab :: IO (Maybe RDRand) rdrandGrab = supported `fmap` c_cpu_has_rdrand- where supported 0 = Nothing- supported _ = Just RDRand+ where+ supported 0 = Nothing+ supported _ = Just RDRand rdrandGetBytes :: Ptr Word8 -> Int -> IO Int rdrandGetBytes ptr sz = fromIntegral `fmap` c_get_rand_bytes ptr (fromIntegral sz)
Crypto/Random/Entropy/Source.hs view
@@ -4,19 +4,20 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good--- module Crypto.Random.Entropy.Source where -import Foreign.Ptr import Data.Word (Word8)+import Foreign.Ptr -- | A handle to an entropy maker, either a system capability -- or a hardware generator. class EntropySource a where -- | Try to open an handle for this source- entropyOpen :: IO (Maybe a)+ entropyOpen :: IO (Maybe a)+ -- | Try to gather a number of entropy bytes into a buffer. -- Return the number of actual bytes gathered entropyGather :: a -> Ptr Word8 -> Int -> IO Int+ -- | Close an open handle- entropyClose :: a -> IO ()+ entropyClose :: a -> IO ()
Crypto/Random/Entropy/Unix.hs view
@@ -1,29 +1,29 @@+{-# LANGUAGE ScopedTypeVariables #-}+ -- | -- Module : Crypto.Random.Entropy.Unix -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----{-# LANGUAGE ScopedTypeVariables #-}-module Crypto.Random.Entropy.Unix- ( DevRandom- , DevURandom- ) where+module Crypto.Random.Entropy.Unix (+ DevRandom,+ DevURandom,+) where -import Foreign.Ptr-import Data.Word (Word8)-import Crypto.Random.Entropy.Source import Control.Exception as E+import Crypto.Random.Entropy.Source+import Data.Word (Word8)+import Foreign.Ptr ---import System.Posix.Types (Fd)+-- import System.Posix.Types (Fd) import System.IO type H = Handle type DeviceName = String -- | Entropy device @/dev/random@ on unix system-newtype DevRandom = DevRandom DeviceName+newtype DevRandom = DevRandom DeviceName -- | Entropy device @/dev/urandom@ on unix system newtype DevURandom = DevURandom DeviceName@@ -32,43 +32,46 @@ entropyOpen = fmap DevRandom `fmap` testOpen "/dev/random" entropyGather (DevRandom name) ptr n = withDev name $ \h -> gatherDevEntropyNonBlock h ptr n- entropyClose (DevRandom _) = return ()+ entropyClose (DevRandom _) = return () instance EntropySource DevURandom where entropyOpen = fmap DevURandom `fmap` testOpen "/dev/urandom" entropyGather (DevURandom name) ptr n = withDev name $ \h -> gatherDevEntropy h ptr n- entropyClose (DevURandom _) = return ()+ entropyClose (DevURandom _) = return () testOpen :: DeviceName -> IO (Maybe DeviceName) testOpen filepath = do d <- openDev filepath case d of Nothing -> return Nothing- Just h -> closeDev h >> return (Just filepath)+ Just h -> closeDev h >> return (Just filepath) openDev :: String -> IO (Maybe H)-openDev filepath = (Just `fmap` openAndNoBuffering) `E.catch` \(_ :: IOException) -> return Nothing- where openAndNoBuffering = do- h <- openBinaryFile filepath ReadMode- hSetBuffering h NoBuffering- return h+openDev filepath =+ (Just `fmap` openAndNoBuffering) `E.catch` \(_ :: IOException) -> return Nothing+ where+ openAndNoBuffering = do+ h <- openBinaryFile filepath ReadMode+ hSetBuffering h NoBuffering+ return h withDev :: String -> (H -> IO a) -> IO a-withDev filepath f = openDev filepath >>= \h ->- case h of- Nothing -> error ("device " ++ filepath ++ " cannot be grabbed")- Just fd -> f fd `E.finally` closeDev fd+withDev filepath f =+ openDev filepath >>= \h ->+ case h of+ Nothing -> error ("device " ++ filepath ++ " cannot be grabbed")+ Just fd -> f fd `E.finally` closeDev fd closeDev :: H -> IO () closeDev h = hClose h `E.catch` \(_ :: IOException) -> return () gatherDevEntropy :: H -> Ptr Word8 -> Int -> IO Int gatherDevEntropy h ptr sz =- (fromIntegral `fmap` hGetBufSome h ptr (fromIntegral sz))- `E.catch` \(_ :: IOException) -> return 0+ (fromIntegral `fmap` hGetBufSome h ptr (fromIntegral sz))+ `E.catch` \(_ :: IOException) -> return 0 gatherDevEntropyNonBlock :: H -> Ptr Word8 -> Int -> IO Int gatherDevEntropyNonBlock h ptr sz =- (fromIntegral `fmap` hGetBufNonBlocking h ptr (fromIntegral sz))- `E.catch` \(_ :: IOException) -> return 0+ (fromIntegral `fmap` hGetBufNonBlocking h ptr (fromIntegral sz))+ `E.catch` \(_ :: IOException) -> return 0
Crypto/Random/Entropy/Unsafe.hs view
@@ -4,15 +4,14 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----module Crypto.Random.Entropy.Unsafe- ( replenish- , module Crypto.Random.Entropy.Backend- ) where+module Crypto.Random.Entropy.Unsafe (+ replenish,+ module Crypto.Random.Entropy.Backend,+) where +import Crypto.Random.Entropy.Backend import Data.Word (Word8) import Foreign.Ptr (Ptr, plusPtr)-import Crypto.Random.Entropy.Backend -- | Refill the entropy in a buffer --@@ -22,12 +21,14 @@ -- If the buffer cannot be refill after 3 loopings, this will raise -- an User Error exception replenish :: Int -> [EntropyBackend] -> Ptr Word8 -> IO ()-replenish _ [] _ = fail "crypton: random: cannot get any source of entropy on this system"+replenish _ [] _ = fail "crypton: random: cannot get any source of entropy on this system" replenish poolSize backends ptr = loop 0 backends ptr poolSize- where loop :: Int -> [EntropyBackend] -> Ptr Word8 -> Int -> IO ()- loop _ _ _ 0 = return ()- loop retry [] p n | retry == 3 = error "crypton: random: cannot fully replenish"- | otherwise = loop (retry+1) backends p n- loop retry (b:bs) p n = do- r <- gatherBackend b p n- loop retry bs (p `plusPtr` r) (n - r)+ where+ loop :: Int -> [EntropyBackend] -> Ptr Word8 -> Int -> IO ()+ loop _ _ _ 0 = return ()+ loop retry [] p n+ | retry == 3 = error "crypton: random: cannot fully replenish"+ | otherwise = loop (retry + 1) backends p n+ loop retry (b : bs) p n = do+ r <- gatherBackend b p n+ loop retry bs (p `plusPtr` r) (n - r)
Crypto/Random/EntropyPool.hs view
@@ -4,22 +4,21 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----module Crypto.Random.EntropyPool- ( EntropyPool- , createEntropyPool- , createEntropyPoolWith- , getEntropyFrom- ) where+module Crypto.Random.EntropyPool (+ EntropyPool,+ createEntropyPool,+ createEntropyPoolWith,+ getEntropyFrom,+) where -import Control.Concurrent.MVar-import Crypto.Random.Entropy.Unsafe-import Crypto.Internal.ByteArray (ByteArray, ScrubbedBytes)+import Control.Concurrent.MVar+import Crypto.Internal.ByteArray (ByteArray, ScrubbedBytes) import qualified Crypto.Internal.ByteArray as B-import Data.Word (Word8)-import Data.Maybe (catMaybes)-import Foreign.Marshal.Utils (copyBytes)-import Foreign.Ptr (plusPtr, Ptr)+import Crypto.Random.Entropy.Unsafe+import Data.Maybe (catMaybes)+import Data.Word (Word8)+import Foreign.Marshal.Utils (copyBytes)+import Foreign.Ptr (Ptr, plusPtr) -- | Pool of Entropy. Contains a self-mutating pool of entropy, -- that is always guaranteed to contain data.@@ -35,7 +34,7 @@ -- the pool can be shared between multiples RNGs. createEntropyPoolWith :: Int -> [EntropyBackend] -> IO EntropyPool createEntropyPoolWith poolSize backends = do- m <- newMVar 0+ m <- newMVar 0 sm <- B.alloc poolSize (replenish poolSize backends) return $ EntropyPool backends m sm @@ -54,17 +53,18 @@ B.withByteArray sm $ \entropyPoolPtr -> modifyMVar_ posM $ \pos -> copyLoop outPtr entropyPoolPtr pos n- where poolSize = B.length sm- copyLoop d s pos left- | left == 0 = return pos- | otherwise = do- wrappedPos <-- if pos == poolSize- then replenish poolSize backends s >> return 0- else return pos- let m = min (poolSize - wrappedPos) left- copyBytes d (s `plusPtr` wrappedPos) m- copyLoop (d `plusPtr` m) s (wrappedPos + m) (left - m)+ where+ poolSize = B.length sm+ copyLoop d s pos left+ | left == 0 = return pos+ | otherwise = do+ wrappedPos <-+ if pos == poolSize+ then replenish poolSize backends s >> return 0+ else return pos+ let m = min (poolSize - wrappedPos) left+ copyBytes d (s `plusPtr` wrappedPos) m+ copyLoop (d `plusPtr` m) s (wrappedPos + m) (left - m) -- | Grab a chunk of entropy from the entropy pool. getEntropyFrom :: ByteArray byteArray => EntropyPool -> Int -> IO byteArray
+ Crypto/Random/HmacDRG.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE TypeApplications #-}++module Crypto.Random.HmacDRG (HmacDRG, initial, update) where++import Crypto.Hash+import Crypto.MAC.HMAC (HMAC (..), hmac)+import Crypto.Random.Types+import Data.ByteArray (ByteArrayAccess, Bytes, ScrubbedBytes)+import qualified Data.ByteArray as M+import Data.Maybe++-- | HMAC-based Deterministic Random Generator+--+-- Adapted from NIST Special Publication 800-90A Revision 1, Section 10.1.2+data HmacDRG hash = HmacDRG (Digest hash) (Digest hash)++-- | The initial DRG state. It should be seeded via 'update' before use.+initial :: HashAlgorithm hash => hash -> HmacDRG hash+initial algorithm = HmacDRG (constant 0x00) (constant 0x01)+ where+ constant =+ fromJust . digestFromByteString . M.replicate @Bytes (hashDigestSize algorithm)++-- | Update the DRG state with optional provided data.+update+ :: ByteArrayAccess input+ => HashAlgorithm hash+ => input -> HmacDRG hash -> HmacDRG hash+update input state0 = if M.null input then state1 else state2+ where+ state1 = step 0x00 state0+ state2 = step 0x01 state1+ step byte (HmacDRG key value) = HmacDRG keyNew valueNew+ where+ keyNew =+ hmacGetDigest $+ hmac key $+ M.convert value <> M.singleton @ScrubbedBytes byte <> M.convert input+ valueNew = hmacGetDigest $ hmac keyNew value++instance HashAlgorithm hash => DRG (HmacDRG hash) where+ randomBytesGenerate count (HmacDRG key value) = (output, state)+ where+ output = M.take count result+ state = update @Bytes M.empty $ HmacDRG key new+ (result, new) = go M.empty value+ go buffer current+ | M.length buffer >= count = (buffer, current)+ | otherwise = go (buffer <> M.convert next) next+ where+ next = hmacGetDigest $ hmac key current
Crypto/Random/Probabilistic.hs view
@@ -4,25 +4,24 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----module Crypto.Random.Probabilistic- ( probabilistic- ) where+module Crypto.Random.Probabilistic (+ probabilistic,+) where import Crypto.Internal.Compat-import Crypto.Random.Types import Crypto.Random -- | This create a random number generator out of thin air with -- the system entropy; don't generally use as the IO is not exposed -- this can have unexpected random for.--- +-- -- This is useful for probabilistic algorithm like Miller Rabin -- probably prime algorithm, given appropriate choice of the heuristic -- -- Generally, it's advised not to use this function. probabilistic :: MonadPseudoRandom ChaChaDRG a -> a probabilistic f = fst $ withDRG drg f- where {-# NOINLINE drg #-}- drg = unsafeDoIO drgNew+ where+ {-# NOINLINE drg #-}+ drg = unsafeDoIO drgNew {-# NOINLINE probabilistic #-}
Crypto/Random/SystemDRG.hs view
@@ -1,26 +1,26 @@+{-# LANGUAGE BangPatterns #-}+ -- | -- Module : Crypto.Random.SystemDRG -- License : BSD-style -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----{-# LANGUAGE BangPatterns #-}-module Crypto.Random.SystemDRG- ( SystemDRG- , getSystemDRG- ) where+module Crypto.Random.SystemDRG (+ SystemDRG,+ getSystemDRG,+) where -import Crypto.Random.Types-import Crypto.Random.Entropy.Unsafe-import Crypto.Internal.Compat-import Data.ByteArray (ScrubbedBytes, ByteArray)-import Data.Memory.PtrMethods as B (memCopy)-import Data.Maybe (catMaybes)-import Data.Tuple (swap)-import Foreign.Ptr+import Crypto.Internal.Compat+import Crypto.Random.Entropy.Unsafe+import Crypto.Random.Types+import Data.ByteArray (ByteArray, ScrubbedBytes) import qualified Data.ByteArray as B-import System.IO.Unsafe (unsafeInterleaveIO)+import Data.Maybe (catMaybes)+import Data.Memory.PtrMethods as B (memCopy)+import Data.Tuple (swap)+import Foreign.Ptr+import System.IO.Unsafe (unsafeInterleaveIO) -- | A referentially transparent System representation of -- the random evaluated out of the system.@@ -43,21 +43,22 @@ getSystemDRG = do backends <- catMaybes `fmap` sequence supportedBackends let getNext = unsafeInterleaveIO $ do- bs <- B.alloc systemChunkSize (replenish systemChunkSize backends)+ bs <- B.alloc systemChunkSize (replenish systemChunkSize backends) more <- getNext- return (bs:more)+ return (bs : more) SystemDRG 0 <$> getNext generate :: ByteArray output => Int -> SystemDRG -> (output, SystemDRG) generate nbBytes (SystemDRG ofs sysChunks) = swap $ unsafeDoIO $ B.allocRet nbBytes $ loop ofs sysChunks nbBytes- where loop currentOfs chunks 0 _ = return $! SystemDRG currentOfs chunks- loop _ [] _ _ = error "SystemDRG: the impossible happened: empty chunk"- loop currentOfs oChunks@(c:cs) n d = do- let currentLeft = B.length c - currentOfs- toCopy = min n currentLeft- nextOfs = currentOfs + toCopy- n' = n - toCopy- B.withByteArray c $ \src -> B.memCopy d (src `plusPtr` currentOfs) toCopy- if nextOfs == B.length c- then loop 0 cs n' (d `plusPtr` toCopy)- else loop nextOfs oChunks n' (d `plusPtr` toCopy)+ where+ loop currentOfs chunks 0 _ = return $! SystemDRG currentOfs chunks+ loop _ [] _ _ = error "SystemDRG: the impossible happened: empty chunk"+ loop currentOfs oChunks@(c : cs) n d = do+ let currentLeft = B.length c - currentOfs+ toCopy = min n currentLeft+ nextOfs = currentOfs + toCopy+ n' = n - toCopy+ B.withByteArray c $ \src -> B.memCopy d (src `plusPtr` currentOfs) toCopy+ if nextOfs == B.length c+ then loop 0 cs n' (d `plusPtr` toCopy)+ else loop nextOfs oChunks n' (d `plusPtr` toCopy)
Crypto/Random/Types.hs view
@@ -4,17 +4,15 @@ -- Maintainer : Vincent Hanquez <vincent@snarc.org> -- Stability : experimental -- Portability : Good----module Crypto.Random.Types- (- MonadRandom(..)- , MonadPseudoRandom- , DRG(..)- , withDRG- ) where+module Crypto.Random.Types (+ MonadRandom (..),+ MonadPseudoRandom,+ DRG (..),+ withDRG,+) where -import Crypto.Random.Entropy import Crypto.Internal.ByteArray+import Crypto.Random.Entropy -- | A monad constraint that allows to generate random bytes class Monad m => MonadRandom m where@@ -39,14 +37,14 @@ let (a, g2) = runPseudoRandom m g1 in (f a, g2) instance DRG gen => Applicative (MonadPseudoRandom gen) where- pure a = MonadPseudoRandom $ \g -> (a, g)+ pure a = MonadPseudoRandom $ \g -> (a, g) (<*>) fm m = MonadPseudoRandom $ \g1 -> let (f, g2) = runPseudoRandom fm g1 (a, g3) = runPseudoRandom m g2 in (f a, g3) instance DRG gen => Monad (MonadPseudoRandom gen) where- return = pure+ return = pure (>>=) m1 m2 = MonadPseudoRandom $ \g1 -> let (a, g2) = runPseudoRandom m1 g1 in runPseudoRandom (m2 a) g2
Crypto/System/CPU.hs view
@@ -1,3 +1,7 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ForeignFunctionInterface #-}+ -- | -- Module : Crypto.System.CPU -- License : BSD-style@@ -6,14 +10,10 @@ -- Portability : unknown -- -- Gives information about crypton runtime environment.----{-# LANGUAGE CPP #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE ForeignFunctionInterface #-}-module Crypto.System.CPU- ( ProcessorOption (..)- , processorOptions- ) where+module Crypto.System.CPU (+ ProcessorOption (..),+ processorOptions,+) where import Data.Data import Data.List (findIndices)@@ -33,10 +33,13 @@ -- | CPU options impacting cryptography implementation and library performance. data ProcessorOption- = AESNI -- ^ Support for AES instructions, with flag @support_aesni@- | PCLMUL -- ^ Support for CLMUL instructions, with flag @support_pclmuldq@- | RDRAND -- ^ Support for RDRAND instruction, with flag @support_rdrand@- deriving (Show,Eq,Enum,Data)+ = -- | Support for AES instructions, with flag @support_aesni@+ AESNI+ | -- | Support for CLMUL instructions, with flag @support_pclmuldq@+ PCLMUL+ | -- | Support for RDRAND instruction, with flag @support_rdrand@+ RDRAND+ deriving (Show, Eq, Enum, Data) -- | Options which have been enabled at compile time and are supported by the -- current CPU.@@ -44,11 +47,11 @@ processorOptions = unsafeDoIO $ do p <- crypton_aes_cpu_init options <- traverse (getOption p) aesOptions- rdrand <- hasRDRand- return (decodeOptions options ++ [ RDRAND | rdrand ])+ rdrand <- hasRDRand+ return (decodeOptions options ++ [RDRAND | rdrand]) where- aesOptions = [ AESNI .. PCLMUL ]- getOption p = peekElemOff p . fromEnum+ aesOptions = [AESNI .. PCLMUL]+ getOption p = peekElemOff p . fromEnum decodeOptions = map toEnum . findIndices (> 0) {-# NOINLINE processorOptions #-}
Crypto/Tutorial.hs view
@@ -1,17 +1,17 @@ -- | Examples of how to use @crypton@.-module Crypto.Tutorial- ( -- * API design- -- $api_design+module Crypto.Tutorial (+ -- * API design+ -- $api_design - -- * Hash algorithms- -- $hash_algorithms+ -- * Hash algorithms+ -- $hash_algorithms - -- * Symmetric block ciphers- -- $symmetric_block_ciphers+ -- * Symmetric block ciphers+ -- $symmetric_block_ciphers - -- * Combining primitives- -- $combining_primitives- ) where+ -- * Combining primitives+ -- $combining_primitives+) where -- $api_design --
Setup.hs view
@@ -1,2 +1,3 @@ import Distribution.Simple+ main = defaultMain
benchs/Bench.hs view
@@ -1,43 +1,44 @@-{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-}+ module Main where import Gauge.Main -import Crypto.Cipher.AES+import Crypto.Cipher.AES import qualified Crypto.Cipher.AESGCMSIV as AESGCMSIV-import Crypto.Cipher.Blowfish-import Crypto.Cipher.CAST5+import Crypto.Cipher.Blowfish+import Crypto.Cipher.CAST5 import qualified Crypto.Cipher.ChaChaPoly1305 as CP-import Crypto.Cipher.DES-import Crypto.Cipher.Twofish-import Crypto.Cipher.Types-import Crypto.ECC-import Crypto.Error-import Crypto.Hash+import Crypto.Cipher.DES+import Crypto.Cipher.Twofish+import Crypto.Cipher.Types+import Crypto.ECC+import Crypto.Error+import Crypto.Hash import qualified Crypto.KDF.BCrypt as BCrypt import qualified Crypto.KDF.PBKDF2 as PBKDF2-import Crypto.Number.Basic (numBits)-import Crypto.Number.Generate+import Crypto.Number.Basic (numBits)+import Crypto.Number.Generate import qualified Crypto.PubKey.DH as DH-import qualified Crypto.PubKey.ECC.Types as ECC import qualified Crypto.PubKey.ECC.Prim as ECC+import qualified Crypto.PubKey.ECC.Types as ECC import qualified Crypto.PubKey.ECDSA as ECDSA import qualified Crypto.PubKey.Ed25519 as Ed25519 import qualified Crypto.PubKey.EdDSA as EdDSA-import Crypto.Random+import Crypto.Random -import Control.DeepSeq (NFData)-import Data.ByteArray (ByteArray, Bytes)+import Control.DeepSeq (NFData)+import Data.ByteArray (ByteArray, Bytes) import qualified Data.ByteString as B import qualified Crypto.PubKey.ECC.P256 as P256 import Number.F2m -data HashAlg = forall alg . HashAlgorithm alg => HashAlg alg+data HashAlg = forall alg. HashAlgorithm alg => HashAlg alg benchHash = [ env oneKB $ \b -> bgroup "1KB" $ map (doHashBench b) hashAlgs@@ -65,13 +66,13 @@ , ("SHA512t_256", HashAlg SHA512t_256) , ("RIPEMD160", HashAlg RIPEMD160) , ("Tiger", HashAlg Tiger)- --, ("Skein256-160", HashAlg Skein256_160)- , ("Skein256-256", HashAlg Skein256_256)- --, ("Skein512-160", HashAlg Skein512_160)- , ("Skein512-384", HashAlg Skein512_384)+ , -- , ("Skein256-160", HashAlg Skein256_160)+ ("Skein256-256", HashAlg Skein256_256)+ , -- , ("Skein512-160", HashAlg Skein512_160)+ ("Skein512-384", HashAlg Skein512_384) , ("Skein512-512", HashAlg Skein512_512)- --, ("Skein512-896", HashAlg Skein512_896)- , ("Whirlpool", HashAlg Whirlpool)+ , -- , ("Skein512-896", HashAlg Skein512_896)+ ("Whirlpool", HashAlg Whirlpool) , ("Keccak-224", HashAlg Keccak_224) , ("Keccak-256", HashAlg Keccak_256) , ("Keccak-384", HashAlg Keccak_384)@@ -91,82 +92,99 @@ ] benchPBKDF2 =- [ bgroup "64"+ [ bgroup+ "64" [ bench "cryptonite-PBKDF2-100-64" $ nf (pbkdf2 64) 100 , bench "cryptonite-PBKDF2-1000-64" $ nf (pbkdf2 64) 1000 , bench "cryptonite-PBKDF2-10000-64" $ nf (pbkdf2 64) 10000 ]- , bgroup "128"+ , bgroup+ "128" [ bench "cryptonite-PBKDF2-100-128" $ nf (pbkdf2 128) 100 , bench "cryptonite-PBKDF2-1000-128" $ nf (pbkdf2 128) 1000 , bench "cryptonite-PBKDF2-10000-128" $ nf (pbkdf2 128) 10000 ] ] where- pbkdf2 :: Int -> Int -> B.ByteString- pbkdf2 n iter = PBKDF2.generate (PBKDF2.prfHMAC SHA512) (params n iter) mypass mysalt+ pbkdf2 :: Int -> Int -> B.ByteString+ pbkdf2 n iter = PBKDF2.generate (PBKDF2.prfHMAC SHA512) (params n iter) mypass mysalt - mypass, mysalt :: B.ByteString- mypass = "password"- mysalt = "salt"+ mypass, mysalt :: B.ByteString+ mypass = "password"+ mysalt = "salt" - params n iter = PBKDF2.Parameters iter n+ params n iter = PBKDF2.Parameters iter n benchBCrypt =- [ bench "cryptonite-BCrypt-4" $ nf bcrypt 4- , bench "cryptonite-BCrypt-5" $ nf bcrypt 5- , bench "cryptonite-BCrypt-7" $ nf bcrypt 7+ [ bench "cryptonite-BCrypt-4" $ nf bcrypt 4+ , bench "cryptonite-BCrypt-5" $ nf bcrypt 5+ , bench "cryptonite-BCrypt-7" $ nf bcrypt 7 , bench "cryptonite-BCrypt-11" $ nf bcrypt 11 ] where- bcrypt :: Int -> B.ByteString- bcrypt cost = BCrypt.bcrypt cost mysalt mypass+ bcrypt :: Int -> B.ByteString+ bcrypt cost = BCrypt.bcrypt cost mysalt mypass - mypass, mysalt :: B.ByteString- mypass = "password"- mysalt = "saltsaltsaltsalt"+ mypass, mysalt :: B.ByteString+ mypass = "password"+ mysalt = "saltsaltsaltsalt" benchBlockCipher = [ bgroup "ECB" benchECB , bgroup "CBC" benchCBC ] where- benchECB =- [ bench "DES-input=1024" $ nf (run (undefined :: DES) cipherInit key8) input1024- , bench "Blowfish128-input=1024" $ nf (run (undefined :: Blowfish128) cipherInit key16) input1024- , bench "Twofish128-input=1024" $ nf (run (undefined :: Twofish128) cipherInit key16) input1024- , bench "CAST5-128-input=1024" $ nf (run (undefined :: CAST5) cipherInit key16) input1024- , bench "AES128-input=1024" $ nf (run (undefined :: AES128) cipherInit key16) input1024- , bench "AES256-input=1024" $ nf (run (undefined :: AES256) cipherInit key32) input1024- ]- where run :: (ByteArray ba, ByteArray key, BlockCipher c)- => c -> (key -> CryptoFailable c) -> key -> ba -> ba- run _witness initF key input =- (ecbEncrypt (throwCryptoError (initF key))) input+ benchECB =+ [ bench "DES-input=1024" $ nf (run (undefined :: DES) cipherInit key8) input1024+ , bench "Blowfish128-input=1024" $+ nf (run (undefined :: Blowfish128) cipherInit key16) input1024+ , bench "Twofish128-input=1024" $+ nf (run (undefined :: Twofish128) cipherInit key16) input1024+ , bench "CAST5-128-input=1024" $+ nf (run (undefined :: CAST5) cipherInit key16) input1024+ , bench "AES128-input=1024" $+ nf (run (undefined :: AES128) cipherInit key16) input1024+ , bench "AES256-input=1024" $+ nf (run (undefined :: AES256) cipherInit key32) input1024+ ]+ where+ run+ :: (ByteArray ba, ByteArray key, BlockCipher c)+ => c -> (key -> CryptoFailable c) -> key -> ba -> ba+ run _witness initF key input =+ (ecbEncrypt (throwCryptoError (initF key))) input - benchCBC =- [ bench "DES-input=1024" $ nf (run (undefined :: DES) cipherInit key8 iv8) input1024- , bench "Blowfish128-input=1024" $ nf (run (undefined :: Blowfish128) cipherInit key16 iv8) input1024- , bench "Twofish128-input=1024" $ nf (run (undefined :: Twofish128) cipherInit key16 iv16) input1024- , bench "CAST5-128-input=1024" $ nf (run (undefined :: CAST5) cipherInit key16 iv8) input1024- , bench "AES128-input=1024" $ nf (run (undefined :: AES128) cipherInit key16 iv16) input1024- , bench "AES256-input=1024" $ nf (run (undefined :: AES256) cipherInit key32 iv16) input1024- ]- where run :: (ByteArray ba, ByteArray key, BlockCipher c)- => c -> (key -> CryptoFailable c) -> key -> IV c -> ba -> ba- run _witness initF key iv input =- (cbcEncrypt (throwCryptoError (initF key))) iv input+ benchCBC =+ [ bench "DES-input=1024" $+ nf (run (undefined :: DES) cipherInit key8 iv8) input1024+ , bench "Blowfish128-input=1024" $+ nf (run (undefined :: Blowfish128) cipherInit key16 iv8) input1024+ , bench "Twofish128-input=1024" $+ nf (run (undefined :: Twofish128) cipherInit key16 iv16) input1024+ , bench "CAST5-128-input=1024" $+ nf (run (undefined :: CAST5) cipherInit key16 iv8) input1024+ , bench "AES128-input=1024" $+ nf (run (undefined :: AES128) cipherInit key16 iv16) input1024+ , bench "AES256-input=1024" $+ nf (run (undefined :: AES256) cipherInit key32 iv16) input1024+ ]+ where+ run+ :: (ByteArray ba, ByteArray key, BlockCipher c)+ => c -> (key -> CryptoFailable c) -> key -> IV c -> ba -> ba+ run _witness initF key iv input =+ (cbcEncrypt (throwCryptoError (initF key))) iv input - key8 = B.replicate 8 0- key16 = B.replicate 16 0- key32 = B.replicate 32 0- input1024 = B.replicate 1024 0+ key8 = B.replicate 8 0+ key16 = B.replicate 16 0+ key32 = B.replicate 32 0+ input1024 = B.replicate 1024 0 - iv8 :: BlockCipher c => IV c- iv8 = maybe (error "iv size 8") id $ makeIV key8+ iv8 :: BlockCipher c => IV c+ iv8 = maybe (error "iv size 8") id $ makeIV key8 - iv16 :: BlockCipher c => IV c- iv16 = maybe (error "iv size 16") id $ makeIV key16+ iv16 :: BlockCipher c => IV c+ iv16 = maybe (error "iv size 16") id $ makeIV key16 benchAE = [ bench "ChaChaPoly1305" $ nf (cp key32) (input64, input1024)@@ -174,81 +192,92 @@ , bench "AES-CCM" $ nf (ccm key32) (input64, input1024) , bench "AES-GCM-SIV" $ nf (gcmsiv key32) (input64, input1024) ]- where cp k (ini, plain) =- let iniState = throwCryptoError $ CP.initialize k (throwCryptoError $ CP.nonce12 nonce12)- afterAAD = CP.finalizeAAD (CP.appendAAD ini iniState)- (out, afterEncrypt) = CP.encrypt plain afterAAD- outtag = CP.finalize afterEncrypt- in (outtag, out)+ where+ cp k (ini, plain) =+ let iniState =+ throwCryptoError $ CP.initialize k (throwCryptoError $ CP.nonce12 nonce12)+ afterAAD = CP.finalizeAAD (CP.appendAAD ini iniState)+ (out, afterEncrypt) = CP.encrypt plain afterAAD+ outtag = CP.finalize afterEncrypt+ in (outtag, out) - gcm k (ini, plain) =- let ctx = throwCryptoError (cipherInit k) :: AES256- state = throwCryptoError $ aeadInit AEAD_GCM ctx nonce12- in aeadSimpleEncrypt state ini plain 16+ gcm k (ini, plain) =+ let ctx = throwCryptoError (cipherInit k) :: AES256+ state = throwCryptoError $ aeadInit AEAD_GCM ctx nonce12+ in aeadSimpleEncrypt state ini plain 16 - ccm k (ini, plain) =- let ctx = throwCryptoError (cipherInit k) :: AES256- mode = AEAD_CCM 1024 CCM_M16 CCM_L3- state = throwCryptoError $ aeadInit mode ctx nonce12- in aeadSimpleEncrypt state ini plain 16+ ccm k (ini, plain) =+ let ctx = throwCryptoError (cipherInit k) :: AES256+ mode = AEAD_CCM 1024 CCM_M16 CCM_L3+ state = throwCryptoError $ aeadInit mode ctx nonce12+ in aeadSimpleEncrypt state ini plain 16 - gcmsiv k (ini, plain) =- let ctx = throwCryptoError (cipherInit k) :: AES256- iv = throwCryptoError (AESGCMSIV.nonce nonce12)- in AESGCMSIV.encrypt ctx iv ini plain+ gcmsiv k (ini, plain) =+ let ctx = throwCryptoError (cipherInit k) :: AES256+ iv = throwCryptoError (AESGCMSIV.nonce nonce12)+ in AESGCMSIV.encrypt ctx iv ini plain - input64 = B.replicate 64 0- input1024 = B.replicate 1024 0+ input64 = B.replicate 64 0+ input1024 = B.replicate 1024 0 - nonce12 :: B.ByteString- nonce12 = B.replicate 12 0+ nonce12 :: B.ByteString+ nonce12 = B.replicate 12 0 - key32 = B.replicate 32 0+ key32 = B.replicate 32 0 benchECC =- [ bench "pointAddTwoMuls-baseline" $ nf run_b (n1, p1, n2, p2)+ [ bench "pointAddTwoMuls-baseline" $ nf run_b (n1, p1, n2, p2) , bench "pointAddTwoMuls-optimized" $ nf run_o (n1, p1, n2, p2) , bench "pointAdd-ECC" $ nf run_c (p1, p2) , bench "pointMul-ECC" $ nf run_d (n1, p2) ]- where run_b (n, p, k, q) = ECC.pointAdd c (ECC.pointMul c n p)- (ECC.pointMul c k q)+ where+ run_b (n, p, k, q) =+ ECC.pointAdd+ c+ (ECC.pointMul c n p)+ (ECC.pointMul c k q) - run_o (n, p, k, q) = ECC.pointAddTwoMuls c n p k q- run_c (p, q) = ECC.pointAdd c p q- run_d (n, p) = ECC.pointMul c n p+ run_o (n, p, k, q) = ECC.pointAddTwoMuls c n p k q+ run_c (p, q) = ECC.pointAdd c p q+ run_d (n, p) = ECC.pointMul c n p - c = ECC.getCurveByName ECC.SEC_p256r1- p1 = ECC.pointBaseMul c n1- p2 = ECC.pointBaseMul c n2- n1 = 0x2ba9daf2363b2819e69b34a39cf496c2458a9b2a21505ea9e7b7cbca42dc7435- n2 = 0xf054a7f60d10b8c2cf847ee90e9e029f8b0e971b09ca5f55c4d49921a11fadc1+ c = ECC.getCurveByName ECC.SEC_p256r1+ p1 = ECC.pointBaseMul c n1+ p2 = ECC.pointBaseMul c n2+ n1 = 0x2ba9daf2363b2819e69b34a39cf496c2458a9b2a21505ea9e7b7cbca42dc7435+ n2 = 0xf054a7f60d10b8c2cf847ee90e9e029f8b0e971b09ca5f55c4d49921a11fadc1 benchP256 =- [ bench "pointAddTwoMuls-P256" $ nf run_p (n1, p1, n2, p2)- , bench "pointAdd-P256" $ nf run_q (p1, p2)- , bench "pointMul-P256" $ nf run_t (n1, p1)+ [ bench "pointAddTwoMuls-P256" $ nf run_p (n1, p1, n2, p2)+ , bench "pointAdd-P256" $ nf run_q (p1, p2)+ , bench "pointMul-P256" $ nf run_t (n1, p1) ]- where run_p (n, p, k, q) = P256.pointAdd (P256.pointMul n p) (P256.pointMul k q)- run_q (p, q) = P256.pointAdd p q- run_t (n, p) = P256.pointMul n p-- xS = 0xde2444bebc8d36e682edd27e0f271508617519b3221a8fa0b77cab3989da97c9- yS = 0xc093ae7ff36e5380fc01a5aad1e66659702de80f53cec576b6350b243042a256- xT = 0x55a8b00f8da1d44e62f6b3b25316212e39540dc861c89575bb8cf92e35e0986b- yT = 0x5421c3209c2d6c704835d82ac4c3dd90f61a8a52598b9e7ab656e9d8c8b24316- p1 = P256.pointFromIntegers (xS, yS)- p2 = P256.pointFromIntegers (xT, yT)- n1 = throwCryptoError $ P256.scalarFromInteger 0x2ba9daf2363b2819e69b34a39cf496c2458a9b2a21505ea9e7b7cbca42dc7435- n2 = throwCryptoError $ P256.scalarFromInteger 0xf054a7f60d10b8c2cf847ee90e9e029f8b0e971b09ca5f55c4d49921a11fadc1-+ where+ run_p (n, p, k, q) = P256.pointAdd (P256.pointMul n p) (P256.pointMul k q)+ run_q (p, q) = P256.pointAdd p q+ run_t (n, p) = P256.pointMul n p + xS = 0xde2444bebc8d36e682edd27e0f271508617519b3221a8fa0b77cab3989da97c9+ yS = 0xc093ae7ff36e5380fc01a5aad1e66659702de80f53cec576b6350b243042a256+ xT = 0x55a8b00f8da1d44e62f6b3b25316212e39540dc861c89575bb8cf92e35e0986b+ yT = 0x5421c3209c2d6c704835d82ac4c3dd90f61a8a52598b9e7ab656e9d8c8b24316+ p1 = P256.pointFromIntegers (xS, yS)+ p2 = P256.pointFromIntegers (xT, yT)+ n1 =+ throwCryptoError $+ P256.scalarFromInteger+ 0x2ba9daf2363b2819e69b34a39cf496c2458a9b2a21505ea9e7b7cbca42dc7435+ n2 =+ throwCryptoError $+ P256.scalarFromInteger+ 0xf054a7f60d10b8c2cf847ee90e9e029f8b0e971b09ca5f55c4d49921a11fadc1 benchFFDH = map doFFDHBench primes where doFFDHBench (e, p) = let bits = numBits p- params = DH.Params { DH.params_p = p, DH.params_g = 2, DH.params_bits = bits }+ params = DH.Params{DH.params_p = p, DH.params_g = 2, DH.params_bits = bits} in env (generate e params) $ bench (show bits) . nf (run params) generate e params = do@@ -261,14 +290,31 @@ run params (priv, pub) = DH.getShared params priv pub -- RFC 7919: prime p with minimal size of exponent- primes = [ (225, 0xFFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF97D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD65612433F51F5F066ED0856365553DED1AF3B557135E7F57C935984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE73530ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FBB96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB190B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F619172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD733BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA886B423861285C97FFFFFFFFFFFFFFFF)- , (275, 0xFFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF97D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD65612433F51F5F066ED0856365553DED1AF3B557135E7F57C935984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE73530ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FBB96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB190B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F619172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD733BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C023861B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91CAEFE130985139270B4130C93BC437944F4FD4452E2D74DD364F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0DABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF3C1B20EE3FD59D7C25E41D2B66C62E37FFFFFFFFFFFFFFFF)- , (325, 0xFFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF97D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD65612433F51F5F066ED0856365553DED1AF3B557135E7F57C935984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE73530ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FBB96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB190B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F619172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD733BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C023861B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91CAEFE130985139270B4130C93BC437944F4FD4452E2D74DD364F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0DABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF3C1B20EE3FD59D7C25E41D2B669E1EF16E6F52C3164DF4FB7930E9E4E58857B6AC7D5F42D69F6D187763CF1D5503400487F55BA57E31CC7A7135C886EFB4318AED6A1E012D9E6832A907600A918130C46DC778F971AD0038092999A333CB8B7A1A1DB93D7140003C2A4ECEA9F98D0ACC0A8291CDCEC97DCF8EC9B55A7F88A46B4DB5A851F44182E1C68A007E5E655F6AFFFFFFFFFFFFFFFF)- , (375, 0xFFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF97D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD65612433F51F5F066ED0856365553DED1AF3B557135E7F57C935984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE73530ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FBB96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB190B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F619172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD733BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C023861B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91CAEFE130985139270B4130C93BC437944F4FD4452E2D74DD364F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0DABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF3C1B20EE3FD59D7C25E41D2B669E1EF16E6F52C3164DF4FB7930E9E4E58857B6AC7D5F42D69F6D187763CF1D5503400487F55BA57E31CC7A7135C886EFB4318AED6A1E012D9E6832A907600A918130C46DC778F971AD0038092999A333CB8B7A1A1DB93D7140003C2A4ECEA9F98D0ACC0A8291CDCEC97DCF8EC9B55A7F88A46B4DB5A851F44182E1C68A007E5E0DD9020BFD64B645036C7A4E677D2C38532A3A23BA4442CAF53EA63BB454329B7624C8917BDD64B1C0FD4CB38E8C334C701C3ACDAD0657FCCFEC719B1F5C3E4E46041F388147FB4CFDB477A52471F7A9A96910B855322EDB6340D8A00EF092350511E30ABEC1FFF9E3A26E7FB29F8C183023C3587E38DA0077D9B4763E4E4B94B2BBC194C6651E77CAF992EEAAC0232A281BF6B3A739C1226116820AE8DB5847A67CBEF9C9091B462D538CD72B03746AE77F5E62292C311562A846505DC82DB854338AE49F5235C95B91178CCF2DD5CACEF403EC9D1810C6272B045B3B71F9DC6B80D63FDD4A8E9ADB1E6962A69526D43161C1A41D570D7938DAD4A40E329CD0E40E65FFFFFFFFFFFFFFFF)- , (400, 0xFFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF97D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD65612433F51F5F066ED0856365553DED1AF3B557135E7F57C935984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE73530ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FBB96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB190B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F619172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD733BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C023861B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91CAEFE130985139270B4130C93BC437944F4FD4452E2D74DD364F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0DABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF3C1B20EE3FD59D7C25E41D2B669E1EF16E6F52C3164DF4FB7930E9E4E58857B6AC7D5F42D69F6D187763CF1D5503400487F55BA57E31CC7A7135C886EFB4318AED6A1E012D9E6832A907600A918130C46DC778F971AD0038092999A333CB8B7A1A1DB93D7140003C2A4ECEA9F98D0ACC0A8291CDCEC97DCF8EC9B55A7F88A46B4DB5A851F44182E1C68A007E5E0DD9020BFD64B645036C7A4E677D2C38532A3A23BA4442CAF53EA63BB454329B7624C8917BDD64B1C0FD4CB38E8C334C701C3ACDAD0657FCCFEC719B1F5C3E4E46041F388147FB4CFDB477A52471F7A9A96910B855322EDB6340D8A00EF092350511E30ABEC1FFF9E3A26E7FB29F8C183023C3587E38DA0077D9B4763E4E4B94B2BBC194C6651E77CAF992EEAAC0232A281BF6B3A739C1226116820AE8DB5847A67CBEF9C9091B462D538CD72B03746AE77F5E62292C311562A846505DC82DB854338AE49F5235C95B91178CCF2DD5CACEF403EC9D1810C6272B045B3B71F9DC6B80D63FDD4A8E9ADB1E6962A69526D43161C1A41D570D7938DAD4A40E329CCFF46AAA36AD004CF600C8381E425A31D951AE64FDB23FCEC9509D43687FEB69EDD1CC5E0B8CC3BDF64B10EF86B63142A3AB8829555B2F747C932665CB2C0F1CC01BD70229388839D2AF05E454504AC78B7582822846C0BA35C35F5C59160CC046FD8251541FC68C9C86B022BB7099876A460E7451A8A93109703FEE1C217E6C3826E52C51AA691E0E423CFC99E9E31650C1217B624816CDAD9A95F9D5B8019488D9C0A0A1FE3075A577E23183F81D4A3F2FA4571EFC8CE0BA8A4FE8B6855DFE72B0A66EDED2FBABFBE58A30FAFABE1C5D71A87E2F741EF8C1FE86FEA6BBFDE530677F0D97D11D49F7A8443D0822E506A9F4614E011E2A94838FF88CD68C8BB7C5C6424CFFFFFFFFFFFFFFFF)- ]+ primes =+ [+ ( 225+ , 0xFFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF97D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD65612433F51F5F066ED0856365553DED1AF3B557135E7F57C935984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE73530ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FBB96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB190B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F619172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD733BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA886B423861285C97FFFFFFFFFFFFFFFF+ )+ ,+ ( 275+ , 0xFFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF97D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD65612433F51F5F066ED0856365553DED1AF3B557135E7F57C935984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE73530ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FBB96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB190B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F619172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD733BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C023861B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91CAEFE130985139270B4130C93BC437944F4FD4452E2D74DD364F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0DABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF3C1B20EE3FD59D7C25E41D2B66C62E37FFFFFFFFFFFFFFFF+ )+ ,+ ( 325+ , 0xFFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF97D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD65612433F51F5F066ED0856365553DED1AF3B557135E7F57C935984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE73530ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FBB96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB190B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F619172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD733BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C023861B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91CAEFE130985139270B4130C93BC437944F4FD4452E2D74DD364F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0DABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF3C1B20EE3FD59D7C25E41D2B669E1EF16E6F52C3164DF4FB7930E9E4E58857B6AC7D5F42D69F6D187763CF1D5503400487F55BA57E31CC7A7135C886EFB4318AED6A1E012D9E6832A907600A918130C46DC778F971AD0038092999A333CB8B7A1A1DB93D7140003C2A4ECEA9F98D0ACC0A8291CDCEC97DCF8EC9B55A7F88A46B4DB5A851F44182E1C68A007E5E655F6AFFFFFFFFFFFFFFFF+ )+ ,+ ( 375+ , 0xFFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF97D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD65612433F51F5F066ED0856365553DED1AF3B557135E7F57C935984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE73530ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FBB96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB190B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F619172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD733BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C023861B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91CAEFE130985139270B4130C93BC437944F4FD4452E2D74DD364F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0DABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF3C1B20EE3FD59D7C25E41D2B669E1EF16E6F52C3164DF4FB7930E9E4E58857B6AC7D5F42D69F6D187763CF1D5503400487F55BA57E31CC7A7135C886EFB4318AED6A1E012D9E6832A907600A918130C46DC778F971AD0038092999A333CB8B7A1A1DB93D7140003C2A4ECEA9F98D0ACC0A8291CDCEC97DCF8EC9B55A7F88A46B4DB5A851F44182E1C68A007E5E0DD9020BFD64B645036C7A4E677D2C38532A3A23BA4442CAF53EA63BB454329B7624C8917BDD64B1C0FD4CB38E8C334C701C3ACDAD0657FCCFEC719B1F5C3E4E46041F388147FB4CFDB477A52471F7A9A96910B855322EDB6340D8A00EF092350511E30ABEC1FFF9E3A26E7FB29F8C183023C3587E38DA0077D9B4763E4E4B94B2BBC194C6651E77CAF992EEAAC0232A281BF6B3A739C1226116820AE8DB5847A67CBEF9C9091B462D538CD72B03746AE77F5E62292C311562A846505DC82DB854338AE49F5235C95B91178CCF2DD5CACEF403EC9D1810C6272B045B3B71F9DC6B80D63FDD4A8E9ADB1E6962A69526D43161C1A41D570D7938DAD4A40E329CD0E40E65FFFFFFFFFFFFFFFF+ )+ ,+ ( 400+ , 0xFFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF97D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD65612433F51F5F066ED0856365553DED1AF3B557135E7F57C935984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE73530ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FBB96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB190B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F619172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD733BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C023861B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91CAEFE130985139270B4130C93BC437944F4FD4452E2D74DD364F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0DABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF3C1B20EE3FD59D7C25E41D2B669E1EF16E6F52C3164DF4FB7930E9E4E58857B6AC7D5F42D69F6D187763CF1D5503400487F55BA57E31CC7A7135C886EFB4318AED6A1E012D9E6832A907600A918130C46DC778F971AD0038092999A333CB8B7A1A1DB93D7140003C2A4ECEA9F98D0ACC0A8291CDCEC97DCF8EC9B55A7F88A46B4DB5A851F44182E1C68A007E5E0DD9020BFD64B645036C7A4E677D2C38532A3A23BA4442CAF53EA63BB454329B7624C8917BDD64B1C0FD4CB38E8C334C701C3ACDAD0657FCCFEC719B1F5C3E4E46041F388147FB4CFDB477A52471F7A9A96910B855322EDB6340D8A00EF092350511E30ABEC1FFF9E3A26E7FB29F8C183023C3587E38DA0077D9B4763E4E4B94B2BBC194C6651E77CAF992EEAAC0232A281BF6B3A739C1226116820AE8DB5847A67CBEF9C9091B462D538CD72B03746AE77F5E62292C311562A846505DC82DB854338AE49F5235C95B91178CCF2DD5CACEF403EC9D1810C6272B045B3B71F9DC6B80D63FDD4A8E9ADB1E6962A69526D43161C1A41D570D7938DAD4A40E329CCFF46AAA36AD004CF600C8381E425A31D951AE64FDB23FCEC9509D43687FEB69EDD1CC5E0B8CC3BDF64B10EF86B63142A3AB8829555B2F747C932665CB2C0F1CC01BD70229388839D2AF05E454504AC78B7582822846C0BA35C35F5C59160CC046FD8251541FC68C9C86B022BB7099876A460E7451A8A93109703FEE1C217E6C3826E52C51AA691E0E423CFC99E9E31650C1217B624816CDAD9A95F9D5B8019488D9C0A0A1FE3075A577E23183F81D4A3F2FA4571EFC8CE0BA8A4FE8B6855DFE72B0A66EDED2FBABFBE58A30FAFABE1C5D71A87E2F741EF8C1FE86FEA6BBFDE530677F0D97D11D49F7A8443D0822E506A9F4614E011E2A94838FF88CD68C8BB7C5C6424CFFFFFFFFFFFFFFFF+ )+ ] -data CurveDH = forall c . (EllipticCurveDH c, NFData (Scalar c), NFData (Point c)) => CurveDH c+data CurveDH+ = forall c. (EllipticCurveDH c, NFData (Scalar c), NFData (Point c)) => CurveDH c benchECDH = map doECDHBench curves where@@ -277,32 +323,38 @@ in env (generate proxy) $ bench name . nf (run proxy) generate proxy = do- KeyPair _ aScalar <- curveGenerateKeyPair proxy- KeyPair bPoint _ <- curveGenerateKeyPair proxy+ KeyPair _ aScalar <- curveGenerateKeyPair proxy+ KeyPair bPoint _ <- curveGenerateKeyPair proxy return (aScalar, bPoint) run proxy (s, p) = throwCryptoError (ecdh proxy s p) - curves = [ ("P256R1", CurveDH Curve_P256R1)- , ("P384R1", CurveDH Curve_P384R1)- , ("P521R1", CurveDH Curve_P521R1)- , ("X25519", CurveDH Curve_X25519)- , ("X448", CurveDH Curve_X448)- ]+ curves =+ [ ("P256R1", CurveDH Curve_P256R1)+ , ("P384R1", CurveDH Curve_P384R1)+ , ("P521R1", CurveDH Curve_P521R1)+ , ("X25519", CurveDH Curve_X25519)+ , ("X448", CurveDH Curve_X448)+ ] -data CurveHashECDSA =- forall curve hashAlg . (ECDSA.EllipticCurveECDSA curve,- NFData (Scalar curve),- NFData (Point curve),- HashAlgorithm hashAlg) => CurveHashECDSA curve hashAlg+data CurveHashECDSA+ = forall curve hashAlg.+ ( ECDSA.EllipticCurveECDSA curve+ , NFData (Scalar curve)+ , NFData (Point curve)+ , HashAlgorithm hashAlg+ ) =>+ CurveHashECDSA curve hashAlg benchECDSA = map doECDSABench curveHashes where doECDSABench (name, CurveHashECDSA c hashAlg) = let proxy = Just c -- using Maybe as Proxy- in bgroup name+ in bgroup+ name [ env (signGenerate proxy) $ bench "sign" . nfIO . signRun proxy hashAlg- , env (verifyGenerate proxy hashAlg) $ bench "verify" . nf (verifyRun proxy hashAlg)+ , env (verifyGenerate proxy hashAlg) $+ bench "verify" . nf (verifyRun proxy hashAlg) ] signGenerate proxy = do@@ -323,29 +375,29 @@ tenKB :: IO Bytes tenKB = getRandomBytes 10240 - curveHashes = [ ("secp256r1_sha256", CurveHashECDSA Curve_P256R1 SHA256)- , ("secp384r1_sha384", CurveHashECDSA Curve_P384R1 SHA384)- , ("secp521r1_sha512", CurveHashECDSA Curve_P521R1 SHA512)- ]+ curveHashes =+ [ ("secp256r1_sha256", CurveHashECDSA Curve_P256R1 SHA256)+ , ("secp384r1_sha384", CurveHashECDSA Curve_P384R1 SHA384)+ , ("secp521r1_sha512", CurveHashECDSA Curve_P521R1 SHA512)+ ] benchEdDSA = [ bgroup "EdDSA-Ed25519" benchGenEd25519- , bgroup "Ed25519" benchEd25519+ , bgroup "Ed25519" benchEd25519 ] where benchGen prx alg =- [ bench "sign" $ perBatchEnv (genEnv prx alg) (run_gen_sign prx)+ [ bench "sign" $ perBatchEnv (genEnv prx alg) (run_gen_sign prx) , bench "verify" $ perBatchEnv (genEnv prx alg) (run_gen_verify prx) ] benchGenEd25519 = benchGen (Just Curve_Edwards25519) SHA512- benchEd25519 =- [ bench "sign" $ perBatchEnv ed25519Env run_ed25519_sign+ benchEd25519 =+ [ bench "sign" $ perBatchEnv ed25519Env run_ed25519_sign , bench "verify" $ perBatchEnv ed25519Env run_ed25519_verify ] msg = B.empty -- empty message = worst-case scenario showing API overhead- genEnv prx alg _ = do sec <- EdDSA.generateSecretKey prx let pub = EdDSA.toPublic prx alg sec@@ -366,19 +418,21 @@ run_ed25519_verify (_, pub, sig) = return (Ed25519.verify pub msg sig) -main = defaultMain- [ bgroup "hash" benchHash- , bgroup "block-cipher" benchBlockCipher- , bgroup "AE" benchAE- , bgroup "pbkdf2" benchPBKDF2- , bgroup "bcrypt" benchBCrypt- , bgroup "ECC" benchECC- , bgroup "P256" benchP256- , bgroup "DH"- [ bgroup "FFDH" benchFFDH- , bgroup "ECDH" benchECDH- ]- , bgroup "ECDSA" benchECDSA- , bgroup "EdDSA" benchEdDSA- , bgroup "F2m" benchF2m- ]+main =+ defaultMain+ [ bgroup "hash" benchHash+ , bgroup "block-cipher" benchBlockCipher+ , bgroup "AE" benchAE+ , bgroup "pbkdf2" benchPBKDF2+ , bgroup "bcrypt" benchBCrypt+ , bgroup "ECC" benchECC+ , bgroup "P256" benchP256+ , bgroup+ "DH"+ [ bgroup "FFDH" benchFFDH+ , bgroup "ECDH" benchECDH+ ]+ , bgroup "ECDSA" benchECDSA+ , bgroup "EdDSA" benchEdDSA+ , bgroup "F2m" benchF2m+ ]
benchs/Number/F2m.hs view
@@ -9,13 +9,13 @@ import Crypto.Number.F2m genInteger :: Int -> Int -> Integer-genInteger salt bits- = head- . dropWhile ((< bits) . log2)- . scanl (\a r -> a * 2^(31 :: Int) + abs r) 0- . randoms- . mkStdGen- $ salt + bits+genInteger salt bits =+ head+ . dropWhile ((< bits) . log2)+ . scanl (\a r -> a * 2 ^ (31 :: Int) + abs r) 0+ . randoms+ . mkStdGen+ $ salt + bits benchMod :: Int -> Benchmark benchMod bits = bench (show bits) $ nf (modF2m m) a@@ -46,8 +46,8 @@ bitsList = [64, 128, 256, 512, 1024, 2048] benchF2m =- [ bgroup "modF2m" $ map benchMod bitsList- , bgroup "mulF2m" $ map benchMul bitsList+ [ bgroup "modF2m" $ map benchMod bitsList+ , bgroup "mulF2m" $ map benchMul bitsList , bgroup "squareF2m" $ map benchSquare bitsList- , bgroup "invF2m" $ map benchInv bitsList+ , bgroup "invF2m" $ map benchInv bitsList ]
crypton.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: crypton-version: 1.0.1+version: 1.0.2 license: BSD3 license-file: LICENSE copyright: Vincent Hanquez <vincent@snarc.org>@@ -276,6 +276,7 @@ Crypto.Random.Entropy.Source Crypto.Random.Entropy.Backend Crypto.Random.ChaChaDRG+ Crypto.Random.HmacDRG Crypto.Random.SystemDRG Crypto.Random.Probabilistic Crypto.PubKey.Internal@@ -299,17 +300,12 @@ ghc-options: -Wall -fwarn-tabs -optc-O3 build-depends:+ base >=4.13 && <5, bytestring, memory >=0.14.18, basement >=0.0.6, ghc-prim - if impl(ghc <8.8)- buildable: False-- else- build-depends: base- if flag(old_toolchain_inliner) cc-options: -fgnu89-inline @@ -500,7 +496,7 @@ -Wall -fno-warn-orphans -fno-warn-missing-signatures -rtsopts build-depends:- base >=0 && <10,+ base >=4.13 && <5, bytestring, memory, tasty,@@ -517,7 +513,7 @@ default-language: Haskell2010 ghc-options: -Wall -fno-warn-missing-signatures build-depends:- base,+ base >=4.13 && <5, bytestring, deepseq, memory,
tests/BCrypt.hs view
@@ -1,8 +1,8 @@ {-# LANGUAGE OverloadedStrings #-} -module BCrypt- ( tests- )+module BCrypt (+ tests,+) where import Crypto.KDF.BCrypt@@ -15,37 +15,45 @@ [ ("$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW", "U*U") , ("$2a$05$CCCCCCCCCCCCCCCCCCCCC.VGOzA784oUp/Z0DY336zx7pLYAy0lwK", "U*U*") , ("$2a$05$XXXXXXXXXXXXXXXXXXXXXOAcXxm9kjPGEMsLznoKqmqw7tc8WCx4a", "U*U*U")- , ("$2a$05$abcdefghijklmnopqrstuu5s2v8.iXieOjg/.AySBTTZIIVFJeBui",- "0123456789abcdefghijklmnopqrstuvwxyz\- \ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\- \chars after 72 are ignored")+ ,+ ( "$2a$05$abcdefghijklmnopqrstuu5s2v8.iXieOjg/.AySBTTZIIVFJeBui"+ , "0123456789abcdefghijklmnopqrstuvwxyz\+ \ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\+ \chars after 72 are ignored"+ ) , ("$2y$05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e", "\xff\xff\xa3") , ("$2b$05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e", "\xff\xff\xa3") , ("$2y$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq", "\xa3") , ("$2a$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq", "\xa3") , ("$2b$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq", "\xa3")- , ("$2a$05$/OK.fbVrR/bpIqNJ5ianF.swQOIzjOiJ9GHEPuhEkvqrUyvWhEMx6",- "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\- \\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\- \\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\- \\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\- \\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\- \\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\- \chars after 72 are ignored as usual")- , ("$2a$05$/OK.fbVrR/bpIqNJ5ianF.R9xrDjiycxMbQE2bp.vgqlYpW5wx2yy",- "\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\- \\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\- \\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\- \\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\- \\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\- \\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55")- , ("$2a$05$/OK.fbVrR/bpIqNJ5ianF.9tQZzcJfm3uj2NvJ/n5xkhpqLrMpWCe",- "\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\- \\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\- \\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\- \\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\- \\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\- \\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff")+ ,+ ( "$2a$05$/OK.fbVrR/bpIqNJ5ianF.swQOIzjOiJ9GHEPuhEkvqrUyvWhEMx6"+ , "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\+ \\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\+ \\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\+ \\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\+ \\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\+ \\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\+ \chars after 72 are ignored as usual"+ )+ ,+ ( "$2a$05$/OK.fbVrR/bpIqNJ5ianF.R9xrDjiycxMbQE2bp.vgqlYpW5wx2yy"+ , "\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\+ \\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\+ \\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\+ \\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\+ \\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\+ \\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55\xaa\x55"+ )+ ,+ ( "$2a$05$/OK.fbVrR/bpIqNJ5ianF.9tQZzcJfm3uj2NvJ/n5xkhpqLrMpWCe"+ , "\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\+ \\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\+ \\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\+ \\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\+ \\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\+ \\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff\x55\xaa\xff"+ ) , ("$2a$05$CCCCCCCCCCCCCCCCCCCCC.7uG0VCzI2bS7j6ymqJi9CdcdxiRTWNy", "") , ("$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s.", "") , ("$2a$08$HqWuK6/Ng6sg9gQzbLrgb.Tl.ZHfXLhvt/SgVyWhQqgqcZ7ZuUtye", "")@@ -57,26 +65,47 @@ , ("$2a$06$If6bvum7DFjUnE9p2uDeDu0YHzrHM6tf.iqN8.yx.jNN1ILEf7h0i", "abc") , ("$2a$08$Ro0CUfOqk6cXEKf3dyaM7OhSCvnwM9s4wIX9JeLapehKK5YdLxKcm", "abc") , ("$2a$10$WvvTPHKwdBJ3uk0Z37EMR.hLA2W6N9AEBhEgrAOljy2Ae5MtaSIUi", "abc")- , ("$2a$06$.rCVZVOThsIa97pEDOxvGuRRgzG64bvtJ0938xuqzv18d3ZpQhstC", "abcdefghijklmnopqrstuvwxyz")+ ,+ ( "$2a$06$.rCVZVOThsIa97pEDOxvGuRRgzG64bvtJ0938xuqzv18d3ZpQhstC"+ , "abcdefghijklmnopqrstuvwxyz"+ ) ] makeKATs = concatMap maketest (zip3 is passwords hashes) where is :: [Int]- is = [1..]+ is = [1 ..] passwords = map snd expected- hashes = map fst expected+ hashes = map fst expected maketest (i, password, hash) = [ testCase (show i) (assertBool "" (validatePassword password hash)) ] -tests = testGroup "bcrypt"- [ testGroup "KATs" makeKATs- , testCase "Invalid hash length" (assertEqual "" (Left "Invalid hash format") (validatePasswordEither B.empty ("$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s" :: B.ByteString)))- , testCase "Hash and validate" (assertBool "Hashed password should validate" (validatePassword somePassword (bcrypt 5 aSalt somePassword :: B.ByteString)))- ]+tests =+ testGroup+ "bcrypt"+ [ testGroup "KATs" makeKATs+ , testCase+ "Invalid hash length"+ ( assertEqual+ ""+ (Left "Invalid hash format")+ ( validatePasswordEither+ B.empty+ ("$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s" :: B.ByteString)+ )+ )+ , testCase+ "Hash and validate"+ ( assertBool+ "Hashed password should validate"+ (validatePassword somePassword (bcrypt 5 aSalt somePassword :: B.ByteString))+ )+ ] where somePassword = "some password" :: B.ByteString- aSalt = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" :: B.ByteString+ aSalt =+ "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"+ :: B.ByteString
tests/BCryptPBKDF.hs view
@@ -2,74 +2,211 @@ module BCryptPBKDF (tests) where -import qualified Data.ByteString as B+import qualified Data.ByteString as B -import Test.Tasty-import Test.Tasty.HUnit+import Test.Tasty+import Test.Tasty.HUnit -import Crypto.KDF.BCryptPBKDF (Parameters (..), generate,- hashInternal)+import Crypto.KDF.BCryptPBKDF (+ Parameters (..),+ generate,+ hashInternal,+ ) tests :: TestTree-tests = testGroup "BCryptPBKDF"- [ testGroup "generate"- [ testCase "1" generate1- , testCase "2" generate2- , testCase "3" generate3- ]- , testGroup "hashInternal"- [ testCase "1" hashInternal1+tests =+ testGroup+ "BCryptPBKDF"+ [ testGroup+ "generate"+ [ testCase "1" generate1+ , testCase "2" generate2+ , testCase "3" generate3+ ]+ , testGroup+ "hashInternal"+ [ testCase "1" hashInternal1+ ] ]- ] where -- test vector taken from the go implementation by @dchest generate1 = expected @=? generate params pass salt- where- params = Parameters 12 32- pass = "password" :: B.ByteString- salt = "salt" :: B.ByteString- expected = B.pack- [ 0x1a, 0xe4, 0x2c, 0x05, 0xd4, 0x87, 0xbc, 0x02- , 0xf6, 0x49, 0x21, 0xa4, 0xeb, 0xe4, 0xea, 0x93- , 0xbc, 0xac, 0xfe, 0x13, 0x5f, 0xda, 0x99, 0x97- , 0x4c, 0x06, 0xb7, 0xb0, 0x1f, 0xae, 0x14, 0x9a- ] :: B.ByteString+ where+ params = Parameters 12 32+ pass = "password" :: B.ByteString+ salt = "salt" :: B.ByteString+ expected =+ B.pack+ [ 0x1a+ , 0xe4+ , 0x2c+ , 0x05+ , 0xd4+ , 0x87+ , 0xbc+ , 0x02+ , 0xf6+ , 0x49+ , 0x21+ , 0xa4+ , 0xeb+ , 0xe4+ , 0xea+ , 0x93+ , 0xbc+ , 0xac+ , 0xfe+ , 0x13+ , 0x5f+ , 0xda+ , 0x99+ , 0x97+ , 0x4c+ , 0x06+ , 0xb7+ , 0xb0+ , 0x1f+ , 0xae+ , 0x14+ , 0x9a+ ]+ :: B.ByteString -- test vector generated with the go implemenation by @dchest generate2 = expected @=? generate params pass salt- where- params = Parameters 7 71- pass = "DieWuerdeDesMenschenIstUnantastbar" :: B.ByteString- salt = "Tafelsalz" :: B.ByteString- expected = B.pack- [ 0x17, 0xb4, 0x76, 0xaa, 0xd7, 0x42, 0x33, 0x49- , 0x5c, 0xe8, 0x79, 0x49, 0x15, 0x74, 0x4c, 0x71- , 0xf9, 0x99, 0x66, 0x89, 0x7a, 0x60, 0xc3, 0x70- , 0xb4, 0x3c, 0xa8, 0x83, 0x80, 0x5a, 0x56, 0xde- , 0x38, 0xbc, 0x51, 0x8c, 0xd4, 0xeb, 0xd1, 0xcf- , 0x46, 0x0a, 0x68, 0x3d, 0xc8, 0x12, 0xcf, 0xf8- , 0x43, 0xce, 0x21, 0x9d, 0x98, 0x81, 0x20, 0x26- , 0x6e, 0x42, 0x0f, 0xaa, 0x75, 0x5d, 0x09, 0x8d- , 0x45, 0xda, 0xd5, 0x15, 0x6e, 0x65, 0x1d- ] :: B.ByteString+ where+ params = Parameters 7 71+ pass = "DieWuerdeDesMenschenIstUnantastbar" :: B.ByteString+ salt = "Tafelsalz" :: B.ByteString+ expected =+ B.pack+ [ 0x17+ , 0xb4+ , 0x76+ , 0xaa+ , 0xd7+ , 0x42+ , 0x33+ , 0x49+ , 0x5c+ , 0xe8+ , 0x79+ , 0x49+ , 0x15+ , 0x74+ , 0x4c+ , 0x71+ , 0xf9+ , 0x99+ , 0x66+ , 0x89+ , 0x7a+ , 0x60+ , 0xc3+ , 0x70+ , 0xb4+ , 0x3c+ , 0xa8+ , 0x83+ , 0x80+ , 0x5a+ , 0x56+ , 0xde+ , 0x38+ , 0xbc+ , 0x51+ , 0x8c+ , 0xd4+ , 0xeb+ , 0xd1+ , 0xcf+ , 0x46+ , 0x0a+ , 0x68+ , 0x3d+ , 0xc8+ , 0x12+ , 0xcf+ , 0xf8+ , 0x43+ , 0xce+ , 0x21+ , 0x9d+ , 0x98+ , 0x81+ , 0x20+ , 0x26+ , 0x6e+ , 0x42+ , 0x0f+ , 0xaa+ , 0x75+ , 0x5d+ , 0x09+ , 0x8d+ , 0x45+ , 0xda+ , 0xd5+ , 0x15+ , 0x6e+ , 0x65+ , 0x1d+ ]+ :: B.ByteString -- test vector generated with the go implemenation by @dchest generate3 = expected @=? generate params pass salt- where- params = Parameters 5 5- pass = "ABC" :: B.ByteString- salt = "DEF" :: B.ByteString- expected = B.pack- [ 0xdd, 0x6e, 0xa0, 0x69, 0x29- ] :: B.ByteString+ where+ params = Parameters 5 5+ pass = "ABC" :: B.ByteString+ salt = "DEF" :: B.ByteString+ expected =+ B.pack+ [ 0xdd+ , 0x6e+ , 0xa0+ , 0x69+ , 0x29+ ]+ :: B.ByteString hashInternal1 = expected @=? hashInternal passHash saltHash- where- passHash = B.pack [ 0 .. 63 ] :: B.ByteString- saltHash = B.pack [ 64 .. 127 ] :: B.ByteString- expected = B.pack- [ 0x87, 0x90, 0x48, 0x70, 0xee, 0xf9, 0xde, 0xdd- , 0xf8, 0xe7, 0x61, 0x1a, 0x14, 0x01, 0x06, 0xe6- , 0xaa, 0xf1, 0xa3, 0x63, 0xd9, 0xa2, 0xc5, 0x04- , 0xdb, 0x35, 0x64, 0x43, 0x72, 0x1e, 0xb5, 0x55- ] :: B.ByteString+ where+ passHash = B.pack [0 .. 63] :: B.ByteString+ saltHash = B.pack [64 .. 127] :: B.ByteString+ expected =+ B.pack+ [ 0x87+ , 0x90+ , 0x48+ , 0x70+ , 0xee+ , 0xf9+ , 0xde+ , 0xdd+ , 0xf8+ , 0xe7+ , 0x61+ , 0x1a+ , 0x14+ , 0x01+ , 0x06+ , 0xe6+ , 0xaa+ , 0xf1+ , 0xa3+ , 0x63+ , 0xd9+ , 0xa2+ , 0xc5+ , 0x04+ , 0xdb+ , 0x35+ , 0x64+ , 0x43+ , 0x72+ , 0x1e+ , 0xb5+ , 0x55+ ]+ :: B.ByteString
tests/BlockCipher.hs view
@@ -1,24 +1,25 @@ {-# LANGUAGE ViewPatterns #-}-module BlockCipher- ( KAT_ECB(..)- , KAT_CBC(..)- , KAT_CFB(..)- , KAT_CTR(..)- , KAT_XTS(..)- , KAT_AEAD(..)- , KATs(..)- , defaultKATs- , testBlockCipher- , CipherInfo- ) where -import Imports-import Data.Maybe-import Crypto.Error-import Crypto.Cipher.Types-import Data.ByteArray as B hiding (pack, null, length)-import qualified Data.ByteString as B hiding (all, take, replicate)+module BlockCipher (+ KAT_ECB (..),+ KAT_CBC (..),+ KAT_CFB (..),+ KAT_CTR (..),+ KAT_XTS (..),+ KAT_AEAD (..),+ KATs (..),+ defaultKATs,+ testBlockCipher,+ CipherInfo,+) where +import Crypto.Cipher.Types+import Crypto.Error+import Data.ByteArray as B hiding (length, null, pack)+import qualified Data.ByteString as B hiding (all, replicate, take)+import Data.Maybe+import Imports+ ------------------------------------------------------------------------ -- KAT ------------------------------------------------------------------------@@ -32,66 +33,100 @@ -- | ECB KAT data KAT_ECB = KAT_ECB- { ecbKey :: ByteString -- ^ Key- , ecbPlaintext :: ByteString -- ^ Plaintext- , ecbCiphertext :: ByteString -- ^ Ciphertext- } deriving (Show,Eq)+ { ecbKey :: ByteString+ -- ^ Key+ , ecbPlaintext :: ByteString+ -- ^ Plaintext+ , ecbCiphertext :: ByteString+ -- ^ Ciphertext+ }+ deriving (Show, Eq) -- | CBC KAT data KAT_CBC = KAT_CBC- { cbcKey :: ByteString -- ^ Key- , cbcIV :: ByteString -- ^ IV- , cbcPlaintext :: ByteString -- ^ Plaintext- , cbcCiphertext :: ByteString -- ^ Ciphertext- } deriving (Show,Eq)+ { cbcKey :: ByteString+ -- ^ Key+ , cbcIV :: ByteString+ -- ^ IV+ , cbcPlaintext :: ByteString+ -- ^ Plaintext+ , 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)+ { 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- , ctrIV :: ByteString -- ^ IV (usually represented as a 128 bits integer)- , ctrPlaintext :: ByteString -- ^ Plaintext- , ctrCiphertext :: ByteString -- ^ Ciphertext- } deriving (Show,Eq)+ { ctrKey :: ByteString+ -- ^ Key+ , ctrIV :: ByteString+ -- ^ IV (usually represented as a 128 bits integer)+ , ctrPlaintext :: ByteString+ -- ^ Plaintext+ , ctrCiphertext :: ByteString+ -- ^ Ciphertext+ }+ deriving (Show, Eq) -- | XTS KAT data KAT_XTS = KAT_XTS- { xtsKey1 :: ByteString -- ^ 1st XTS key- , xtsKey2 :: ByteString -- ^ 2nd XTS key- , xtsIV :: ByteString -- ^ XTS IV- , xtsPlaintext :: ByteString -- ^ plaintext- , xtsCiphertext :: ByteString -- ^ Ciphertext- } deriving (Show,Eq)+ { xtsKey1 :: ByteString+ -- ^ 1st XTS key+ , xtsKey2 :: ByteString+ -- ^ 2nd XTS key+ , xtsIV :: ByteString+ -- ^ XTS IV+ , xtsPlaintext :: ByteString+ -- ^ plaintext+ , xtsCiphertext :: ByteString+ -- ^ Ciphertext+ }+ deriving (Show, Eq) -- | AEAD KAT data KAT_AEAD = KAT_AEAD- { aeadMode :: AEADMode- , aeadKey :: ByteString -- ^ Key- , aeadIV :: ByteString -- ^ IV for initialization- , aeadHeader :: ByteString -- ^ Authenticated Header- , aeadPlaintext :: ByteString -- ^ Plaintext- , aeadCiphertext :: ByteString -- ^ Ciphertext- , aeadTaglen :: Int -- ^ aead tag len- , aeadTag :: ByteString -- ^ expected tag- } deriving (Show,Eq)+ { aeadMode :: AEADMode+ , aeadKey :: ByteString+ -- ^ Key+ , aeadIV :: ByteString+ -- ^ IV for initialization+ , aeadHeader :: ByteString+ -- ^ Authenticated Header+ , aeadPlaintext :: ByteString+ -- ^ Plaintext+ , aeadCiphertext :: ByteString+ -- ^ Ciphertext+ , aeadTaglen :: Int+ -- ^ aead tag len+ , aeadTag :: ByteString+ -- ^ expected tag+ }+ deriving (Show, Eq) -- | all the KATs. use defaultKATs to prevent compilation error -- from future expansion of this data structure data KATs = KATs- { kat_ECB :: [KAT_ECB]- , kat_CBC :: [KAT_CBC]- , kat_CFB :: [KAT_CFB]- , kat_CTR :: [KAT_CTR]- , kat_XTS :: [KAT_XTS]+ { kat_ECB :: [KAT_ECB]+ , kat_CBC :: [KAT_CBC]+ , kat_CFB :: [KAT_CFB]+ , kat_CTR :: [KAT_CTR]+ , kat_XTS :: [KAT_XTS] , kat_AEAD :: [KAT_AEAD]- } deriving (Show,Eq)+ }+ deriving (Show, Eq) defaultKATs = KATs [] [] [] [] [] [] @@ -151,90 +186,102 @@ dtag = aeadFinalize aeadDFinal (aeadTaglen d) -} -testKATs :: BlockCipher cipher- => KATs- -> cipher- -> TestTree-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)- )- where makeECBTest i d =- [ testCase ("E" ++ i) (ecbEncrypt ctx (ecbPlaintext d) @?= ecbCiphertext d)- , testCase ("D" ++ i) (ecbDecrypt ctx (ecbCiphertext d) @?= ecbPlaintext d)- ]- where ctx = cipherInitNoErr (cipherMakeKey cipher $ ecbKey d)- makeCBCTest i d =- [ testCase ("E" ++ i) (cbcEncrypt ctx iv (cbcPlaintext d) @?= cbcCiphertext d)- , testCase ("D" ++ i) (cbcDecrypt ctx iv (cbcCiphertext d) @?= cbcPlaintext d)- ]- where ctx = cipherInitNoErr (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 = cipherInitNoErr (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)- ]- where ctx = cipherInitNoErr (cipherMakeKey cipher $ ctrKey d)- iv = cipherMakeIV cipher $ ctrIV d-{-- makeXTSTest i d =- [ testCase ("E" ++ i) (xtsEncrypt ctx iv 0 (xtsPlaintext d) @?= xtsCiphertext d)- , testCase ("D" ++ i) (xtsDecrypt ctx iv 0 (xtsCiphertext d) @?= xtsPlaintext d)- ]- where ctx1 = cipherInitNoErr (cipherMakeKey cipher $ xtsKey1 d)- ctx2 = cipherInitNoErr (cipherMakeKey cipher $ xtsKey2 d)- ctx = (ctx1, ctx2)- iv = cipherMakeIV cipher $ xtsIV d--}- makeAEADTest i d =- [ testCase ("AE" ++ i) (etag @?= AuthTag (B.convert (aeadTag d)))- , testCase ("AD" ++ i) (dtag @?= AuthTag (B.convert (aeadTag d)))- , testCase ("E" ++ i) (ebs @?= aeadCiphertext d)- , testCase ("D" ++ i) (dbs @?= aeadPlaintext d)- ]- where ctx = cipherInitNoErr (cipherMakeKey cipher $ aeadKey d)- aead = aeadInitNoErr (aeadMode d) ctx (aeadIV d)- aeadHeaded = aeadAppendHeader aead (aeadHeader d)- (ebs,aeadEFinal) = aeadEncrypt aeadHeaded (aeadPlaintext d)- (dbs,aeadDFinal) = aeadDecrypt aeadHeaded (aeadCiphertext d)- etag = aeadFinalize aeadEFinal (aeadTaglen d)- dtag = aeadFinalize aeadDFinal (aeadTaglen d)+testKATs+ :: BlockCipher cipher+ => KATs+ -> cipher+ -> TestTree+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)+ )+ where+ makeECBTest i d =+ [ testCase ("E" ++ i) (ecbEncrypt ctx (ecbPlaintext d) @?= ecbCiphertext d)+ , testCase ("D" ++ i) (ecbDecrypt ctx (ecbCiphertext d) @?= ecbPlaintext d)+ ]+ where+ ctx = cipherInitNoErr (cipherMakeKey cipher $ ecbKey d)+ makeCBCTest i d =+ [ testCase ("E" ++ i) (cbcEncrypt ctx iv (cbcPlaintext d) @?= cbcCiphertext d)+ , testCase ("D" ++ i) (cbcDecrypt ctx iv (cbcCiphertext d) @?= cbcPlaintext d)+ ]+ where+ ctx = cipherInitNoErr (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 = cipherInitNoErr (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)+ ]+ where+ ctx = cipherInitNoErr (cipherMakeKey cipher $ ctrKey d)+ iv = cipherMakeIV cipher $ ctrIV d+ {-+ makeXTSTest i d =+ [ testCase ("E" ++ i) (xtsEncrypt ctx iv 0 (xtsPlaintext d) @?= xtsCiphertext d)+ , testCase ("D" ++ i) (xtsDecrypt ctx iv 0 (xtsCiphertext d) @?= xtsPlaintext d)+ ]+ where ctx1 = cipherInitNoErr (cipherMakeKey cipher $ xtsKey1 d)+ ctx2 = cipherInitNoErr (cipherMakeKey cipher $ xtsKey2 d)+ ctx = (ctx1, ctx2)+ iv = cipherMakeIV cipher $ xtsIV d+ -}+ makeAEADTest i d =+ [ testCase ("AE" ++ i) (etag @?= AuthTag (B.convert (aeadTag d)))+ , testCase ("AD" ++ i) (dtag @?= AuthTag (B.convert (aeadTag d)))+ , testCase ("E" ++ i) (ebs @?= aeadCiphertext d)+ , testCase ("D" ++ i) (dbs @?= aeadPlaintext d)+ ]+ where+ ctx = cipherInitNoErr (cipherMakeKey cipher $ aeadKey d)+ aead = aeadInitNoErr (aeadMode d) ctx (aeadIV d)+ aeadHeaded = aeadAppendHeader aead (aeadHeader d)+ (ebs, aeadEFinal) = aeadEncrypt aeadHeaded (aeadPlaintext d)+ (dbs, aeadDFinal) = aeadDecrypt aeadHeaded (aeadCiphertext d)+ etag = aeadFinalize aeadEFinal (aeadTaglen d)+ dtag = aeadFinalize aeadDFinal (aeadTaglen d) - cipherInitNoErr :: BlockCipher c => Key c -> c- cipherInitNoErr (Key k) =- case cipherInit k of- CryptoPassed a -> a- CryptoFailed e -> error (show e)+ cipherInitNoErr :: BlockCipher c => Key c -> c+ cipherInitNoErr (Key k) =+ case cipherInit k of+ CryptoPassed a -> a+ CryptoFailed e -> error (show e) - aeadInitNoErr :: (ByteArrayAccess iv, BlockCipher cipher) => AEADMode -> cipher -> iv -> AEAD cipher- aeadInitNoErr mode ct iv =- case aeadInit mode ct iv of- CryptoPassed a -> a- CryptoFailed _ -> error $ "cipher doesn't support aead mode: " ++ show mode+ aeadInitNoErr+ :: (ByteArrayAccess iv, BlockCipher cipher)+ => AEADMode -> cipher -> iv -> AEAD cipher+ aeadInitNoErr mode ct iv =+ case aeadInit mode ct iv of+ CryptoPassed a -> a+ CryptoFailed _ -> error $ "cipher doesn't support aead mode: " ++ show mode+ ------------------------------------------------------------------------ -- Properties ------------------------------------------------------------------------ -- | any sized bytestring-newtype Plaintext a = Plaintext { unPlaintext :: B.ByteString }- deriving (Show,Eq)+newtype Plaintext a = Plaintext {unPlaintext :: B.ByteString}+ deriving (Show, Eq) -- | A multiple of blocksize bytestring-newtype PlaintextBS a = PlaintextBS { unPlaintextBS :: B.ByteString }- deriving (Show,Eq)+newtype PlaintextBS a = PlaintextBS {unPlaintextBS :: B.ByteString}+ deriving (Show, Eq) newtype Key a = Key ByteString- deriving (Show,Eq)+ deriving (Show, Eq) -- | a ECB unit test data ECBUnit a = ECBUnit (Key a) (PlaintextBS a)@@ -279,116 +326,159 @@ instance Show (CTRUnit a) where show (CTRUnit key iv b) = "CTR(key=" ++ show key ++ ",iv=" ++ show iv ++ ",input=" ++ show b ++ ")" instance Show (XTSUnit a) where- show (XTSUnit key1 key2 iv b) = "XTS(key1=" ++ show key1 ++ ",key2=" ++ show key2 ++ ",iv=" ++ show iv ++ ",input=" ++ show b ++ ")"+ show (XTSUnit key1 key2 iv b) =+ "XTS(key1="+ ++ show key1+ ++ ",key2="+ ++ show key2+ ++ ",iv="+ ++ show iv+ ++ ",input="+ ++ show b+ ++ ")" instance Show (AEADUnit a) where- show (AEADUnit key iv aad b) = "AEAD(key=" ++ show key ++ ",iv=" ++ show iv ++ ",aad=" ++ show (unPlaintext aad) ++ ",input=" ++ show b ++ ")"+ show (AEADUnit key iv aad b) =+ "AEAD(key="+ ++ show key+ ++ ",iv="+ ++ show iv+ ++ ",aad="+ ++ show (unPlaintext aad)+ ++ ",input="+ ++ show b+ ++ ")" instance Show (StreamUnit a) where show (StreamUnit key b) = "Stream(key=" ++ show key ++ ",input=" ++ show b ++ ")" -- | Generate an arbitrary valid key for a specific block cipher generateKey :: Cipher a => Gen (Key a) generateKey = keyFromCipher undefined- where keyFromCipher :: Cipher a => a -> Gen (Key a)- keyFromCipher cipher = do- sz <- case cipherKeySize cipher of- KeySizeRange low high -> choose (low, high)- KeySizeFixed v -> return v- KeySizeEnum l -> elements l- Key . B.pack <$> replicateM sz arbitrary+ where+ keyFromCipher :: Cipher a => a -> Gen (Key a)+ keyFromCipher cipher = do+ sz <- case cipherKeySize cipher of+ KeySizeRange low high -> choose (low, high)+ KeySizeFixed v -> return v+ KeySizeEnum l -> elements l+ Key . B.pack <$> replicateM sz arbitrary -- | Generate an arbitrary valid IV for a specific block cipher generateIv :: BlockCipher a => Gen (IV a) generateIv = ivFromCipher undefined- where ivFromCipher :: BlockCipher a => a -> Gen (IV a)- ivFromCipher cipher = fromJust . makeIV . B.pack <$> replicateM (blockSize cipher) arbitrary+ where+ ivFromCipher :: BlockCipher a => a -> Gen (IV a)+ ivFromCipher cipher = fromJust . makeIV . B.pack <$> replicateM (blockSize cipher) arbitrary -- | Generate an arbitrary valid IV for AEAD for a specific block cipher generateIvAEAD :: Gen B.ByteString-generateIvAEAD = choose (12,90) >>= \sz -> (B.pack <$> replicateM sz arbitrary)+generateIvAEAD = choose (12, 90) >>= \sz -> (B.pack <$> replicateM sz arbitrary) -- | Generate a plaintext multiple of blocksize bytes generatePlaintextMultipleBS :: BlockCipher a => Gen (PlaintextBS a)-generatePlaintextMultipleBS = choose (1,128) >>= \size -> replicateM (size * 16) arbitrary >>= return . PlaintextBS . B.pack+generatePlaintextMultipleBS =+ choose (1, 128) >>= \size -> replicateM (size * 16) arbitrary >>= return . PlaintextBS . B.pack -- | Generate any sized plaintext generatePlaintext :: Gen (Plaintext a)-generatePlaintext = choose (0,324) >>= \size -> replicateM size arbitrary >>= return . Plaintext . B.pack+generatePlaintext =+ choose (0, 324) >>= \size -> replicateM size arbitrary >>= return . Plaintext . B.pack instance BlockCipher a => Arbitrary (ECBUnit a) where- arbitrary = ECBUnit <$> generateKey- <*> generatePlaintextMultipleBS+ arbitrary =+ ECBUnit+ <$> generateKey+ <*> generatePlaintextMultipleBS instance BlockCipher a => Arbitrary (CBCUnit a) where- arbitrary = CBCUnit <$> generateKey- <*> generateIv- <*> generatePlaintextMultipleBS+ arbitrary =+ CBCUnit+ <$> generateKey+ <*> generateIv+ <*> generatePlaintextMultipleBS instance BlockCipher a => Arbitrary (CFBUnit a) where- arbitrary = CFBUnit <$> generateKey- <*> generateIv- <*> generatePlaintextMultipleBS+ arbitrary =+ CFBUnit+ <$> generateKey+ <*> generateIv+ <*> generatePlaintextMultipleBS instance BlockCipher a => Arbitrary (CFB8Unit a) where arbitrary = CFB8Unit <$> generateKey <*> generateIv <*> generatePlaintext instance BlockCipher a => Arbitrary (CTRUnit a) where- arbitrary = CTRUnit <$> generateKey- <*> generateIv- <*> generatePlaintext+ arbitrary =+ CTRUnit+ <$> generateKey+ <*> generateIv+ <*> generatePlaintext instance BlockCipher a => Arbitrary (XTSUnit a) where- arbitrary = XTSUnit <$> generateKey- <*> generateKey- <*> generateIv- <*> generatePlaintextMultipleBS+ arbitrary =+ XTSUnit+ <$> generateKey+ <*> generateKey+ <*> generateIv+ <*> generatePlaintextMultipleBS instance BlockCipher a => Arbitrary (AEADUnit a) where- arbitrary = AEADUnit <$> generateKey- <*> generateIvAEAD- <*> generatePlaintext- <*> generatePlaintext+ arbitrary =+ AEADUnit+ <$> generateKey+ <*> generateIvAEAD+ <*> generatePlaintext+ <*> generatePlaintext instance StreamCipher a => Arbitrary (StreamUnit a) where- arbitrary = StreamUnit <$> generateKey- <*> generatePlaintext+ arbitrary =+ StreamUnit+ <$> generateKey+ <*> generatePlaintext testBlockCipherBasic :: BlockCipher a => a -> [TestTree]-testBlockCipherBasic cipher = [ testProperty "ECB" ecbProp ]- where ecbProp = toTests cipher- toTests :: BlockCipher a => a -> (ECBUnit a -> Bool)- toTests _ = testProperty_ECB- testProperty_ECB (ECBUnit key (unPlaintextBS -> plaintext)) = withCtx key $ \ctx ->- plaintext `assertEq` ecbDecrypt ctx (ecbEncrypt ctx plaintext)+testBlockCipherBasic cipher = [testProperty "ECB" ecbProp]+ where+ ecbProp = toTests cipher+ toTests :: BlockCipher a => a -> (ECBUnit a -> Bool)+ toTests _ = testProperty_ECB+ testProperty_ECB (ECBUnit key (unPlaintextBS -> plaintext)) = withCtx key $ \ctx ->+ plaintext `assertEq` ecbDecrypt ctx (ecbEncrypt ctx plaintext) testBlockCipherModes :: BlockCipher a => a -> [TestTree] testBlockCipherModes cipher = [ testProperty "CBC" cbcProp , testProperty "CFB" cfbProp- --, testProperty "CFB8" cfb8Prop- , testProperty "CTR" ctrProp+ , -- , testProperty "CFB8" cfb8Prop+ testProperty "CTR" ctrProp ]- where (cbcProp,cfbProp,ctrProp) = toTests cipher- toTests :: BlockCipher a- => a- -> ((CBCUnit a -> Bool), (CFBUnit a -> Bool), {-(CFB8Unit a -> Bool),-} (CTRUnit a -> Bool))- toTests _ = (testProperty_CBC- ,testProperty_CFB- --,testProperty_CFB8- ,testProperty_CTR- )- testProperty_CBC (CBCUnit key testIV (unPlaintextBS -> plaintext)) = withCtx key $ \ctx ->- plaintext `assertEq` cbcDecrypt ctx testIV (cbcEncrypt ctx testIV plaintext)+ where+ (cbcProp, cfbProp, ctrProp) = toTests cipher+ toTests+ :: BlockCipher a+ => a+ -> ( (CBCUnit a -> Bool)+ , (CFBUnit a -> Bool {-(CFB8Unit a -> Bool),-})+ , (CTRUnit a -> Bool)+ )+ toTests _ =+ ( testProperty_CBC+ , testProperty_CFB+ , -- ,testProperty_CFB8+ testProperty_CTR+ )+ testProperty_CBC (CBCUnit key testIV (unPlaintextBS -> plaintext)) = withCtx key $ \ctx ->+ plaintext `assertEq` cbcDecrypt ctx testIV (cbcEncrypt ctx testIV plaintext) - testProperty_CFB (CFBUnit key testIV (unPlaintextBS -> plaintext)) = withCtx key $ \ctx ->- plaintext `assertEq` cfbDecrypt ctx testIV (cfbEncrypt ctx testIV plaintext)+ testProperty_CFB (CFBUnit key testIV (unPlaintextBS -> plaintext)) = withCtx key $ \ctx ->+ plaintext `assertEq` cfbDecrypt ctx testIV (cfbEncrypt ctx testIV plaintext) -{-- testProperty_CFB8 (CFB8Unit (cipherInit -> ctx) testIV (unPlaintext -> plaintext)) =- plaintext `assertEq` cfb8Decrypt ctx testIV (cfb8Encrypt ctx testIV plaintext)--}+ {-+ testProperty_CFB8 (CFB8Unit (cipherInit -> ctx) testIV (unPlaintext -> plaintext)) =+ plaintext `assertEq` cfb8Decrypt ctx testIV (cfb8Encrypt ctx testIV plaintext)+ -} - testProperty_CTR (CTRUnit key testIV (unPlaintext -> plaintext)) = withCtx key $ \ctx ->- plaintext `assertEq` ctrCombine ctx testIV (ctrCombine ctx testIV plaintext)+ testProperty_CTR (CTRUnit key testIV (unPlaintext -> plaintext)) = withCtx key $ \ctx ->+ plaintext `assertEq` ctrCombine ctx testIV (ctrCombine ctx testIV plaintext) testBlockCipherAEAD :: BlockCipher a => a -> [TestTree] testBlockCipherAEAD cipher =@@ -398,30 +488,33 @@ , testProperty "CWC" (aeadProp AEAD_CWC) , testProperty "GCM" (aeadProp AEAD_GCM) ]- where aeadProp = toTests cipher- toTests :: BlockCipher a => a -> (AEADMode -> AEADUnit a -> Bool)- toTests _ = testProperty_AEAD- testProperty_AEAD mode (AEADUnit key testIV (unPlaintext -> aad) (unPlaintext -> plaintext)) = withCtx key $ \ctx ->- case aeadInit mode' ctx iv' of- CryptoPassed iniAead ->- let aead = aeadAppendHeader iniAead aad- (eText, aeadE) = aeadEncrypt aead plaintext- (dText, aeadD) = aeadDecrypt aead eText- eTag = aeadFinalize aeadE (blockSize ctx)- dTag = aeadFinalize aeadD (blockSize ctx)- in (plaintext `assertEq` dText) && (eTag `B.eq` dTag)- CryptoFailed err- | err == CryptoError_AEADModeNotSupported -> True- | otherwise -> error ("testProperty_AEAD: " ++ show err)- where (mode', iv') = updateCcmInputSize mode (B.length plaintext) testIV- updateCcmInputSize aeadmode k iv = case aeadmode of- AEAD_CCM _ m l -> (AEAD_CCM k m l, B.take 13 (iv <> (B.replicate 15 0)))- aeadOther -> (aeadOther, iv)+ where+ aeadProp = toTests cipher+ toTests :: BlockCipher a => a -> (AEADMode -> AEADUnit a -> Bool)+ toTests _ = testProperty_AEAD+ testProperty_AEAD mode (AEADUnit key testIV (unPlaintext -> aad) (unPlaintext -> plaintext)) = withCtx key $ \ctx ->+ case aeadInit mode' ctx iv' of+ CryptoPassed iniAead ->+ let aead = aeadAppendHeader iniAead aad+ (eText, aeadE) = aeadEncrypt aead plaintext+ (dText, aeadD) = aeadDecrypt aead eText+ eTag = aeadFinalize aeadE (blockSize ctx)+ dTag = aeadFinalize aeadD (blockSize ctx)+ in (plaintext `assertEq` dText) && (eTag `B.eq` dTag)+ CryptoFailed err+ | err == CryptoError_AEADModeNotSupported -> True+ | otherwise ->+ error ("testProperty_AEAD: " ++ show err)+ where+ (mode', iv') = updateCcmInputSize mode (B.length plaintext) testIV+ updateCcmInputSize aeadmode k iv = case aeadmode of+ AEAD_CCM _ m l -> (AEAD_CCM k m l, B.take 13 (iv <> (B.replicate 15 0)))+ aeadOther -> (aeadOther, iv) withCtx :: Cipher c => Key c -> (c -> a) -> a withCtx (Key key) f = case cipherInit key of- CryptoFailed e -> error ("init failed: " ++ show e)+ CryptoFailed e -> error ("init failed: " ++ show e) CryptoPassed ctx -> f ctx {-@@ -440,19 +533,23 @@ -- related to block cipher modes. testModes :: BlockCipher a => a -> [TestTree] testModes cipher =- [ testGroup "decrypt.encrypt==id"--- (testBlockCipherBasic cipher ++ testBlockCipherModes cipher ++ testBlockCipherAEAD cipher ++ testBlockCipherXTS cipher)- (testBlockCipherBasic cipher ++ testBlockCipherModes cipher ++ testBlockCipherAEAD cipher)+ [ testGroup+ "decrypt.encrypt==id"+ -- (testBlockCipherBasic cipher ++ testBlockCipherModes cipher ++ testBlockCipherAEAD cipher ++ testBlockCipherXTS cipher)+ ( testBlockCipherBasic cipher+ ++ testBlockCipherModes cipher+ ++ testBlockCipherAEAD cipher+ ) ] -- | Test IV arithmetic (based on the cipher block size) testIvArith :: BlockCipher a => a -> [TestTree] testIvArith cipher = [ testCase "nullIV is null" $- True @=? B.all (== 0) (ivNull cipher)+ True @=? B.all (== 0) (ivNull cipher) , testProperty "ivAdd is linear" $ \a b -> do- iv <- generateIvFromCipher cipher- return $ ivAdd iv (a + b) `propertyEq` ivAdd (ivAdd iv a) b+ iv <- generateIvFromCipher cipher+ return $ ivAdd iv (a + b) `propertyEq` ivAdd (ivAdd iv a) b ] where ivNull :: BlockCipher a => a -> IV a@@ -464,15 +561,18 @@ let n = blockSize c i <- choose (0, n) let zeros = Prelude.replicate (n - i) 0x00- ones = Prelude.replicate i 0xFF+ ones = Prelude.replicate i 0xFF return $ cipherMakeIV c (B.pack $ zeros ++ ones) -- | Return tests for a specific blockcipher and a list of KATs testBlockCipher :: BlockCipher a => KATs -> a -> TestTree-testBlockCipher kats cipher = testGroup (cipherName cipher)- ( (if kats == defaultKATs then [] else [testKATs kats cipher])- ++ testModes cipher ++ testIvArith cipher- )+testBlockCipher kats cipher =+ testGroup+ (cipherName cipher)+ ( (if kats == defaultKATs then [] else [testKATs kats cipher])+ ++ testModes cipher+ ++ testIvArith cipher+ ) cipherMakeKey :: Cipher cipher => cipher -> ByteString -> Key cipher cipherMakeKey _ bs = Key bs@@ -482,7 +582,9 @@ maybeGroup :: (String -> t -> [TestTree]) -> TestName -> [t] -> [TestTree] maybeGroup mkTest groupName l- | null l = []- | otherwise = [testGroup groupName (concatMap (\(i, d) -> mkTest (show i) d) $ zip nbs l)]- where nbs :: [Int]- nbs = [0..]+ | null l = []+ | otherwise =+ [testGroup groupName (concatMap (\(i, d) -> mkTest (show i) d) $ zip nbs l)]+ where+ nbs :: [Int]+ nbs = [0 ..]
tests/ChaCha.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+ module ChaCha (tests) where import qualified Crypto.Cipher.ChaCha as ChaCha@@ -6,7 +7,8 @@ import qualified Data.ByteString as B -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"+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" b12_128_k0_i0 = "\xe1\x04\x7b\xa9\x47\x6b\xf8\xff\x31\x2c\x01\xb4\x34\x5a\x7d\x8c\xa5\x79\x2b\x0a\xd4\x67\x31\x3f\x1d\xc4\x12\xb5\xfd\xce\x32\x41\x0d\xea\x8b\x68\xbd\x77\x4c\x36\xa9\x20\xf0\x92\xa0\x4d\x3f\x95\x27\x4f\xbe\xff\x97\xbc\x84\x91\xfc\xef\x37\xf8\x59\x70\xb4\x50\x1d\x43\xb6\x1a\x8f\x7e\x19\xfc\xed\xde\xf3\x68\xae\x6b\xfb\x11\x10\x1b\xd9\xfd\x3e\x4d\x12\x7d\xe3\x0d\xb2\xdb\x1b\x47\x2e\x76\x42\x68\x03\xa4\x5e\x15\xb9\x62\x75\x19\x86\xef\x1d\x9d\x50\xf5\x98\xa5\xdc\xdc\x9f\xa5\x29\xa2\x83\x57\x99\x1e\x78\x4e\xa2\x0f"@@ -26,78 +28,85 @@ -- XChaCha20 test vector from RFC draft: https://datatracker.ietf.org/doc/html/draft-arciszewski-xchacha xChaCha20_ExampleKAT = expected @=? fst (ChaCha.combine initState plaintext)- where iv = B.pack $ [0x40 .. 0x56] ++ [0x58]- key = B.pack [0x80 .. 0x9f]- initState = ChaCha.initializeX 20 key iv- plaintext :: B.ByteString- plaintext = "The dhole (pronounced \"dole\") is also known as the Asiatic wild dog, red dog, and whistling dog. It is about the size of a German shepherd but looks more like a long-legged fox. This highly elusive and skilled jumper is classified with wolves, coyotes, jackals, and foxes in the taxonomic family Canidae."- expected :: B.ByteString- expected = "\x45\x59\xab\xba\x4e\x48\xc1\x61\x02\xe8\xbb\x2c\x05\xe6\x94\x7f\x50\xa7\x86\xde\x16\x2f\x9b\x0b\x7e\x59\x2a\x9b\x53\xd0\xd4\xe9\x8d\x8d\x64\x10\xd5\x40\xa1\xa6\x37\x5b\x26\xd8\x0d\xac\xe4\xfa\xb5\x23\x84\xc7\x31\xac\xbf\x16\xa5\x92\x3c\x0c\x48\xd3\x57\x5d\x4d\x0d\x2c\x67\x3b\x66\x6f\xaa\x73\x10\x61\x27\x77\x01\x09\x3a\x6b\xf7\xa1\x58\xa8\x86\x42\x92\xa4\x1c\x48\xe3\xa9\xb4\xc0\xda\xec\xe0\xf8\xd9\x8d\x0d\x7e\x05\xb3\x7a\x30\x7b\xbb\x66\x33\x31\x64\xec\x9e\x1b\x24\xea\x0d\x6c\x3f\xfd\xdc\xec\x4f\x68\xe7\x44\x30\x56\x19\x3a\x03\xc8\x10\xe1\x13\x44\xca\x06\xd8\xed\x8a\x2b\xfb\x1e\x8d\x48\xcf\xa6\xbc\x0e\xb4\xe2\x46\x4b\x74\x81\x42\x40\x7c\x9f\x43\x1a\xee\x76\x99\x60\xe1\x5b\xa8\xb9\x68\x90\x46\x6e\xf2\x45\x75\x99\x85\x23\x85\xc6\x61\xf7\x52\xce\x20\xf9\xda\x0c\x09\xab\x6b\x19\xdf\x74\xe7\x6a\x95\x96\x74\x46\xf8\xd0\xfd\x41\x5e\x7b\xee\x2a\x12\xa1\x14\xc2\x0e\xb5\x29\x2a\xe7\xa3\x49\xae\x57\x78\x20\xd5\x52\x0a\x1f\x3f\xb6\x2a\x17\xce\x6a\x7e\x68\xfa\x7c\x79\x11\x1d\x88\x60\x92\x0b\xc0\x48\xef\x43\xfe\x84\x48\x6c\xcb\x87\xc2\x5f\x0a\xe0\x45\xf0\xcc\xe1\xe7\x98\x9a\x9a\xa2\x20\xa2\x8b\xdd\x48\x27\xe7\x51\xa2\x4a\x6d\x5c\x62\xd7\x90\xa6\x63\x93\xb9\x31\x11\xc1\xa5\x5d\xd7\x42\x1a\x10\x18\x49\x74\xc7\xc5"-+ where+ iv = B.pack $ [0x40 .. 0x56] ++ [0x58]+ key = B.pack [0x80 .. 0x9f]+ initState = ChaCha.initializeX 20 key iv+ plaintext :: B.ByteString+ plaintext =+ "The dhole (pronounced \"dole\") is also known as the Asiatic wild dog, red dog, and whistling dog. It is about the size of a German shepherd but looks more like a long-legged fox. This highly elusive and skilled jumper is classified with wolves, coyotes, jackals, and foxes in the taxonomic family Canidae."+ expected :: B.ByteString+ expected =+ "\x45\x59\xab\xba\x4e\x48\xc1\x61\x02\xe8\xbb\x2c\x05\xe6\x94\x7f\x50\xa7\x86\xde\x16\x2f\x9b\x0b\x7e\x59\x2a\x9b\x53\xd0\xd4\xe9\x8d\x8d\x64\x10\xd5\x40\xa1\xa6\x37\x5b\x26\xd8\x0d\xac\xe4\xfa\xb5\x23\x84\xc7\x31\xac\xbf\x16\xa5\x92\x3c\x0c\x48\xd3\x57\x5d\x4d\x0d\x2c\x67\x3b\x66\x6f\xaa\x73\x10\x61\x27\x77\x01\x09\x3a\x6b\xf7\xa1\x58\xa8\x86\x42\x92\xa4\x1c\x48\xe3\xa9\xb4\xc0\xda\xec\xe0\xf8\xd9\x8d\x0d\x7e\x05\xb3\x7a\x30\x7b\xbb\x66\x33\x31\x64\xec\x9e\x1b\x24\xea\x0d\x6c\x3f\xfd\xdc\xec\x4f\x68\xe7\x44\x30\x56\x19\x3a\x03\xc8\x10\xe1\x13\x44\xca\x06\xd8\xed\x8a\x2b\xfb\x1e\x8d\x48\xcf\xa6\xbc\x0e\xb4\xe2\x46\x4b\x74\x81\x42\x40\x7c\x9f\x43\x1a\xee\x76\x99\x60\xe1\x5b\xa8\xb9\x68\x90\x46\x6e\xf2\x45\x75\x99\x85\x23\x85\xc6\x61\xf7\x52\xce\x20\xf9\xda\x0c\x09\xab\x6b\x19\xdf\x74\xe7\x6a\x95\x96\x74\x46\xf8\xd0\xfd\x41\x5e\x7b\xee\x2a\x12\xa1\x14\xc2\x0e\xb5\x29\x2a\xe7\xa3\x49\xae\x57\x78\x20\xd5\x52\x0a\x1f\x3f\xb6\x2a\x17\xce\x6a\x7e\x68\xfa\x7c\x79\x11\x1d\x88\x60\x92\x0b\xc0\x48\xef\x43\xfe\x84\x48\x6c\xcb\x87\xc2\x5f\x0a\xe0\x45\xf0\xcc\xe1\xe7\x98\x9a\x9a\xa2\x20\xa2\x8b\xdd\x48\x27\xe7\x51\xa2\x4a\x6d\x5c\x62\xd7\x90\xa6\x63\x93\xb9\x31\x11\xc1\xa5\x5d\xd7\x42\x1a\x10\x18\x49\x74\xc7\xc5" -data Vector = Vector Int -- rounds- ByteString -- key- ByteString -- nonce- deriving (Show,Eq)+data Vector+ = Vector+ Int -- rounds+ ByteString -- key+ ByteString -- nonce+ deriving (Show, Eq) instance Arbitrary Vector where arbitrary = Vector 20 <$> arbitraryBS 16 <*> arbitraryBS 12 -tests = testGroup "ChaCha"- [ testCase "8-128-K0-I0" (chachaRunSimple b8_128_k0_i0 8 16 8)- , testCase "12-128-K0-I0" (chachaRunSimple b12_128_k0_i0 12 16 8)- , testCase "20-128-K0-I0" (chachaRunSimple b20_128_k0_i0 20 16 8)- , testCase "8-256-K0-I0" (chachaRunSimple b8_256_k0_i0 8 32 8)- , testCase "12-256-K0-I0" (chachaRunSimple b12_256_k0_i0 12 32 8)- , testCase "20-256-K0-I0" (chachaRunSimple b20_256_k0_i0 20 32 8)- , testCase "XChaCha20 example KAT" xChaCha20_ExampleKAT- , testProperty "generate-combine" chachaGenerateCombine- , testProperty "chunking-generate" chachaGenerateChunks- , testProperty "chunking-combine" chachaCombineChunks- ]- where chachaRunSimple expected rounds klen nonceLen =- let chacha = ChaCha.initialize rounds (B.replicate klen 0) (B.replicate nonceLen 0)- in expected @=? fst (ChaCha.generate chacha (B.length expected))-- chachaGenerateChunks :: ChunkingLen -> Vector -> Bool- chachaGenerateChunks (ChunkingLen ckLen) (Vector rounds key iv) =- let initChaCha = ChaCha.initialize rounds key iv- nbBytes = 1048- (expected,_) = ChaCha.generate initChaCha nbBytes- chunks = loop nbBytes ckLen initChaCha- in expected `propertyEq` B.concat chunks-- where loop n [] chacha = loop n ckLen chacha- loop 0 _ _ = []- loop n (x:xs) chacha =- let len = min x n- (c, next) = ChaCha.generate chacha len- in c : loop (n - len) xs next-- chachaGenerateCombine :: ChunkingLen0_127 -> Vector -> Int0_2901 -> Bool- chachaGenerateCombine (ChunkingLen0_127 ckLen) (Vector rounds key iv) (Int0_2901 nbBytes) =- let initChaCha = ChaCha.initialize rounds key iv- in loop nbBytes ckLen initChaCha- where loop n [] chacha = loop n ckLen chacha- loop 0 _ _ = True- loop n (x:xs) chacha =- let len = min x n- (c1, next) = ChaCha.generate chacha len- (c2, _) = ChaCha.combine chacha (B.replicate len 0)- in if c1 == c2 then loop (n - len) xs next else False+tests =+ testGroup+ "ChaCha"+ [ testCase "8-128-K0-I0" (chachaRunSimple b8_128_k0_i0 8 16 8)+ , testCase "12-128-K0-I0" (chachaRunSimple b12_128_k0_i0 12 16 8)+ , testCase "20-128-K0-I0" (chachaRunSimple b20_128_k0_i0 20 16 8)+ , testCase "8-256-K0-I0" (chachaRunSimple b8_256_k0_i0 8 32 8)+ , testCase "12-256-K0-I0" (chachaRunSimple b12_256_k0_i0 12 32 8)+ , testCase "20-256-K0-I0" (chachaRunSimple b20_256_k0_i0 20 32 8)+ , testCase "XChaCha20 example KAT" xChaCha20_ExampleKAT+ , testProperty "generate-combine" chachaGenerateCombine+ , testProperty "chunking-generate" chachaGenerateChunks+ , testProperty "chunking-combine" chachaCombineChunks+ ]+ where+ chachaRunSimple expected rounds klen nonceLen =+ let chacha = ChaCha.initialize rounds (B.replicate klen 0) (B.replicate nonceLen 0)+ in expected @=? fst (ChaCha.generate chacha (B.length expected)) + chachaGenerateChunks :: ChunkingLen -> Vector -> Bool+ chachaGenerateChunks (ChunkingLen ckLen) (Vector rounds key iv) =+ let initChaCha = ChaCha.initialize rounds key iv+ nbBytes = 1048+ (expected, _) = ChaCha.generate initChaCha nbBytes+ chunks = loop nbBytes ckLen initChaCha+ in expected `propertyEq` B.concat chunks+ where+ loop n [] chacha = loop n ckLen chacha+ loop 0 _ _ = []+ loop n (x : xs) chacha =+ let len = min x n+ (c, next) = ChaCha.generate chacha len+ in c : loop (n - len) xs next - chachaCombineChunks :: ChunkingLen0_127 -> Vector -> ArbitraryBS0_2901 -> Bool- chachaCombineChunks (ChunkingLen0_127 ckLen) (Vector rounds key iv) (ArbitraryBS0_2901 wholebs) =- let initChaCha = ChaCha.initialize rounds key iv- (expected,_) = ChaCha.combine initChaCha wholebs- chunks = loop wholebs ckLen initChaCha- in expected `propertyEq` B.concat chunks+ chachaGenerateCombine :: ChunkingLen0_127 -> Vector -> Int0_2901 -> Bool+ chachaGenerateCombine (ChunkingLen0_127 ckLen) (Vector rounds key iv) (Int0_2901 nbBytes) =+ let initChaCha = ChaCha.initialize rounds key iv+ in loop nbBytes ckLen initChaCha+ where+ loop n [] chacha = loop n ckLen chacha+ loop 0 _ _ = True+ loop n (x : xs) chacha =+ let len = min x n+ (c1, next) = ChaCha.generate chacha len+ (c2, _) = ChaCha.combine chacha (B.replicate len 0)+ in if c1 == c2 then loop (n - len) xs next else False - where loop bs [] chacha = loop bs ckLen chacha- loop bs (x:xs) chacha- | B.null bs = []- | otherwise =- let (bs1, bs2) = B.splitAt (min x (B.length bs)) bs- (c, next) = ChaCha.combine chacha bs1- in c : loop bs2 xs next+ chachaCombineChunks :: ChunkingLen0_127 -> Vector -> ArbitraryBS0_2901 -> Bool+ chachaCombineChunks (ChunkingLen0_127 ckLen) (Vector rounds key iv) (ArbitraryBS0_2901 wholebs) =+ let initChaCha = ChaCha.initialize rounds key iv+ (expected, _) = ChaCha.combine initChaCha wholebs+ chunks = loop wholebs ckLen initChaCha+ in expected `propertyEq` B.concat chunks+ where+ loop bs [] chacha = loop bs ckLen chacha+ loop bs (x : xs) chacha+ | B.null bs = []+ | otherwise =+ let (bs1, bs2) = B.splitAt (min x (B.length bs)) bs+ (c, next) = ChaCha.combine chacha bs1+ in c : loop bs2 xs next
tests/ChaChaPoly1305.hs view
@@ -1,89 +1,133 @@ {-# LANGUAGE OverloadedStrings #-}+ module ChaChaPoly1305 where import qualified Crypto.Cipher.ChaChaPoly1305 as AEAD-import Imports import Crypto.Error+import Imports import Poly1305 () -import qualified Data.ByteString as B import qualified Data.ByteArray as B (convert)+import qualified Data.ByteString as B -plaintext, aad, key, iv, ivX, ciphertext, ciphertextX, tag, tagX, nonce1, nonce2, nonce3, nonce4, nonce5, nonce6, nonce7, nonce8, nonce9, nonce10 :: B.ByteString-plaintext = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it."+plaintext+ , aad+ , key+ , iv+ , ivX+ , ciphertext+ , ciphertextX+ , tag+ , tagX+ , nonce1+ , nonce2+ , nonce3+ , nonce4+ , nonce5+ , nonce6+ , nonce7+ , nonce8+ , nonce9+ , nonce10+ :: B.ByteString+plaintext =+ "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it." aad = "\x50\x51\x52\x53\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7"-key = "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"+key =+ "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" iv = "\x40\x41\x42\x43\x44\x45\x46\x47" ivX = B.pack [0x40 .. 0x57] constant = "\x07\x00\x00\x00"-ciphertext = "\xd3\x1a\x8d\x34\x64\x8e\x60\xdb\x7b\x86\xaf\xbc\x53\xef\x7e\xc2\xa4\xad\xed\x51\x29\x6e\x08\xfe\xa9\xe2\xb5\xa7\x36\xee\x62\xd6\x3d\xbe\xa4\x5e\x8c\xa9\x67\x12\x82\xfa\xfb\x69\xda\x92\x72\x8b\x1a\x71\xde\x0a\x9e\x06\x0b\x29\x05\xd6\xa5\xb6\x7e\xcd\x3b\x36\x92\xdd\xbd\x7f\x2d\x77\x8b\x8c\x98\x03\xae\xe3\x28\x09\x1b\x58\xfa\xb3\x24\xe4\xfa\xd6\x75\x94\x55\x85\x80\x8b\x48\x31\xd7\xbc\x3f\xf4\xde\xf0\x8e\x4b\x7a\x9d\xe5\x76\xd2\x65\x86\xce\xc6\x4b\x61\x16"-ciphertextX = "\xbd\x6d\x17\x9d\x3e\x83\xd4\x3b\x95\x76\x57\x94\x93\xc0\xe9\x39\x57\x2a\x17\x00\x25\x2b\xfa\xcc\xbe\xd2\x90\x2c\x21\x39\x6c\xbb\x73\x1c\x7f\x1b\x0b\x4a\xa6\x44\x0b\xf3\xa8\x2f\x4e\xda\x7e\x39\xae\x64\xc6\x70\x8c\x54\xc2\x16\xcb\x96\xb7\x2e\x12\x13\xb4\x52\x2f\x8c\x9b\xa4\x0d\xb5\xd9\x45\xb1\x1b\x69\xb9\x82\xc1\xbb\x9e\x3f\x3f\xac\x2b\xc3\x69\x48\x8f\x76\xb2\x38\x35\x65\xd3\xff\xf9\x21\xf9\x66\x4c\x97\x63\x7d\xa9\x76\x88\x12\xf6\x15\xc6\x8b\x13\xb5\x2e"+ciphertext =+ "\xd3\x1a\x8d\x34\x64\x8e\x60\xdb\x7b\x86\xaf\xbc\x53\xef\x7e\xc2\xa4\xad\xed\x51\x29\x6e\x08\xfe\xa9\xe2\xb5\xa7\x36\xee\x62\xd6\x3d\xbe\xa4\x5e\x8c\xa9\x67\x12\x82\xfa\xfb\x69\xda\x92\x72\x8b\x1a\x71\xde\x0a\x9e\x06\x0b\x29\x05\xd6\xa5\xb6\x7e\xcd\x3b\x36\x92\xdd\xbd\x7f\x2d\x77\x8b\x8c\x98\x03\xae\xe3\x28\x09\x1b\x58\xfa\xb3\x24\xe4\xfa\xd6\x75\x94\x55\x85\x80\x8b\x48\x31\xd7\xbc\x3f\xf4\xde\xf0\x8e\x4b\x7a\x9d\xe5\x76\xd2\x65\x86\xce\xc6\x4b\x61\x16"+ciphertextX =+ "\xbd\x6d\x17\x9d\x3e\x83\xd4\x3b\x95\x76\x57\x94\x93\xc0\xe9\x39\x57\x2a\x17\x00\x25\x2b\xfa\xcc\xbe\xd2\x90\x2c\x21\x39\x6c\xbb\x73\x1c\x7f\x1b\x0b\x4a\xa6\x44\x0b\xf3\xa8\x2f\x4e\xda\x7e\x39\xae\x64\xc6\x70\x8c\x54\xc2\x16\xcb\x96\xb7\x2e\x12\x13\xb4\x52\x2f\x8c\x9b\xa4\x0d\xb5\xd9\x45\xb1\x1b\x69\xb9\x82\xc1\xbb\x9e\x3f\x3f\xac\x2b\xc3\x69\x48\x8f\x76\xb2\x38\x35\x65\xd3\xff\xf9\x21\xf9\x66\x4c\x97\x63\x7d\xa9\x76\x88\x12\xf6\x15\xc6\x8b\x13\xb5\x2e" tag = "\x1a\xe1\x0b\x59\x4f\x09\xe2\x6a\x7e\x90\x2e\xcb\xd0\x60\x06\x91" tagX = "\xc0\x87\x59\x24\xc1\xc7\x98\x79\x47\xde\xaf\xd8\x78\x0a\xcf\x49"-nonce1 = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"-nonce2 = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"-nonce3 = "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"-nonce4 = "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"-nonce5 = "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"-nonce6 = "\x00\x00\x00\x00\x00\x00\x00\x00"-nonce7 = "\x01\x00\x00\x00\x00\x00\x00\x00"-nonce8 = "\xff\x00\x00\x00\x00\x00\x00\x00"-nonce9 = "\x00\x01\x00\x00\x00\x00\x00\x00"+nonce1 = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+nonce2 = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+nonce3 = "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+nonce4 = "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+nonce5 = "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"+nonce6 = "\x00\x00\x00\x00\x00\x00\x00\x00"+nonce7 = "\x01\x00\x00\x00\x00\x00\x00\x00"+nonce8 = "\xff\x00\x00\x00\x00\x00\x00\x00"+nonce9 = "\x00\x01\x00\x00\x00\x00\x00\x00" nonce10 = "\xff\xff\xff\xff\xff\xff\xff\xff" -tests = testGroup "ChaChaPoly1305"- [ testCase "V1" runEncrypt- , testCase "V1-decrypt" runDecrypt- , testCase "V1-extended" runEncryptX- , testCase "V1-extended-decrypt" runDecryptX- , testCase "nonce increment" runNonceInc- ]- where runEncrypt =- let ini = throwCryptoError $ AEAD.initialize key (throwCryptoError $ AEAD.nonce8 constant iv)- afterAAD = AEAD.finalizeAAD (AEAD.appendAAD aad ini)- (out, afterEncrypt) = AEAD.encrypt plaintext afterAAD- outtag = AEAD.finalize afterEncrypt- in propertyHoldCase [ eqTest "ciphertext" ciphertext out- , eqTest "tag" tag (B.convert outtag)- ]- runEncryptX =- let ini = throwCryptoError $ AEAD.initializeX key (throwCryptoError $ AEAD.nonce24 ivX)- afterAAD = AEAD.finalizeAAD (AEAD.appendAAD aad ini)- (out, afterEncrypt) = AEAD.encrypt plaintext afterAAD- outtag = AEAD.finalize afterEncrypt- in propertyHoldCase [ eqTest "ciphertext" ciphertextX out- , eqTest "tag" tagX (B.convert outtag)- ]+tests =+ testGroup+ "ChaChaPoly1305"+ [ testCase "V1" runEncrypt+ , testCase "V1-decrypt" runDecrypt+ , testCase "V1-extended" runEncryptX+ , testCase "V1-extended-decrypt" runDecryptX+ , testCase "nonce increment" runNonceInc+ ]+ where+ runEncrypt =+ let ini =+ throwCryptoError $+ AEAD.initialize key (throwCryptoError $ AEAD.nonce8 constant iv)+ afterAAD = AEAD.finalizeAAD (AEAD.appendAAD aad ini)+ (out, afterEncrypt) = AEAD.encrypt plaintext afterAAD+ outtag = AEAD.finalize afterEncrypt+ in propertyHoldCase+ [ eqTest "ciphertext" ciphertext out+ , eqTest "tag" tag (B.convert outtag)+ ]+ runEncryptX =+ let ini =+ throwCryptoError $ AEAD.initializeX key (throwCryptoError $ AEAD.nonce24 ivX)+ afterAAD = AEAD.finalizeAAD (AEAD.appendAAD aad ini)+ (out, afterEncrypt) = AEAD.encrypt plaintext afterAAD+ outtag = AEAD.finalize afterEncrypt+ in propertyHoldCase+ [ eqTest "ciphertext" ciphertextX out+ , eqTest "tag" tagX (B.convert outtag)+ ] - runDecrypt =- let ini = throwCryptoError $ AEAD.initialize key (throwCryptoError $ AEAD.nonce8 constant iv)- afterAAD = AEAD.finalizeAAD (AEAD.appendAAD aad ini)- (out, afterDecrypt) = AEAD.decrypt ciphertext afterAAD- outtag = AEAD.finalize afterDecrypt- in propertyHoldCase [ eqTest "plaintext" plaintext out- , eqTest "tag" tag (B.convert outtag)- ]+ runDecrypt =+ let ini =+ throwCryptoError $+ AEAD.initialize key (throwCryptoError $ AEAD.nonce8 constant iv)+ afterAAD = AEAD.finalizeAAD (AEAD.appendAAD aad ini)+ (out, afterDecrypt) = AEAD.decrypt ciphertext afterAAD+ outtag = AEAD.finalize afterDecrypt+ in propertyHoldCase+ [ eqTest "plaintext" plaintext out+ , eqTest "tag" tag (B.convert outtag)+ ] - runDecryptX =- let ini = throwCryptoError $ AEAD.initializeX key (throwCryptoError $ AEAD.nonce24 ivX)- afterAAD = AEAD.finalizeAAD (AEAD.appendAAD aad ini)- (out, afterDecrypt) = AEAD.decrypt ciphertextX afterAAD- outtag = AEAD.finalize afterDecrypt- in propertyHoldCase [ eqTest "plaintext" plaintext out- , eqTest "tag" tagX (B.convert outtag)- ]+ runDecryptX =+ let ini =+ throwCryptoError $ AEAD.initializeX key (throwCryptoError $ AEAD.nonce24 ivX)+ afterAAD = AEAD.finalizeAAD (AEAD.appendAAD aad ini)+ (out, afterDecrypt) = AEAD.decrypt ciphertextX afterAAD+ outtag = AEAD.finalize afterDecrypt+ in propertyHoldCase+ [ eqTest "plaintext" plaintext out+ , eqTest "tag" tagX (B.convert outtag)+ ] - runNonceInc =- let n1 = throwCryptoError . AEAD.nonce12 $ nonce1- n3 = throwCryptoError . AEAD.nonce12 $ nonce3- n5 = throwCryptoError . AEAD.nonce12 $ nonce5- n6 = throwCryptoError . AEAD.nonce8 constant $ nonce6- n8 = throwCryptoError . AEAD.nonce8 constant $ nonce8- n10 = throwCryptoError . AEAD.nonce8 constant $ nonce10- in propertyHoldCase [ eqTest "nonce12a" nonce2 $ B.convert . AEAD.incrementNonce $ n1- , eqTest "nonce12b" nonce4 $ B.convert . AEAD.incrementNonce $ n3- , eqTest "nonce12c" nonce1 $ B.convert . AEAD.incrementNonce $ n5- , eqTest "nonce8a" (B.concat [constant, nonce7]) $ B.convert . AEAD.incrementNonce $ n6- , eqTest "nonce8b" (B.concat [constant, nonce9]) $ B.convert . AEAD.incrementNonce $ n8- , eqTest "nonce8c" (B.concat [constant, nonce6]) $ B.convert . AEAD.incrementNonce $ n10- ]+ runNonceInc =+ let n1 = throwCryptoError . AEAD.nonce12 $ nonce1+ n3 = throwCryptoError . AEAD.nonce12 $ nonce3+ n5 = throwCryptoError . AEAD.nonce12 $ nonce5+ n6 = throwCryptoError . AEAD.nonce8 constant $ nonce6+ n8 = throwCryptoError . AEAD.nonce8 constant $ nonce8+ n10 = throwCryptoError . AEAD.nonce8 constant $ nonce10+ in propertyHoldCase+ [ eqTest "nonce12a" nonce2 $ B.convert . AEAD.incrementNonce $ n1+ , eqTest "nonce12b" nonce4 $ B.convert . AEAD.incrementNonce $ n3+ , eqTest "nonce12c" nonce1 $ B.convert . AEAD.incrementNonce $ n5+ , eqTest "nonce8a" (B.concat [constant, nonce7]) $+ B.convert . AEAD.incrementNonce $+ n6+ , eqTest "nonce8b" (B.concat [constant, nonce9]) $+ B.convert . AEAD.incrementNonce $+ n8+ , eqTest "nonce8c" (B.concat [constant, nonce6]) $+ B.convert . AEAD.incrementNonce $+ n10+ ]
tests/ECC.hs view
@@ -1,343 +1,399 @@ {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-}+ module ECC (tests) where -import Crypto.Error+import Data.Either+ import qualified Crypto.ECC as ECC+import Crypto.Error -import Data.ByteArray.Encoding+import Data.ByteArray.Encoding import Imports -data Curve = forall curve. (ECC.EllipticCurveDH curve, Show curve, Eq (ECC.Point curve)) => Curve curve+data Curve+ = forall curve.+ (ECC.EllipticCurveDH curve, Show curve, Eq (ECC.Point curve)) =>+ Curve curve instance Show Curve where showsPrec d (Curve curve) = showsPrec d curve instance Arbitrary Curve where- arbitrary = elements- [ Curve ECC.Curve_P256R1- , Curve ECC.Curve_P384R1- , Curve ECC.Curve_P521R1- , Curve ECC.Curve_X25519- , Curve ECC.Curve_X448- ]+ arbitrary =+ elements+ [ Curve ECC.Curve_P256R1+ , Curve ECC.Curve_P384R1+ , Curve ECC.Curve_P521R1+ , Curve ECC.Curve_X25519+ , Curve ECC.Curve_X448+ ] -data CurveArith = forall curve. (ECC.EllipticCurveBasepointArith curve, Show curve) => CurveArith curve+data CurveArith+ = forall curve. (ECC.EllipticCurveBasepointArith curve, Show curve) => CurveArith curve instance Show CurveArith where showsPrec d (CurveArith curve) = showsPrec d curve instance Arbitrary CurveArith where- arbitrary = elements- [ CurveArith ECC.Curve_P256R1- , CurveArith ECC.Curve_P384R1- , CurveArith ECC.Curve_P521R1- , CurveArith ECC.Curve_Edwards25519- ]+ arbitrary =+ elements+ [ CurveArith ECC.Curve_P256R1+ , CurveArith ECC.Curve_P384R1+ , CurveArith ECC.Curve_P521R1+ , CurveArith ECC.Curve_Edwards25519+ ] data VectorPoint = VectorPoint { vpCurve :: Curve- , vpHex :: ByteString+ , vpHex :: ByteString , vpError :: Maybe CryptoError } +vectorsPoint :: [VectorPoint] vectorsPoint = [ VectorPoint { vpCurve = Curve ECC.Curve_P256R1- , vpHex = ""+ , vpHex = "" , vpError = Just CryptoError_PointSizeInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_P256R1- , vpHex = "00"+ , vpHex = "00" , vpError = Just CryptoError_PointFormatInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_P256R1- , vpHex = "0408edd7b50085a952172228aca391beebe9ba942a0ae9eb15bcc8d50795d1a5505221c7b9b3bb4310f165fc3ac3114339db8170ceae6697e0f9736698b33551b8"+ , vpHex =+ "0408edd7b50085a952172228aca391beebe9ba942a0ae9eb15bcc8d50795d1a5505221c7b9b3bb4310f165fc3ac3114339db8170ceae6697e0f9736698b33551b8" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P256R1- , vpHex = "04216f25b00717d46deef3402628f6abf265bfa12aea515ae8f100ce415e251e72cd5cd8f47f613a0f4e0f4f9410dd9c85c149cffcb320c2d52bf550a397ec92e5"+ , vpHex =+ "04216f25b00717d46deef3402628f6abf265bfa12aea515ae8f100ce415e251e72cd5cd8f47f613a0f4e0f4f9410dd9c85c149cffcb320c2d52bf550a397ec92e5" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P256R1- , vpHex = "0421eba6080610926609bb8d52afd3331ed1b07e0ba4c1441a118b62497d3e85f39a50c865027cdd84298cdf094b7818f2a65ae59f46c971a32ab4ea3c2c93c959"+ , vpHex =+ "0421eba6080610926609bb8d52afd3331ed1b07e0ba4c1441a118b62497d3e85f39a50c865027cdd84298cdf094b7818f2a65ae59f46c971a32ab4ea3c2c93c959" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P256R1- , vpHex = "0400d7fc4050dfe73475502d5d1fadc105d7725508f48da2cd4729bf191fd6490a0001a16f417a27530e756efeb4a228f02db878072b9f833e99a2821d85fa78fc"+ , vpHex =+ "0400d7fc4050dfe73475502d5d1fadc105d7725508f48da2cd4729bf191fd6490a0001a16f417a27530e756efeb4a228f02db878072b9f833e99a2821d85fa78fc" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P256R1- , vpHex = "040000fc4050dfe73475502d5d1fadc105d7725508f48da2cd4729bf191fd6490a0001a16f417a27530e756efeb4a228f02db878072b9f833e99a2821d85fa78fc"+ , vpHex =+ "040000fc4050dfe73475502d5d1fadc105d7725508f48da2cd4729bf191fd6490a0001a16f417a27530e756efeb4a228f02db878072b9f833e99a2821d85fa78fc" , vpError = Just CryptoError_PointCoordinatesInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_P256R1- , vpHex = "04d7fc4050dfe73475502d5d1fadc105d7725508f48da2cd4729bf191fd6490a01a16f417a27530e756efeb4a228f02db878072b9f833e99a2821d85fa78fc"+ , vpHex =+ "04d7fc4050dfe73475502d5d1fadc105d7725508f48da2cd4729bf191fd6490a01a16f417a27530e756efeb4a228f02db878072b9f833e99a2821d85fa78fc" , vpError = Just CryptoError_PublicKeySizeInvalid -- tests leading zeros } , VectorPoint { vpCurve = Curve ECC.Curve_P256R1- , vpHex = "040000d7fc4050dfe73475502d5d1fadc105d7725508f48da2cd4729bf191fd6490a000001a16f417a27530e756efeb4a228f02db878072b9f833e99a2821d85fa78fc"+ , vpHex =+ "040000d7fc4050dfe73475502d5d1fadc105d7725508f48da2cd4729bf191fd6490a000001a16f417a27530e756efeb4a228f02db878072b9f833e99a2821d85fa78fc" , vpError = Just CryptoError_PublicKeySizeInvalid -- tests leading zeros } , VectorPoint { vpCurve = Curve ECC.Curve_P384R1- , vpHex = ""+ , vpHex = "" , vpError = Just CryptoError_PointSizeInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_P384R1- , vpHex = "00"+ , vpHex = "00" , vpError = Just CryptoError_PointFormatInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_P384R1- , vpHex = "0409281a103fb1773445e16eec86adb095e32928ccc9c806bd210c649712813bdb6cab40163a8cb163b578ea8dda5eb32cfb5208ebf0d31a6c590fa92f5a61f32dbc0d518b166ea5a9adf9dd21c1bd09932ca21c6a5725ca89542ac57b6a9eca6f"+ , vpHex =+ "0409281a103fb1773445e16eec86adb095e32928ccc9c806bd210c649712813bdb6cab40163a8cb163b578ea8dda5eb32cfb5208ebf0d31a6c590fa92f5a61f32dbc0d518b166ea5a9adf9dd21c1bd09932ca21c6a5725ca89542ac57b6a9eca6f" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P384R1- , vpHex = "040c7b3fb575c1db7bc61fe7a456cc34a8289f41e167938a56e5ba2787723f3de2c645112705e13ed24f477730173935ca4e0ff468e7e0acf78a9f59dadff8193a0e23789eb3737730c089b27a0f94de7d95b8db4466d017fb21a5710d6ca85775"+ , vpHex =+ "040c7b3fb575c1db7bc61fe7a456cc34a8289f41e167938a56e5ba2787723f3de2c645112705e13ed24f477730173935ca4e0ff468e7e0acf78a9f59dadff8193a0e23789eb3737730c089b27a0f94de7d95b8db4466d017fb21a5710d6ca85775" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P384R1- , vpHex = "0438e7705220b60460194be63d21c8945be2a211957168fa60f26b2ad4e8f5cd96a7779e7edff4deda9ded63243c2127e273d4444edaaba03b79b6caafc5033432af13776f851c0c7e1080c60d7ee3b61740720ab98461813dab5fb8c31bfa9ed9"+ , vpHex =+ "0438e7705220b60460194be63d21c8945be2a211957168fa60f26b2ad4e8f5cd96a7779e7edff4deda9ded63243c2127e273d4444edaaba03b79b6caafc5033432af13776f851c0c7e1080c60d7ee3b61740720ab98461813dab5fb8c31bfa9ed9" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P384R1- , vpHex = "04000836bf09614bf5b3c0ffe9b0822a2cc109a90b13d4d3510ce14f766e7d90875ec4bc8d6bee11fc1fdf97473a67884c00b1e2685367bdb846c95181b0f35a35cfbee04451122cc55a1e363acaa6c002e71b0b6ff7d0f5dc830a32f0e5086189"+ , vpHex =+ "04000836bf09614bf5b3c0ffe9b0822a2cc109a90b13d4d3510ce14f766e7d90875ec4bc8d6bee11fc1fdf97473a67884c00b1e2685367bdb846c95181b0f35a35cfbee04451122cc55a1e363acaa6c002e71b0b6ff7d0f5dc830a32f0e5086189" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P384R1- , vpHex = "04000036bf09614bf5b3c0ffe9b0822a2cc109a90b13d4d3510ce14f766e7d90875ec4bc8d6bee11fc1fdf97473a67884c00b1e2685367bdb846c95181b0f35a35cfbee04451122cc55a1e363acaa6c002e71b0b6ff7d0f5dc830a32f0e5086189"+ , vpHex =+ "04000036bf09614bf5b3c0ffe9b0822a2cc109a90b13d4d3510ce14f766e7d90875ec4bc8d6bee11fc1fdf97473a67884c00b1e2685367bdb846c95181b0f35a35cfbee04451122cc55a1e363acaa6c002e71b0b6ff7d0f5dc830a32f0e5086189" , vpError = Just CryptoError_PointCoordinatesInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_P384R1- , vpHex = "040836bf09614bf5b3c0ffe9b0822a2cc109a90b13d4d3510ce14f766e7d90875ec4bc8d6bee11fc1fdf97473a67884cb1e2685367bdb846c95181b0f35a35cfbee04451122cc55a1e363acaa6c002e71b0b6ff7d0f5dc830a32f0e5086189"+ , vpHex =+ "040836bf09614bf5b3c0ffe9b0822a2cc109a90b13d4d3510ce14f766e7d90875ec4bc8d6bee11fc1fdf97473a67884cb1e2685367bdb846c95181b0f35a35cfbee04451122cc55a1e363acaa6c002e71b0b6ff7d0f5dc830a32f0e5086189" , vpError = Nothing -- ignores leading zeros } , VectorPoint { vpCurve = Curve ECC.Curve_P384R1- , vpHex = "0400000836bf09614bf5b3c0ffe9b0822a2cc109a90b13d4d3510ce14f766e7d90875ec4bc8d6bee11fc1fdf97473a67884c0000b1e2685367bdb846c95181b0f35a35cfbee04451122cc55a1e363acaa6c002e71b0b6ff7d0f5dc830a32f0e5086189"+ , vpHex =+ "0400000836bf09614bf5b3c0ffe9b0822a2cc109a90b13d4d3510ce14f766e7d90875ec4bc8d6bee11fc1fdf97473a67884c0000b1e2685367bdb846c95181b0f35a35cfbee04451122cc55a1e363acaa6c002e71b0b6ff7d0f5dc830a32f0e5086189" , vpError = Nothing -- ignores leading zeros } , VectorPoint { vpCurve = Curve ECC.Curve_P521R1- , vpHex = ""+ , vpHex = "" , vpError = Just CryptoError_PointSizeInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_P521R1- , vpHex = "00"+ , vpHex = "00" , vpError = Just CryptoError_PointFormatInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_P521R1- , vpHex = "04000ce5c207335134567026063743df82c1b551a009cf616471f0e23fa9767a50cc7f8771ef13a65c49ce7e1cd1ac3ad721dcc3ddd35f98ae5d380a0832f87a9f0ca4012914911d6bea7f3c481d694fb1645be27c7b66b09b28e261f8030b3fb8206f6a95f6ad73db755765b64f592a799234f8f451cb787abe95b1a54991a799ad0d69da"+ , vpHex =+ "04000ce5c207335134567026063743df82c1b551a009cf616471f0e23fa9767a50cc7f8771ef13a65c49ce7e1cd1ac3ad721dcc3ddd35f98ae5d380a0832f87a9f0ca4012914911d6bea7f3c481d694fb1645be27c7b66b09b28e261f8030b3fb8206f6a95f6ad73db755765b64f592a799234f8f451cb787abe95b1a54991a799ad0d69da" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P521R1- , vpHex = "04003a5e6c1ce3a6a323757005da17b357db991bd1ad835e6201411f458b5c2edb3c66786b727b7e15fbad7dd74a4b0eb542183b5242e5952061cb85e7229353eb0dc300aac2dbd5232d582481ba7a59a993eb04c4466a1b17ba0015b65c616ce8703e70880969d8d58e633acb29c3ca017eb1b88649387b867466090ce1a57c2b4f8376bb"+ , vpHex =+ "04003a5e6c1ce3a6a323757005da17b357db991bd1ad835e6201411f458b5c2edb3c66786b727b7e15fbad7dd74a4b0eb542183b5242e5952061cb85e7229353eb0dc300aac2dbd5232d582481ba7a59a993eb04c4466a1b17ba0015b65c616ce8703e70880969d8d58e633acb29c3ca017eb1b88649387b867466090ce1a57c2b4f8376bb" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P521R1- , vpHex = "04003e0659fe9498695a3d8c88b8e25fa8133c30ab10eccbe9094344c99924f89fb69d9b3acf03bf438328f9cba55fa28a05be9a7e18780706b3728abfee2592aeb86d0001ea5ff64f2ca7a6453c79f80550e971843e073f4f8fec75bad2e52a4483ebf1f16f43d0de27e1967ea22f9722527652fa74439fdc03a569fba29e2d6f7c012db6"+ , vpHex =+ "04003e0659fe9498695a3d8c88b8e25fa8133c30ab10eccbe9094344c99924f89fb69d9b3acf03bf438328f9cba55fa28a05be9a7e18780706b3728abfee2592aeb86d0001ea5ff64f2ca7a6453c79f80550e971843e073f4f8fec75bad2e52a4483ebf1f16f43d0de27e1967ea22f9722527652fa74439fdc03a569fba29e2d6f7c012db6" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P521R1- , vpHex = "040043f91fd92d9ccd6d5584b265a2a775d222f4a41ff98190677d985e0889737cbe631d525835fe04faffcdebeccb783538280f4600ae82347b0470583abd9def306000a2e9bdc34f42b134517fc1e961befea0affd1f9666361a039192082a892dd722931d5865b62b69d7369e74895120e540cb10030cccb6049d809fbcf3f54537b378"+ , vpHex =+ "040043f91fd92d9ccd6d5584b265a2a775d222f4a41ff98190677d985e0889737cbe631d525835fe04faffcdebeccb783538280f4600ae82347b0470583abd9def306000a2e9bdc34f42b134517fc1e961befea0affd1f9666361a039192082a892dd722931d5865b62b69d7369e74895120e540cb10030cccb6049d809fbcf3f54537b378" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_P521R1- , vpHex = "040000f91fd92d9ccd6d5584b265a2a775d222f4a41ff98190677d985e0889737cbe631d525835fe04faffcdebeccb783538280f4600ae82347b0470583abd9def306000a2e9bdc34f42b134517fc1e961befea0affd1f9666361a039192082a892dd722931d5865b62b69d7369e74895120e540cb10030cccb6049d809fbcf3f54537b378"+ , vpHex =+ "040000f91fd92d9ccd6d5584b265a2a775d222f4a41ff98190677d985e0889737cbe631d525835fe04faffcdebeccb783538280f4600ae82347b0470583abd9def306000a2e9bdc34f42b134517fc1e961befea0affd1f9666361a039192082a892dd722931d5865b62b69d7369e74895120e540cb10030cccb6049d809fbcf3f54537b378" , vpError = Just CryptoError_PointCoordinatesInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_P521R1- , vpHex = "0443f91fd92d9ccd6d5584b265a2a775d222f4a41ff98190677d985e0889737cbe631d525835fe04faffcdebeccb783538280f4600ae82347b0470583abd9def3060a2e9bdc34f42b134517fc1e961befea0affd1f9666361a039192082a892dd722931d5865b62b69d7369e74895120e540cb10030cccb6049d809fbcf3f54537b378"+ , vpHex =+ "0443f91fd92d9ccd6d5584b265a2a775d222f4a41ff98190677d985e0889737cbe631d525835fe04faffcdebeccb783538280f4600ae82347b0470583abd9def3060a2e9bdc34f42b134517fc1e961befea0affd1f9666361a039192082a892dd722931d5865b62b69d7369e74895120e540cb10030cccb6049d809fbcf3f54537b378" , vpError = Nothing -- ignores leading zeros } , VectorPoint { vpCurve = Curve ECC.Curve_P521R1- , vpHex = "04000043f91fd92d9ccd6d5584b265a2a775d222f4a41ff98190677d985e0889737cbe631d525835fe04faffcdebeccb783538280f4600ae82347b0470583abd9def30600000a2e9bdc34f42b134517fc1e961befea0affd1f9666361a039192082a892dd722931d5865b62b69d7369e74895120e540cb10030cccb6049d809fbcf3f54537b378"+ , vpHex =+ "04000043f91fd92d9ccd6d5584b265a2a775d222f4a41ff98190677d985e0889737cbe631d525835fe04faffcdebeccb783538280f4600ae82347b0470583abd9def30600000a2e9bdc34f42b134517fc1e961befea0affd1f9666361a039192082a892dd722931d5865b62b69d7369e74895120e540cb10030cccb6049d809fbcf3f54537b378" , vpError = Nothing -- ignores leading zeros } , VectorPoint { vpCurve = Curve ECC.Curve_X25519- , vpHex = ""+ , vpHex = "" , vpError = Just CryptoError_PublicKeySizeInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_X25519- , vpHex = "22cd98c65fb50db3be0d6d359456c0cd3516952a6e7229ff672893944f703f10"+ , vpHex = "22cd98c65fb50db3be0d6d359456c0cd3516952a6e7229ff672893944f703f10" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_X25519- , vpHex = "23cd98c65fb50db3be0d6d359456c0cd3516952a6e7229ff672893944f703f10"+ , vpHex = "23cd98c65fb50db3be0d6d359456c0cd3516952a6e7229ff672893944f703f10" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_X25519- , vpHex = "0023cd98c65fb50db3be0d6d359456c0cd3516952a6e7229ff672893944f703f10"+ , vpHex = "0023cd98c65fb50db3be0d6d359456c0cd3516952a6e7229ff672893944f703f10" , vpError = Just CryptoError_PublicKeySizeInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_X448- , vpHex = ""+ , vpHex = "" , vpError = Just CryptoError_PublicKeySizeInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_X448- , vpHex = "2b162c2fef165ecbb203e40975ae4424f0f8db25ab582cb96b2e5ffe90a31798b35480b594c99dc32b437e61a74f792d8ecf5fc3e8cfeb75"+ , vpHex =+ "2b162c2fef165ecbb203e40975ae4424f0f8db25ab582cb96b2e5ffe90a31798b35480b594c99dc32b437e61a74f792d8ecf5fc3e8cfeb75" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_X448- , vpHex = "2c162c2fef165ecbb203e40975ae4424f0f8db25ab582cb96b2e5ffe90a31798b35480b594c99dc32b437e61a74f792d8ecf5fc3e8cfeb75"+ , vpHex =+ "2c162c2fef165ecbb203e40975ae4424f0f8db25ab582cb96b2e5ffe90a31798b35480b594c99dc32b437e61a74f792d8ecf5fc3e8cfeb75" , vpError = Nothing } , VectorPoint { vpCurve = Curve ECC.Curve_X448- , vpHex = "002c162c2fef165ecbb203e40975ae4424f0f8db25ab582cb96b2e5ffe90a31798b35480b594c99dc32b437e61a74f792d8ecf5fc3e8cfeb75"+ , vpHex =+ "002c162c2fef165ecbb203e40975ae4424f0f8db25ab582cb96b2e5ffe90a31798b35480b594c99dc32b437e61a74f792d8ecf5fc3e8cfeb75" , vpError = Just CryptoError_PublicKeySizeInvalid } ] +vectorsWeakPoint :: [VectorPoint] vectorsWeakPoint = [ VectorPoint { vpCurve = Curve ECC.Curve_X25519- , vpHex = "0000000000000000000000000000000000000000000000000000000000000000"+ , vpHex = "0000000000000000000000000000000000000000000000000000000000000000" , vpError = Just CryptoError_ScalarMultiplicationInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_X25519- , vpHex = "0100000000000000000000000000000000000000000000000000000000000000"+ , vpHex = "0100000000000000000000000000000000000000000000000000000000000000" , vpError = Just CryptoError_ScalarMultiplicationInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_X25519- , vpHex = "e0eb7a7c3b41b8ae1656e3faf19fc46ada098deb9c32b1fd866205165f49b800"+ , vpHex = "e0eb7a7c3b41b8ae1656e3faf19fc46ada098deb9c32b1fd866205165f49b800" , vpError = Just CryptoError_ScalarMultiplicationInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_X25519- , vpHex = "5f9c95bca3508c24b1d0b1559c83ef5b04445cc4581c8e86d8224eddd09f1157"+ , vpHex = "5f9c95bca3508c24b1d0b1559c83ef5b04445cc4581c8e86d8224eddd09f1157" , vpError = Just CryptoError_ScalarMultiplicationInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_X25519- , vpHex = "ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f"+ , vpHex = "ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f" , vpError = Just CryptoError_ScalarMultiplicationInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_X25519- , vpHex = "edffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f"+ , vpHex = "edffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f" , vpError = Just CryptoError_ScalarMultiplicationInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_X25519- , vpHex = "eeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f"+ , vpHex = "eeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f" , vpError = Just CryptoError_ScalarMultiplicationInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_X448- , vpHex = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"+ , vpHex =+ "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" , vpError = Just CryptoError_ScalarMultiplicationInvalid } , VectorPoint { vpCurve = Curve ECC.Curve_X448- , vpHex = "0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"+ , vpHex =+ "0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" , vpError = Just CryptoError_ScalarMultiplicationInvalid } ] vpEncodedPoint :: VectorPoint -> ByteString-vpEncodedPoint vector = let Right bs = convertFromBase Base16 (vpHex vector) in bs+vpEncodedPoint vector = fromRight (error "vpEncodedPoint") $ convertFromBase Base16 (vpHex vector) cryptoError :: CryptoFailable a -> Maybe CryptoError cryptoError = onCryptoFailure Just (const Nothing) +doPointDecodeTest :: Show p => p -> VectorPoint -> TestTree 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))+ in testCase+ (show i)+ (vpError vector @=? cryptoError (ECC.decodePoint prx $ vpEncodedPoint vector)) +doWeakPointECDHTest :: Show p => p -> VectorPoint -> TestTree doWeakPointECDHTest i vector = case vpCurve vector of Curve curve -> testCase (show i) $ do let prx = Just curve -- using Maybe as Proxy- CryptoPassed public = ECC.decodePoint prx $ vpEncodedPoint vector+ public = throwCryptoError $ ECC.decodePoint prx $ vpEncodedPoint vector keyPair <- ECC.curveGenerateKeyPair prx- vpError vector @=? cryptoError (ECC.ecdh prx (ECC.keypairGetPrivate keyPair) public)+ vpError vector+ @=? cryptoError (ECC.ecdh prx (ECC.keypairGetPrivate keyPair) public) -tests = testGroup "ECC"- [ 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- keyPair = withTestDRG testDRG $ ECC.curveGenerateKeyPair prx- p1 = ECC.keypairGetPublic keyPair- bs = ECC.encodePoint prx p1 :: ByteString- p2 = ECC.decodePoint prx bs- in CryptoPassed p1 == p2- , localOption (QuickCheckTests 20) $ testProperty "ECDH commutes" $ \testDRG (Curve curve) ->- let prx = Just curve -- using Maybe as Proxy- (alice, bob) = withTestDRG testDRG $- (,) <$> ECC.curveGenerateKeyPair prx- <*> ECC.curveGenerateKeyPair prx- aliceShared = ECC.ecdh prx (ECC.keypairGetPrivate alice) (ECC.keypairGetPublic bob)- bobShared = ECC.ecdh prx (ECC.keypairGetPrivate bob) (ECC.keypairGetPublic alice)- aliceShared' = ECC.ecdhRaw prx (ECC.keypairGetPrivate alice) (ECC.keypairGetPublic bob)- bobShared' = ECC.ecdhRaw prx (ECC.keypairGetPrivate bob) (ECC.keypairGetPublic alice)- in aliceShared == bobShared && aliceShared == CryptoPassed aliceShared'- && bobShared == CryptoPassed bobShared'- , testProperty "decodeScalar.encodeScalar==id" $ \testDRG (CurveArith curve) ->- let prx = Just curve -- using Maybe as Proxy- s1 = withTestDRG testDRG $ ECC.curveGenerateScalar prx- bs = ECC.encodeScalar prx s1 :: ByteString- s2 = ECC.decodeScalar prx bs- in CryptoPassed s1 == s2- , testProperty "scalarFromInteger.scalarToInteger==id" $ \testDRG (CurveArith curve) ->- let prx = Just curve -- using Maybe as Proxy- s1 = withTestDRG testDRG $ ECC.curveGenerateScalar prx- bs = ECC.scalarToInteger prx s1- s2 = ECC.scalarFromInteger prx bs- in CryptoPassed s1 == s2- , localOption (QuickCheckTests 20) $ testProperty "(a + b).P = a.P + b.P" $ \testDRG (CurveArith curve) ->- let prx = Just curve -- using Maybe as Proxy- (s, a, b) = withTestDRG testDRG $- (,,) <$> ECC.curveGenerateScalar prx- <*> ECC.curveGenerateScalar prx- <*> ECC.curveGenerateScalar prx- p = ECC.pointBaseSmul prx s- in ECC.pointSmul prx (ECC.scalarAdd prx a b) p == ECC.pointAdd prx (ECC.pointSmul prx a p) (ECC.pointSmul prx b p)- , localOption (QuickCheckTests 20) $ testProperty "(a * b).P = a.(b.P)" $ \testDRG (CurveArith curve) ->- let prx = Just curve -- using Maybe as Proxy- (s, a, b) = withTestDRG testDRG $- (,,) <$> ECC.curveGenerateScalar prx- <*> ECC.curveGenerateScalar prx- <*> ECC.curveGenerateScalar prx- p = ECC.pointBaseSmul prx s- in ECC.pointSmul prx (ECC.scalarMul prx a b) p == ECC.pointSmul prx a (ECC.pointSmul prx b p)+tests :: TestTree+tests =+ testGroup+ "ECC"+ [ 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+ keyPair = withTestDRG testDRG $ ECC.curveGenerateKeyPair prx+ p1 = ECC.keypairGetPublic keyPair+ bs = ECC.encodePoint prx p1 :: ByteString+ p2 = ECC.decodePoint prx bs+ in CryptoPassed p1 == p2+ , localOption (QuickCheckTests 20) $ testProperty "ECDH commutes" $ \testDRG (Curve curve) ->+ let prx = Just curve -- using Maybe as Proxy+ (alice, bob) =+ withTestDRG testDRG $+ (,)+ <$> ECC.curveGenerateKeyPair prx+ <*> ECC.curveGenerateKeyPair prx+ aliceShared = ECC.ecdh prx (ECC.keypairGetPrivate alice) (ECC.keypairGetPublic bob)+ bobShared = ECC.ecdh prx (ECC.keypairGetPrivate bob) (ECC.keypairGetPublic alice)+ aliceShared' = ECC.ecdhRaw prx (ECC.keypairGetPrivate alice) (ECC.keypairGetPublic bob)+ bobShared' = ECC.ecdhRaw prx (ECC.keypairGetPrivate bob) (ECC.keypairGetPublic alice)+ in aliceShared == bobShared+ && aliceShared == CryptoPassed aliceShared'+ && bobShared == CryptoPassed bobShared'+ , testProperty "decodeScalar.encodeScalar==id" $ \testDRG (CurveArith curve) ->+ let prx = Just curve -- using Maybe as Proxy+ s1 = withTestDRG testDRG $ ECC.curveGenerateScalar prx+ bs = ECC.encodeScalar prx s1 :: ByteString+ s2 = ECC.decodeScalar prx bs+ in CryptoPassed s1 == s2+ , testProperty "scalarFromInteger.scalarToInteger==id" $ \testDRG (CurveArith curve) ->+ let prx = Just curve -- using Maybe as Proxy+ s1 = withTestDRG testDRG $ ECC.curveGenerateScalar prx+ bs = ECC.scalarToInteger prx s1+ s2 = ECC.scalarFromInteger prx bs+ in CryptoPassed s1 == s2+ , localOption (QuickCheckTests 20) $ testProperty "(a + b).P = a.P + b.P" $ \testDRG (CurveArith curve) ->+ let prx = Just curve -- using Maybe as Proxy+ (s, a, b) =+ withTestDRG testDRG $+ (,,)+ <$> ECC.curveGenerateScalar prx+ <*> ECC.curveGenerateScalar prx+ <*> ECC.curveGenerateScalar prx+ p = ECC.pointBaseSmul prx s+ in ECC.pointSmul prx (ECC.scalarAdd prx a b) p+ == ECC.pointAdd prx (ECC.pointSmul prx a p) (ECC.pointSmul prx b p)+ , localOption (QuickCheckTests 20) $ testProperty "(a * b).P = a.(b.P)" $ \testDRG (CurveArith curve) ->+ let prx = Just curve -- using Maybe as Proxy+ (s, a, b) =+ withTestDRG testDRG $+ (,,)+ <$> ECC.curveGenerateScalar prx+ <*> ECC.curveGenerateScalar prx+ <*> ECC.curveGenerateScalar prx+ p = ECC.pointBaseSmul prx s+ in ECC.pointSmul prx (ECC.scalarMul prx a b) p+ == ECC.pointSmul prx a (ECC.pointSmul prx b p)+ ] ]- ]
tests/ECC/Edwards25519.hs view
@@ -1,21 +1,24 @@ {-# LANGUAGE OverloadedStrings #-}-module ECC.Edwards25519 ( tests ) where -import Crypto.Error-import Crypto.ECC.Edwards25519+module ECC.Edwards25519 (tests) where++import Crypto.ECC.Edwards25519+import Crypto.Error import qualified Data.ByteString as B-import Data.Word (Word8)-import Imports+import Data.Word (Word8)+import Imports instance Arbitrary Scalar where- arbitrary = fmap (throwCryptoError . scalarDecodeLong)- (arbitraryBS 64)+ arbitrary =+ fmap+ (throwCryptoError . scalarDecodeLong)+ (arbitraryBS 64) smallScalar :: Word8 -> Scalar smallScalar = throwCryptoError . scalarDecodeLong . B.singleton newtype PrimeOrder = PrimeOrder Point- deriving Show+ deriving (Show) -- points in the prime-order subgroup instance Arbitrary PrimeOrder where@@ -23,101 +26,121 @@ -- arbitrary curve point, including points with a torsion component instance Arbitrary Point where- arbitrary = do a <- arbitrary- b <- elements $ map smallScalar [0 .. 7]- return (pointsMulVarTime a b torsion8)+ arbitrary = do+ a <- arbitrary+ b <- elements $ map smallScalar [0 .. 7]+ return (pointsMulVarTime a b torsion8) -- an 8-torsion point torsion8 :: Point-torsion8 = throwCryptoError $ pointDecode ("\199\ETBjp=M\216O\186<\vv\r\DLEg\SI* S\250,9\204\198N\199\253w\146\172\ETXz" :: ByteString)+torsion8 =+ throwCryptoError $+ pointDecode+ ( "\199\ETBjp=M\216O\186<\vv\r\DLEg\SI* S\250,9\204\198N\199\253w\146\172\ETXz"+ :: ByteString+ ) -tests = testGroup "ECC.Edwards25519"- [ testGroup "vectors"- [ testCase "11*G" $ p011 @=? toPoint s011- , testCase "123*G" $ p123 @=? toPoint s123- , testCase "134*G" $ p134 @=? toPoint s134- , testCase "123*G + 11*G" $ p134 @=? pointAdd p123 p011- ]- , testGroup "scalar arithmetic"- [ testProperty "scalarDecodeLong.scalarEncode==id" $ \s ->- let bs = scalarEncode s :: ByteString- ss = scalarDecodeLong bs- in CryptoPassed s `propertyEq` ss- , testCase "curve order" $ s0 @=? sN- , testProperty "addition with zero" $ \s ->- propertyHold [ eqTest "zero left" s (scalarAdd s0 s)- , eqTest "zero right" s (scalarAdd s s0)- ]- , testProperty "addition associative" $ \sa sb sc ->- scalarAdd sa (scalarAdd sb sc) === scalarAdd (scalarAdd sa sb) sc- , testProperty "addition commutative" $ \sa sb ->- scalarAdd sa sb === scalarAdd sb sa- , testProperty "multiplication with zero" $ \s ->- propertyHold [ eqTest "zero left" s0 (scalarMul s0 s)- , eqTest "zero right" s0 (scalarMul s s0)- ]- , testProperty "multiplication with one" $ \s ->- propertyHold [ eqTest "one left" s (scalarMul s1 s)- , eqTest "one right" s (scalarMul s s1)- ]- , testProperty "multiplication associative" $ \sa sb sc ->- scalarMul sa (scalarMul sb sc) === scalarMul (scalarMul sa sb) sc- , testProperty "multiplication commutative" $ \sa sb ->- scalarMul sa sb === scalarMul sb sa- , testProperty "multiplication distributive" $ \sa sb sc ->- propertyHold [ eqTest "distributive left" ((sa `scalarMul` sb) `scalarAdd` (sa `scalarMul` sc))- (sa `scalarMul` (sb `scalarAdd` sc))- , eqTest "distributive right" ((sb `scalarMul` sa) `scalarAdd` (sc `scalarMul` sa))- ((sb `scalarAdd` sc) `scalarMul` sa)- ]- ]- , testGroup "point arithmetic"- [ testProperty "pointDecode.pointEncode==id" $ \p ->- let bs = pointEncode p :: ByteString- p' = pointDecode bs- in CryptoPassed p `propertyEq` p'- , testProperty "pointEncode.pointDecode==id" $ \p ->- let b = pointEncode p :: ByteString- p' = pointDecode b- b' = pointEncode `fmap` p'- in CryptoPassed b `propertyEq` b'- , testProperty "addition with identity" $ \p ->- propertyHold [ eqTest "identity left" p (pointAdd p0 p)- , eqTest "identity right" p (pointAdd p p0)- ]- , testProperty "addition associative" $ \pa pb pc ->- pointAdd pa (pointAdd pb pc) === pointAdd (pointAdd pa pb) pc- , testProperty "addition commutative" $ \pa pb ->- pointAdd pa pb === pointAdd pb pa- , testProperty "negation" $ \p ->- p0 `propertyEq` pointAdd p (pointNegate p)- , testProperty "doubling" $ \p ->- pointAdd p p `propertyEq` pointDouble p- , testProperty "multiplication by cofactor" $ \p ->- pointMul s8 p `propertyEq` pointMulByCofactor p- , testProperty "prime order" $ \(PrimeOrder p) ->- True `propertyEq` pointHasPrimeOrder p- , testCase "8-torsion point" $ do- assertBool "mul by 4" $ p0 /= pointMul s4 torsion8- assertBool "mul by 8" $ p0 == pointMul s8 torsion8- , testProperty "scalarmult with zero" $ \p ->- p0 `propertyEq` pointMul s0 p- , testProperty "scalarmult with one" $ \p ->- p `propertyEq` pointMul s1 p- , testProperty "scalarmult with two" $ \p ->- pointDouble p `propertyEq` pointMul s2 p- , testProperty "scalarmult with curve order - 1" $ \p ->- pointHasPrimeOrder p === (pointNegate p == pointMul sI p)- , testProperty "scalarmult commutative" $ \a b ->- pointMul a (toPoint b) === pointMul b (toPoint a)- , testProperty "scalarmult distributive" $ \x y (PrimeOrder p) ->- let pR = pointMul x p `pointAdd` pointMul y p- in pR `propertyEq` pointMul (x `scalarAdd` y) p- , testProperty "double scalarmult" $ \n1 n2 p ->- let pR = pointAdd (toPoint n1) (pointMul n2 p)- in pR `propertyEq` pointsMulVarTime n1 n2 p+tests =+ testGroup+ "ECC.Edwards25519"+ [ testGroup+ "vectors"+ [ testCase "11*G" $ p011 @=? toPoint s011+ , testCase "123*G" $ p123 @=? toPoint s123+ , testCase "134*G" $ p134 @=? toPoint s134+ , testCase "123*G + 11*G" $ p134 @=? pointAdd p123 p011+ ]+ , testGroup+ "scalar arithmetic"+ [ testProperty "scalarDecodeLong.scalarEncode==id" $ \s ->+ let bs = scalarEncode s :: ByteString+ ss = scalarDecodeLong bs+ in CryptoPassed s `propertyEq` ss+ , testCase "curve order" $ s0 @=? sN+ , testProperty "addition with zero" $ \s ->+ propertyHold+ [ eqTest "zero left" s (scalarAdd s0 s)+ , eqTest "zero right" s (scalarAdd s s0)+ ]+ , testProperty "addition associative" $ \sa sb sc ->+ scalarAdd sa (scalarAdd sb sc) === scalarAdd (scalarAdd sa sb) sc+ , testProperty "addition commutative" $ \sa sb ->+ scalarAdd sa sb === scalarAdd sb sa+ , testProperty "multiplication with zero" $ \s ->+ propertyHold+ [ eqTest "zero left" s0 (scalarMul s0 s)+ , eqTest "zero right" s0 (scalarMul s s0)+ ]+ , testProperty "multiplication with one" $ \s ->+ propertyHold+ [ eqTest "one left" s (scalarMul s1 s)+ , eqTest "one right" s (scalarMul s s1)+ ]+ , testProperty "multiplication associative" $ \sa sb sc ->+ scalarMul sa (scalarMul sb sc) === scalarMul (scalarMul sa sb) sc+ , testProperty "multiplication commutative" $ \sa sb ->+ scalarMul sa sb === scalarMul sb sa+ , testProperty "multiplication distributive" $ \sa sb sc ->+ propertyHold+ [ eqTest+ "distributive left"+ ((sa `scalarMul` sb) `scalarAdd` (sa `scalarMul` sc))+ (sa `scalarMul` (sb `scalarAdd` sc))+ , eqTest+ "distributive right"+ ((sb `scalarMul` sa) `scalarAdd` (sc `scalarMul` sa))+ ((sb `scalarAdd` sc) `scalarMul` sa)+ ]+ ]+ , testGroup+ "point arithmetic"+ [ testProperty "pointDecode.pointEncode==id" $ \p ->+ let bs = pointEncode p :: ByteString+ p' = pointDecode bs+ in CryptoPassed p `propertyEq` p'+ , testProperty "pointEncode.pointDecode==id" $ \p ->+ let b = pointEncode p :: ByteString+ p' = pointDecode b+ b' = pointEncode `fmap` p'+ in CryptoPassed b `propertyEq` b'+ , testProperty "addition with identity" $ \p ->+ propertyHold+ [ eqTest "identity left" p (pointAdd p0 p)+ , eqTest "identity right" p (pointAdd p p0)+ ]+ , testProperty "addition associative" $ \pa pb pc ->+ pointAdd pa (pointAdd pb pc) === pointAdd (pointAdd pa pb) pc+ , testProperty "addition commutative" $ \pa pb ->+ pointAdd pa pb === pointAdd pb pa+ , testProperty "negation" $ \p ->+ p0 `propertyEq` pointAdd p (pointNegate p)+ , testProperty "doubling" $ \p ->+ pointAdd p p `propertyEq` pointDouble p+ , testProperty "multiplication by cofactor" $ \p ->+ pointMul s8 p `propertyEq` pointMulByCofactor p+ , testProperty "prime order" $ \(PrimeOrder p) ->+ True `propertyEq` pointHasPrimeOrder p+ , testCase "8-torsion point" $ do+ assertBool "mul by 4" $ p0 /= pointMul s4 torsion8+ assertBool "mul by 8" $ p0 == pointMul s8 torsion8+ , testProperty "scalarmult with zero" $ \p ->+ p0 `propertyEq` pointMul s0 p+ , testProperty "scalarmult with one" $ \p ->+ p `propertyEq` pointMul s1 p+ , testProperty "scalarmult with two" $ \p ->+ pointDouble p `propertyEq` pointMul s2 p+ , testProperty "scalarmult with curve order - 1" $ \p ->+ pointHasPrimeOrder p === (pointNegate p == pointMul sI p)+ , testProperty "scalarmult commutative" $ \a b ->+ pointMul a (toPoint b) === pointMul b (toPoint a)+ , testProperty "scalarmult distributive" $ \x y (PrimeOrder p) ->+ let pR = pointMul x p `pointAdd` pointMul y p+ in pR `propertyEq` pointMul (x `scalarAdd` y) p+ , testProperty "double scalarmult" $ \n1 n2 p ->+ let pR = pointAdd (toPoint n1) (pointMul n2 p)+ in pR `propertyEq` pointsMulVarTime n1 n2 p+ ] ]- ] where p0 = toPoint s0 s0 = smallScalar 0@@ -125,23 +148,48 @@ s2 = smallScalar 2 s4 = smallScalar 4 s8 = smallScalar 8- sI = throwCryptoError $ scalarDecodeLong ("\236\211\245\\\SUBc\DC2X\214\156\247\162\222\249\222\DC4\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\DLE" :: ByteString)- sN = throwCryptoError $ scalarDecodeLong ("\237\211\245\\\SUBc\DC2X\214\156\247\162\222\249\222\DC4\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\DLE" :: ByteString)+ sI =+ throwCryptoError $+ scalarDecodeLong+ ( "\236\211\245\\\SUBc\DC2X\214\156\247\162\222\249\222\DC4\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\DLE"+ :: ByteString+ )+ sN =+ throwCryptoError $+ scalarDecodeLong+ ( "\237\211\245\\\SUBc\DC2X\214\156\247\162\222\249\222\DC4\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\DLE"+ :: ByteString+ ) s011 = throwCryptoError $ scalarDecodeLong ("\011" :: ByteString) s123 = throwCryptoError $ scalarDecodeLong ("\123" :: ByteString) s134 = throwCryptoError $ scalarDecodeLong ("\134" :: ByteString) - p011 = throwCryptoError $ pointDecode ("\x13\x37\x03\x6a\xc3\x2d\x8f\x30\xd4\x58\x9c\x3c\x1c\x59\x58\x12\xce\x0f\xff\x40\xe3\x7c\x6f\x5a\x97\xab\x21\x3f\x31\x82\x90\xad" :: ByteString)- p123 = throwCryptoError $ pointDecode ("\xc4\xb8\x00\xc8\x70\x10\xf9\x46\x83\x03\xde\xea\x87\x65\x03\xe8\x86\xbf\xde\x19\x00\xe9\xe8\x46\xfd\x4c\x3c\xd0\x9c\x1c\xbc\x9f" :: ByteString)- p134 = throwCryptoError $ pointDecode ("\x51\x20\xab\xe0\x3c\xa2\xaf\x66\xc7\x7c\xa3\x20\xf0\xb2\x1f\xb5\x56\xf6\xb6\x5f\xdd\x7e\x32\x64\xc1\x4a\x30\xd9\x7b\xf7\xa7\x6f" :: ByteString)+ p011 =+ throwCryptoError $+ pointDecode+ ( "\x13\x37\x03\x6a\xc3\x2d\x8f\x30\xd4\x58\x9c\x3c\x1c\x59\x58\x12\xce\x0f\xff\x40\xe3\x7c\x6f\x5a\x97\xab\x21\x3f\x31\x82\x90\xad"+ :: ByteString+ )+ p123 =+ throwCryptoError $+ pointDecode+ ( "\xc4\xb8\x00\xc8\x70\x10\xf9\x46\x83\x03\xde\xea\x87\x65\x03\xe8\x86\xbf\xde\x19\x00\xe9\xe8\x46\xfd\x4c\x3c\xd0\x9c\x1c\xbc\x9f"+ :: ByteString+ )+ p134 =+ throwCryptoError $+ pointDecode+ ( "\x51\x20\xab\xe0\x3c\xa2\xaf\x66\xc7\x7c\xa3\x20\xf0\xb2\x1f\xb5\x56\xf6\xb6\x5f\xdd\x7e\x32\x64\xc1\x4a\x30\xd9\x7b\xf7\xa7\x6f"+ :: ByteString+ ) - -- Using <http://cr.yp.to/python/py>:- --- -- >>> import ed25519- -- >>> encodepoint(scalarmult(B, 11)).encode('hex')- -- '1337036ac32d8f30d4589c3c1c595812ce0fff40e37c6f5a97ab213f318290ad'- -- >>> encodepoint(scalarmult(B, 123)).encode('hex')- -- 'c4b800c87010f9468303deea876503e886bfde1900e9e846fd4c3cd09c1cbc9f'- -- >>> encodepoint(scalarmult(B, 134)).encode('hex')- -- '5120abe03ca2af66c77ca320f0b21fb556f6b65fdd7e3264c14a30d97bf7a76f'+-- Using <http://cr.yp.to/python/py>:+--+-- >>> import ed25519+-- >>> encodepoint(scalarmult(B, 11)).encode('hex')+-- '1337036ac32d8f30d4589c3c1c595812ce0fff40e37c6f5a97ab213f318290ad'+-- >>> encodepoint(scalarmult(B, 123)).encode('hex')+-- 'c4b800c87010f9468303deea876503e886bfde1900e9e846fd4c3cd09c1cbc9f'+-- >>> encodepoint(scalarmult(B, 134)).encode('hex')+-- '5120abe03ca2af66c77ca320f0b21fb556f6b65fdd7e3264c14a30d97bf7a76f'
tests/ECDSA.hs view
@@ -1,61 +1,132 @@ {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts #-}+ module ECDSA (tests) where import qualified Crypto.ECC as ECDSA+import Crypto.Error+import Crypto.Hash import qualified Crypto.PubKey.ECC.ECDSA as ECC+import qualified Crypto.PubKey.ECC.Generate as ECC import qualified Crypto.PubKey.ECC.Types as ECC import qualified Crypto.PubKey.ECDSA as ECDSA-import Crypto.Hash.Algorithms-import Crypto.Error import qualified Data.ByteString as B+import Data.Maybe import Imports -data Curve = forall curve. (ECDSA.EllipticCurveECDSA curve, Show (ECDSA.Scalar curve)) => Curve curve ECC.Curve ECC.CurveName+data Curve+ = forall curve.+ (ECDSA.EllipticCurveECDSA curve, Show (ECDSA.Scalar curve)) =>+ Curve curve ECC.Curve ECC.CurveName instance Show Curve where showsPrec d (Curve _ _ name) = showsPrec d name instance Arbitrary Curve where- arbitrary = elements- [ makeCurve ECDSA.Curve_P256R1 ECC.SEC_p256r1- , makeCurve ECDSA.Curve_P384R1 ECC.SEC_p384r1- , makeCurve ECDSA.Curve_P521R1 ECC.SEC_p521r1- ]+ arbitrary =+ elements+ [ makeCurve ECDSA.Curve_P256R1 ECC.SEC_p256r1+ , makeCurve ECDSA.Curve_P384R1 ECC.SEC_p384r1+ , makeCurve ECDSA.Curve_P521R1 ECC.SEC_p521r1+ ] where makeCurve c name = Curve c (ECC.getCurveByName name) name +arbitraryScalar :: ECC.Curve -> Gen Integer arbitraryScalar curve = choose (1, n - 1)- where n = ECC.ecc_n (ECC.common_curve curve)+ where+ n = ECC.ecc_n (ECC.common_curve curve) -sigECCToECDSA :: ECDSA.EllipticCurveECDSA curve- => proxy curve -> ECC.Signature -> ECDSA.Signature curve-sigECCToECDSA prx (ECC.Signature r s) =- ECDSA.Signature (throwCryptoError $ ECDSA.scalarFromInteger prx r)- (throwCryptoError $ ECDSA.scalarFromInteger prx s)+sigECDSAtoECC+ :: ECDSA.EllipticCurveECDSA curve+ => proxy curve -> ECDSA.Signature curve -> ECC.Signature+sigECDSAtoECC prx (ECDSA.Signature r s) = ECC.Signature (ECDSA.scalarToInteger prx r) (ECDSA.scalarToInteger prx s) -tests = localOption (QuickCheckTests 5) $ testGroup "ECDSA"- [ testProperty "SHA1" $ propertyECDSA SHA1- , testProperty "SHA224" $ propertyECDSA SHA224- , testProperty "SHA256" $ propertyECDSA SHA256- , testProperty "SHA384" $ propertyECDSA SHA384- , testProperty "SHA512" $ propertyECDSA SHA512- ]+normalizeECC :: ECC.Curve -> ECC.Signature -> ECC.Signature+normalizeECC curve (ECC.Signature r s)+ | s <= n `div` 2 = ECC.Signature r s+ | otherwise = ECC.Signature r (n - s) where+ n = ECC.ecc_n $ ECC.common_curve curve++testRecover :: ECC.CurveName -> TestTree+testRecover name = testProperty (show name) $ \(ArbitraryBS0_2901 msg) -> do+ let curve = ECC.getCurveByName name+ let n = ECC.ecc_n $ ECC.common_curve curve+ k <- choose (1, n - 1)+ d <- choose (1, n - 1)+ let key = ECC.PrivateKey curve d+ let digest = hashWith SHA256 msg+ let pub =+ ECC.signExtendedDigestWith k key digest >>= \signature -> ECC.recoverDigest curve signature digest+ pure $+ propertyHold+ [eqTest "recovery" (Just $ ECC.generateQ curve d) (ECC.public_q <$> pub)]++testNormalize :: ECC.CurveName -> TestTree+testNormalize name = testProperty (show name) $ \(ArbitraryBS0_2901 msg) -> do+ let curve = ECC.getCurveByName name+ let n = ECC.ecc_n $ ECC.common_curve curve+ k <- choose (1, n - 1)+ d <- choose (1, n - 1)+ let key = ECC.PrivateKey curve d+ let digest = hashWith SHA256 msg+ let check =+ ECC.signExtendedDigestWith k key digest >>= \s -> pure $ ECC.sign_s (ECC.signature s) <= n `div` 2+ pure $ propertyHold [eqTest "normalized" (Just True) check]++tests :: TestTree+tests =+ testGroup+ "ECDSA"+ [ localOption (QuickCheckTests 5) $+ testGroup+ "verification"+ [ testProperty "SHA1" $ propertyECDSA SHA1+ , testProperty "SHA224" $ propertyECDSA SHA224+ , testProperty "SHA256" $ propertyECDSA SHA256+ , testProperty "SHA384" $ propertyECDSA SHA384+ , testProperty "SHA512" $ propertyECDSA SHA512+ ]+ , testGroup+ "recovery"+ [ localOption (QuickCheckTests 100) $ testRecover ECC.SEC_p128r1+ , localOption (QuickCheckTests 100) $ testRecover ECC.SEC_p128r2+ , localOption (QuickCheckTests 100) $ testRecover ECC.SEC_p256k1+ , localOption (QuickCheckTests 100) $ testRecover ECC.SEC_p256r1+ , localOption (QuickCheckTests 50) $ testRecover ECC.SEC_t131r1+ , localOption (QuickCheckTests 50) $ testRecover ECC.SEC_t131r2+ , localOption (QuickCheckTests 20) $ testRecover ECC.SEC_t233k1+ , localOption (QuickCheckTests 20) $ testRecover ECC.SEC_t233r1+ ]+ , testGroup+ "normalize"+ [ localOption (QuickCheckTests 100) $ testNormalize ECC.SEC_p128r1+ , localOption (QuickCheckTests 100) $ testNormalize ECC.SEC_p128r2+ , localOption (QuickCheckTests 100) $ testNormalize ECC.SEC_p256k1+ , localOption (QuickCheckTests 100) $ testNormalize ECC.SEC_p256r1+ , localOption (QuickCheckTests 50) $ testNormalize ECC.SEC_t131r1+ , localOption (QuickCheckTests 50) $ testNormalize ECC.SEC_t131r2+ , localOption (QuickCheckTests 20) $ testNormalize ECC.SEC_t233k1+ , localOption (QuickCheckTests 20) $ testNormalize ECC.SEC_t233r1+ ]+ ]+ where propertyECDSA hashAlg (Curve c curve _) (ArbitraryBS0_2901 msg) = do- d <- arbitraryScalar curve+ d <- arbitraryScalar curve kECC <- arbitraryScalar curve- let privECC = ECC.PrivateKey curve d- prx = Just c -- using Maybe as Proxy- kECDSA = throwCryptoError $ ECDSA.scalarFromInteger prx kECC+ let privECC = ECC.PrivateKey curve d+ prx = Just c -- using Maybe as Proxy+ kECDSA = throwCryptoError $ ECDSA.scalarFromInteger prx kECC privECDSA = throwCryptoError $ ECDSA.scalarFromInteger prx d- pubECDSA = ECDSA.toPublic prx privECDSA- Just sigECC = ECC.signWith kECC privECC hashAlg msg- Just sigECDSA = ECDSA.signWith prx kECDSA privECDSA hashAlg msg- sigECDSA' = sigECCToECDSA prx sigECC+ pubECDSA = ECDSA.toPublic prx privECDSA+ sigECC = fromJust $ ECC.signWith kECC privECC hashAlg msg+ sigECDSA = fromJust $ ECDSA.signWith prx kECDSA privECDSA hashAlg msg msg' = msg `B.append` B.singleton 42- return $ propertyHold [ eqTest "signature" sigECDSA sigECDSA'- , eqTest "verification" True (ECDSA.verify prx hashAlg pubECDSA sigECDSA' msg)- , eqTest "alteration" False (ECDSA.verify prx hashAlg pubECDSA sigECDSA msg')- ]+ return $+ propertyHold+ [ eqTest "signature" sigECC $ normalizeECC curve $ sigECDSAtoECC prx sigECDSA+ , eqTest "verification" True (ECDSA.verify prx hashAlg pubECDSA sigECDSA msg)+ , eqTest "alteration" False (ECDSA.verify prx hashAlg pubECDSA sigECDSA msg')+ ]
tests/Hash.hs view
@@ -1,217 +1,428 @@-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE DataKinds #-}-module Hash- ( tests- ) where+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE OverloadedStrings #-} +module Hash (+ tests,+) where+ import Crypto.Hash +import Data.ByteArray (convert)+import qualified Data.ByteArray.Encoding as B (Base (..), convertToBase) import qualified Data.ByteString as B-import Data.ByteArray (convert)-import qualified Data.ByteArray.Encoding as B (convertToBase, Base(..))-import GHC.TypeLits+import GHC.TypeLits import Imports -v0,v1,v2 :: ByteString+v0, v1, v2 :: ByteString v0 = "" v1 = "The quick brown fox jumps over the lazy dog" v2 = "The quick brown fox jumps over the lazy cog"-vectors = [ v0, v1, v2 ]+vectors = [v0, v1, v2] instance Arbitrary ByteString where arbitrary = B.pack `fmap` arbitrary -data HashAlg = forall alg . HashAlgorithm alg => HashAlg alg+data HashAlg = forall alg. HashAlgorithm alg => HashAlg alg -expected :: [ (String, HashAlg, [ByteString]) ]-expected = [- ("MD2", HashAlg MD2, [- "8350e5a3e24c153df2275c9f80692773",- "03d85a0d629d2c442e987525319fc471",- "6b890c9292668cdbbfda00a4ebf31f05" ]),- ("MD4", HashAlg MD4, [- "31d6cfe0d16ae931b73c59d7e0c089c0",- "1bee69a46ba811185c194762abaeae90",- "b86e130ce7028da59e672d56ad0113df" ]),- ("MD5", HashAlg MD5, [- "d41d8cd98f00b204e9800998ecf8427e",- "9e107d9d372bb6826bd81d3542a419d6",- "1055d3e698d289f2af8663725127bd4b" ]),- ("SHA1", HashAlg SHA1, [- "da39a3ee5e6b4b0d3255bfef95601890afd80709",- "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",- "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3" ]),- ("SHA224", HashAlg SHA224, [- "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f",- "730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525",- "fee755f44a55f20fb3362cdc3c493615b3cb574ed95ce610ee5b1e9b" ]),- ("SHA256", HashAlg SHA256, [- "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",- "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592",- "e4c4d8f3bf76b692de791a173e05321150f7a345b46484fe427f6acc7ecc81be" ]),- ("SHA384", HashAlg SHA384, [- "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b",- "ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1",- "098cea620b0978caa5f0befba6ddcf22764bea977e1c70b3483edfdf1de25f4b40d6cea3cadf00f809d422feb1f0161b" ]),- ("SHA512", HashAlg SHA512, [- "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e",- "07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6",- "3eeee1d0e11733ef152a6c29503b3ae20c4f1f3cda4cb26f1bc1a41f91c7fe4ab3bd86494049e201c4bd5155f31ecb7a3c8606843c4cc8dfcab7da11c8ae5045" ]),- ("SHA512/224", HashAlg SHA512t_224, [- "6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4",- "944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37",- "2b9d6565a7e40f780ba8ab7c8dcf41e3ed3b77997f4c55aa987eede5" ]),- ("SHA512/256", HashAlg SHA512t_256, [- "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a",- "dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d",- "cc8d255a7f2f38fd50388fd1f65ea7910835c5c1e73da46fba01ea50d5dd76fb" ]),- ("RIPEMD160", HashAlg RIPEMD160, [- "9c1185a5c5e9fc54612808977ee8f548b2258d31",- "37f332f68db77bd9d7edd4969571ad671cf9dd3b",- "132072df690933835eb8b6ad0b77e7b6f14acad7" ]),- ("Tiger", HashAlg Tiger, [- "3293ac630c13f0245f92bbb1766e16167a4e58492dde73f3",- "6d12a41e72e644f017b6f0e2f7b44c6285f06dd5d2c5b075",- "a8f04b0f7201a0d728101c9d26525b31764a3493fcd8458f" ])-{-- , ("Skein256-160", HashAlg Skein256_160, [- "ff800bed6d2044ee9d604a674e3fda50d9b24a72",- "3265703c166aa3e0d7da070b9cf1b1a5953f0a77",- "17b29aa1424b3ec022505bd215ff73fd2e6d1e5a" ])--}- , ("Skein256-256", HashAlg Skein256_256, [- "c8877087da56e072870daa843f176e9453115929094c3a40c463a196c29bf7ba",- "c0fbd7d779b20f0a4614a66697f9e41859eaf382f14bf857e8cdb210adb9b3fe",- "fb2f2f2deed0e1dd7ee2b91cee34e2d1c22072e1f5eaee288c35a0723eb653cd" ])-{-- , ("Skein512-160", HashAlg Skein512_160, [- "49daf1ccebb3544bc93cb5019ba91b0eea8876ee",- "826325ee55a6dd18c3b2dbbc9c10420f5475975e",- "7544ec7a35712ec953f02b0d0c86641cae4eb6e5" ])--}- , ("Skein512-384", HashAlg Skein512_384, [- "dd5aaf4589dc227bd1eb7bc68771f5baeaa3586ef6c7680167a023ec8ce26980f06c4082c488b4ac9ef313f8cbe70808",- "f814c107f3465e7c54048a5503547deddc377264f05c706b0d19db4847b354855ee52ab6a785c238c9e710d848542041",- "e06520eeadc1d0a44fee1d2492547499c1e58526387c8b9c53905e5edb79f9840575cbf844e21b1ad1ea126dd8a8ca6f" ])- , ("Skein512-512", HashAlg Skein512_512, [- "bc5b4c50925519c290cc634277ae3d6257212395cba733bbad37a4af0fa06af41fca7903d06564fea7a2d3730dbdb80c1f85562dfcc070334ea4d1d9e72cba7a",- "94c2ae036dba8783d0b3f7d6cc111ff810702f5c77707999be7e1c9486ff238a7044de734293147359b4ac7e1d09cd247c351d69826b78dcddd951f0ef912713",- "7f81113575e4b4d3441940e87aca331e6d63d103fe5107f29cd877af0d0f5e0ea34164258c60da5190189d0872e63a96596d2ef25e709099842da71d64111e0f" ])-{-- , ("Skein512-896", HashAlg Skein512_896, [- "b95175236c83a459ce7ec6c12b761a838b22d750e765b3fdaa892201b2aa714bc3d1d887dd64028bbf177c1dd11baa09c6c4ddb598fd07d6a8c131a09fc5b958e2999a8006754b25abe3bf8492b7eabec70e52e04e5ac867df2393c573f16eee3244554f1d2b724f2c0437c62007f770",- "3265708553e7d146e5c7bcbc97b3e9e9f5b53a5e4af53612bdd6454da4fa7b13d413184fe34ed57b6574be10e389d0ec4b1d2b1dd2c80e0257d5a76b2cd86a19a27b1bcb3cc24d911b5dc5ee74d19ad558fd85b5f024e99f56d1d3199f1f9f88ed85fab9f945f11cf9fc00e94e3ca4c7",- "3d23d3db9be719bbd2119f8402a28f38d8225faa79d5b68b80738c64a82004aafc7a840cd6dd9bced6644fa894a3d8d7d2ee89525fd1956a2db052c4c2f8d2111c91ef46b0997540d42bcf384826af1a5ef6510077f52d0574cf2b46f1b6a5dad07ed40f3d21a13ca2d079fa602ff02d" ])--}- , ("Whirlpool", HashAlg Whirlpool, [- "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3",- "b97de512e91e3828b40d2b0fdce9ceb3c4a71f9bea8d88e75c4fa854df36725fd2b52eb6544edcacd6f8beddfea403cb55ae31f03ad62a5ef54e42ee82c3fb35",- "dce81fc695cfea3d7e1446509238daf89f24cc61896f2d265927daa70f2108f8902f0dfd68be085d5abb9fcd2e482c1dc24f2fabf81f40b73495cad44d7360d3"])- , ("Keccak-224", HashAlg Keccak_224, [- "f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd",- "310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe",- "0b27ff3b732133287f6831e2af47cf342b7ef1f3fcdee248811090cd" ])- , ("Keccak-256", HashAlg Keccak_256, [- "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",- "4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15",- "ed6c07f044d7573cc53bf1276f8cba3dac497919597a45b4599c8f73e22aa334" ])- , ("Keccak-384", HashAlg Keccak_384, [- "2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff",- "283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3",- "1cc515e1812491058d8b8b226fd85045e746b4937a58b0111b6b7a39dd431b6295bd6b6d05e01e225586b4dab3cbb87a" ])- , ("Keccak-512", HashAlg Keccak_512, [- "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e",- "d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609",- "10f8caabb5b179861da5e447d34b84d604e3eb81830880e1c2135ffc94580a47cb21f6243ec0053d58b1124d13af2090033659075ee718e0f111bb3f69fb24cf" ])- , ("SHA3-224", HashAlg SHA3_224, [- "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7",- "d15dadceaa4d5d7bb3b48f446421d542e08ad8887305e28d58335795",- "b770eb6ac3ac52bd2f9e8dc186d6b604e7c3b7ffc8bd9220b0078ced" ])- , ("SHA3-256", HashAlg SHA3_256, [- "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a",- "69070dda01975c8c120c3aada1b282394e7f032fa9cf32f4cb2259a0897dfc04",- "cc80b0b13ba89613d93f02ee7ccbe72ee26c6edfe577f22e63a1380221caedbc" ])- , ("SHA3-384", HashAlg SHA3_384, [- "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004",- "7063465e08a93bce31cd89d2e3ca8f602498696e253592ed26f07bf7e703cf328581e1471a7ba7ab119b1a9ebdf8be41",- "e414797403c7d01ab64b41e90df4165d59b7f147e4292ba2da336acba242fd651949eb1cfff7e9012e134b40981842e1" ])- , ("SHA3-512", HashAlg SHA3_512, [- "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26",- "01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450",- "28e361fe8c56e617caa56c28c7c36e5c13be552b77081be82b642f08bb7ef085b9a81910fe98269386b9aacfd2349076c9506126e198f6f6ad44c12017ca77b1" ])- , ("Blake2b-160", HashAlg Blake2b_160, [- "3345524abf6bbe1809449224b5972c41790b6cf2",- "3c523ed102ab45a37d54f5610d5a983162fde84f",- "a3d365b5fba5d36fbb19c03b7fde496058969c5a" ])- , ("Blake2b-224", HashAlg Blake2b_224, [- "836cc68931c2e4e3e838602eca1902591d216837bafddfe6f0c8cb07",- "477c3985751dd4d1b8c93827ea5310b33bb02a26463a050dffd3e857",- "a4a1b6851be66891a3deff406c4d7556879ebf952407450755f90eb6" ])- , ("Blake2b-256", HashAlg Blake2b_256, [- "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8",- "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9",- "036c13096926b3dfccfe3f233bd1b2f583b818b8b15c01be65af69238e900b2c" ])- , ("Blake2b-384", HashAlg Blake2b_384, [- "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100",- "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d",- "927a1f297873cbe887a93b2183c4e2eba53966ba92c6db8b87029a1d8c673471d09740676cced79c5016838973f630c3" ])- , ("Blake2b-512", HashAlg Blake2b_512, [- "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce",- "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918",- "af438eea5d8cdb209336a7e85bf58090dc21b49d823f89a7d064c119f127bd361af9c7d109edda0f0e91bdce078d1d86b8e6f25727c98f6d3bb6f50acb2dd376" ])- , ("Blake2s-160", HashAlg Blake2s_160, [- "354c9c33f735962418bdacb9479873429c34916f",- "5a604fec9713c369e84b0ed68daed7d7504ef240",- "759bef6d041bcbd861b8b51baaece6c8fffd0acf" ])- , ("Blake2s-224", HashAlg Blake2s_224, [- "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4",- "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912",- "e220025fd46a9a635c3f7f60bb96a84c01019ac0817f5901e7eeaa2c" ])- , ("Blake2s-256", HashAlg Blake2s_256, [- "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9",- "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812",- "94662583a600a12dff357c0a6f1b514a710ef0f587a38e8d2e4d7f67e9c81667" ])- , ("SHAKE128_4096", HashAlg (SHAKE128 :: SHAKE128 4096), [- "7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef263cb1eea988004b93103cfb0aeefd2a686e01fa4a58e8a3639ca8a1e3f9ae57e235b8cc873c23dc62b8d260169afa2f75ab916a58d974918835d25e6a435085b2badfd6dfaac359a5efbb7bcc4b59d538df9a04302e10c8bc1cbf1a0b3a5120ea17cda7cfad765f5623474d368ccca8af0007cd9f5e4c849f167a580b14aabdefaee7eef47cb0fca9767be1fda69419dfb927e9df07348b196691abaeb580b32def58538b8d23f87732ea63b02b4fa0f4873360e2841928cd60dd4cee8cc0d4c922a96188d032675c8ac850933c7aff1533b94c834adbb69c6115bad4692d8619f90b0cdf8a7b9c264029ac185b70b83f2801f2f4b3f70c593ea3aeeb613a7f1b1de33fd75081f592305f2e4526edc09631b10958f464d889f31ba010250fda7f1368ec2967fc84ef2ae9aff268e0b1700affc6820b523a3d917135f2dff2ee06bfe72b3124721d4a26c04e53a75e30e73a7a9c4a95d91c55d495e9f51dd0b5e9d83c6d5e8ce803aa62b8d654db53d09b8dcff273cdfeb573fad8bcd45578bec2e770d01efde86e721a3f7c6cce275dabe6e2143f1af18da7efddc4c7b70b5e345db93cc936bea323491ccb38a388f546a9ff00dd4e1300b9b2153d2041d205b443e41b45a653f2a5c4492c1add544512dda2529833462b71a41a45be97290b6f",- "f4202e3c5852f9182a0430fd8144f0a74b95e7417ecae17db0f8cfeed0e3e66eb5585ec6f86021cacf272c798bcf97d368b886b18fec3a571f096086a523717a3732d50db2b0b7998b4117ae66a761ccf1847a1616f4c07d5178d0d965f9feba351420f8bfb6f5ab9a0cb102568eabf3dfa4e22279f8082dce8143eb78235a1a54914ab71abb07f2f3648468370b9fbb071e074f1c030a4030225f40c39480339f3dc71d0f04f71326de1381674cc89e259e219927fae8ea2799a03da862a55afafe670957a2af3318d919d0a3358f3b891236d6a8e8d19999d1076b529968faefbd880d77bb300829dca87e9c8e4c28e0800ff37490a5bd8c36c0b0bdb2701a5d58d03378b9dbd384389e3ef0fd4003b08998fd3f32fe1a0810fc0eccaad94bca8dd83b34559c333f0b16dfc2896ed87b30ba14c81f87cd8b4bb6317db89b0e7e94c0616f9a665fba5b0e6fb3549c9d7b68e66d08a86eb2faec05cc462a771806b93cc38b0a4feb9935c6c8945da6a589891ba5ee99753cfdd38e1abc7147fd74b7c7d1ce0609b6680a2e18888d84949b6e6cf6a2aa4113535aaee079459e3f257b569a9450523c41f5b5ba4b79b3ba5949140a74bb048de0657d04954bdd71dae76f61e2a1f88aecb91cfa5b36c1bf3350a798dc4dcf48628effe3a0c5340c756bd922f78d0e36ef7df12ce78c179cc721ad087e15ea496bf5f60b21b5822d",- "22fd225fb8f2c8d0d2097e1f8d38b6a9e619d39664dad3795f0336fda544d305e1be56a9953ecd6e4bec14b622f53da492eccbe257b9af84775a6bdf81aab6b1ba3492149b7ce4ea402c56e343939f78b9a9727193269798420c9323a9eb1fa63006e1482fcf15e3696aa1ae5cb66eb8aad4ac6041ca0b576b78785ad95bc5fb6f8a420ba9e1726552c0f2b97050ae69fc018d3f63b3a812a2d39ef64b8ae368472dec4341511b02cf77363c74f216055d5905412bc2bf57b4010b1bdce2882cb28fc7e4d470ed05219fc4d1ce11d11e10db369c807cd71891653638956b2f9d176e116188aff2fbb8519d9ad8c3fb52fa8bb4a0413364e89d9f9d7db627f2a2288babedcc314a19e45c6b7fb93b16a15d9953ff619ab4d523c481552588f711b450f854c858ebcb8cf49492d6240a753bde2109c486cac666bdba767c6e9254cc723f67855534c34d08ed486c67c1b8dd288c6010ce8e6c1c9b7f927acf4d71ee99729cee55ecec544245d0b51b31dd78eb99c2723e8ba5cf92ac7720e8933d9fd3596b90073f6980c5ed3f1cbfada26bdb6946e72391198e3d1cedebdba092324500e32b8e04e32550f6dd6c4befafa95acc206c5708300d2a8df2765751102f9738a1449c4c0d588f0076d0c1a5ee445eb85c97ada5837d5dc1d34ea081c8411d64a4d9ce9279bfe9feb25696cf741c705ed46f171e2239216d6c45dc8d15" ])- , ("SHAKE256_4096", HashAlg (SHAKE256 :: SHAKE256 4096), [- "46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec468a2d621a7c06c6a957c62b54dafc3be87567d677231395f6147293b68ceab7a9e0c58d864e8efde4e1b9a46cbe854713672f5caaae314ed9083dab4b099f8e300f01b8650f1f4b1d8fcf3f3cb53fb8e9eb2ea203bdc970f50ae55428a91f7f53ac266b28419c3778a15fd248d339ede785fb7f5a1aaa96d313eacc890936c173cdcd0fab882c45755feb3aed96d477ff96390bf9a66d1368b208e21f7c10d04a3dbd4e360633e5db4b602601c14cea737db3dcf722632cc77851cbdde2aaf0a33a07b373445df490cc8fc1e4160ff118378f11f0477de055a81a9eda57a4a2cfb0c83929d310912f729ec6cfa36c6ac6a75837143045d791cc85eff5b21932f23861bcf23a52b5da67eaf7baae0f5fb1369db78f3ac45f8c4ac5671d85735cdddb09d2b1e34a1fc066ff4a162cb263d6541274ae2fcc865f618abe27c124cd8b074ccd516301b91875824d09958f341ef274bdab0bae316339894304e35877b0c28a9b1fd166c796b9cc258a064a8f57e27f2a",- "2f671343d9b2e1604dc9dcf0753e5fe15c7c64a0d283cbbf722d411a0e36f6ca1d01d1369a23539cd80f7c054b6e5daf9c962cad5b8ed5bd11998b40d5734442bed798f6e5c915bd8bb07e0188d0a55c1290074f1c287af06352299184492cbdec9acba737ee292e5adaa445547355e72a03a3bac3aac770fe5d6b66600ff15d37d5b4789994ea2aeb097f550aa5e88e4d8ff0ba07b88c1c88573063f5d96df820abc2abd177ab037f351c375e553af917132cf2f563c79a619e1bb76e8e2266b0c5617d695f2c496a25f4073b6840c1833757ebb386f16757a8e16a21e9355e9b248f3b33be672da700266be99b8f8725e8ab06075f0219e655ebc188976364b7db139390d34a6ea67b4b223229183a94cf455ece91fdaf5b9c707fa4b40ec39816c1120c7aaaf47920977be900e6b9ca4b8940e192b927c475bd58e836f512ae3e52924e36ff8e9b1d0251047770a5e465905622b1f159be121ab93819c5e5c6dae299ac73bf1c4ed4a1e2c7fa3caa1039b05e94c9f993d04feb272b6e00bb0276939cf746c42936831fc8f2b4cb0cf94808ae0af405ce4bc67d1e7acfc6fd6590d3de91f795df5aaf57e2cee1845a303d0ea564be3f1299acdce67efe0d62cfc6d6829ff4ecc0a05153c24696c4d34c076453827e796f3062f94f62f4528b7cfc870f0dcd615b7c97b95da4b9be5830e8b3f66cce71e0f622c771994443e2",- "fffcaac0606c0edb7bc0d15f033accb68538159016e5ae8470bf9ebea89fa6c9fcc3e027d94f7f967b7246346bd9f6b8084e45a057b976847c4db03bf383c834054866f6a8282a497368c46e1852fc09e20f22c45607a27c8b2a4798ebefada54f8d3795b9f07606b1cd6e41f90d765480ef5c0d5790659cf1d210adfd412378b92e1dd9bd7fd95a1a66677fc6baa0e3a53c9031c1fb59cbad9f5dc5881a3c8e25c80ecb1abf0971488ada1f533dcbf8d37031335378574b8d3fad61159c9fae28caa543b3072ce308d369be340e78c6edc664cc6dde9b2f0a4ad2e60ce9c8b1e5722b8d5b73d0962b74fb9ed86307a180f53933339f9d56d3b345c2a0e98fcf5de7754f3845f6be30089f0e142ad4602f18abdc750bda7c91c3f32872e66640db46045ab4c276b379f1b834c2cbb1bd8601305649ec6b3bf20618695136dee6541492d1d985ea1fb765fd7a559e810eba30f2f710233ae5a411b94ddcaa01a08f1c31320d111c0714422cd5e987c9a76fc865de34003ab12664081be8017d23d977f2bf4ed9e3ce09ea3d64bb4ae8ebfa9d0721f57841008c297e2f455a0441a2bd618ca379dbd239a21e410defb4001b1e11f87e36bf894c222f76f12ddcc3771bbb17d5c0dfd86d89a3e13e084f6dc1c4762bcd393c1757db7afb1434221569e7ddaaffd6318253ec3df8cf5f826b81896d6474ee06a2e30ccc8c6a96bdd5" ])- , ("Blake2b 160", HashAlg (Blake2b :: Blake2b 160), [- "3345524abf6bbe1809449224b5972c41790b6cf2",- "3c523ed102ab45a37d54f5610d5a983162fde84f",- "a3d365b5fba5d36fbb19c03b7fde496058969c5a" ])- , ("Blake2b 224", HashAlg (Blake2b :: Blake2b 224), [- "836cc68931c2e4e3e838602eca1902591d216837bafddfe6f0c8cb07",- "477c3985751dd4d1b8c93827ea5310b33bb02a26463a050dffd3e857",- "a4a1b6851be66891a3deff406c4d7556879ebf952407450755f90eb6" ])- , ("Blake2b 256", HashAlg (Blake2b :: Blake2b 256), [- "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8",- "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9",- "036c13096926b3dfccfe3f233bd1b2f583b818b8b15c01be65af69238e900b2c" ])- , ("Blake2b 384", HashAlg (Blake2b :: Blake2b 384), [- "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100",- "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d",- "927a1f297873cbe887a93b2183c4e2eba53966ba92c6db8b87029a1d8c673471d09740676cced79c5016838973f630c3" ])- , ("Blake2b 512", HashAlg (Blake2b :: Blake2b 512), [- "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce",- "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918",- "af438eea5d8cdb209336a7e85bf58090dc21b49d823f89a7d064c119f127bd361af9c7d109edda0f0e91bdce078d1d86b8e6f25727c98f6d3bb6f50acb2dd376" ])- , ("Blake2s 160", HashAlg (Blake2s :: Blake2s 160), [- "354c9c33f735962418bdacb9479873429c34916f",- "5a604fec9713c369e84b0ed68daed7d7504ef240",- "759bef6d041bcbd861b8b51baaece6c8fffd0acf" ])- , ("Blake2s 224", HashAlg (Blake2s :: Blake2s 224), [- "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4",- "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912",- "e220025fd46a9a635c3f7f60bb96a84c01019ac0817f5901e7eeaa2c" ])- , ("Blake2s 256", HashAlg (Blake2s ::Blake2s 256), [- "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9",- "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812",- "94662583a600a12dff357c0a6f1b514a710ef0f587a38e8d2e4d7f67e9c81667" ])+expected :: [(String, HashAlg, [ByteString])]+expected =+ [+ ( "MD2"+ , HashAlg MD2+ ,+ [ "8350e5a3e24c153df2275c9f80692773"+ , "03d85a0d629d2c442e987525319fc471"+ , "6b890c9292668cdbbfda00a4ebf31f05"+ ]+ )+ ,+ ( "MD4"+ , HashAlg MD4+ ,+ [ "31d6cfe0d16ae931b73c59d7e0c089c0"+ , "1bee69a46ba811185c194762abaeae90"+ , "b86e130ce7028da59e672d56ad0113df"+ ]+ )+ ,+ ( "MD5"+ , HashAlg MD5+ ,+ [ "d41d8cd98f00b204e9800998ecf8427e"+ , "9e107d9d372bb6826bd81d3542a419d6"+ , "1055d3e698d289f2af8663725127bd4b"+ ]+ )+ ,+ ( "SHA1"+ , HashAlg SHA1+ ,+ [ "da39a3ee5e6b4b0d3255bfef95601890afd80709"+ , "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"+ , "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3"+ ]+ )+ ,+ ( "SHA224"+ , HashAlg SHA224+ ,+ [ "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f"+ , "730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525"+ , "fee755f44a55f20fb3362cdc3c493615b3cb574ed95ce610ee5b1e9b"+ ]+ )+ ,+ ( "SHA256"+ , HashAlg SHA256+ ,+ [ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"+ , "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"+ , "e4c4d8f3bf76b692de791a173e05321150f7a345b46484fe427f6acc7ecc81be"+ ]+ )+ ,+ ( "SHA384"+ , HashAlg SHA384+ ,+ [ "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"+ , "ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1"+ , "098cea620b0978caa5f0befba6ddcf22764bea977e1c70b3483edfdf1de25f4b40d6cea3cadf00f809d422feb1f0161b"+ ]+ )+ ,+ ( "SHA512"+ , HashAlg SHA512+ ,+ [ "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"+ , "07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6"+ , "3eeee1d0e11733ef152a6c29503b3ae20c4f1f3cda4cb26f1bc1a41f91c7fe4ab3bd86494049e201c4bd5155f31ecb7a3c8606843c4cc8dfcab7da11c8ae5045"+ ]+ )+ ,+ ( "SHA512/224"+ , HashAlg SHA512t_224+ ,+ [ "6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4"+ , "944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37"+ , "2b9d6565a7e40f780ba8ab7c8dcf41e3ed3b77997f4c55aa987eede5"+ ]+ )+ ,+ ( "SHA512/256"+ , HashAlg SHA512t_256+ ,+ [ "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a"+ , "dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d"+ , "cc8d255a7f2f38fd50388fd1f65ea7910835c5c1e73da46fba01ea50d5dd76fb"+ ]+ )+ ,+ ( "RIPEMD160"+ , HashAlg RIPEMD160+ ,+ [ "9c1185a5c5e9fc54612808977ee8f548b2258d31"+ , "37f332f68db77bd9d7edd4969571ad671cf9dd3b"+ , "132072df690933835eb8b6ad0b77e7b6f14acad7"+ ]+ )+ ,+ ( "Tiger"+ , HashAlg Tiger+ ,+ [ "3293ac630c13f0245f92bbb1766e16167a4e58492dde73f3"+ , "6d12a41e72e644f017b6f0e2f7b44c6285f06dd5d2c5b075"+ , "a8f04b0f7201a0d728101c9d26525b31764a3493fcd8458f"+ ]+ )+ , {-+ , ("Skein256-160", HashAlg Skein256_160, [+ "ff800bed6d2044ee9d604a674e3fda50d9b24a72",+ "3265703c166aa3e0d7da070b9cf1b1a5953f0a77",+ "17b29aa1424b3ec022505bd215ff73fd2e6d1e5a" ])+ -}++ ( "Skein256-256"+ , HashAlg Skein256_256+ ,+ [ "c8877087da56e072870daa843f176e9453115929094c3a40c463a196c29bf7ba"+ , "c0fbd7d779b20f0a4614a66697f9e41859eaf382f14bf857e8cdb210adb9b3fe"+ , "fb2f2f2deed0e1dd7ee2b91cee34e2d1c22072e1f5eaee288c35a0723eb653cd"+ ]+ )+ , {-+ , ("Skein512-160", HashAlg Skein512_160, [+ "49daf1ccebb3544bc93cb5019ba91b0eea8876ee",+ "826325ee55a6dd18c3b2dbbc9c10420f5475975e",+ "7544ec7a35712ec953f02b0d0c86641cae4eb6e5" ])+ -}++ ( "Skein512-384"+ , HashAlg Skein512_384+ ,+ [ "dd5aaf4589dc227bd1eb7bc68771f5baeaa3586ef6c7680167a023ec8ce26980f06c4082c488b4ac9ef313f8cbe70808"+ , "f814c107f3465e7c54048a5503547deddc377264f05c706b0d19db4847b354855ee52ab6a785c238c9e710d848542041"+ , "e06520eeadc1d0a44fee1d2492547499c1e58526387c8b9c53905e5edb79f9840575cbf844e21b1ad1ea126dd8a8ca6f"+ ]+ )+ ,+ ( "Skein512-512"+ , HashAlg Skein512_512+ ,+ [ "bc5b4c50925519c290cc634277ae3d6257212395cba733bbad37a4af0fa06af41fca7903d06564fea7a2d3730dbdb80c1f85562dfcc070334ea4d1d9e72cba7a"+ , "94c2ae036dba8783d0b3f7d6cc111ff810702f5c77707999be7e1c9486ff238a7044de734293147359b4ac7e1d09cd247c351d69826b78dcddd951f0ef912713"+ , "7f81113575e4b4d3441940e87aca331e6d63d103fe5107f29cd877af0d0f5e0ea34164258c60da5190189d0872e63a96596d2ef25e709099842da71d64111e0f"+ ]+ )+ , {-+ , ("Skein512-896", HashAlg Skein512_896, [+ "b95175236c83a459ce7ec6c12b761a838b22d750e765b3fdaa892201b2aa714bc3d1d887dd64028bbf177c1dd11baa09c6c4ddb598fd07d6a8c131a09fc5b958e2999a8006754b25abe3bf8492b7eabec70e52e04e5ac867df2393c573f16eee3244554f1d2b724f2c0437c62007f770",+ "3265708553e7d146e5c7bcbc97b3e9e9f5b53a5e4af53612bdd6454da4fa7b13d413184fe34ed57b6574be10e389d0ec4b1d2b1dd2c80e0257d5a76b2cd86a19a27b1bcb3cc24d911b5dc5ee74d19ad558fd85b5f024e99f56d1d3199f1f9f88ed85fab9f945f11cf9fc00e94e3ca4c7",+ "3d23d3db9be719bbd2119f8402a28f38d8225faa79d5b68b80738c64a82004aafc7a840cd6dd9bced6644fa894a3d8d7d2ee89525fd1956a2db052c4c2f8d2111c91ef46b0997540d42bcf384826af1a5ef6510077f52d0574cf2b46f1b6a5dad07ed40f3d21a13ca2d079fa602ff02d" ])+ -}++ ( "Whirlpool"+ , HashAlg Whirlpool+ ,+ [ "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3"+ , "b97de512e91e3828b40d2b0fdce9ceb3c4a71f9bea8d88e75c4fa854df36725fd2b52eb6544edcacd6f8beddfea403cb55ae31f03ad62a5ef54e42ee82c3fb35"+ , "dce81fc695cfea3d7e1446509238daf89f24cc61896f2d265927daa70f2108f8902f0dfd68be085d5abb9fcd2e482c1dc24f2fabf81f40b73495cad44d7360d3"+ ]+ )+ ,+ ( "Keccak-224"+ , HashAlg Keccak_224+ ,+ [ "f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd"+ , "310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe"+ , "0b27ff3b732133287f6831e2af47cf342b7ef1f3fcdee248811090cd"+ ]+ )+ ,+ ( "Keccak-256"+ , HashAlg Keccak_256+ ,+ [ "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"+ , "4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15"+ , "ed6c07f044d7573cc53bf1276f8cba3dac497919597a45b4599c8f73e22aa334"+ ]+ )+ ,+ ( "Keccak-384"+ , HashAlg Keccak_384+ ,+ [ "2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff"+ , "283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3"+ , "1cc515e1812491058d8b8b226fd85045e746b4937a58b0111b6b7a39dd431b6295bd6b6d05e01e225586b4dab3cbb87a"+ ]+ )+ ,+ ( "Keccak-512"+ , HashAlg Keccak_512+ ,+ [ "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e"+ , "d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609"+ , "10f8caabb5b179861da5e447d34b84d604e3eb81830880e1c2135ffc94580a47cb21f6243ec0053d58b1124d13af2090033659075ee718e0f111bb3f69fb24cf"+ ]+ )+ ,+ ( "SHA3-224"+ , HashAlg SHA3_224+ ,+ [ "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7"+ , "d15dadceaa4d5d7bb3b48f446421d542e08ad8887305e28d58335795"+ , "b770eb6ac3ac52bd2f9e8dc186d6b604e7c3b7ffc8bd9220b0078ced"+ ]+ )+ ,+ ( "SHA3-256"+ , HashAlg SHA3_256+ ,+ [ "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a"+ , "69070dda01975c8c120c3aada1b282394e7f032fa9cf32f4cb2259a0897dfc04"+ , "cc80b0b13ba89613d93f02ee7ccbe72ee26c6edfe577f22e63a1380221caedbc"+ ]+ )+ ,+ ( "SHA3-384"+ , HashAlg SHA3_384+ ,+ [ "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004"+ , "7063465e08a93bce31cd89d2e3ca8f602498696e253592ed26f07bf7e703cf328581e1471a7ba7ab119b1a9ebdf8be41"+ , "e414797403c7d01ab64b41e90df4165d59b7f147e4292ba2da336acba242fd651949eb1cfff7e9012e134b40981842e1"+ ]+ )+ ,+ ( "SHA3-512"+ , HashAlg SHA3_512+ ,+ [ "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26"+ , "01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450"+ , "28e361fe8c56e617caa56c28c7c36e5c13be552b77081be82b642f08bb7ef085b9a81910fe98269386b9aacfd2349076c9506126e198f6f6ad44c12017ca77b1"+ ]+ )+ ,+ ( "Blake2b-160"+ , HashAlg Blake2b_160+ ,+ [ "3345524abf6bbe1809449224b5972c41790b6cf2"+ , "3c523ed102ab45a37d54f5610d5a983162fde84f"+ , "a3d365b5fba5d36fbb19c03b7fde496058969c5a"+ ]+ )+ ,+ ( "Blake2b-224"+ , HashAlg Blake2b_224+ ,+ [ "836cc68931c2e4e3e838602eca1902591d216837bafddfe6f0c8cb07"+ , "477c3985751dd4d1b8c93827ea5310b33bb02a26463a050dffd3e857"+ , "a4a1b6851be66891a3deff406c4d7556879ebf952407450755f90eb6"+ ]+ )+ ,+ ( "Blake2b-256"+ , HashAlg Blake2b_256+ ,+ [ "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"+ , "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"+ , "036c13096926b3dfccfe3f233bd1b2f583b818b8b15c01be65af69238e900b2c"+ ]+ )+ ,+ ( "Blake2b-384"+ , HashAlg Blake2b_384+ ,+ [ "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100"+ , "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d"+ , "927a1f297873cbe887a93b2183c4e2eba53966ba92c6db8b87029a1d8c673471d09740676cced79c5016838973f630c3"+ ]+ )+ ,+ ( "Blake2b-512"+ , HashAlg Blake2b_512+ ,+ [ "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce"+ , "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918"+ , "af438eea5d8cdb209336a7e85bf58090dc21b49d823f89a7d064c119f127bd361af9c7d109edda0f0e91bdce078d1d86b8e6f25727c98f6d3bb6f50acb2dd376"+ ]+ )+ ,+ ( "Blake2s-160"+ , HashAlg Blake2s_160+ ,+ [ "354c9c33f735962418bdacb9479873429c34916f"+ , "5a604fec9713c369e84b0ed68daed7d7504ef240"+ , "759bef6d041bcbd861b8b51baaece6c8fffd0acf"+ ]+ )+ ,+ ( "Blake2s-224"+ , HashAlg Blake2s_224+ ,+ [ "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4"+ , "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912"+ , "e220025fd46a9a635c3f7f60bb96a84c01019ac0817f5901e7eeaa2c"+ ]+ )+ ,+ ( "Blake2s-256"+ , HashAlg Blake2s_256+ ,+ [ "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9"+ , "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812"+ , "94662583a600a12dff357c0a6f1b514a710ef0f587a38e8d2e4d7f67e9c81667"+ ]+ )+ ,+ ( "SHAKE128_4096"+ , HashAlg (SHAKE128 :: SHAKE128 4096)+ ,+ [ "7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef263cb1eea988004b93103cfb0aeefd2a686e01fa4a58e8a3639ca8a1e3f9ae57e235b8cc873c23dc62b8d260169afa2f75ab916a58d974918835d25e6a435085b2badfd6dfaac359a5efbb7bcc4b59d538df9a04302e10c8bc1cbf1a0b3a5120ea17cda7cfad765f5623474d368ccca8af0007cd9f5e4c849f167a580b14aabdefaee7eef47cb0fca9767be1fda69419dfb927e9df07348b196691abaeb580b32def58538b8d23f87732ea63b02b4fa0f4873360e2841928cd60dd4cee8cc0d4c922a96188d032675c8ac850933c7aff1533b94c834adbb69c6115bad4692d8619f90b0cdf8a7b9c264029ac185b70b83f2801f2f4b3f70c593ea3aeeb613a7f1b1de33fd75081f592305f2e4526edc09631b10958f464d889f31ba010250fda7f1368ec2967fc84ef2ae9aff268e0b1700affc6820b523a3d917135f2dff2ee06bfe72b3124721d4a26c04e53a75e30e73a7a9c4a95d91c55d495e9f51dd0b5e9d83c6d5e8ce803aa62b8d654db53d09b8dcff273cdfeb573fad8bcd45578bec2e770d01efde86e721a3f7c6cce275dabe6e2143f1af18da7efddc4c7b70b5e345db93cc936bea323491ccb38a388f546a9ff00dd4e1300b9b2153d2041d205b443e41b45a653f2a5c4492c1add544512dda2529833462b71a41a45be97290b6f"+ , "f4202e3c5852f9182a0430fd8144f0a74b95e7417ecae17db0f8cfeed0e3e66eb5585ec6f86021cacf272c798bcf97d368b886b18fec3a571f096086a523717a3732d50db2b0b7998b4117ae66a761ccf1847a1616f4c07d5178d0d965f9feba351420f8bfb6f5ab9a0cb102568eabf3dfa4e22279f8082dce8143eb78235a1a54914ab71abb07f2f3648468370b9fbb071e074f1c030a4030225f40c39480339f3dc71d0f04f71326de1381674cc89e259e219927fae8ea2799a03da862a55afafe670957a2af3318d919d0a3358f3b891236d6a8e8d19999d1076b529968faefbd880d77bb300829dca87e9c8e4c28e0800ff37490a5bd8c36c0b0bdb2701a5d58d03378b9dbd384389e3ef0fd4003b08998fd3f32fe1a0810fc0eccaad94bca8dd83b34559c333f0b16dfc2896ed87b30ba14c81f87cd8b4bb6317db89b0e7e94c0616f9a665fba5b0e6fb3549c9d7b68e66d08a86eb2faec05cc462a771806b93cc38b0a4feb9935c6c8945da6a589891ba5ee99753cfdd38e1abc7147fd74b7c7d1ce0609b6680a2e18888d84949b6e6cf6a2aa4113535aaee079459e3f257b569a9450523c41f5b5ba4b79b3ba5949140a74bb048de0657d04954bdd71dae76f61e2a1f88aecb91cfa5b36c1bf3350a798dc4dcf48628effe3a0c5340c756bd922f78d0e36ef7df12ce78c179cc721ad087e15ea496bf5f60b21b5822d"+ , "22fd225fb8f2c8d0d2097e1f8d38b6a9e619d39664dad3795f0336fda544d305e1be56a9953ecd6e4bec14b622f53da492eccbe257b9af84775a6bdf81aab6b1ba3492149b7ce4ea402c56e343939f78b9a9727193269798420c9323a9eb1fa63006e1482fcf15e3696aa1ae5cb66eb8aad4ac6041ca0b576b78785ad95bc5fb6f8a420ba9e1726552c0f2b97050ae69fc018d3f63b3a812a2d39ef64b8ae368472dec4341511b02cf77363c74f216055d5905412bc2bf57b4010b1bdce2882cb28fc7e4d470ed05219fc4d1ce11d11e10db369c807cd71891653638956b2f9d176e116188aff2fbb8519d9ad8c3fb52fa8bb4a0413364e89d9f9d7db627f2a2288babedcc314a19e45c6b7fb93b16a15d9953ff619ab4d523c481552588f711b450f854c858ebcb8cf49492d6240a753bde2109c486cac666bdba767c6e9254cc723f67855534c34d08ed486c67c1b8dd288c6010ce8e6c1c9b7f927acf4d71ee99729cee55ecec544245d0b51b31dd78eb99c2723e8ba5cf92ac7720e8933d9fd3596b90073f6980c5ed3f1cbfada26bdb6946e72391198e3d1cedebdba092324500e32b8e04e32550f6dd6c4befafa95acc206c5708300d2a8df2765751102f9738a1449c4c0d588f0076d0c1a5ee445eb85c97ada5837d5dc1d34ea081c8411d64a4d9ce9279bfe9feb25696cf741c705ed46f171e2239216d6c45dc8d15"+ ]+ )+ ,+ ( "SHAKE256_4096"+ , HashAlg (SHAKE256 :: SHAKE256 4096)+ ,+ [ "46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec468a2d621a7c06c6a957c62b54dafc3be87567d677231395f6147293b68ceab7a9e0c58d864e8efde4e1b9a46cbe854713672f5caaae314ed9083dab4b099f8e300f01b8650f1f4b1d8fcf3f3cb53fb8e9eb2ea203bdc970f50ae55428a91f7f53ac266b28419c3778a15fd248d339ede785fb7f5a1aaa96d313eacc890936c173cdcd0fab882c45755feb3aed96d477ff96390bf9a66d1368b208e21f7c10d04a3dbd4e360633e5db4b602601c14cea737db3dcf722632cc77851cbdde2aaf0a33a07b373445df490cc8fc1e4160ff118378f11f0477de055a81a9eda57a4a2cfb0c83929d310912f729ec6cfa36c6ac6a75837143045d791cc85eff5b21932f23861bcf23a52b5da67eaf7baae0f5fb1369db78f3ac45f8c4ac5671d85735cdddb09d2b1e34a1fc066ff4a162cb263d6541274ae2fcc865f618abe27c124cd8b074ccd516301b91875824d09958f341ef274bdab0bae316339894304e35877b0c28a9b1fd166c796b9cc258a064a8f57e27f2a"+ , "2f671343d9b2e1604dc9dcf0753e5fe15c7c64a0d283cbbf722d411a0e36f6ca1d01d1369a23539cd80f7c054b6e5daf9c962cad5b8ed5bd11998b40d5734442bed798f6e5c915bd8bb07e0188d0a55c1290074f1c287af06352299184492cbdec9acba737ee292e5adaa445547355e72a03a3bac3aac770fe5d6b66600ff15d37d5b4789994ea2aeb097f550aa5e88e4d8ff0ba07b88c1c88573063f5d96df820abc2abd177ab037f351c375e553af917132cf2f563c79a619e1bb76e8e2266b0c5617d695f2c496a25f4073b6840c1833757ebb386f16757a8e16a21e9355e9b248f3b33be672da700266be99b8f8725e8ab06075f0219e655ebc188976364b7db139390d34a6ea67b4b223229183a94cf455ece91fdaf5b9c707fa4b40ec39816c1120c7aaaf47920977be900e6b9ca4b8940e192b927c475bd58e836f512ae3e52924e36ff8e9b1d0251047770a5e465905622b1f159be121ab93819c5e5c6dae299ac73bf1c4ed4a1e2c7fa3caa1039b05e94c9f993d04feb272b6e00bb0276939cf746c42936831fc8f2b4cb0cf94808ae0af405ce4bc67d1e7acfc6fd6590d3de91f795df5aaf57e2cee1845a303d0ea564be3f1299acdce67efe0d62cfc6d6829ff4ecc0a05153c24696c4d34c076453827e796f3062f94f62f4528b7cfc870f0dcd615b7c97b95da4b9be5830e8b3f66cce71e0f622c771994443e2"+ , "fffcaac0606c0edb7bc0d15f033accb68538159016e5ae8470bf9ebea89fa6c9fcc3e027d94f7f967b7246346bd9f6b8084e45a057b976847c4db03bf383c834054866f6a8282a497368c46e1852fc09e20f22c45607a27c8b2a4798ebefada54f8d3795b9f07606b1cd6e41f90d765480ef5c0d5790659cf1d210adfd412378b92e1dd9bd7fd95a1a66677fc6baa0e3a53c9031c1fb59cbad9f5dc5881a3c8e25c80ecb1abf0971488ada1f533dcbf8d37031335378574b8d3fad61159c9fae28caa543b3072ce308d369be340e78c6edc664cc6dde9b2f0a4ad2e60ce9c8b1e5722b8d5b73d0962b74fb9ed86307a180f53933339f9d56d3b345c2a0e98fcf5de7754f3845f6be30089f0e142ad4602f18abdc750bda7c91c3f32872e66640db46045ab4c276b379f1b834c2cbb1bd8601305649ec6b3bf20618695136dee6541492d1d985ea1fb765fd7a559e810eba30f2f710233ae5a411b94ddcaa01a08f1c31320d111c0714422cd5e987c9a76fc865de34003ab12664081be8017d23d977f2bf4ed9e3ce09ea3d64bb4ae8ebfa9d0721f57841008c297e2f455a0441a2bd618ca379dbd239a21e410defb4001b1e11f87e36bf894c222f76f12ddcc3771bbb17d5c0dfd86d89a3e13e084f6dc1c4762bcd393c1757db7afb1434221569e7ddaaffd6318253ec3df8cf5f826b81896d6474ee06a2e30ccc8c6a96bdd5"+ ]+ )+ ,+ ( "Blake2b 160"+ , HashAlg (Blake2b :: Blake2b 160)+ ,+ [ "3345524abf6bbe1809449224b5972c41790b6cf2"+ , "3c523ed102ab45a37d54f5610d5a983162fde84f"+ , "a3d365b5fba5d36fbb19c03b7fde496058969c5a"+ ]+ )+ ,+ ( "Blake2b 224"+ , HashAlg (Blake2b :: Blake2b 224)+ ,+ [ "836cc68931c2e4e3e838602eca1902591d216837bafddfe6f0c8cb07"+ , "477c3985751dd4d1b8c93827ea5310b33bb02a26463a050dffd3e857"+ , "a4a1b6851be66891a3deff406c4d7556879ebf952407450755f90eb6"+ ]+ )+ ,+ ( "Blake2b 256"+ , HashAlg (Blake2b :: Blake2b 256)+ ,+ [ "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"+ , "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"+ , "036c13096926b3dfccfe3f233bd1b2f583b818b8b15c01be65af69238e900b2c"+ ]+ )+ ,+ ( "Blake2b 384"+ , HashAlg (Blake2b :: Blake2b 384)+ ,+ [ "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100"+ , "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d"+ , "927a1f297873cbe887a93b2183c4e2eba53966ba92c6db8b87029a1d8c673471d09740676cced79c5016838973f630c3"+ ]+ )+ ,+ ( "Blake2b 512"+ , HashAlg (Blake2b :: Blake2b 512)+ ,+ [ "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce"+ , "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918"+ , "af438eea5d8cdb209336a7e85bf58090dc21b49d823f89a7d064c119f127bd361af9c7d109edda0f0e91bdce078d1d86b8e6f25727c98f6d3bb6f50acb2dd376"+ ]+ )+ ,+ ( "Blake2s 160"+ , HashAlg (Blake2s :: Blake2s 160)+ ,+ [ "354c9c33f735962418bdacb9479873429c34916f"+ , "5a604fec9713c369e84b0ed68daed7d7504ef240"+ , "759bef6d041bcbd861b8b51baaece6c8fffd0acf"+ ]+ )+ ,+ ( "Blake2s 224"+ , HashAlg (Blake2s :: Blake2s 224)+ ,+ [ "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4"+ , "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912"+ , "e220025fd46a9a635c3f7f60bb96a84c01019ac0817f5901e7eeaa2c"+ ]+ )+ ,+ ( "Blake2s 256"+ , HashAlg (Blake2s :: Blake2s 256)+ ,+ [ "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9"+ , "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812"+ , "94662583a600a12dff357c0a6f1b514a710ef0f587a38e8d2e4d7f67e9c81667"+ ]+ ) ] runhash :: HashAlg -> ByteString -> ByteString@@ -219,11 +430,12 @@ runhashinc :: HashAlg -> [ByteString] -> ByteString runhashinc (HashAlg hashAlg) v = B.convertToBase B.Base16 $ hashinc $ v- where hashinc = hashFinalize . foldl hashUpdate (hashInitWith hashAlg)+ where+ hashinc = hashFinalize . foldl hashUpdate (hashInitWith hashAlg) -data HashPrefixAlg = forall alg . HashAlgorithmPrefix alg => HashPrefixAlg alg+data HashPrefixAlg = forall alg. HashAlgorithmPrefix alg => HashPrefixAlg alg -expectedPrefix :: [ (String, HashPrefixAlg) ]+expectedPrefix :: [(String, HashPrefixAlg)] expectedPrefix = [ ("MD5", HashPrefixAlg MD5) , ("SHA1", HashPrefixAlg SHA1)@@ -242,12 +454,12 @@ makeTestAlg (name, hashAlg, results) = testGroup name $ concatMap maketest (zip3 is vectors results) where- is :: [Int]- is = [1..]+ is :: [Int]+ is = [1 ..] - maketest (i, v, r) =- [ testCase (show i) (r @=? runhash hashAlg v)- ]+ maketest (i, v, r) =+ [ testCase (show i) (r @=? runhash hashAlg v)+ ] makeTestChunk (hashName, hashAlg, _) = [ testProperty hashName $ \ckLen (ArbitraryBS0_2901 inp) ->@@ -278,16 +490,20 @@ hashEmpty _ = hash B.empty xof n = case someNatVal n of- Nothing -> error ("invalid Nat: " ++ show n)- Just (SomeNat p) -> convert (hashEmpty p)+ Nothing -> error ("invalid Nat: " ++ show n)+ Just (SomeNat p) -> convert (hashEmpty p) -tests = testGroup "hash"- [ testGroup "KATs" (map makeTestAlg expected)- , testGroup "Chunking" (concatMap makeTestChunk expected)- , testGroup "Prefix" (concatMap makeTestPrefix expectedPrefix)- , testGroup "Hybrid" (concatMap makeTestHybrid expectedPrefix)- , testGroup "Truncating"- [ testGroup "SHAKE128"- (zipWith makeTestSHAKE128Truncation [1..] shake128TruncationBytes)+tests =+ testGroup+ "hash"+ [ testGroup "KATs" (map makeTestAlg expected)+ , testGroup "Chunking" (concatMap makeTestChunk expected)+ , testGroup "Prefix" (concatMap makeTestPrefix expectedPrefix)+ , testGroup "Hybrid" (concatMap makeTestHybrid expectedPrefix)+ , testGroup+ "Truncating"+ [ testGroup+ "SHAKE128"+ (zipWith makeTestSHAKE128Truncation [1 ..] shake128TruncationBytes)+ ] ]- ]
tests/Imports.hs view
@@ -1,20 +1,22 @@-module Imports- (+module Imports ( -- * Individual Types- Word16, Word32, Word64- , ByteString+ Word16,+ Word32,+ Word64,+ ByteString,+ -- * Modules- , module X- ) where+ module X,+) where -import Data.Word (Word16, Word32, Word64) import Data.ByteString (ByteString)+import Data.Word (Word16, Word32, Word64) import Control.Applicative as X import Control.Monad as X+import Data.ByteString.Char8 as X () import Data.Foldable as X (foldl') import Data.Monoid as X-import Data.ByteString.Char8 as X () import Test.Tasty as X import Test.Tasty.HUnit as X
tests/KAT_AES.hs view
@@ -1,19 +1,20 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_AES (tests) where -import Imports import BlockCipher-import Data.Maybe-import Crypto.Cipher.Types import qualified Crypto.Cipher.AES as AES+import Crypto.Cipher.Types import qualified Data.ByteString as B+import Data.Maybe+import Imports -import qualified KAT_AES.KATECB as KATECB import qualified KAT_AES.KATCBC as KATCBC-import qualified KAT_AES.KATXTS as KATXTS-import qualified KAT_AES.KATGCM as KATGCM import qualified KAT_AES.KATCCM as KATCCM+import qualified KAT_AES.KATECB as KATECB+import qualified KAT_AES.KATGCM as KATGCM import qualified KAT_AES.KATOCB3 as KATOCB3+import qualified KAT_AES.KATXTS as KATXTS {- instance Show AES.AES where@@ -24,75 +25,105 @@ arbitrary = AES.initAES . B.pack <$> replicateM 16 arbitrary -} -toKatECB (k,p,c) = KAT_ECB { ecbKey = k, ecbPlaintext = p, ecbCiphertext = c }-toKatCBC (k,iv,p,c) = KAT_CBC { cbcKey = k, cbcIV = iv, cbcPlaintext = p, cbcCiphertext = c }-toKatXTS (k1,k2,iv,p,_,c) = KAT_XTS { xtsKey1 = k1, xtsKey2 = k2, xtsIV = iv, xtsPlaintext = p, xtsCiphertext = c }-toKatAEAD mode (k,iv,h,p,c,taglen,tag) =- KAT_AEAD { aeadMode = mode- , aeadKey = k- , aeadIV = iv- , aeadHeader = h- , aeadPlaintext = p- , aeadCiphertext = c- , aeadTaglen = taglen- , aeadTag = tag- }+toKatECB (k, p, c) = KAT_ECB{ecbKey = k, ecbPlaintext = p, ecbCiphertext = c}+toKatCBC (k, iv, p, c) = KAT_CBC{cbcKey = k, cbcIV = iv, cbcPlaintext = p, cbcCiphertext = c}+toKatXTS (k1, k2, iv, p, _, c) =+ KAT_XTS+ { xtsKey1 = k1+ , xtsKey2 = k2+ , xtsIV = iv+ , xtsPlaintext = p+ , xtsCiphertext = c+ }+toKatAEAD mode (k, iv, h, p, c, taglen, tag) =+ KAT_AEAD+ { aeadMode = mode+ , aeadKey = k+ , aeadIV = iv+ , aeadHeader = h+ , aeadPlaintext = p+ , aeadCiphertext = c+ , aeadTaglen = taglen+ , aeadTag = tag+ } toKatGCM = toKatAEAD AEAD_GCM toKatOCB = toKatAEAD AEAD_OCB -toKatCCM (k,iv,h,i,o,m) =- KAT_AEAD { aeadMode = AEAD_CCM (B.length i) (ccmMVal m) CCM_L2- , aeadKey = k- , aeadIV = iv- , aeadHeader = h- , aeadPlaintext = i- , aeadCiphertext = ct- , aeadTaglen = m- , aeadTag = at- }- where ccmMVal x = fromMaybe (error $ "unsupported CCM tag length: " ++ show x) $- lookup x [ (4, CCM_M4), (6, CCM_M6), (8, CCM_M8), (10, CCM_M10)- , (12, CCM_M12), (14, CCM_M14), (16, CCM_M16)- ]- ctWithTag = B.drop (B.length h) o- (ct, at) = B.splitAt (B.length ctWithTag - m) ctWithTag+toKatCCM (k, iv, h, i, o, m) =+ KAT_AEAD+ { aeadMode = AEAD_CCM (B.length i) (ccmMVal m) CCM_L2+ , aeadKey = k+ , aeadIV = iv+ , aeadHeader = h+ , aeadPlaintext = i+ , aeadCiphertext = ct+ , aeadTaglen = m+ , aeadTag = at+ }+ where+ ccmMVal x =+ fromMaybe (error $ "unsupported CCM tag length: " ++ show x) $+ lookup+ x+ [ (4, CCM_M4)+ , (6, CCM_M6)+ , (8, CCM_M8)+ , (10, CCM_M10)+ , (12, CCM_M12)+ , (14, CCM_M14)+ , (16, CCM_M16)+ ]+ ctWithTag = B.drop (B.length h) o+ (ct, at) = B.splitAt (B.length ctWithTag - m) ctWithTag -kats128 = defaultKATs- { kat_ECB = map toKatECB KATECB.vectors_aes128_enc- , kat_CBC = map toKatCBC KATCBC.vectors_aes128_enc- , kat_CFB = [ KAT_CFB { cfbKey = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c"- , cfbIV = "\xC8\xA6\x45\x37\xA0\xB3\xA9\x3F\xCD\xE3\xCD\xAD\x9F\x1C\xE5\x8B"- , cfbPlaintext = "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"- , cfbCiphertext = "\x26\x75\x1f\x67\xa3\xcb\xb1\x40\xb1\x80\x8c\xf1\x87\xa4\xf4\xdf"- }- ]- , kat_XTS = map toKatXTS KATXTS.vectors_aes128_enc- , kat_AEAD = map toKatGCM KATGCM.vectors_aes128_enc ++- map toKatOCB KATOCB3.vectors_aes128_enc ++- map toKatCCM KATCCM.vectors_aes128_enc- }+kats128 =+ defaultKATs+ { kat_ECB = map toKatECB KATECB.vectors_aes128_enc+ , kat_CBC = map toKatCBC KATCBC.vectors_aes128_enc+ , kat_CFB =+ [ KAT_CFB+ { cfbKey =+ "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c"+ , cfbIV =+ "\xC8\xA6\x45\x37\xA0\xB3\xA9\x3F\xCD\xE3\xCD\xAD\x9F\x1C\xE5\x8B"+ , cfbPlaintext =+ "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"+ , cfbCiphertext =+ "\x26\x75\x1f\x67\xa3\xcb\xb1\x40\xb1\x80\x8c\xf1\x87\xa4\xf4\xdf"+ }+ ]+ , kat_XTS = map toKatXTS KATXTS.vectors_aes128_enc+ , kat_AEAD =+ map toKatGCM KATGCM.vectors_aes128_enc+ ++ map toKatOCB KATOCB3.vectors_aes128_enc+ ++ map toKatCCM KATCCM.vectors_aes128_enc+ } -kats192 = defaultKATs- { kat_ECB = map toKatECB KATECB.vectors_aes192_enc- , kat_CBC = map toKatCBC KATCBC.vectors_aes192_enc- }+kats192 =+ defaultKATs+ { kat_ECB = map toKatECB KATECB.vectors_aes192_enc+ , kat_CBC = map toKatCBC KATCBC.vectors_aes192_enc+ } -kats256 = defaultKATs- { kat_ECB = map toKatECB KATECB.vectors_aes256_enc- , kat_CBC = map toKatCBC KATCBC.vectors_aes256_enc- , kat_XTS = map toKatXTS KATXTS.vectors_aes256_enc- , kat_AEAD = map toKatGCM KATGCM.vectors_aes256_enc- }+kats256 =+ defaultKATs+ { kat_ECB = map toKatECB KATECB.vectors_aes256_enc+ , kat_CBC = map toKatCBC KATCBC.vectors_aes256_enc+ , kat_XTS = map toKatXTS KATXTS.vectors_aes256_enc+ , kat_AEAD = map toKatGCM KATGCM.vectors_aes256_enc+ } -tests = testGroup "AES"- [ testBlockCipher kats128 (undefined :: AES.AES128)- , testBlockCipher kats192 (undefined :: AES.AES192)- , testBlockCipher kats256 (undefined :: AES.AES256)-{-- , testProperty "genCtr" $ \(key, iv1) ->- let (bs1, iv2) = AES.genCounter key iv1 32- (bs2, iv3) = AES.genCounter key iv2 32- (bsAll, iv3') = AES.genCounter key iv1 64- in (B.concat [bs1,bs2] == bsAll && iv3 == iv3')--}- ]+tests =+ testGroup+ "AES"+ [ testBlockCipher kats128 (undefined :: AES.AES128)+ , testBlockCipher kats192 (undefined :: AES.AES192)+ , testBlockCipher kats256 (undefined :: AES.AES256)+ {-+ , testProperty "genCtr" $ \(key, iv1) ->+ let (bs1, iv2) = AES.genCounter key iv1 32+ (bs2, iv3) = AES.genCounter key iv2 32+ (bsAll, iv3') = AES.genCounter key iv1 64+ in (B.concat [bs1,bs2] == bsAll && iv3 == iv3')+ -}+ ]
tests/KAT_AES/KATCBC.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_AES.KATCBC where import qualified Data.ByteString as B@@ -6,102 +7,454 @@ type KATCBC = (B.ByteString, B.ByteString, B.ByteString, B.ByteString) -vectors_aes128_enc, vectors_aes128_dec- , vectors_aes192_enc, vectors_aes192_dec- , vectors_aes256_enc, vectors_aes256_dec :: [KATCBC]+vectors_aes128_enc+ , vectors_aes128_dec+ , vectors_aes192_enc+ , vectors_aes192_dec+ , vectors_aes256_enc+ , vectors_aes256_dec+ :: [KATCBC] vectors_aes128_enc = [- ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x66\xe9\x4b\xd4\xef\x8a\x2c\x3b\x88\x4c\xfa\x59\xca\x34\x2b\x2e")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xb6\xae\xaf\xfa\x75\x2d\xc0\x8b\x51\x63\x97\x31\x76\x1a\xed\x00")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xcb\x64\xcf\x3f\x42\x2a\xe8\x4b\xb9\x0e\x3a\xb4\xdb\xa7\xbd\x86")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xe5\xb5\x07\x7f\x93\x46\x46\x2c\x62\xa0\x75\xc0\xc7\x08\xee\x96")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xe1\x4d\x5d\x0e\xe2\x77\x15\xdf\x08\xb4\x15\x2b\xa2\x3d\xa8\xe0")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x5e\x77\xe5\x9f\x8f\x85\x94\x34\x89\xa2\x41\x49\xc7\x5f\x4e\xc9")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x8f\x42\xc2\x4b\xee\x6e\x63\x47\x2b\x16\x5a\xa9\x41\x31\x2f\x7c")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xb0\xea\x4a\xc0\xd2\x5c\xcd\x7c\x82\xcb\x8a\x30\x68\xc6\xfe\x2e")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\xe1\x4d\x5d\x0e\xe2\x77\x15\xdf\x08\xb4\x15\x2b\xa2\x3d\xa8\xe0")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x17\xd6\x14\xf3\x79\xa9\x35\x90\x77\xe9\x55\x77\xfd\x31\xc2\x0a")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x8f\x42\xc2\x4b\xee\x6e\x63\x47\x2b\x16\x5a\xa9\x41\x31\x2f\x7c")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\xe5\xb5\x07\x7f\x93\x46\x46\x2c\x62\xa0\x75\xc0\xc7\x08\xee\x96")+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x66\xe9\x4b\xd4\xef\x8a\x2c\x3b\x88\x4c\xfa\x59\xca\x34\x2b\x2e"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xb6\xae\xaf\xfa\x75\x2d\xc0\x8b\x51\x63\x97\x31\x76\x1a\xed\x00"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xcb\x64\xcf\x3f\x42\x2a\xe8\x4b\xb9\x0e\x3a\xb4\xdb\xa7\xbd\x86"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xe5\xb5\x07\x7f\x93\x46\x46\x2c\x62\xa0\x75\xc0\xc7\x08\xee\x96"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xe1\x4d\x5d\x0e\xe2\x77\x15\xdf\x08\xb4\x15\x2b\xa2\x3d\xa8\xe0"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x5e\x77\xe5\x9f\x8f\x85\x94\x34\x89\xa2\x41\x49\xc7\x5f\x4e\xc9"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x8f\x42\xc2\x4b\xee\x6e\x63\x47\x2b\x16\x5a\xa9\x41\x31\x2f\x7c"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xb0\xea\x4a\xc0\xd2\x5c\xcd\x7c\x82\xcb\x8a\x30\x68\xc6\xfe\x2e"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\xe1\x4d\x5d\x0e\xe2\x77\x15\xdf\x08\xb4\x15\x2b\xa2\x3d\xa8\xe0"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x17\xd6\x14\xf3\x79\xa9\x35\x90\x77\xe9\x55\x77\xfd\x31\xc2\x0a"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x8f\x42\xc2\x4b\xee\x6e\x63\x47\x2b\x16\x5a\xa9\x41\x31\x2f\x7c"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\xe5\xb5\x07\x7f\x93\x46\x46\x2c\x62\xa0\x75\xc0\xc7\x08\xee\x96"+ ) ]- vectors_aes192_enc = [- ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xaa\xe0\x69\x92\xac\xbf\x52\xa3\xe8\xf4\xa9\x6e\xc9\x30\x0b\xd7")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x5f\x88\xef\x3f\xbd\xeb\xf2\xe4\xe2\x66\x65\x12\xd3\xbc\xb7\x0f")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xdb\x42\xf5\x1c\xd2\x0e\xca\xd2\x9e\xb0\x13\x2b\x0f\xaa\x4b\x85")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xda\xb4\x01\x5f\x98\x70\x25\xeb\xb8\xa8\x5f\x3c\x7f\x73\x70\x19")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xcf\x1e\xce\x3c\x44\xb0\x78\xfb\x27\xcb\x0a\x3e\x07\x1b\x08\x20")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x98\xb8\x95\xa1\x45\xca\x4e\x0b\xf8\x3e\x69\x32\x81\xc1\xa0\x97")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xf2\xf0\xae\xd8\xcd\xc9\x21\xca\x4b\x55\x84\x5d\xa4\x15\x21\xc2")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x5e\xea\x4b\x13\xdd\xd9\x17\x12\xb0\x14\xe2\x82\x2d\x18\x76\xfb")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\xcf\x1e\xce\x3c\x44\xb0\x78\xfb\x27\xcb\x0a\x3e\x07\x1b\x08\x20")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\xeb\x8c\x17\x30\x90\xc7\x5b\x77\xd6\x72\xb4\x57\xa7\x78\xd9\xd0")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\xf2\xf0\xae\xd8\xcd\xc9\x21\xca\x4b\x55\x84\x5d\xa4\x15\x21\xc2")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\xda\xb4\x01\x5f\x98\x70\x25\xeb\xb8\xa8\x5f\x3c\x7f\x73\x70\x19")-+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xaa\xe0\x69\x92\xac\xbf\x52\xa3\xe8\xf4\xa9\x6e\xc9\x30\x0b\xd7"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x5f\x88\xef\x3f\xbd\xeb\xf2\xe4\xe2\x66\x65\x12\xd3\xbc\xb7\x0f"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xdb\x42\xf5\x1c\xd2\x0e\xca\xd2\x9e\xb0\x13\x2b\x0f\xaa\x4b\x85"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xda\xb4\x01\x5f\x98\x70\x25\xeb\xb8\xa8\x5f\x3c\x7f\x73\x70\x19"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xcf\x1e\xce\x3c\x44\xb0\x78\xfb\x27\xcb\x0a\x3e\x07\x1b\x08\x20"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x98\xb8\x95\xa1\x45\xca\x4e\x0b\xf8\x3e\x69\x32\x81\xc1\xa0\x97"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xf2\xf0\xae\xd8\xcd\xc9\x21\xca\x4b\x55\x84\x5d\xa4\x15\x21\xc2"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x5e\xea\x4b\x13\xdd\xd9\x17\x12\xb0\x14\xe2\x82\x2d\x18\x76\xfb"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\xcf\x1e\xce\x3c\x44\xb0\x78\xfb\x27\xcb\x0a\x3e\x07\x1b\x08\x20"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\xeb\x8c\x17\x30\x90\xc7\x5b\x77\xd6\x72\xb4\x57\xa7\x78\xd9\xd0"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\xf2\xf0\xae\xd8\xcd\xc9\x21\xca\x4b\x55\x84\x5d\xa4\x15\x21\xc2"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\xda\xb4\x01\x5f\x98\x70\x25\xeb\xb8\xa8\x5f\x3c\x7f\x73\x70\x19"+ ) ]- vectors_aes256_enc = [- ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xdc\x95\xc0\x78\xa2\x40\x89\x89\xad\x48\xa2\x14\x92\x84\x20\x87")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x72\x98\xca\xa5\x65\x03\x1e\xad\xc6\xce\x23\xd2\x3e\xa6\x63\x78")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xf4\x35\xa1\x11\xa3\xe4\xa1\x94\x49\x19\xf9\x12\xc5\xa2\x41\xde")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x91\xc0\x87\x62\x87\x6d\xcc\xf9\xba\x20\x4a\x33\x76\x8f\xa5\xfe")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x7b\xc3\x02\x6c\xd7\x37\x10\x3e\x62\x90\x2b\xcd\x18\xfb\x01\x63")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x9c\xac\x94\xc6\xb4\x85\x61\xf8\xff\xaa\xa7\x86\x16\xba\x48\x92")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\xf9\xc7\x44\x4b\xb0\xcc\x80\x6c\x7c\x39\xee\x22\x11\xf1\x46")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x6d\xed\xd0\xa3\xe6\x94\xa0\xde\x65\x1d\x68\xa6\xb5\x5a\x64\xa2")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x7b\xc3\x02\x6c\xd7\x37\x10\x3e\x62\x90\x2b\xcd\x18\xfb\x01\x63")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x62\xae\x12\xf3\x24\xbf\xea\x08\xd5\xf6\x75\xb5\x13\x02\x6b\xbf")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x00\xf9\xc7\x44\x4b\xb0\xcc\x80\x6c\x7c\x39\xee\x22\x11\xf1\x46")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x91\xc0\x87\x62\x87\x6d\xcc\xf9\xba\x20\x4a\x33\x76\x8f\xa5\xfe")+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xdc\x95\xc0\x78\xa2\x40\x89\x89\xad\x48\xa2\x14\x92\x84\x20\x87"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x72\x98\xca\xa5\x65\x03\x1e\xad\xc6\xce\x23\xd2\x3e\xa6\x63\x78"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xf4\x35\xa1\x11\xa3\xe4\xa1\x94\x49\x19\xf9\x12\xc5\xa2\x41\xde"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x91\xc0\x87\x62\x87\x6d\xcc\xf9\xba\x20\x4a\x33\x76\x8f\xa5\xfe"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x7b\xc3\x02\x6c\xd7\x37\x10\x3e\x62\x90\x2b\xcd\x18\xfb\x01\x63"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x9c\xac\x94\xc6\xb4\x85\x61\xf8\xff\xaa\xa7\x86\x16\xba\x48\x92"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\xf9\xc7\x44\x4b\xb0\xcc\x80\x6c\x7c\x39\xee\x22\x11\xf1\x46"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x6d\xed\xd0\xa3\xe6\x94\xa0\xde\x65\x1d\x68\xa6\xb5\x5a\x64\xa2"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x7b\xc3\x02\x6c\xd7\x37\x10\x3e\x62\x90\x2b\xcd\x18\xfb\x01\x63"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x62\xae\x12\xf3\x24\xbf\xea\x08\xd5\xf6\x75\xb5\x13\x02\x6b\xbf"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x00\xf9\xc7\x44\x4b\xb0\xcc\x80\x6c\x7c\x39\xee\x22\x11\xf1\x46"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x91\xc0\x87\x62\x87\x6d\xcc\xf9\xba\x20\x4a\x33\x76\x8f\xa5\xfe"+ ) ]- vectors_aes128_dec = [- ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x14\x0f\x0f\x10\x11\xb5\x22\x3d\x79\x58\x77\x17\xff\xd9\xec\x3a")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x33\x08\x32\x40\xd6\x5c\xbc\x72\xaa\x0b\x44\xf3\xe1\x9e\xa9\x5a")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x65\x0a\x42\xa0\x3c\x4b\x93\xa4\xb7\x43\xdc\x9e\x9c\xf4\xc0\x9b")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x80\xcd\x20\xe1\xbd\x89\x3c\x5e\xe4\x20\x76\x85\xb0\x9a\x0e\x3e")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x15\x0e\x0e\x11\x10\xb4\x23\x3c\x78\x59\x76\x16\xfe\xd8\xed\x3b")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x32\x09\x33\x41\xd7\x5d\xbd\x73\xab\x0a\x45\xf2\xe0\x9f\xa8\x5b")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x64\x0b\x43\xa1\x3d\x4a\x92\xa5\xb6\x42\xdd\x9f\x9d\xf5\xc1\x9a")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x81\xcc\x21\xe0\xbc\x88\x3d\x5f\xe5\x21\x77\x84\xb1\x9b\x0f\x3f")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\xf5\x06\x41\x7e\x6a\x8f\xbc\x32\xdd\xa5\x52\x73\xbf\x9f\x4d\x5c")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\xbf\x6d\x28\xac\x20\xc9\x1d\x65\xa9\xd4\xb0\x96\xc2\xd5\xa5\x09")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x5f\x2a\x46\xab\x8d\xb9\x5b\x22\x15\xfe\x1a\xa4\xdd\x69\x59\x26")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x71\x9b\x21\xb5\x39\x7c\x2f\x16\x7c\x8b\x45\x22\xb5\x20\xec\x2e")+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x14\x0f\x0f\x10\x11\xb5\x22\x3d\x79\x58\x77\x17\xff\xd9\xec\x3a"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x33\x08\x32\x40\xd6\x5c\xbc\x72\xaa\x0b\x44\xf3\xe1\x9e\xa9\x5a"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x65\x0a\x42\xa0\x3c\x4b\x93\xa4\xb7\x43\xdc\x9e\x9c\xf4\xc0\x9b"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x80\xcd\x20\xe1\xbd\x89\x3c\x5e\xe4\x20\x76\x85\xb0\x9a\x0e\x3e"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x15\x0e\x0e\x11\x10\xb4\x23\x3c\x78\x59\x76\x16\xfe\xd8\xed\x3b"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x32\x09\x33\x41\xd7\x5d\xbd\x73\xab\x0a\x45\xf2\xe0\x9f\xa8\x5b"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x64\x0b\x43\xa1\x3d\x4a\x92\xa5\xb6\x42\xdd\x9f\x9d\xf5\xc1\x9a"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x81\xcc\x21\xe0\xbc\x88\x3d\x5f\xe5\x21\x77\x84\xb1\x9b\x0f\x3f"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\xf5\x06\x41\x7e\x6a\x8f\xbc\x32\xdd\xa5\x52\x73\xbf\x9f\x4d\x5c"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\xbf\x6d\x28\xac\x20\xc9\x1d\x65\xa9\xd4\xb0\x96\xc2\xd5\xa5\x09"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x5f\x2a\x46\xab\x8d\xb9\x5b\x22\x15\xfe\x1a\xa4\xdd\x69\x59\x26"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x71\x9b\x21\xb5\x39\x7c\x2f\x16\x7c\x8b\x45\x22\xb5\x20\xec\x2e"+ ) ]- vectors_aes192_dec = [- ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x13\x46\x0e\x87\xa8\xfc\x02\x3e\xf2\x50\x1a\xfe\x7f\xf5\x1c\x51")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x91\x75\x27\xfc\xd4\xa0\x6f\x32\x27\x29\x90\x14\xca\xde\xd4\x1a")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x29\x64\x80\xb6\xa5\xd6\xcf\xb3\x78\x3f\x21\x6b\x80\x31\x3d\xb3")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xbc\xa5\x06\x07\xd0\x67\x30\x85\x2d\x3a\x50\x4b\x68\x0a\x19\xcc")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x12\x47\x0f\x86\xa9\xfd\x03\x3f\xf3\x51\x1b\xff\x7e\xf4\x1d\x50")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x90\x74\x26\xfd\xd5\xa1\x6e\x33\x26\x28\x91\x15\xcb\xdf\xd5\x1b")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x28\x65\x81\xb7\xa4\xd7\xce\xb2\x79\x3e\x20\x6a\x81\x30\x3c\xb2")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xbd\xa4\x07\x06\xd1\x66\x31\x84\x2c\x3b\x51\x4a\x69\x0b\x18\xcd")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x38\xf9\xf9\xd1\x7e\x2c\x82\xaf\xdc\xed\x68\x03\xb6\x31\x46\x3e")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x35\x4e\xc1\x01\x0f\x17\x50\x5e\x63\x37\x40\x4b\x9a\xf2\xc0\x5c")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\xa7\x7c\xc9\xd1\x4f\x44\xf7\xf7\xcc\x45\x80\x83\x19\xb7\xa4\x71")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\xf9\x1d\xb1\x13\x0b\xd1\xc0\x66\x9f\xfa\xc2\x0e\xbe\xdd\xcb\xca")+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x13\x46\x0e\x87\xa8\xfc\x02\x3e\xf2\x50\x1a\xfe\x7f\xf5\x1c\x51"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x91\x75\x27\xfc\xd4\xa0\x6f\x32\x27\x29\x90\x14\xca\xde\xd4\x1a"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x29\x64\x80\xb6\xa5\xd6\xcf\xb3\x78\x3f\x21\x6b\x80\x31\x3d\xb3"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xbc\xa5\x06\x07\xd0\x67\x30\x85\x2d\x3a\x50\x4b\x68\x0a\x19\xcc"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x12\x47\x0f\x86\xa9\xfd\x03\x3f\xf3\x51\x1b\xff\x7e\xf4\x1d\x50"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x90\x74\x26\xfd\xd5\xa1\x6e\x33\x26\x28\x91\x15\xcb\xdf\xd5\x1b"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x28\x65\x81\xb7\xa4\xd7\xce\xb2\x79\x3e\x20\x6a\x81\x30\x3c\xb2"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xbd\xa4\x07\x06\xd1\x66\x31\x84\x2c\x3b\x51\x4a\x69\x0b\x18\xcd"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x38\xf9\xf9\xd1\x7e\x2c\x82\xaf\xdc\xed\x68\x03\xb6\x31\x46\x3e"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x35\x4e\xc1\x01\x0f\x17\x50\x5e\x63\x37\x40\x4b\x9a\xf2\xc0\x5c"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\xa7\x7c\xc9\xd1\x4f\x44\xf7\xf7\xcc\x45\x80\x83\x19\xb7\xa4\x71"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\xf9\x1d\xb1\x13\x0b\xd1\xc0\x66\x9f\xfa\xc2\x0e\xbe\xdd\xcb\xca"+ ) ]- vectors_aes256_dec = [- ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x67\x67\x1c\xe1\xfa\x91\xdd\xeb\x0f\x8f\xbb\xb3\x66\xb5\x31\xb4")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x7b\xd3\xfb\x90\x65\x56\x9f\x39\x8b\x09\xcb\x93\x4b\x1e\x01\x23")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xda\xa8\xbf\x5c\xde\x2e\x52\x45\x5f\xa3\xb3\xfe\x33\x32\x47\xca")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x83\x24\xdc\xb4\x30\x12\x73\x6c\xed\x58\xab\x8f\x4b\x05\xca\x0b")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x66\x66\x1d\xe0\xfb\x90\xdc\xea\x0e\x8e\xba\xb2\x67\xb4\x30\xb5")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x7a\xd2\xfa\x91\x64\x57\x9e\x38\x8a\x08\xca\x92\x4a\x1f\x00\x22")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\xdb\xa9\xbe\x5d\xdf\x2f\x53\x44\x5e\xa2\xb2\xff\x32\x33\x46\xcb")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x82\x25\xdd\xb5\x31\x13\x72\x6d\xec\x59\xaa\x8e\x4a\x04\xcb\x0a")- , ("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x68\xe9\x07\x16\xe3\x66\x1b\x1d\xb1\x89\x74\xb0\x9c\x46\x47\xe4")- , ("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01","\x7f\xb9\xeb\xa4\xd3\x5f\x70\x40\xab\x52\xec\xd2\x3b\x48\xb7\x6e")- , ("\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02","\x6c\x58\x0f\x41\x82\x36\xbc\xff\x64\x1d\xac\xa7\x3e\x34\x11\x18")- , ("\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03","\x3f\x62\xd6\x8c\xb1\xf7\x62\x28\xa4\xc3\x82\x4f\x8b\x24\xe7\x4b")+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x67\x67\x1c\xe1\xfa\x91\xdd\xeb\x0f\x8f\xbb\xb3\x66\xb5\x31\xb4"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x7b\xd3\xfb\x90\x65\x56\x9f\x39\x8b\x09\xcb\x93\x4b\x1e\x01\x23"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xda\xa8\xbf\x5c\xde\x2e\x52\x45\x5f\xa3\xb3\xfe\x33\x32\x47\xca"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x83\x24\xdc\xb4\x30\x12\x73\x6c\xed\x58\xab\x8f\x4b\x05\xca\x0b"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x66\x66\x1d\xe0\xfb\x90\xdc\xea\x0e\x8e\xba\xb2\x67\xb4\x30\xb5"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x7a\xd2\xfa\x91\x64\x57\x9e\x38\x8a\x08\xca\x92\x4a\x1f\x00\x22"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\xdb\xa9\xbe\x5d\xdf\x2f\x53\x44\x5e\xa2\xb2\xff\x32\x33\x46\xcb"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x82\x25\xdd\xb5\x31\x13\x72\x6d\xec\x59\xaa\x8e\x4a\x04\xcb\x0a"+ )+ ,+ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x68\xe9\x07\x16\xe3\x66\x1b\x1d\xb1\x89\x74\xb0\x9c\x46\x47\xe4"+ )+ ,+ ( "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , "\x7f\xb9\xeb\xa4\xd3\x5f\x70\x40\xab\x52\xec\xd2\x3b\x48\xb7\x6e"+ )+ ,+ ( "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02"+ , "\x6c\x58\x0f\x41\x82\x36\xbc\xff\x64\x1d\xac\xa7\x3e\x34\x11\x18"+ )+ ,+ ( "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03"+ , "\x3f\x62\xd6\x8c\xb1\xf7\x62\x28\xa4\xc3\x82\x4f\x8b\x24\xe7\x4b"+ ) ]
tests/KAT_AES/KATCCM.hs view
@@ -1,155 +1,205 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_AES.KATCCM where import qualified Data.ByteString as B -- (key, iv, header, in, out+atag, taglen)-type KATCCM = (B.ByteString, B.ByteString, B.ByteString, B.ByteString, B.ByteString, Int)+type KATCCM =+ (B.ByteString, B.ByteString, B.ByteString, B.ByteString, B.ByteString, Int) vectors_aes128_enc :: [KATCCM] vectors_aes128_enc =- [ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x03\x02\x01\x00\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"- , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x58\x8c\x97\x9a\x61\xc6\x63\xd2\xf0\x66\xd0\xc2\xc0\xf9\x89\x80\x6d\x5f\x6b\x61\xda\xc3\x84\x17\xe8\xd1\x2c\xfd\xf9\x26\xe0"- , {- M = -} 8)- , ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x04\x03\x02\x01\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"- , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x72\xc9\x1a\x36\xe1\x35\xf8\xcf\x29\x1c\xa8\x94\x08\x5c\x87\xe3\xcc\x15\xc4\x39\xc9\xe4\x3a\x3b\xa0\x91\xd5\x6e\x10\x40\x09\x16"- , {- M = -} 8)- , ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x05\x04\x03\x02\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"- , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x51\xb1\xe5\xf4\x4a\x19\x7d\x1d\xa4\x6b\x0f\x8e\x2d\x28\x2a\xe8\x71\xe8\x38\xbb\x64\xda\x85\x96\x57\x4a\xda\xa7\x6f\xbd\x9f\xb0\xc5"- , {- M = -} 8)- , ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x06\x05\x04\x03\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"- , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\xa2\x8c\x68\x65\x93\x9a\x9a\x79\xfa\xaa\x5c\x4c\x2a\x9d\x4a\x91\xcd\xac\x8c\x96\xc8\x61\xb9\xc9\xe6\x1e\xf1"- , {- M = -} 8)- , ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x07\x06\x05\x04\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"- , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\xdc\xf1\xfb\x7b\x5d\x9e\x23\xfb\x9d\x4e\x13\x12\x53\x65\x8a\xd8\x6e\xbd\xca\x3e\x51\xe8\x3f\x07\x7d\x9c\x2d\x93"- , {- M = -} 8)- , ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x08\x07\x06\x05\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"- , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x6f\xc1\xb0\x11\xf0\x06\x56\x8b\x51\x71\xa4\x2d\x95\x3d\x46\x9b\x25\x70\xa4\xbd\x87\x40\x5a\x04\x43\xac\x91\xcb\x94"- , {- M = -} 8)- , ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x09\x08\x07\x06\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"- , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x01\x35\xd1\xb2\xc9\x5f\x41\xd5\xd1\xd4\xfe\xc1\x85\xd1\x66\xb8\x09\x4e\x99\x9d\xfe\xd9\x6c\x04\x8c\x56\x60\x2c\x97\xac\xbb\x74\x90"- , {- M = -} 10)- , ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x0a\x09\x08\x07\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"- , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x7b\x75\x39\x9a\xc0\x83\x1d\xd2\xf0\xbb\xd7\x58\x79\xa2\xfd\x8f\x6c\xae\x6b\x6c\xd9\xb7\xdb\x24\xc1\x7b\x44\x33\xf4\x34\x96\x3f\x34\xb4"- , {- M = -} 10)- , ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x0b\x0a\x09\x08\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"- , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x82\x53\x1a\x60\xcc\x24\x94\x5a\x4b\x82\x79\x18\x1a\xb5\xc8\x4d\xf2\x1c\xe7\xf9\xb7\x3f\x42\xe1\x97\xea\x9c\x07\xe5\x6b\x5e\xb1\x7e\x5f\x4e"- , {- M = -} 10)- , ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x0c\x0b\x0a\x09\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"- , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x07\x34\x25\x94\x15\x77\x85\x15\x2b\x07\x40\x98\x33\x0a\xbb\x14\x1b\x94\x7b\x56\x6a\xa9\x40\x6b\x4d\x99\x99\x88\xdd"- , {- M = -} 10)- , ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x0d\x0c\x0b\x0a\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"- , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x67\x6b\xb2\x03\x80\xb0\xe3\x01\xe8\xab\x79\x59\x0a\x39\x6d\xa7\x8b\x83\x49\x34\xf5\x3a\xa2\xe9\x10\x7a\x8b\x6c\x02\x2c"- , {- M = -} 10)- , ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"- , {- iv = -} "\x00\x00\x00\x0e\x0d\x0c\x0b\xa0\xa1\xa2\xa3\xa4\xa5"- , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"- , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"- , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\xc0\xff\xa0\xd6\xf0\x5b\xdb\x67\xf2\x4d\x43\xa4\x33\x8d\x2a\xa4\xbe\xd7\xb2\x0e\x43\xcd\x1a\xa3\x16\x62\xe7\xad\x65\xd6\xdb"- , {- M = -} 10)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\x41\x2b\x4e\xa9\xcd\xbe\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\x0b\xe1\xa8\x8b\xac\xe0\x18\xb1"- , {- in = -} "\x08\xe8\xcf\x97\xd8\x20\xea\x25\x84\x60\xe9\x6a\xd9\xcf\x52\x89\x05\x4d\x89\x5c\xea\xc4\x7c"- , {- out = -} "\x0b\xe1\xa8\x8b\xac\xe0\x18\xb1\x4c\xb9\x7f\x86\xa2\xa4\x68\x9a\x87\x79\x47\xab\x80\x91\xef\x53\x86\xa6\xff\xbd\xd0\x80\xf8\xe7\x8c\xf7\xcb\x0c\xdd\xd7\xb3"- , {- M = -} 8)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\x33\x56\x8e\xf7\xb2\x63\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\x63\x01\x8f\x76\xdc\x8a\x1b\xcb"- , {- in = -} "\x90\x20\xea\x6f\x91\xbd\xd8\x5a\xfa\x00\x39\xba\x4b\xaf\xf9\xbf\xb7\x9c\x70\x28\x94\x9c\xd0\xec"- , {- out = -} "\x63\x01\x8f\x76\xdc\x8a\x1b\xcb\x4c\xcb\x1e\x7c\xa9\x81\xbe\xfa\xa0\x72\x6c\x55\xd3\x78\x06\x12\x98\xc8\x5c\x92\x81\x4a\xbc\x33\xc5\x2e\xe8\x1d\x7d\x77\xc0\x8a"- , {- M = -} 8)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\x10\x3f\xe4\x13\x36\x71\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\xaa\x6c\xfa\x36\xca\xe8\x6b\x40"- , {- in = -} "\xb9\x16\xe0\xea\xcc\x1c\x00\xd7\xdc\xec\x68\xec\x0b\x3b\xbb\x1a\x02\xde\x8a\x2d\x1a\xa3\x46\x13\x2e"- , {- out = -} "\xaa\x6c\xfa\x36\xca\xe8\x6b\x40\xb1\xd2\x3a\x22\x20\xdd\xc0\xac\x90\x0d\x9a\xa0\x3c\x61\xfc\xf4\xa5\x59\xa4\x41\x77\x67\x08\x97\x08\xa7\x76\x79\x6e\xdb\x72\x35\x06"- , {- M = -} 8)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\x76\x4c\x63\xb8\x05\x8e\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\xd0\xd0\x73\x5c\x53\x1e\x1b\xec\xf0\x49\xc2\x44"- , {- in = -} "\x12\xda\xac\x56\x30\xef\xa5\x39\x6f\x77\x0c\xe1\xa6\x6b\x21\xf7\xb2\x10\x1c"- , {- out = -} "\xd0\xd0\x73\x5c\x53\x1e\x1b\xec\xf0\x49\xc2\x44\x14\xd2\x53\xc3\x96\x7b\x70\x60\x9b\x7c\xbb\x7c\x49\x91\x60\x28\x32\x45\x26\x9a\x6f\x49\x97\x5b\xca\xde\xaf"- , {- M = -} 8)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\xf8\xb6\x78\x09\x4e\x3b\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\x77\xb6\x0f\x01\x1c\x03\xe1\x52\x58\x99\xbc\xae"- , {- in = -} "\xe8\x8b\x6a\x46\xc7\x8d\x63\xe5\x2e\xb8\xc5\x46\xef\xb5\xde\x6f\x75\xe9\xcc\x0d"- , {- out = -} "\x77\xb6\x0f\x01\x1c\x03\xe1\x52\x58\x99\xbc\xae\x55\x45\xff\x1a\x08\x5e\xe2\xef\xbf\x52\xb2\xe0\x4b\xee\x1e\x23\x36\xc7\x3e\x3f\x76\x2c\x0c\x77\x44\xfe\x7e\x3c"- , {- M = -} 8)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\xd5\x60\x91\x2d\x3f\x70\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\xcd\x90\x44\xd2\xb7\x1f\xdb\x81\x20\xea\x60\xc0"- , {- in = -} "\x64\x35\xac\xba\xfb\x11\xa8\x2e\x2f\x07\x1d\x7c\xa4\xa5\xeb\xd9\x3a\x80\x3b\xa8\x7f"- , {- out = -} "\xcd\x90\x44\xd2\xb7\x1f\xdb\x81\x20\xea\x60\xc0\x00\x97\x69\xec\xab\xdf\x48\x62\x55\x94\xc5\x92\x51\xe6\x03\x57\x22\x67\x5e\x04\xc8\x47\x09\x9e\x5a\xe0\x70\x45\x51"- , {- M = -} 8)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\x42\xff\xf8\xf1\x95\x1c\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\xd8\x5b\xc7\xe6\x9f\x94\x4f\xb8"- , {- in = -} "\x8a\x19\xb9\x50\xbc\xf7\x1a\x01\x8e\x5e\x67\x01\xc9\x17\x87\x65\x98\x09\xd6\x7d\xbe\xdd\x18"- , {- out = -} "\xd8\x5b\xc7\xe6\x9f\x94\x4f\xb8\xbc\x21\x8d\xaa\x94\x74\x27\xb6\xdb\x38\x6a\x99\xac\x1a\xef\x23\xad\xe0\xb5\x29\x39\xcb\x6a\x63\x7c\xf9\xbe\xc2\x40\x88\x97\xc6\xba"- , {- M = -} 10)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\x92\x0f\x40\xe5\x6c\xdc\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\x74\xa0\xeb\xc9\x06\x9f\x5b\x37"- , {- in = -} "\x17\x61\x43\x3c\x37\xc5\xa3\x5f\xc1\xf3\x9f\x40\x63\x02\xeb\x90\x7c\x61\x63\xbe\x38\xc9\x84\x37"- , {- out = -} "\x74\xa0\xeb\xc9\x06\x9f\x5b\x37\x58\x10\xe6\xfd\x25\x87\x40\x22\xe8\x03\x61\xa4\x78\xe3\xe9\xcf\x48\x4a\xb0\x4f\x44\x7e\xff\xf6\xf0\xa4\x77\xcc\x2f\xc9\xbf\x54\x89\x44"- , {- M = -} 10)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\x27\xca\x0c\x71\x20\xbc\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\x44\xa3\xaa\x3a\xae\x64\x75\xca"- , {- in = -} "\xa4\x34\xa8\xe5\x85\x00\xc6\xe4\x15\x30\x53\x88\x62\xd6\x86\xea\x9e\x81\x30\x1b\x5a\xe4\x22\x6b\xfa"- , {- out = -} "\x44\xa3\xaa\x3a\xae\x64\x75\xca\xf2\xbe\xed\x7b\xc5\x09\x8e\x83\xfe\xb5\xb3\x16\x08\xf8\xe2\x9c\x38\x81\x9a\x89\xc8\xe7\x76\xf1\x54\x4d\x41\x51\xa4\xed\x3a\x8b\x87\xb9\xce"- , {- M = -} 10)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\x5b\x8c\xcb\xcd\x9a\xf8\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\xec\x46\xbb\x63\xb0\x25\x20\xc3\x3c\x49\xfd\x70"- , {- in = -} "\xb9\x6b\x49\xe2\x1d\x62\x17\x41\x63\x28\x75\xdb\x7f\x6c\x92\x43\xd2\xd7\xc2"- , {- out = -} "\xec\x46\xbb\x63\xb0\x25\x20\xc3\x3c\x49\xfd\x70\x31\xd7\x50\xa0\x9d\xa3\xed\x7f\xdd\xd4\x9a\x20\x32\xaa\xbf\x17\xec\x8e\xbf\x7d\x22\xc8\x08\x8c\x66\x6b\xe5\xc1\x97"- , {- M = -} 10)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\x3e\xbe\x94\x04\x4b\x9a\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\x47\xa6\x5a\xc7\x8b\x3d\x59\x42\x27\xe8\x5e\x71"- , {- in = -} "\xe2\xfc\xfb\xb8\x80\x44\x2c\x73\x1b\xf9\x51\x67\xc8\xff\xd7\x89\x5e\x33\x70\x76"- , {- out = -} "\x47\xa6\x5a\xc7\x8b\x3d\x59\x42\x27\xe8\x5e\x71\xe8\x82\xf1\xdb\xd3\x8c\xe3\xed\xa7\xc2\x3f\x04\xdd\x65\x07\x1e\xb4\x13\x42\xac\xdf\x7e\x00\xdc\xce\xc7\xae\x52\x98\x7d"- , {- M = -} 10)- , ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"- , {- iv = -} "\x00\x8d\x49\x3b\x30\xae\x8b\x3c\x96\x96\x76\x6c\xfa"- , {- hdr = -} "\x6e\x37\xa6\xef\x54\x6d\x95\x5d\x34\xab\x60\x59"- , {- in = -} "\xab\xf2\x1c\x0b\x02\xfe\xb8\x8f\x85\x6d\xf4\xa3\x73\x81\xbc\xe3\xcc\x12\x85\x17\xd4"- , {- out = -} "\x6e\x37\xa6\xef\x54\x6d\x95\x5d\x34\xab\x60\x59\xf3\x29\x05\xb8\x8a\x64\x1b\x04\xb9\xc9\xff\xb5\x8c\xc3\x90\x90\x0f\x3d\xa1\x2a\xb1\x6d\xce\x9e\x82\xef\xa1\x6d\xa6\x20\x59"- , {- M = -} 10)- ]+ [+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x03\x02\x01\x00\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"+ , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x58\x8c\x97\x9a\x61\xc6\x63\xd2\xf0\x66\xd0\xc2\xc0\xf9\x89\x80\x6d\x5f\x6b\x61\xda\xc3\x84\x17\xe8\xd1\x2c\xfd\xf9\x26\xe0"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x04\x03\x02\x01\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"+ , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x72\xc9\x1a\x36\xe1\x35\xf8\xcf\x29\x1c\xa8\x94\x08\x5c\x87\xe3\xcc\x15\xc4\x39\xc9\xe4\x3a\x3b\xa0\x91\xd5\x6e\x10\x40\x09\x16"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x05\x04\x03\x02\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"+ , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x51\xb1\xe5\xf4\x4a\x19\x7d\x1d\xa4\x6b\x0f\x8e\x2d\x28\x2a\xe8\x71\xe8\x38\xbb\x64\xda\x85\x96\x57\x4a\xda\xa7\x6f\xbd\x9f\xb0\xc5"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x06\x05\x04\x03\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"+ , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\xa2\x8c\x68\x65\x93\x9a\x9a\x79\xfa\xaa\x5c\x4c\x2a\x9d\x4a\x91\xcd\xac\x8c\x96\xc8\x61\xb9\xc9\xe6\x1e\xf1"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x07\x06\x05\x04\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"+ , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\xdc\xf1\xfb\x7b\x5d\x9e\x23\xfb\x9d\x4e\x13\x12\x53\x65\x8a\xd8\x6e\xbd\xca\x3e\x51\xe8\x3f\x07\x7d\x9c\x2d\x93"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x08\x07\x06\x05\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"+ , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x6f\xc1\xb0\x11\xf0\x06\x56\x8b\x51\x71\xa4\x2d\x95\x3d\x46\x9b\x25\x70\xa4\xbd\x87\x40\x5a\x04\x43\xac\x91\xcb\x94"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x09\x08\x07\x06\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"+ , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x01\x35\xd1\xb2\xc9\x5f\x41\xd5\xd1\xd4\xfe\xc1\x85\xd1\x66\xb8\x09\x4e\x99\x9d\xfe\xd9\x6c\x04\x8c\x56\x60\x2c\x97\xac\xbb\x74\x90"+ , {- M = -} 10+ )+ ,+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x0a\x09\x08\x07\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"+ , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x7b\x75\x39\x9a\xc0\x83\x1d\xd2\xf0\xbb\xd7\x58\x79\xa2\xfd\x8f\x6c\xae\x6b\x6c\xd9\xb7\xdb\x24\xc1\x7b\x44\x33\xf4\x34\x96\x3f\x34\xb4"+ , {- M = -} 10+ )+ ,+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x0b\x0a\x09\x08\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07"+ , {- in = -} "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x82\x53\x1a\x60\xcc\x24\x94\x5a\x4b\x82\x79\x18\x1a\xb5\xc8\x4d\xf2\x1c\xe7\xf9\xb7\x3f\x42\xe1\x97\xea\x9c\x07\xe5\x6b\x5e\xb1\x7e\x5f\x4e"+ , {- M = -} 10+ )+ ,+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x0c\x0b\x0a\x09\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"+ , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x07\x34\x25\x94\x15\x77\x85\x15\x2b\x07\x40\x98\x33\x0a\xbb\x14\x1b\x94\x7b\x56\x6a\xa9\x40\x6b\x4d\x99\x99\x88\xdd"+ , {- M = -} 10+ )+ ,+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x0d\x0c\x0b\x0a\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"+ , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x67\x6b\xb2\x03\x80\xb0\xe3\x01\xe8\xab\x79\x59\x0a\x39\x6d\xa7\x8b\x83\x49\x34\xf5\x3a\xa2\xe9\x10\x7a\x8b\x6c\x02\x2c"+ , {- M = -} 10+ )+ ,+ ( {- key = -} "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"+ , {- iv = -} "\x00\x00\x00\x0e\x0d\x0c\x0b\xa0\xa1\xa2\xa3\xa4\xa5"+ , {- hdr = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"+ , {- in = -} "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"+ , {- out = -} "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\xc0\xff\xa0\xd6\xf0\x5b\xdb\x67\xf2\x4d\x43\xa4\x33\x8d\x2a\xa4\xbe\xd7\xb2\x0e\x43\xcd\x1a\xa3\x16\x62\xe7\xad\x65\xd6\xdb"+ , {- M = -} 10+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\x41\x2b\x4e\xa9\xcd\xbe\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\x0b\xe1\xa8\x8b\xac\xe0\x18\xb1"+ , {- in = -} "\x08\xe8\xcf\x97\xd8\x20\xea\x25\x84\x60\xe9\x6a\xd9\xcf\x52\x89\x05\x4d\x89\x5c\xea\xc4\x7c"+ , {- out = -} "\x0b\xe1\xa8\x8b\xac\xe0\x18\xb1\x4c\xb9\x7f\x86\xa2\xa4\x68\x9a\x87\x79\x47\xab\x80\x91\xef\x53\x86\xa6\xff\xbd\xd0\x80\xf8\xe7\x8c\xf7\xcb\x0c\xdd\xd7\xb3"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\x33\x56\x8e\xf7\xb2\x63\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\x63\x01\x8f\x76\xdc\x8a\x1b\xcb"+ , {- in = -} "\x90\x20\xea\x6f\x91\xbd\xd8\x5a\xfa\x00\x39\xba\x4b\xaf\xf9\xbf\xb7\x9c\x70\x28\x94\x9c\xd0\xec"+ , {- out = -} "\x63\x01\x8f\x76\xdc\x8a\x1b\xcb\x4c\xcb\x1e\x7c\xa9\x81\xbe\xfa\xa0\x72\x6c\x55\xd3\x78\x06\x12\x98\xc8\x5c\x92\x81\x4a\xbc\x33\xc5\x2e\xe8\x1d\x7d\x77\xc0\x8a"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\x10\x3f\xe4\x13\x36\x71\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\xaa\x6c\xfa\x36\xca\xe8\x6b\x40"+ , {- in = -} "\xb9\x16\xe0\xea\xcc\x1c\x00\xd7\xdc\xec\x68\xec\x0b\x3b\xbb\x1a\x02\xde\x8a\x2d\x1a\xa3\x46\x13\x2e"+ , {- out = -} "\xaa\x6c\xfa\x36\xca\xe8\x6b\x40\xb1\xd2\x3a\x22\x20\xdd\xc0\xac\x90\x0d\x9a\xa0\x3c\x61\xfc\xf4\xa5\x59\xa4\x41\x77\x67\x08\x97\x08\xa7\x76\x79\x6e\xdb\x72\x35\x06"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\x76\x4c\x63\xb8\x05\x8e\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\xd0\xd0\x73\x5c\x53\x1e\x1b\xec\xf0\x49\xc2\x44"+ , {- in = -} "\x12\xda\xac\x56\x30\xef\xa5\x39\x6f\x77\x0c\xe1\xa6\x6b\x21\xf7\xb2\x10\x1c"+ , {- out = -} "\xd0\xd0\x73\x5c\x53\x1e\x1b\xec\xf0\x49\xc2\x44\x14\xd2\x53\xc3\x96\x7b\x70\x60\x9b\x7c\xbb\x7c\x49\x91\x60\x28\x32\x45\x26\x9a\x6f\x49\x97\x5b\xca\xde\xaf"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\xf8\xb6\x78\x09\x4e\x3b\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\x77\xb6\x0f\x01\x1c\x03\xe1\x52\x58\x99\xbc\xae"+ , {- in = -} "\xe8\x8b\x6a\x46\xc7\x8d\x63\xe5\x2e\xb8\xc5\x46\xef\xb5\xde\x6f\x75\xe9\xcc\x0d"+ , {- out = -} "\x77\xb6\x0f\x01\x1c\x03\xe1\x52\x58\x99\xbc\xae\x55\x45\xff\x1a\x08\x5e\xe2\xef\xbf\x52\xb2\xe0\x4b\xee\x1e\x23\x36\xc7\x3e\x3f\x76\x2c\x0c\x77\x44\xfe\x7e\x3c"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\xd5\x60\x91\x2d\x3f\x70\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\xcd\x90\x44\xd2\xb7\x1f\xdb\x81\x20\xea\x60\xc0"+ , {- in = -} "\x64\x35\xac\xba\xfb\x11\xa8\x2e\x2f\x07\x1d\x7c\xa4\xa5\xeb\xd9\x3a\x80\x3b\xa8\x7f"+ , {- out = -} "\xcd\x90\x44\xd2\xb7\x1f\xdb\x81\x20\xea\x60\xc0\x00\x97\x69\xec\xab\xdf\x48\x62\x55\x94\xc5\x92\x51\xe6\x03\x57\x22\x67\x5e\x04\xc8\x47\x09\x9e\x5a\xe0\x70\x45\x51"+ , {- M = -} 8+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\x42\xff\xf8\xf1\x95\x1c\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\xd8\x5b\xc7\xe6\x9f\x94\x4f\xb8"+ , {- in = -} "\x8a\x19\xb9\x50\xbc\xf7\x1a\x01\x8e\x5e\x67\x01\xc9\x17\x87\x65\x98\x09\xd6\x7d\xbe\xdd\x18"+ , {- out = -} "\xd8\x5b\xc7\xe6\x9f\x94\x4f\xb8\xbc\x21\x8d\xaa\x94\x74\x27\xb6\xdb\x38\x6a\x99\xac\x1a\xef\x23\xad\xe0\xb5\x29\x39\xcb\x6a\x63\x7c\xf9\xbe\xc2\x40\x88\x97\xc6\xba"+ , {- M = -} 10+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\x92\x0f\x40\xe5\x6c\xdc\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\x74\xa0\xeb\xc9\x06\x9f\x5b\x37"+ , {- in = -} "\x17\x61\x43\x3c\x37\xc5\xa3\x5f\xc1\xf3\x9f\x40\x63\x02\xeb\x90\x7c\x61\x63\xbe\x38\xc9\x84\x37"+ , {- out = -} "\x74\xa0\xeb\xc9\x06\x9f\x5b\x37\x58\x10\xe6\xfd\x25\x87\x40\x22\xe8\x03\x61\xa4\x78\xe3\xe9\xcf\x48\x4a\xb0\x4f\x44\x7e\xff\xf6\xf0\xa4\x77\xcc\x2f\xc9\xbf\x54\x89\x44"+ , {- M = -} 10+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\x27\xca\x0c\x71\x20\xbc\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\x44\xa3\xaa\x3a\xae\x64\x75\xca"+ , {- in = -} "\xa4\x34\xa8\xe5\x85\x00\xc6\xe4\x15\x30\x53\x88\x62\xd6\x86\xea\x9e\x81\x30\x1b\x5a\xe4\x22\x6b\xfa"+ , {- out = -} "\x44\xa3\xaa\x3a\xae\x64\x75\xca\xf2\xbe\xed\x7b\xc5\x09\x8e\x83\xfe\xb5\xb3\x16\x08\xf8\xe2\x9c\x38\x81\x9a\x89\xc8\xe7\x76\xf1\x54\x4d\x41\x51\xa4\xed\x3a\x8b\x87\xb9\xce"+ , {- M = -} 10+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\x5b\x8c\xcb\xcd\x9a\xf8\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\xec\x46\xbb\x63\xb0\x25\x20\xc3\x3c\x49\xfd\x70"+ , {- in = -} "\xb9\x6b\x49\xe2\x1d\x62\x17\x41\x63\x28\x75\xdb\x7f\x6c\x92\x43\xd2\xd7\xc2"+ , {- out = -} "\xec\x46\xbb\x63\xb0\x25\x20\xc3\x3c\x49\xfd\x70\x31\xd7\x50\xa0\x9d\xa3\xed\x7f\xdd\xd4\x9a\x20\x32\xaa\xbf\x17\xec\x8e\xbf\x7d\x22\xc8\x08\x8c\x66\x6b\xe5\xc1\x97"+ , {- M = -} 10+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\x3e\xbe\x94\x04\x4b\x9a\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\x47\xa6\x5a\xc7\x8b\x3d\x59\x42\x27\xe8\x5e\x71"+ , {- in = -} "\xe2\xfc\xfb\xb8\x80\x44\x2c\x73\x1b\xf9\x51\x67\xc8\xff\xd7\x89\x5e\x33\x70\x76"+ , {- out = -} "\x47\xa6\x5a\xc7\x8b\x3d\x59\x42\x27\xe8\x5e\x71\xe8\x82\xf1\xdb\xd3\x8c\xe3\xed\xa7\xc2\x3f\x04\xdd\x65\x07\x1e\xb4\x13\x42\xac\xdf\x7e\x00\xdc\xce\xc7\xae\x52\x98\x7d"+ , {- M = -} 10+ )+ ,+ ( {- key = -} "\xd7\x82\x8d\x13\xb2\xb0\xbd\xc3\x25\xa7\x62\x36\xdf\x93\xcc\x6b"+ , {- iv = -} "\x00\x8d\x49\x3b\x30\xae\x8b\x3c\x96\x96\x76\x6c\xfa"+ , {- hdr = -} "\x6e\x37\xa6\xef\x54\x6d\x95\x5d\x34\xab\x60\x59"+ , {- in = -} "\xab\xf2\x1c\x0b\x02\xfe\xb8\x8f\x85\x6d\xf4\xa3\x73\x81\xbc\xe3\xcc\x12\x85\x17\xd4"+ , {- out = -} "\x6e\x37\xa6\xef\x54\x6d\x95\x5d\x34\xab\x60\x59\xf3\x29\x05\xb8\x8a\x64\x1b\x04\xb9\xc9\xff\xb5\x8c\xc3\x90\x90\x0f\x3d\xa1\x2a\xb1\x6d\xce\x9e\x82\xef\xa1\x6d\xa6\x20\x59"+ , {- M = -} 10+ )+ ]
tests/KAT_AES/KATECB.hs view
@@ -4,145 +4,717 @@ vectors_aes128_enc = [- ( B.pack [0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,0x74,0xcf,0x86,0x7c,0xfb,0x47,0x38,0x59]- , B.replicate 16 0- , B.pack [0x6d,0x25,0x1e,0x69,0x44,0xb0,0x51,0xe0,0x4e,0xaa,0x6f,0xb4,0xdb,0xf7,0x84,0x65]- )- , ( B.replicate 16 0- , B.replicate 16 0- , B.pack [0x66,0xe9,0x4b,0xd4,0xef,0x8a,0x2c,0x3b,0x88,0x4c,0xfa,0x59,0xca,0x34,0x2b,0x2e]- )- , ( B.replicate 16 0- , B.replicate 16 1- , B.pack [0xe1,0x4d,0x5d,0x0e,0xe2,0x77,0x15,0xdf,0x08,0xb4,0x15,0x2b,0xa2,0x3d,0xa8,0xe0]- )- , ( B.replicate 16 1- , B.replicate 16 2- , B.pack [0x17,0xd6,0x14,0xf3,0x79,0xa9,0x35,0x90,0x77,0xe9,0x55,0x77,0xfd,0x31,0xc2,0x0a]- )- , ( B.replicate 16 2- , B.replicate 16 1- , B.pack [0x8f,0x42,0xc2,0x4b,0xee,0x6e,0x63,0x47,0x2b,0x16,0x5a,0xa9,0x41,0x31,0x2f,0x7c]- )- , ( B.replicate 16 3- , B.replicate 16 2- , B.pack [0x90,0x98,0x85,0xe4,0x77,0xbc,0x20,0xf5,0x8a,0x66,0x97,0x1d,0xa0,0xbc,0x75,0xe3]- )+ ( B.pack+ [ 0x10+ , 0xa5+ , 0x88+ , 0x69+ , 0xd7+ , 0x4b+ , 0xe5+ , 0xa3+ , 0x74+ , 0xcf+ , 0x86+ , 0x7c+ , 0xfb+ , 0x47+ , 0x38+ , 0x59+ ]+ , B.replicate 16 0+ , B.pack+ [ 0x6d+ , 0x25+ , 0x1e+ , 0x69+ , 0x44+ , 0xb0+ , 0x51+ , 0xe0+ , 0x4e+ , 0xaa+ , 0x6f+ , 0xb4+ , 0xdb+ , 0xf7+ , 0x84+ , 0x65+ ]+ )+ ,+ ( B.replicate 16 0+ , B.replicate 16 0+ , B.pack+ [ 0x66+ , 0xe9+ , 0x4b+ , 0xd4+ , 0xef+ , 0x8a+ , 0x2c+ , 0x3b+ , 0x88+ , 0x4c+ , 0xfa+ , 0x59+ , 0xca+ , 0x34+ , 0x2b+ , 0x2e+ ]+ )+ ,+ ( B.replicate 16 0+ , B.replicate 16 1+ , B.pack+ [ 0xe1+ , 0x4d+ , 0x5d+ , 0x0e+ , 0xe2+ , 0x77+ , 0x15+ , 0xdf+ , 0x08+ , 0xb4+ , 0x15+ , 0x2b+ , 0xa2+ , 0x3d+ , 0xa8+ , 0xe0+ ]+ )+ ,+ ( B.replicate 16 1+ , B.replicate 16 2+ , B.pack+ [ 0x17+ , 0xd6+ , 0x14+ , 0xf3+ , 0x79+ , 0xa9+ , 0x35+ , 0x90+ , 0x77+ , 0xe9+ , 0x55+ , 0x77+ , 0xfd+ , 0x31+ , 0xc2+ , 0x0a+ ]+ )+ ,+ ( B.replicate 16 2+ , B.replicate 16 1+ , B.pack+ [ 0x8f+ , 0x42+ , 0xc2+ , 0x4b+ , 0xee+ , 0x6e+ , 0x63+ , 0x47+ , 0x2b+ , 0x16+ , 0x5a+ , 0xa9+ , 0x41+ , 0x31+ , 0x2f+ , 0x7c+ ]+ )+ ,+ ( B.replicate 16 3+ , B.replicate 16 2+ , B.pack+ [ 0x90+ , 0x98+ , 0x85+ , 0xe4+ , 0x77+ , 0xbc+ , 0x20+ , 0xf5+ , 0x8a+ , 0x66+ , 0x97+ , 0x1d+ , 0xa0+ , 0xbc+ , 0x75+ , 0xe3+ ]+ ) ] vectors_aes192_enc = [- ( B.replicate 24 0- , B.replicate 16 0- , B.pack [0xaa,0xe0,0x69,0x92,0xac,0xbf,0x52,0xa3,0xe8,0xf4,0xa9,0x6e,0xc9,0x30,0x0b,0xd7]- )- , ( B.replicate 24 0- , B.replicate 16 1- , B.pack [0xcf,0x1e,0xce,0x3c,0x44,0xb0,0x78,0xfb,0x27,0xcb,0x0a,0x3e,0x07,0x1b,0x08,0x20]- )- , ( B.replicate 24 1- , B.replicate 16 2- , B.pack [0xeb,0x8c,0x17,0x30,0x90,0xc7,0x5b,0x77,0xd6,0x72,0xb4,0x57,0xa7,0x78,0xd9,0xd0]- )- , ( B.replicate 24 2- , B.replicate 16 1- , B.pack [0xf2,0xf0,0xae,0xd8,0xcd,0xc9,0x21,0xca,0x4b,0x55,0x84,0x5d,0xa4,0x15,0x21,0xc2]- )- , ( B.replicate 24 3- , B.replicate 16 2- , B.pack [0xca,0xcc,0x30,0x79,0xe4,0xb7,0x95,0x27,0x63,0xd2,0x55,0xd6,0x34,0x10,0x46,0x14]- )+ ( B.replicate 24 0+ , B.replicate 16 0+ , B.pack+ [ 0xaa+ , 0xe0+ , 0x69+ , 0x92+ , 0xac+ , 0xbf+ , 0x52+ , 0xa3+ , 0xe8+ , 0xf4+ , 0xa9+ , 0x6e+ , 0xc9+ , 0x30+ , 0x0b+ , 0xd7+ ]+ )+ ,+ ( B.replicate 24 0+ , B.replicate 16 1+ , B.pack+ [ 0xcf+ , 0x1e+ , 0xce+ , 0x3c+ , 0x44+ , 0xb0+ , 0x78+ , 0xfb+ , 0x27+ , 0xcb+ , 0x0a+ , 0x3e+ , 0x07+ , 0x1b+ , 0x08+ , 0x20+ ]+ )+ ,+ ( B.replicate 24 1+ , B.replicate 16 2+ , B.pack+ [ 0xeb+ , 0x8c+ , 0x17+ , 0x30+ , 0x90+ , 0xc7+ , 0x5b+ , 0x77+ , 0xd6+ , 0x72+ , 0xb4+ , 0x57+ , 0xa7+ , 0x78+ , 0xd9+ , 0xd0+ ]+ )+ ,+ ( B.replicate 24 2+ , B.replicate 16 1+ , B.pack+ [ 0xf2+ , 0xf0+ , 0xae+ , 0xd8+ , 0xcd+ , 0xc9+ , 0x21+ , 0xca+ , 0x4b+ , 0x55+ , 0x84+ , 0x5d+ , 0xa4+ , 0x15+ , 0x21+ , 0xc2+ ]+ )+ ,+ ( B.replicate 24 3+ , B.replicate 16 2+ , B.pack+ [ 0xca+ , 0xcc+ , 0x30+ , 0x79+ , 0xe4+ , 0xb7+ , 0x95+ , 0x27+ , 0x63+ , 0xd2+ , 0x55+ , 0xd6+ , 0x34+ , 0x10+ , 0x46+ , 0x14+ ]+ ) ] vectors_aes256_enc =- [ ( B.replicate 32 0- , B.replicate 16 0- , B.pack [0xdc,0x95,0xc0,0x78,0xa2,0x40,0x89,0x89,0xad,0x48,0xa2,0x14,0x92,0x84,0x20,0x87]- )- , ( B.replicate 32 0- , B.replicate 16 1- , B.pack [0x7b,0xc3,0x02,0x6c,0xd7,0x37,0x10,0x3e,0x62,0x90,0x2b,0xcd,0x18,0xfb,0x01,0x63]- )- , ( B.replicate 32 1- , B.replicate 16 2- , B.pack [0x62,0xae,0x12,0xf3,0x24,0xbf,0xea,0x08,0xd5,0xf6,0x75,0xb5,0x13,0x02,0x6b,0xbf]- )- , ( B.replicate 32 2- , B.replicate 16 1- , B.pack [0x00,0xf9,0xc7,0x44,0x4b,0xb0,0xcc,0x80,0x6c,0x7c,0x39,0xee,0x22,0x11,0xf1,0x46]- )- , ( B.replicate 32 3- , B.replicate 16 2- , B.pack [0xb4,0x05,0x87,0x3e,0xa0,0x76,0x1b,0x9c,0xa9,0x9f,0x70,0xb0,0x16,0x16,0xce,0xb1]- )+ [+ ( B.replicate 32 0+ , B.replicate 16 0+ , B.pack+ [ 0xdc+ , 0x95+ , 0xc0+ , 0x78+ , 0xa2+ , 0x40+ , 0x89+ , 0x89+ , 0xad+ , 0x48+ , 0xa2+ , 0x14+ , 0x92+ , 0x84+ , 0x20+ , 0x87+ ]+ )+ ,+ ( B.replicate 32 0+ , B.replicate 16 1+ , B.pack+ [ 0x7b+ , 0xc3+ , 0x02+ , 0x6c+ , 0xd7+ , 0x37+ , 0x10+ , 0x3e+ , 0x62+ , 0x90+ , 0x2b+ , 0xcd+ , 0x18+ , 0xfb+ , 0x01+ , 0x63+ ]+ )+ ,+ ( B.replicate 32 1+ , B.replicate 16 2+ , B.pack+ [ 0x62+ , 0xae+ , 0x12+ , 0xf3+ , 0x24+ , 0xbf+ , 0xea+ , 0x08+ , 0xd5+ , 0xf6+ , 0x75+ , 0xb5+ , 0x13+ , 0x02+ , 0x6b+ , 0xbf+ ]+ )+ ,+ ( B.replicate 32 2+ , B.replicate 16 1+ , B.pack+ [ 0x00+ , 0xf9+ , 0xc7+ , 0x44+ , 0x4b+ , 0xb0+ , 0xcc+ , 0x80+ , 0x6c+ , 0x7c+ , 0x39+ , 0xee+ , 0x22+ , 0x11+ , 0xf1+ , 0x46+ ]+ )+ ,+ ( B.replicate 32 3+ , B.replicate 16 2+ , B.pack+ [ 0xb4+ , 0x05+ , 0x87+ , 0x3e+ , 0xa0+ , 0x76+ , 0x1b+ , 0x9c+ , 0xa9+ , 0x9f+ , 0x70+ , 0xb0+ , 0x16+ , 0x16+ , 0xce+ , 0xb1+ ]+ ) ] vectors_aes128_dec =- [ ( B.replicate 16 0- , B.replicate 16 0- , B.pack [0x14,0x0f,0x0f,0x10,0x11,0xb5,0x22,0x3d,0x79,0x58,0x77,0x17,0xff,0xd9,0xec,0x3a]- )- , ( B.replicate 16 0- , B.replicate 16 1- , B.pack [0x15,0x6d,0x0f,0x85,0x75,0xd5,0x33,0x07,0x52,0xf8,0x4a,0xf2,0x72,0xff,0x30,0x50]- )- , ( B.replicate 16 1- , B.replicate 16 2- , B.pack [0x34,0x37,0xd6,0xe2,0x31,0xd7,0x02,0x41,0x9b,0x51,0xb4,0x94,0x72,0x71,0xb6,0x11]- )- , ( B.replicate 16 2- , B.replicate 16 1- , B.pack [0xe3,0xcd,0xe2,0x37,0xc8,0xf2,0xd9,0x7b,0x8d,0x79,0xf9,0x17,0x1d,0x4b,0xda,0xc1]- )- , ( B.replicate 16 3- , B.replicate 16 2- , B.pack [0x5b,0x94,0xaa,0xed,0xd7,0x83,0x99,0x8c,0xd5,0x15,0x35,0x35,0x18,0xcc,0x45,0xe2]- )+ [+ ( B.replicate 16 0+ , B.replicate 16 0+ , B.pack+ [ 0x14+ , 0x0f+ , 0x0f+ , 0x10+ , 0x11+ , 0xb5+ , 0x22+ , 0x3d+ , 0x79+ , 0x58+ , 0x77+ , 0x17+ , 0xff+ , 0xd9+ , 0xec+ , 0x3a+ ]+ )+ ,+ ( B.replicate 16 0+ , B.replicate 16 1+ , B.pack+ [ 0x15+ , 0x6d+ , 0x0f+ , 0x85+ , 0x75+ , 0xd5+ , 0x33+ , 0x07+ , 0x52+ , 0xf8+ , 0x4a+ , 0xf2+ , 0x72+ , 0xff+ , 0x30+ , 0x50+ ]+ )+ ,+ ( B.replicate 16 1+ , B.replicate 16 2+ , B.pack+ [ 0x34+ , 0x37+ , 0xd6+ , 0xe2+ , 0x31+ , 0xd7+ , 0x02+ , 0x41+ , 0x9b+ , 0x51+ , 0xb4+ , 0x94+ , 0x72+ , 0x71+ , 0xb6+ , 0x11+ ]+ )+ ,+ ( B.replicate 16 2+ , B.replicate 16 1+ , B.pack+ [ 0xe3+ , 0xcd+ , 0xe2+ , 0x37+ , 0xc8+ , 0xf2+ , 0xd9+ , 0x7b+ , 0x8d+ , 0x79+ , 0xf9+ , 0x17+ , 0x1d+ , 0x4b+ , 0xda+ , 0xc1+ ]+ )+ ,+ ( B.replicate 16 3+ , B.replicate 16 2+ , B.pack+ [ 0x5b+ , 0x94+ , 0xaa+ , 0xed+ , 0xd7+ , 0x83+ , 0x99+ , 0x8c+ , 0xd5+ , 0x15+ , 0x35+ , 0x35+ , 0x18+ , 0xcc+ , 0x45+ , 0xe2+ ]+ ) ] vectors_aes192_dec = [- ( B.replicate 24 0- , B.replicate 16 0- , B.pack [0x13,0x46,0x0e,0x87,0xa8,0xfc,0x02,0x3e,0xf2,0x50,0x1a,0xfe,0x7f,0xf5,0x1c,0x51]- )- , ( B.replicate 24 0- , B.replicate 16 1- , B.pack [0x92,0x17,0x07,0xc3,0x3d,0x1c,0xc5,0x96,0x7d,0xa5,0x1d,0xbb,0xb0,0x66,0xb2,0x6c]- )- , ( B.replicate 24 1- , B.replicate 16 2- , B.pack [0xee,0x92,0x97,0xc6,0xba,0xe8,0x26,0x4d,0xff,0x08,0x0e,0xbb,0x1e,0x74,0x11,0xc1]- )- , ( B.replicate 24 2- , B.replicate 16 1- , B.pack [0x49,0x67,0xdf,0x70,0xd2,0x9e,0x9a,0x7f,0x5d,0x7c,0xb9,0xc1,0x20,0xc3,0x8a,0x71]- )- , ( B.replicate 24 3- , B.replicate 16 2- , B.pack [0x74,0x38,0x62,0x42,0x6b,0x56,0x7f,0xd5,0xf0,0x1d,0x1b,0x59,0x56,0x01,0x26,0x29]- )+ ( B.replicate 24 0+ , B.replicate 16 0+ , B.pack+ [ 0x13+ , 0x46+ , 0x0e+ , 0x87+ , 0xa8+ , 0xfc+ , 0x02+ , 0x3e+ , 0xf2+ , 0x50+ , 0x1a+ , 0xfe+ , 0x7f+ , 0xf5+ , 0x1c+ , 0x51+ ]+ )+ ,+ ( B.replicate 24 0+ , B.replicate 16 1+ , B.pack+ [ 0x92+ , 0x17+ , 0x07+ , 0xc3+ , 0x3d+ , 0x1c+ , 0xc5+ , 0x96+ , 0x7d+ , 0xa5+ , 0x1d+ , 0xbb+ , 0xb0+ , 0x66+ , 0xb2+ , 0x6c+ ]+ )+ ,+ ( B.replicate 24 1+ , B.replicate 16 2+ , B.pack+ [ 0xee+ , 0x92+ , 0x97+ , 0xc6+ , 0xba+ , 0xe8+ , 0x26+ , 0x4d+ , 0xff+ , 0x08+ , 0x0e+ , 0xbb+ , 0x1e+ , 0x74+ , 0x11+ , 0xc1+ ]+ )+ ,+ ( B.replicate 24 2+ , B.replicate 16 1+ , B.pack+ [ 0x49+ , 0x67+ , 0xdf+ , 0x70+ , 0xd2+ , 0x9e+ , 0x9a+ , 0x7f+ , 0x5d+ , 0x7c+ , 0xb9+ , 0xc1+ , 0x20+ , 0xc3+ , 0x8a+ , 0x71+ ]+ )+ ,+ ( B.replicate 24 3+ , B.replicate 16 2+ , B.pack+ [ 0x74+ , 0x38+ , 0x62+ , 0x42+ , 0x6b+ , 0x56+ , 0x7f+ , 0xd5+ , 0xf0+ , 0x1d+ , 0x1b+ , 0x59+ , 0x56+ , 0x01+ , 0x26+ , 0x29+ ]+ ) ] vectors_aes256_dec =- [ ( B.replicate 32 0- , B.replicate 16 0- , B.pack [0x67,0x67,0x1c,0xe1,0xfa,0x91,0xdd,0xeb,0x0f,0x8f,0xbb,0xb3,0x66,0xb5,0x31,0xb4]- )- , ( B.replicate 32 0- , B.replicate 16 1- , B.pack [0xcc,0x09,0x21,0xa3,0xc5,0xca,0x17,0xf7,0x48,0xb7,0xc2,0x7b,0x73,0xba,0x87,0xa2]- )- , ( B.replicate 32 1- , B.replicate 16 2- , B.pack [0xc0,0x4b,0x27,0x90,0x1a,0x50,0xcf,0xfa,0xf1,0xbb,0x88,0x9f,0xc0,0x92,0x5e,0x14]- )- , ( B.replicate 32 2- , B.replicate 16 1- , B.pack [0x24,0x61,0x53,0x5d,0x16,0x1c,0x15,0x39,0x88,0x32,0x77,0x29,0xc5,0x8c,0xc0,0x3a]- )- , ( B.replicate 32 3- , B.replicate 16 2- , B.pack [0x30,0xc9,0x1c,0xce,0xfe,0x89,0x30,0xcf,0xff,0x31,0xdb,0xcc,0xfc,0x11,0xc5,0x23]- )+ [+ ( B.replicate 32 0+ , B.replicate 16 0+ , B.pack+ [ 0x67+ , 0x67+ , 0x1c+ , 0xe1+ , 0xfa+ , 0x91+ , 0xdd+ , 0xeb+ , 0x0f+ , 0x8f+ , 0xbb+ , 0xb3+ , 0x66+ , 0xb5+ , 0x31+ , 0xb4+ ]+ )+ ,+ ( B.replicate 32 0+ , B.replicate 16 1+ , B.pack+ [ 0xcc+ , 0x09+ , 0x21+ , 0xa3+ , 0xc5+ , 0xca+ , 0x17+ , 0xf7+ , 0x48+ , 0xb7+ , 0xc2+ , 0x7b+ , 0x73+ , 0xba+ , 0x87+ , 0xa2+ ]+ )+ ,+ ( B.replicate 32 1+ , B.replicate 16 2+ , B.pack+ [ 0xc0+ , 0x4b+ , 0x27+ , 0x90+ , 0x1a+ , 0x50+ , 0xcf+ , 0xfa+ , 0xf1+ , 0xbb+ , 0x88+ , 0x9f+ , 0xc0+ , 0x92+ , 0x5e+ , 0x14+ ]+ )+ ,+ ( B.replicate 32 2+ , B.replicate 16 1+ , B.pack+ [ 0x24+ , 0x61+ , 0x53+ , 0x5d+ , 0x16+ , 0x1c+ , 0x15+ , 0x39+ , 0x88+ , 0x32+ , 0x77+ , 0x29+ , 0xc5+ , 0x8c+ , 0xc0+ , 0x3a+ ]+ )+ ,+ ( B.replicate 32 3+ , B.replicate 16 2+ , B.pack+ [ 0x30+ , 0xc9+ , 0x1c+ , 0xce+ , 0xfe+ , 0x89+ , 0x30+ , 0xcf+ , 0xff+ , 0x31+ , 0xdb+ , 0xcc+ , 0xfc+ , 0x11+ , 0xc5+ , 0x23+ ]+ ) ]
tests/KAT_AES/KATGCM.hs view
@@ -1,69 +1,91 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_AES.KATGCM where import qualified Data.ByteString as B import Data.ByteString.Char8 () -- (key, iv, aad, input, out, taglen, tag)-type KATGCM = (B.ByteString, B.ByteString, B.ByteString, B.ByteString, B.ByteString, Int, B.ByteString)+type KATGCM =+ ( B.ByteString+ , B.ByteString+ , B.ByteString+ , B.ByteString+ , B.ByteString+ , Int+ , B.ByteString+ ) vectors_aes128_enc :: [KATGCM] vectors_aes128_enc = [ -- vectors 0- ( {-key = -}"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-iv = -}"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-aad = -}""- , {-input = -}""- , {-out = -}""- , {-taglen = -}16- , {-tag = -}"\x58\xe2\xfc\xce\xfa\x7e\x30\x61\x36\x7f\x1d\x57\xa4\xe7\x45\x5a")- -- vectors 1- , ( {-key = -}"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-iv = -}"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-aad = -}"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"- , {-input = -}"\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a"- , {-out = -}"\x09\x82\xd0\xc4\x6a\xbc\xa9\x98\xf9\x22\xc8\xb3\x7b\xb8\xf4\x72\xfd\x9f\xa0\xa1\x43\x41\x53\x29\xfd\xf7\x83\xf5\x9e\x81\xcb\xea"- , {-taglen = -}16- , {-tag = -}"\x28\x50\x64\x2f\xa8\x8b\xab\x21\x2a\x67\x1a\x97\x48\x69\xa5\x6c") - -- vectors 2- , ( {-key = -}"\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-iv = -}"\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-aad = -}"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"- , {-input = -}"\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a"- , {-out = -}"\x1c\xa3\xb5\x41\x39\x6f\x19\x7a\x91\x2d\x27\x15\x70\xd1\xf5\x76\xde\xf1\xbe\x84\x42\x2a\xbb\xbe\x0b\x2d\x91\x21\x82\xbf\x7f\x17"- , {-taglen = -}16- , {-tag = -}"\x15\x2a\x05\xbb\x7e\x13\x5d\xbe\x93\x7f\xa0\x54\x7a\x8e\x74\xb6")- -- vectors 3- , ( {-key = -}"\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-iv = -}"\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-aad = -}"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"- , {-input = -}"\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a"- , {-out = -}"\xda\x35\xf6\x0a\x65\xc2\xa4\x6c\xb6\x6e\xb6\xf8\x1f\x0b\x9c\x74\x53\x4c\x97\x70\x36\xf7\xdf\x05\x6d\x00\xfe\xbf\xb4\xcb\xf5\x27"- , {-taglen = -}16- , {-tag = -}"\xb7\x76\x7c\x3b\x9e\xf1\xe2\xcb\xc9\x11\xf1\x9a\xdc\xfa\x35\x0d")- , ( {-key = -}"\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-iv = -}"\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-aad = -}"\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76"- , {-input = -}"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"- , {-out = -}"\xe4\x42\xf8\xc4\xc6\x67\x84\x86\x4a\x5a\x6e\xc7\xe0\xca\x68\xac\x16\xbc\x5b\xbf\xf7\xd5\xf3\xfa\xf3\xb2\xcb\xb0\xa2\x14\xa1\x81"- , {-taglen = -}16- , {-tag = -}"\x5f\x63\xb8\xeb\x1d\x6f\xa8\x7a\xeb\x39\xa5\xf6\xd7\xed\xc3\x13")- , ( {-key = -}"\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-iv = -}"\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-aad = -}"\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76"- , {-input = -}"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"- , {-out = -}"\xe4\x42\xf8\xc4\xc6\x67\x84\x86\x4a\x5a\x6e\xc7\xe0\xca\x68\xac\x16\xbc\x5b\xbf\xf7\xd5\xf3\xfa\xf3\xb2\xcb\xb0\xa2\x14\xa1"- , {-taglen = -}16- , {-tag = -}"\x94\xd1\x47\xc3\xa2\xca\x93\xe9\x66\x93\x1e\x3b\xb3\xbb\x67\x01")- -- vector 6 tests 32-bit counter wrapping- , ( {-key = -}"\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , {-iv = -}"\xe8\x38\x84\x1d\x75\xae\x33\xb5\x4b\x51\x57\x89\xc9\x5f\xbe\x65"- , {-aad = -}"\x54\x68\x65\x20\x66\x69\x76\x65\x20\x62\x6f\x78\x69\x6e\x67\x20\x77\x69\x7a\x61\x72\x64\x73\x20\x6a\x75\x6d\x70\x20\x71\x75\x69\x63\x6b\x6c\x79\x2e"- , {-input = -}"\x54\x68\x65\x20\x71\x75\x69\x63\x6b\x20\x62\x72\x6f\x77\x6e\x20\x66\x6f\x78\x20\x6a\x75\x6d\x70\x73\x20\x6f\x76\x65\x72\x20\x74\x68\x65\x20\x6c\x61\x7a\x79\x20\x64\x6f\x67"- , {-out = -}"\x82\x31\x9e\x5a\x6a\x7f\x43\xd0\x42\x8c\xf1\x01\xcf\x0c\x75\xf1\x5d\xda\x4f\xa1\x28\x95\xcd\xd7\x7b\xd5\x42\x68\x2f\xcd\x10\x1b\x0c\x75\x05\x54\xf4\x2f\x2b\xf6\x69\x96\x29"- , {-taglen = -}16- , {-tag = -}"\x9a\xfa\xf4\xea\xae\x2e\x6f\x40\x00\xf4\x89\x77\xd0\x1e\xd5\x14")+ ( {-key = -} "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-iv = -} "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-aad = -} ""+ , {-input = -} ""+ , {-out = -} ""+ , {-taglen = -} 16+ , {-tag = -} "\x58\xe2\xfc\xce\xfa\x7e\x30\x61\x36\x7f\x1d\x57\xa4\xe7\x45\x5a"+ )+ , -- vectors 1++ ( {-key = -} "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-iv = -} "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-aad = -} "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , {-input = -} "\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a"+ , {-out = -} "\x09\x82\xd0\xc4\x6a\xbc\xa9\x98\xf9\x22\xc8\xb3\x7b\xb8\xf4\x72\xfd\x9f\xa0\xa1\x43\x41\x53\x29\xfd\xf7\x83\xf5\x9e\x81\xcb\xea"+ , {-taglen = -} 16+ , {-tag = -} "\x28\x50\x64\x2f\xa8\x8b\xab\x21\x2a\x67\x1a\x97\x48\x69\xa5\x6c"+ )+ , -- vectors 2++ ( {-key = -} "\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-iv = -} "\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-aad = -} "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , {-input = -} "\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a"+ , {-out = -} "\x1c\xa3\xb5\x41\x39\x6f\x19\x7a\x91\x2d\x27\x15\x70\xd1\xf5\x76\xde\xf1\xbe\x84\x42\x2a\xbb\xbe\x0b\x2d\x91\x21\x82\xbf\x7f\x17"+ , {-taglen = -} 16+ , {-tag = -} "\x15\x2a\x05\xbb\x7e\x13\x5d\xbe\x93\x7f\xa0\x54\x7a\x8e\x74\xb6"+ )+ , -- vectors 3++ ( {-key = -} "\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-iv = -} "\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-aad = -} "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"+ , {-input = -} "\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a"+ , {-out = -} "\xda\x35\xf6\x0a\x65\xc2\xa4\x6c\xb6\x6e\xb6\xf8\x1f\x0b\x9c\x74\x53\x4c\x97\x70\x36\xf7\xdf\x05\x6d\x00\xfe\xbf\xb4\xcb\xf5\x27"+ , {-taglen = -} 16+ , {-tag = -} "\xb7\x76\x7c\x3b\x9e\xf1\xe2\xcb\xc9\x11\xf1\x9a\xdc\xfa\x35\x0d"+ )+ ,+ ( {-key = -} "\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-iv = -} "\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-aad = -} "\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76"+ , {-input = -} "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"+ , {-out = -} "\xe4\x42\xf8\xc4\xc6\x67\x84\x86\x4a\x5a\x6e\xc7\xe0\xca\x68\xac\x16\xbc\x5b\xbf\xf7\xd5\xf3\xfa\xf3\xb2\xcb\xb0\xa2\x14\xa1\x81"+ , {-taglen = -} 16+ , {-tag = -} "\x5f\x63\xb8\xeb\x1d\x6f\xa8\x7a\xeb\x39\xa5\xf6\xd7\xed\xc3\x13"+ )+ ,+ ( {-key = -} "\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-iv = -} "\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-aad = -} "\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76\x76"+ , {-input = -} "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"+ , {-out = -} "\xe4\x42\xf8\xc4\xc6\x67\x84\x86\x4a\x5a\x6e\xc7\xe0\xca\x68\xac\x16\xbc\x5b\xbf\xf7\xd5\xf3\xfa\xf3\xb2\xcb\xb0\xa2\x14\xa1"+ , {-taglen = -} 16+ , {-tag = -} "\x94\xd1\x47\xc3\xa2\xca\x93\xe9\x66\x93\x1e\x3b\xb3\xbb\x67\x01"+ )+ , -- vector 6 tests 32-bit counter wrapping++ ( {-key = -} "\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , {-iv = -} "\xe8\x38\x84\x1d\x75\xae\x33\xb5\x4b\x51\x57\x89\xc9\x5f\xbe\x65"+ , {-aad = -} "\x54\x68\x65\x20\x66\x69\x76\x65\x20\x62\x6f\x78\x69\x6e\x67\x20\x77\x69\x7a\x61\x72\x64\x73\x20\x6a\x75\x6d\x70\x20\x71\x75\x69\x63\x6b\x6c\x79\x2e"+ , {-input = -} "\x54\x68\x65\x20\x71\x75\x69\x63\x6b\x20\x62\x72\x6f\x77\x6e\x20\x66\x6f\x78\x20\x6a\x75\x6d\x70\x73\x20\x6f\x76\x65\x72\x20\x74\x68\x65\x20\x6c\x61\x7a\x79\x20\x64\x6f\x67"+ , {-out = -} "\x82\x31\x9e\x5a\x6a\x7f\x43\xd0\x42\x8c\xf1\x01\xcf\x0c\x75\xf1\x5d\xda\x4f\xa1\x28\x95\xcd\xd7\x7b\xd5\x42\x68\x2f\xcd\x10\x1b\x0c\x75\x05\x54\xf4\x2f\x2b\xf6\x69\x96\x29"+ , {-taglen = -} 16+ , {-tag = -} "\x9a\xfa\xf4\xea\xae\x2e\x6f\x40\x00\xf4\x89\x77\xd0\x1e\xd5\x14"+ ) ] vectors_aes256_enc :: [KATGCM]@@ -75,15 +97,19 @@ , "" , "" , 16- , "\xbd\xc1\xac\x88\x4d\x33\x24\x57\xa1\xd2\x66\x4f\x16\x8c\x76\xf0")- , ( "\x78\xdc\x4e\x0a\xaf\x52\xd9\x35\xc3\xc0\x1e\xea\x57\x42\x8f\x00\xca\x1f\xd4\x75\xf5\xda\x86\xa4\x9c\x8d\xd7\x3d\x68\xc8\xe2\x23"+ , "\xbd\xc1\xac\x88\x4d\x33\x24\x57\xa1\xd2\x66\x4f\x16\x8c\x76\xf0"+ )+ ,+ ( "\x78\xdc\x4e\x0a\xaf\x52\xd9\x35\xc3\xc0\x1e\xea\x57\x42\x8f\x00\xca\x1f\xd4\x75\xf5\xda\x86\xa4\x9c\x8d\xd7\x3d\x68\xc8\xe2\x23" , "\xd7\x9c\xf2\x2d\x50\x4c\xc7\x93\xc3\xfb\x6c\x8a" , "\xb9\x6b\xaa\x8c\x1c\x75\xa6\x71\xbf\xb2\xd0\x8d\x06\xbe\x5f\x36" , "" , "" , 16- , "\x3e\x5d\x48\x6a\xa2\xe3\x0b\x22\xe0\x40\xb8\x57\x23\xa0\x6e\x76")- , ( "\xc3\xf1\x05\x86\xf2\x46\xaa\xca\xdc\xce\x37\x01\x44\x17\x70\xc0\x3c\xfe\xc9\x40\xaf\xe1\x90\x8c\x4c\x53\x7d\xf4\xe0\x1c\x50\xa0"+ , "\x3e\x5d\x48\x6a\xa2\xe3\x0b\x22\xe0\x40\xb8\x57\x23\xa0\x6e\x76"+ )+ ,+ ( "\xc3\xf1\x05\x86\xf2\x46\xaa\xca\xdc\xce\x37\x01\x44\x17\x70\xc0\x3c\xfe\xc9\x40\xaf\xe1\x90\x8c\x4c\x53\x7d\xf4\xe0\x1c\x50\xa0" , "\x4f\x52\xfa\xa1\xfa\x67\xa0\xe5\xf4\x19\x64\x52" , "\x46\xf9\xa2\x2b\x4e\x52\xe1\x52\x65\x13\xa9\x52\xdb\xee\x3b\x91\xf6\x95\x95\x50\x1e\x01\x77\xd5\x0f\xf3\x64\x63\x85\x88\xc0\x8d\x92\xfa\xb8\xc5\x8a\x96\x9b\xdc\xc8\x4c\x46\x8d\x84\x98\xc4\xf0\x63\x92\xb9\x9e\xd5\xe0\xc4\x84\x50\x7f\xc4\x8d\xc1\x8d\x87\xc4\x0e\x2e\xd8\x48\xb4\x31\x50\xbe\x9d\x36\xf1\x4c\xf2\xce\xf1\x31\x0b\xa4\xa7\x45\xad\xcc\x7b\xdc\x41\xf6" , "\x79\xd9\x7e\xa3\xa2\xed\xd6\x50\x45\x82\x1e\xa7\x45\xa4\x47\x42"
tests/KAT_AES/KATOCB3.hs view
@@ -1,46 +1,69 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_AES.KATOCB3 where import qualified Data.ByteString as B import Data.ByteString.Char8 () -- (key, iv, aad, input, out, taglen, tag)-type KATOCB3 = (B.ByteString, B.ByteString, B.ByteString, B.ByteString, B.ByteString, Int, B.ByteString)+type KATOCB3 =+ ( B.ByteString+ , B.ByteString+ , B.ByteString+ , B.ByteString+ , B.ByteString+ , Int+ , B.ByteString+ ) -key1 = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"+key1 = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" nonce1 = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b" vectors_aes128_enc :: [KATOCB3] vectors_aes128_enc =- [ ( {-key = -} key1- , {-iv = -} nonce1- , {-aad = -}""- , {-input = -}""- , {-out = -}""- , {-taglen = -} 16- , {-tag = -} "\x19\x7b\x9c\x3c\x44\x1d\x3c\x83\xea\xfb\x2b\xef\x63\x3b\x91\x82")- , ( key1, nonce1- , "\x00\x01\x02\x03\x04\x05\x06\x07"- , "\x00\x01\x02\x03\x04\x05\x06\x07"- , "\x92\xb6\x57\x13\x0a\x74\xb8\x5a"- , 16- , "\x16\xdc\x76\xa4\x6d\x47\xe1\xea\xd5\x37\x20\x9e\x8a\x96\xd1\x4e")- , ( key1, nonce1- , "\x00\x01\x02\x03\x04\x05\x06\x07"- , ""- , ""- , 16- , "\x98\xb9\x15\x52\xc8\xc0\x09\x18\x50\x44\xe3\x0a\x6e\xb2\xfe\x21")- , ( key1, nonce1- , ""- , "\x00\x01\x02\x03\x04\x05\x06\x07"- , "\x92\xb6\x57\x13\x0a\x74\xb8\x5a"- , 16- , "\x97\x1e\xff\xca\xe1\x9a\xd4\x71\x6f\x88\xe8\x7b\x87\x1f\xbe\xed")- , ( key1, nonce1- , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"- , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"- , "\xbe\xa5\xe8\x79\x8d\xbe\x71\x10\x03\x1c\x14\x4d\xa0\xb2\x61\x22"- , 16- , "\x77\x6c\x99\x24\xd6\x72\x3a\x1f\xc4\x52\x45\x32\xac\x3e\x5b\xeb")+ [+ ( {-key = -} key1+ , {-iv = -} nonce1+ , {-aad = -} ""+ , {-input = -} ""+ , {-out = -} ""+ , {-taglen = -} 16+ , {-tag = -} "\x19\x7b\x9c\x3c\x44\x1d\x3c\x83\xea\xfb\x2b\xef\x63\x3b\x91\x82"+ )+ ,+ ( key1+ , nonce1+ , "\x00\x01\x02\x03\x04\x05\x06\x07"+ , "\x00\x01\x02\x03\x04\x05\x06\x07"+ , "\x92\xb6\x57\x13\x0a\x74\xb8\x5a"+ , 16+ , "\x16\xdc\x76\xa4\x6d\x47\xe1\xea\xd5\x37\x20\x9e\x8a\x96\xd1\x4e"+ )+ ,+ ( key1+ , nonce1+ , "\x00\x01\x02\x03\x04\x05\x06\x07"+ , ""+ , ""+ , 16+ , "\x98\xb9\x15\x52\xc8\xc0\x09\x18\x50\x44\xe3\x0a\x6e\xb2\xfe\x21"+ )+ ,+ ( key1+ , nonce1+ , ""+ , "\x00\x01\x02\x03\x04\x05\x06\x07"+ , "\x92\xb6\x57\x13\x0a\x74\xb8\x5a"+ , 16+ , "\x97\x1e\xff\xca\xe1\x9a\xd4\x71\x6f\x88\xe8\x7b\x87\x1f\xbe\xed"+ )+ ,+ ( key1+ , nonce1+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"+ , "\xbe\xa5\xe8\x79\x8d\xbe\x71\x10\x03\x1c\x14\x4d\xa0\xb2\x61\x22"+ , 16+ , "\x77\x6c\x99\x24\xd6\x72\x3a\x1f\xc4\x52\x45\x32\xac\x3e\x5b\xeb"+ ) ]
tests/KAT_AES/KATXTS.hs view
@@ -1,12 +1,24 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_AES.KATXTS where import qualified Data.ByteString as B import Data.ByteString.Char8 () -type KATXTS = (B.ByteString, B.ByteString, B.ByteString, B.ByteString, B.ByteString, B.ByteString)+type KATXTS =+ ( B.ByteString+ , B.ByteString+ , B.ByteString+ , B.ByteString+ , B.ByteString+ , B.ByteString+ ) -vectors_aes128_enc, vectors_aes128_dec, vectors_aes256_enc, vectors_aes256_dec :: [KATXTS]+vectors_aes128_enc+ , vectors_aes128_dec+ , vectors_aes256_enc+ , vectors_aes256_dec+ :: [KATXTS] vectors_aes128_enc = [ ( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"@@ -41,10 +53,8 @@ , "\x27\xa7\x47\x9b\xef\xa1\xd4\x76\x48\x9f\x30\x8c\xd4\xcf\xa6\xe2\xa9\x6e\x4b\xbe\x32\x08\xff\x25\x28\x7d\xd3\x81\x96\x16\xe8\x9c\xc7\x8c\xf7\xf5\xe5\x43\x44\x5f\x83\x33\xd8\xfa\x7f\x56\x00\x00\x05\x27\x9f\xa5\xd8\xb5\xe4\xad\x40\xe7\x36\xdd\xb4\xd3\x54\x12\x32\x80\x63\xfd\x2a\xab\x53\xe5\xea\x1e\x0a\x9f\x33\x25\x00\xa5\xdf\x94\x87\xd0\x7a\x5c\x92\xcc\x51\x2c\x88\x66\xc7\xe8\x60\xce\x93\xfd\xf1\x66\xa2\x49\x12\xb4\x22\x97\x61\x46\xae\x20\xce\x84\x6b\xb7\xdc\x9b\xa9\x4a\x76\x7a\xae\xf2\x0c\x0d\x61\xad\x02\x65\x5e\xa9\x2d\xc4\xc4\xe4\x1a\x89\x52\xc6\x51\xd3\x31\x74\xbe\x51\xa1\x0c\x42\x11\x10\xe6\xd8\x15\x88\xed\xe8\x21\x03\xa2\x52\xd8\xa7\x50\xe8\x76\x8d\xef\xff\xed\x91\x22\x81\x0a\xae\xb9\x9f\x91\x72\xaf\x82\xb6\x04\xdc\x4b\x8e\x51\xbc\xb0\x82\x35\xa6\xf4\x34\x13\x32\xe4\xca\x60\x48\x2a\x4b\xa1\xa0\x3b\x3e\x65\x00\x8f\xc5\xda\x76\xb7\x0b\xf1\x69\x0d\xb4\xea\xe2\x9c\x5f\x1b\xad\xd0\x3c\x5c\xcf\x2a\x55\xd7\x05\xdd\xcd\x86\xd4\x49\x51\x1c\xeb\x7e\xc3\x0b\xf1\x2b\x1f\xa3\x5b\x91\x3f\x9f\x74\x7a\x8a\xfd\x1b\x13\x0e\x94\xbf\xf9\x4e\xff\xd0\x1a\x91\x73\x5c\xa1\x72\x6a\xcd\x0b\x19\x7c\x4e\x5b\x03\x39\x36\x97\xe1\x26\x82\x6f\xb6\xbb\xde\x8e\xcc\x1e\x08\x29\x85\x16\xe2\xc9\xed\x03\xff\x3c\x1b\x78\x60\xf6\xde\x76\xd4\xce\xcd\x94\xc8\x11\x98\x55\xef\x52\x97\xca\x67\xe9\xf3\xe7\xff\x72\xb1\xe9\x97\x85\xca\x0a\x7e\x77\x20\xc5\xb3\x6d\xc6\xd7\x2c\xac\x95\x74\xc8\xcb\xbc\x2f\x80\x1e\x23\xe5\x6f\xd3\x44\xb0\x7f\x22\x15\x4b\xeb\xa0\xf0\x8c\xe8\x89\x1e\x64\x3e\xd9\x95\xc9\x4d\x9a\x69\xc9\xf1\xb5\xf4\x99\x02\x7a\x78\x57\x2a\xee\xbd\x74\xd2\x0c\xc3\x98\x81\xc2\x13\xee\x77\x0b\x10\x10\xe4\xbe\xa7\x18\x84\x69\x77\xae\x11\x9f\x7a\x02\x3a\xb5\x8c\xca\x0a\xd7\x52\xaf\xe6\x56\xbb\x3c\x17\x25\x6a\x9f\x6e\x9b\xf1\x9f\xdd\x5a\x38\xfc\x82\xbb\xe8\x72\xc5\x53\x9e\xdb\x60\x9e\xf4\xf7\x9c\x20\x3e\xbb\x14\x0f\x2e\x58\x3c\xb2\xad\x15\xb4\xaa\x5b\x65\x50\x16\xa8\x44\x92\x77\xdb\xd4\x77\xef\x2c\x8d\x6c\x01\x7d\xb7\x38\xb1\x8d\xeb\x4a\x42\x7d\x19\x23\xce\x3f\xf2\x62\x73\x57\x79\xa4\x18\xf2\x0a\x28\x2d\xf9\x20\x14\x7b\xea\xbe\x42\x1e\xe5\x31\x9d\x05\x68" ) ]- vectors_aes128_dec = []- vectors_aes256_enc = [ ( "\x27\x18\x28\x18\x28\x45\x90\x45\x23\x53\x60\x28\x74\x71\x35\x26\x62\x49\x77\x57\x24\x70\x93\x69\x99\x59\x57\x49\x66\x96\x76\x27"@@ -55,5 +65,4 @@ , "\x1c\x3b\x3a\x10\x2f\x77\x03\x86\xe4\x83\x6c\x99\xe3\x70\xcf\x9b\xea\x00\x80\x3f\x5e\x48\x23\x57\xa4\xae\x12\xd4\x14\xa3\xe6\x3b\x5d\x31\xe2\x76\xf8\xfe\x4a\x8d\x66\xb3\x17\xf9\xac\x68\x3f\x44\x68\x0a\x86\xac\x35\xad\xfc\x33\x45\xbe\xfe\xcb\x4b\xb1\x88\xfd\x57\x76\x92\x6c\x49\xa3\x09\x5e\xb1\x08\xfd\x10\x98\xba\xec\x70\xaa\xa6\x69\x99\xa7\x2a\x82\xf2\x7d\x84\x8b\x21\xd4\xa7\x41\xb0\xc5\xcd\x4d\x5f\xff\x9d\xac\x89\xae\xba\x12\x29\x61\xd0\x3a\x75\x71\x23\xe9\x87\x0f\x8a\xcf\x10\x00\x02\x08\x87\x89\x14\x29\xca\x2a\x3e\x7a\x7d\x7d\xf7\xb1\x03\x55\x16\x5c\x8b\x9a\x6d\x0a\x7d\xe8\xb0\x62\xc4\x50\x0d\xc4\xcd\x12\x0c\x0f\x74\x18\xda\xe3\xd0\xb5\x78\x1c\x34\x80\x3f\xa7\x54\x21\xc7\x90\xdf\xe1\xde\x18\x34\xf2\x80\xd7\x66\x7b\x32\x7f\x6c\x8c\xd7\x55\x7e\x12\xac\x3a\x0f\x93\xec\x05\xc5\x2e\x04\x93\xef\x31\xa1\x2d\x3d\x92\x60\xf7\x9a\x28\x9d\x6a\x37\x9b\xc7\x0c\x50\x84\x14\x73\xd1\xa8\xcc\x81\xec\x58\x3e\x96\x45\xe0\x7b\x8d\x96\x70\x65\x5b\xa5\xbb\xcf\xec\xc6\xdc\x39\x66\x38\x0a\xd8\xfe\xcb\x17\xb6\xba\x02\x46\x9a\x02\x0a\x84\xe1\x8e\x8f\x84\x25\x20\x70\xc1\x3e\x9f\x1f\x28\x9b\xe5\x4f\xbc\x48\x14\x57\x77\x8f\x61\x60\x15\xe1\x32\x7a\x02\xb1\x40\xf1\x50\x5e\xb3\x09\x32\x6d\x68\x37\x8f\x83\x74\x59\x5c\x84\x9d\x84\xf4\xc3\x33\xec\x44\x23\x88\x51\x43\xcb\x47\xbd\x71\xc5\xed\xae\x9b\xe6\x9a\x2f\xfe\xce\xb1\xbe\xc9\xde\x24\x4f\xbe\x15\x99\x2b\x11\xb7\x7c\x04\x0f\x12\xbd\x8f\x6a\x97\x5a\x44\xa0\xf9\x0c\x29\xa9\xab\xc3\xd4\xd8\x93\x92\x72\x84\xc5\x87\x54\xcc\xe2\x94\x52\x9f\x86\x14\xdc\xd2\xab\xa9\x91\x92\x5f\xed\xc4\xae\x74\xff\xac\x6e\x33\x3b\x93\xeb\x4a\xff\x04\x79\xda\x9a\x41\x0e\x44\x50\xe0\xdd\x7a\xe4\xc6\xe2\x91\x09\x00\x57\x5d\xa4\x01\xfc\x07\x05\x9f\x64\x5e\x8b\x7e\x9b\xfd\xef\x33\x94\x30\x54\xff\x84\x01\x14\x93\xc2\x7b\x34\x29\xea\xed\xb4\xed\x53\x76\x44\x1a\x77\xed\x43\x85\x1a\xd7\x7f\x16\xf5\x41\xdf\xd2\x69\xd5\x0d\x6a\x5f\x14\xfb\x0a\xab\x1c\xbb\x4c\x15\x50\xbe\x97\xf7\xab\x40\x66\x19\x3c\x4c\xaa\x77\x3d\xad\x38\x01\x4b\xd2\x09\x2f\xa7\x55\xc8\x24\xbb\x5e\x54\xc4\xf3\x6f\xfd\xa9\xfc\xea\x70\xb9\xc6\xe6\x93\xe1\x48\xc1\x51" ) ]- vectors_aes256_dec = []
tests/KAT_AESGCMSIV.hs view
@@ -2,12 +2,13 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE RecordWildCards #-}+ module KAT_AESGCMSIV (tests) where import Imports -import Data.Proxy import qualified Data.ByteArray as B+import Data.Proxy import Crypto.Cipher.AES import Crypto.Cipher.AESGCMSIV@@ -15,11 +16,11 @@ import Crypto.Error data Vector c = Vector- { vecPlaintext :: ByteString- , vecAAD :: ByteString- , vecKey :: ByteString- , vecNonce :: ByteString- , vecTag :: ByteString+ { vecPlaintext :: ByteString+ , vecAAD :: ByteString+ , vecKey :: ByteString+ , vecNonce :: ByteString+ , vecTag :: ByteString , vecCiphertext :: ByteString } @@ -29,412 +30,576 @@ vectors128 :: [Vector AES128] vectors128 = [ Vector- { vecPlaintext = ""- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xdc\x20\xe2\xd8\x3f\x25\x70\x5b\xb4\x9e\x43\x9e\xca\x56\xde\x25"+ { vecPlaintext = ""+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xdc\x20\xe2\xd8\x3f\x25\x70\x5b\xb4\x9e\x43\x9e\xca\x56\xde\x25" , vecCiphertext = "" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x57\x87\x82\xff\xf6\x01\x3b\x81\x5b\x28\x7c\x22\x49\x3a\x36\x4c"+ { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x57\x87\x82\xff\xf6\x01\x3b\x81\x5b\x28\x7c\x22\x49\x3a\x36\x4c" , vecCiphertext = "\xb5\xd8\x39\x33\x0a\xc7\xb7\x86" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xa4\x97\x8d\xb3\x57\x39\x1a\x0b\xc4\xfd\xec\x8b\x0d\x10\x66\x39"+ { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xa4\x97\x8d\xb3\x57\x39\x1a\x0b\xc4\xfd\xec\x8b\x0d\x10\x66\x39" , vecCiphertext = "\x73\x23\xea\x61\xd0\x59\x32\x26\x00\x47\xd9\x42" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x30\x3a\xaf\x90\xf6\xfe\x21\x19\x9c\x60\x68\x57\x74\x37\xa0\xc4"- , vecCiphertext = "\x74\x3f\x7c\x80\x77\xab\x25\xf8\x62\x4e\x2e\x94\x85\x79\xcf\x77"+ { vecPlaintext =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x30\x3a\xaf\x90\xf6\xfe\x21\x19\x9c\x60\x68\x57\x74\x37\xa0\xc4"+ , vecCiphertext =+ "\x74\x3f\x7c\x80\x77\xab\x25\xf8\x62\x4e\x2e\x94\x85\x79\xcf\x77" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x1a\x8e\x45\xdc\xd4\x57\x8c\x66\x7c\xd8\x68\x47\xbf\x61\x55\xff"- , vecCiphertext = "\x84\xe0\x7e\x62\xba\x83\xa6\x58\x54\x17\x24\x5d\x7e\xc4\x13\xa9\xfe\x42\x7d\x63\x15\xc0\x9b\x57\xce\x45\xf2\xe3\x93\x6a\x94\x45"+ { vecPlaintext =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x1a\x8e\x45\xdc\xd4\x57\x8c\x66\x7c\xd8\x68\x47\xbf\x61\x55\xff"+ , vecCiphertext =+ "\x84\xe0\x7e\x62\xba\x83\xa6\x58\x54\x17\x24\x5d\x7e\xc4\x13\xa9\xfe\x42\x7d\x63\x15\xc0\x9b\x57\xce\x45\xf2\xe3\x93\x6a\x94\x45" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x5e\x6e\x31\x1d\xbf\x39\x5d\x35\xb0\xfe\x39\xc2\x71\x43\x88\xf8"- , vecCiphertext = "\x3f\xd2\x4c\xe1\xf5\xa6\x7b\x75\xbf\x23\x51\xf1\x81\xa4\x75\xc7\xb8\x00\xa5\xb4\xd3\xdc\xf7\x01\x06\xb1\xee\xa8\x2f\xa1\xd6\x4d\xf4\x2b\xf7\x22\x61\x22\xfa\x92\xe1\x7a\x40\xee\xaa\xc1\x20\x1b"+ { vecPlaintext =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x5e\x6e\x31\x1d\xbf\x39\x5d\x35\xb0\xfe\x39\xc2\x71\x43\x88\xf8"+ , vecCiphertext =+ "\x3f\xd2\x4c\xe1\xf5\xa6\x7b\x75\xbf\x23\x51\xf1\x81\xa4\x75\xc7\xb8\x00\xa5\xb4\xd3\xdc\xf7\x01\x06\xb1\xee\xa8\x2f\xa1\xd6\x4d\xf4\x2b\xf7\x22\x61\x22\xfa\x92\xe1\x7a\x40\xee\xaa\xc1\x20\x1b" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x8a\x26\x3d\xd3\x17\xaa\x88\xd5\x6b\xdf\x39\x36\xdb\xa7\x5b\xb8"- , vecCiphertext = "\x24\x33\x66\x8f\x10\x58\x19\x0f\x6d\x43\xe3\x60\xf4\xf3\x5c\xd8\xe4\x75\x12\x7c\xfc\xa7\x02\x8e\xa8\xab\x5c\x20\xf7\xab\x2a\xf0\x25\x16\xa2\xbd\xcb\xc0\x8d\x52\x1b\xe3\x7f\xf2\x8c\x15\x2b\xba\x36\x69\x7f\x25\xb4\xcd\x16\x9c\x65\x90\xd1\xdd\x39\x56\x6d\x3f"+ { vecPlaintext =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x8a\x26\x3d\xd3\x17\xaa\x88\xd5\x6b\xdf\x39\x36\xdb\xa7\x5b\xb8"+ , vecCiphertext =+ "\x24\x33\x66\x8f\x10\x58\x19\x0f\x6d\x43\xe3\x60\xf4\xf3\x5c\xd8\xe4\x75\x12\x7c\xfc\xa7\x02\x8e\xa8\xab\x5c\x20\xf7\xab\x2a\xf0\x25\x16\xa2\xbd\xcb\xc0\x8d\x52\x1b\xe3\x7f\xf2\x8c\x15\x2b\xba\x36\x69\x7f\x25\xb4\xcd\x16\x9c\x65\x90\xd1\xdd\x39\x56\x6d\x3f" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x3b\x0a\x1a\x25\x60\x96\x9c\xdf\x79\x0d\x99\x75\x9a\xbd\x15\x08"+ { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x3b\x0a\x1a\x25\x60\x96\x9c\xdf\x79\x0d\x99\x75\x9a\xbd\x15\x08" , vecCiphertext = "\x1e\x6d\xab\xa3\x56\x69\xf4\x27" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x08\x29\x9c\x51\x02\x74\x5a\xaa\x3a\x0c\x46\x9f\xad\x9e\x07\x5a"+ { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x08\x29\x9c\x51\x02\x74\x5a\xaa\x3a\x0c\x46\x9f\xad\x9e\x07\x5a" , vecCiphertext = "\x29\x6c\x78\x89\xfd\x99\xf4\x19\x17\xf4\x46\x20" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x8f\x89\x36\xec\x03\x9e\x4e\x4b\xb9\x7e\xbd\x8c\x44\x57\x44\x1f"- , vecCiphertext = "\xe2\xb0\xc5\xda\x79\xa9\x01\xc1\x74\x5f\x70\x05\x25\xcb\x33\x5b"+ { vecPlaintext =+ "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x8f\x89\x36\xec\x03\x9e\x4e\x4b\xb9\x7e\xbd\x8c\x44\x57\x44\x1f"+ , vecCiphertext =+ "\xe2\xb0\xc5\xda\x79\xa9\x01\xc1\x74\x5f\x70\x05\x25\xcb\x33\x5b" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xe6\xaf\x6a\x7f\x87\x28\x7d\xa0\x59\xa7\x16\x84\xed\x34\x98\xe1"- , vecCiphertext = "\x62\x00\x48\xef\x3c\x1e\x73\xe5\x7e\x02\xbb\x85\x62\xc4\x16\xa3\x19\xe7\x3e\x4c\xaa\xc8\xe9\x6a\x1e\xcb\x29\x33\x14\x5a\x1d\x71"+ { vecPlaintext =+ "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xe6\xaf\x6a\x7f\x87\x28\x7d\xa0\x59\xa7\x16\x84\xed\x34\x98\xe1"+ , vecCiphertext =+ "\x62\x00\x48\xef\x3c\x1e\x73\xe5\x7e\x02\xbb\x85\x62\xc4\x16\xa3\x19\xe7\x3e\x4c\xaa\xc8\xe9\x6a\x1e\xcb\x29\x33\x14\x5a\x1d\x71" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x6a\x8c\xc3\x86\x5f\x76\x89\x7c\x2e\x4b\x24\x5c\xf3\x1c\x51\xf2"- , vecCiphertext = "\x50\xc8\x30\x3e\xa9\x39\x25\xd6\x40\x90\xd0\x7b\xd1\x09\xdf\xd9\x51\x5a\x5a\x33\x43\x10\x19\xc1\x7d\x93\x46\x59\x99\xa8\xb0\x05\x32\x01\xd7\x23\x12\x0a\x85\x62\xb8\x38\xcd\xff\x25\xbf\x9d\x1e"+ { vecPlaintext =+ "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x6a\x8c\xc3\x86\x5f\x76\x89\x7c\x2e\x4b\x24\x5c\xf3\x1c\x51\xf2"+ , vecCiphertext =+ "\x50\xc8\x30\x3e\xa9\x39\x25\xd6\x40\x90\xd0\x7b\xd1\x09\xdf\xd9\x51\x5a\x5a\x33\x43\x10\x19\xc1\x7d\x93\x46\x59\x99\xa8\xb0\x05\x32\x01\xd7\x23\x12\x0a\x85\x62\xb8\x38\xcd\xff\x25\xbf\x9d\x1e" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xcd\xc4\x6a\xe4\x75\x56\x3d\xe0\x37\x00\x1e\xf8\x4a\xe2\x17\x44"- , vecCiphertext = "\x2f\x5c\x64\x05\x9d\xb5\x5e\xe0\xfb\x84\x7e\xd5\x13\x00\x37\x46\xac\xa4\xe6\x1c\x71\x1b\x5d\xe2\xe7\xa7\x7f\xfd\x02\xda\x42\xfe\xec\x60\x19\x10\xd3\x46\x7b\xb8\xb3\x6e\xbb\xae\xbc\xe5\xfb\xa3\x0d\x36\xc9\x5f\x48\xa3\xe7\x98\x0f\x0e\x7a\xc2\x99\x33\x2a\x80"+ { vecPlaintext =+ "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xcd\xc4\x6a\xe4\x75\x56\x3d\xe0\x37\x00\x1e\xf8\x4a\xe2\x17\x44"+ , vecCiphertext =+ "\x2f\x5c\x64\x05\x9d\xb5\x5e\xe0\xfb\x84\x7e\xd5\x13\x00\x37\x46\xac\xa4\xe6\x1c\x71\x1b\x5d\xe2\xe7\xa7\x7f\xfd\x02\xda\x42\xfe\xec\x60\x19\x10\xd3\x46\x7b\xb8\xb3\x6e\xbb\xae\xbc\xe5\xfb\xa3\x0d\x36\xc9\x5f\x48\xa3\xe7\x98\x0f\x0e\x7a\xc2\x99\x33\x2a\x80" } , Vector- { vecPlaintext = "\x02\x00\x00\x00"- , vecAAD = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x07\xeb\x1f\x84\xfb\x28\xf8\xcb\x73\xde\x8e\x99\xe2\xf4\x8a\x14"+ { vecPlaintext = "\x02\x00\x00\x00"+ , vecAAD = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x07\xeb\x1f\x84\xfb\x28\xf8\xcb\x73\xde\x8e\x99\xe2\xf4\x8a\x14" , vecCiphertext = "\xa8\xfe\x3e\x87" } , Vector- { vecPlaintext = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00"- , vecAAD = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x24\xaf\xc9\x80\x5e\x97\x6f\x45\x1e\x6d\x87\xf6\xfe\x10\x65\x14"- , vecCiphertext = "\x6b\xb0\xfe\xcf\x5d\xed\x9b\x77\xf9\x02\xc7\xd5\xda\x23\x6a\x43\x91\xdd\x02\x97"+ { vecPlaintext =+ "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00"+ , vecAAD =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x24\xaf\xc9\x80\x5e\x97\x6f\x45\x1e\x6d\x87\xf6\xfe\x10\x65\x14"+ , vecCiphertext =+ "\x6b\xb0\xfe\xcf\x5d\xed\x9b\x77\xf9\x02\xc7\xd5\xda\x23\x6a\x43\x91\xdd\x02\x97" } , Vector- { vecPlaintext = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00"- , vecAAD = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xbf\xf9\xb2\xef\x00\xfb\x47\x92\x0c\xc7\x2a\x0c\x0f\x13\xb9\xfd"- , vecCiphertext = "\x44\xd0\xaa\xf6\xfb\x2f\x1f\x34\xad\xd5\xe8\x06\x4e\x83\xe1\x2a\x2a\xda"+ { vecPlaintext =+ "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00"+ , vecAAD =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xbf\xf9\xb2\xef\x00\xfb\x47\x92\x0c\xc7\x2a\x0c\x0f\x13\xb9\xfd"+ , vecCiphertext =+ "\x44\xd0\xaa\xf6\xfb\x2f\x1f\x34\xad\xd5\xe8\x06\x4e\x83\xe1\x2a\x2a\xda" } , Vector- { vecPlaintext = ""- , vecAAD = ""- , vecKey = "\xe6\x60\x21\xd5\xeb\x8e\x4f\x40\x66\xd4\xad\xb9\xc3\x35\x60\xe4"- , vecNonce = "\xf4\x6e\x44\xbb\x3d\xa0\x01\x5c\x94\xf7\x08\x87"- , vecTag = "\xa4\x19\x4b\x79\x07\x1b\x01\xa8\x7d\x65\xf7\x06\xe3\x94\x95\x78"+ { vecPlaintext = ""+ , vecAAD = ""+ , vecKey =+ "\xe6\x60\x21\xd5\xeb\x8e\x4f\x40\x66\xd4\xad\xb9\xc3\x35\x60\xe4"+ , vecNonce = "\xf4\x6e\x44\xbb\x3d\xa0\x01\x5c\x94\xf7\x08\x87"+ , vecTag =+ "\xa4\x19\x4b\x79\x07\x1b\x01\xa8\x7d\x65\xf7\x06\xe3\x94\x95\x78" , vecCiphertext = "" } , Vector- { vecPlaintext = "\x7a\x80\x6c"- , vecAAD = "\x46\xbb\x91\xc3\xc5"- , vecKey = "\x36\x86\x42\x00\xe0\xea\xf5\x28\x4d\x88\x4a\x0e\x77\xd3\x16\x46"- , vecNonce = "\xba\xe8\xe3\x7f\xc8\x34\x41\xb1\x60\x34\x56\x6b"- , vecTag = "\x71\x1b\xd8\x5b\xc1\xe4\xd3\xe0\xa4\x62\xe0\x74\xee\xa4\x28\xa8"+ { vecPlaintext = "\x7a\x80\x6c"+ , vecAAD = "\x46\xbb\x91\xc3\xc5"+ , vecKey =+ "\x36\x86\x42\x00\xe0\xea\xf5\x28\x4d\x88\x4a\x0e\x77\xd3\x16\x46"+ , vecNonce = "\xba\xe8\xe3\x7f\xc8\x34\x41\xb1\x60\x34\x56\x6b"+ , vecTag =+ "\x71\x1b\xd8\x5b\xc1\xe4\xd3\xe0\xa4\x62\xe0\x74\xee\xa4\x28\xa8" , vecCiphertext = "\xaf\x60\xeb" } , Vector- { vecPlaintext = "\xbd\xc6\x6f\x14\x65\x45"- , vecAAD = "\xfc\x88\x0c\x94\xa9\x51\x98\x87\x42\x96"- , vecKey = "\xae\xdb\x64\xa6\xc5\x90\xbc\x84\xd1\xa5\xe2\x69\xe4\xb4\x78\x01"- , vecNonce = "\xaf\xc0\x57\x7e\x34\x69\x9b\x9e\x67\x1f\xdd\x4f"- , vecTag = "\xd6\xa9\xc4\x55\x45\xcf\xc1\x1f\x03\xad\x74\x3d\xba\x20\xf9\x66"+ { vecPlaintext = "\xbd\xc6\x6f\x14\x65\x45"+ , vecAAD = "\xfc\x88\x0c\x94\xa9\x51\x98\x87\x42\x96"+ , vecKey =+ "\xae\xdb\x64\xa6\xc5\x90\xbc\x84\xd1\xa5\xe2\x69\xe4\xb4\x78\x01"+ , vecNonce = "\xaf\xc0\x57\x7e\x34\x69\x9b\x9e\x67\x1f\xdd\x4f"+ , vecTag =+ "\xd6\xa9\xc4\x55\x45\xcf\xc1\x1f\x03\xad\x74\x3d\xba\x20\xf9\x66" , vecCiphertext = "\xbb\x93\xa3\xe3\x4d\x3c" } , Vector- { vecPlaintext = "\x11\x77\x44\x1f\x19\x54\x95\x86\x0f"- , vecAAD = "\x04\x67\x87\xf3\xea\x22\xc1\x27\xaa\xf1\x95\xd1\x89\x47\x28"- , vecKey = "\xd5\xcc\x1f\xd1\x61\x32\x0b\x69\x20\xce\x07\x78\x7f\x86\x74\x3b"- , vecNonce = "\x27\x5d\x1a\xb3\x2f\x6d\x1f\x04\x34\xd8\x84\x8c"- , vecTag = "\x1d\x02\xfd\x0c\xd1\x74\xc8\x4f\xc5\xda\xe2\xf6\x0f\x52\xfd\x2b"+ { vecPlaintext = "\x11\x77\x44\x1f\x19\x54\x95\x86\x0f"+ , vecAAD = "\x04\x67\x87\xf3\xea\x22\xc1\x27\xaa\xf1\x95\xd1\x89\x47\x28"+ , vecKey =+ "\xd5\xcc\x1f\xd1\x61\x32\x0b\x69\x20\xce\x07\x78\x7f\x86\x74\x3b"+ , vecNonce = "\x27\x5d\x1a\xb3\x2f\x6d\x1f\x04\x34\xd8\x84\x8c"+ , vecTag =+ "\x1d\x02\xfd\x0c\xd1\x74\xc8\x4f\xc5\xda\xe2\xf6\x0f\x52\xfd\x2b" , vecCiphertext = "\x4f\x37\x28\x1f\x7a\xd1\x29\x49\xd0" } , Vector- { vecPlaintext = "\x9f\x57\x2c\x61\x4b\x47\x45\x91\x44\x74\xe7\xc7"- , vecAAD = "\xc9\x88\x2e\x53\x86\xfd\x9f\x92\xec\x48\x9c\x8f\xde\x2b\xe2\xcf\x97\xe7\x4e\x93"- , vecKey = "\xb3\xfe\xd1\x47\x3c\x52\x8b\x84\x26\xa5\x82\x99\x59\x29\xa1\x49"- , vecNonce = "\x9e\x9a\xd8\x78\x0c\x8d\x63\xd0\xab\x41\x49\xc0"- , vecTag = "\xc1\xdc\x2f\x87\x1f\xb7\x56\x1d\xa1\x28\x6e\x65\x5e\x24\xb7\xb0"+ { vecPlaintext = "\x9f\x57\x2c\x61\x4b\x47\x45\x91\x44\x74\xe7\xc7"+ , vecAAD =+ "\xc9\x88\x2e\x53\x86\xfd\x9f\x92\xec\x48\x9c\x8f\xde\x2b\xe2\xcf\x97\xe7\x4e\x93"+ , vecKey =+ "\xb3\xfe\xd1\x47\x3c\x52\x8b\x84\x26\xa5\x82\x99\x59\x29\xa1\x49"+ , vecNonce = "\x9e\x9a\xd8\x78\x0c\x8d\x63\xd0\xab\x41\x49\xc0"+ , vecTag =+ "\xc1\xdc\x2f\x87\x1f\xb7\x56\x1d\xa1\x28\x6e\x65\x5e\x24\xb7\xb0" , vecCiphertext = "\xf5\x46\x73\xc5\xdd\xf7\x10\xc7\x45\x64\x1c\x8b" } , Vector- { vecPlaintext = "\x0d\x8c\x84\x51\x17\x80\x82\x35\x5c\x9e\x94\x0f\xea\x2f\x58"- , vecAAD = "\x29\x50\xa7\x0d\x5a\x1d\xb2\x31\x6f\xd5\x68\x37\x8d\xa1\x07\xb5\x2b\x0d\xa5\x52\x10\xcc\x1c\x1b\x0a"- , vecKey = "\x2d\x4e\xd8\x7d\xa4\x41\x02\x95\x2e\xf9\x4b\x02\xb8\x05\x24\x9b"- , vecNonce = "\xac\x80\xe6\xf6\x14\x55\xbf\xac\x83\x08\xa2\xd4"- , vecTag = "\x83\xb3\x44\x9b\x9f\x39\x55\x2d\xe9\x9d\xc2\x14\xa1\x19\x0b\x0b"+ { vecPlaintext = "\x0d\x8c\x84\x51\x17\x80\x82\x35\x5c\x9e\x94\x0f\xea\x2f\x58"+ , vecAAD =+ "\x29\x50\xa7\x0d\x5a\x1d\xb2\x31\x6f\xd5\x68\x37\x8d\xa1\x07\xb5\x2b\x0d\xa5\x52\x10\xcc\x1c\x1b\x0a"+ , vecKey =+ "\x2d\x4e\xd8\x7d\xa4\x41\x02\x95\x2e\xf9\x4b\x02\xb8\x05\x24\x9b"+ , vecNonce = "\xac\x80\xe6\xf6\x14\x55\xbf\xac\x83\x08\xa2\xd4"+ , vecTag =+ "\x83\xb3\x44\x9b\x9f\x39\x55\x2d\xe9\x9d\xc2\x14\xa1\x19\x0b\x0b" , vecCiphertext = "\xc9\xff\x54\x5e\x07\xb8\x8a\x01\x5f\x05\xb2\x74\x54\x0a\xa1" } , Vector- { vecPlaintext = "\x6b\x3d\xb4\xda\x3d\x57\xaa\x94\x84\x2b\x98\x03\xa9\x6e\x07\xfb\x6d\xe7"- , vecAAD = "\x18\x60\xf7\x62\xeb\xfb\xd0\x82\x84\xe4\x21\x70\x2d\xe0\xde\x18\xba\xa9\xc9\x59\x62\x91\xb0\x84\x66\xf3\x7d\xe2\x1c\x7f"- , vecKey = "\xbd\xe3\xb2\xf2\x04\xd1\xe9\xf8\xb0\x6b\xc4\x7f\x97\x45\xb3\xd1"- , vecNonce = "\xae\x06\x55\x6f\xb6\xaa\x78\x90\xbe\xbc\x18\xfe"- , vecTag = "\x3e\x37\x70\x94\xf0\x47\x09\xf6\x4d\x7b\x98\x53\x10\xa4\xdb\x84"- , vecCiphertext = "\x62\x98\xb2\x96\xe2\x4e\x8c\xc3\x5d\xce\x0b\xed\x48\x4b\x7f\x30\xd5\x80"+ { vecPlaintext =+ "\x6b\x3d\xb4\xda\x3d\x57\xaa\x94\x84\x2b\x98\x03\xa9\x6e\x07\xfb\x6d\xe7"+ , vecAAD =+ "\x18\x60\xf7\x62\xeb\xfb\xd0\x82\x84\xe4\x21\x70\x2d\xe0\xde\x18\xba\xa9\xc9\x59\x62\x91\xb0\x84\x66\xf3\x7d\xe2\x1c\x7f"+ , vecKey =+ "\xbd\xe3\xb2\xf2\x04\xd1\xe9\xf8\xb0\x6b\xc4\x7f\x97\x45\xb3\xd1"+ , vecNonce = "\xae\x06\x55\x6f\xb6\xaa\x78\x90\xbe\xbc\x18\xfe"+ , vecTag =+ "\x3e\x37\x70\x94\xf0\x47\x09\xf6\x4d\x7b\x98\x53\x10\xa4\xdb\x84"+ , vecCiphertext =+ "\x62\x98\xb2\x96\xe2\x4e\x8c\xc3\x5d\xce\x0b\xed\x48\x4b\x7f\x30\xd5\x80" } , Vector- { vecPlaintext = "\xe4\x2a\x3c\x02\xc2\x5b\x64\x86\x9e\x14\x6d\x7b\x23\x39\x87\xbd\xdf\xc2\x40\x87\x1d"- , vecAAD = "\x75\x76\xf7\x02\x8e\xc6\xeb\x5e\xa7\xe2\x98\x34\x2a\x94\xd4\xb2\x02\xb3\x70\xef\x97\x68\xec\x65\x61\xc4\xfe\x6b\x7e\x72\x96\xfa\x85\x9c\x21"- , vecKey = "\xf9\x01\xcf\xe8\xa6\x96\x15\xa9\x3f\xdf\x7a\x98\xca\xd4\x81\x79"- , vecNonce = "\x62\x45\x70\x9f\xb1\x88\x53\xf6\x8d\x83\x36\x40"- , vecTag = "\x2d\x15\x50\x6c\x84\xa9\xed\xd6\x5e\x13\xe9\xd2\x4a\x2a\x6e\x70"- , vecCiphertext = "\x39\x1c\xc3\x28\xd4\x84\xa4\xf4\x64\x06\x18\x1b\xcd\x62\xef\xd9\xb3\xee\x19\x7d\x05"+ { vecPlaintext =+ "\xe4\x2a\x3c\x02\xc2\x5b\x64\x86\x9e\x14\x6d\x7b\x23\x39\x87\xbd\xdf\xc2\x40\x87\x1d"+ , vecAAD =+ "\x75\x76\xf7\x02\x8e\xc6\xeb\x5e\xa7\xe2\x98\x34\x2a\x94\xd4\xb2\x02\xb3\x70\xef\x97\x68\xec\x65\x61\xc4\xfe\x6b\x7e\x72\x96\xfa\x85\x9c\x21"+ , vecKey =+ "\xf9\x01\xcf\xe8\xa6\x96\x15\xa9\x3f\xdf\x7a\x98\xca\xd4\x81\x79"+ , vecNonce = "\x62\x45\x70\x9f\xb1\x88\x53\xf6\x8d\x83\x36\x40"+ , vecTag =+ "\x2d\x15\x50\x6c\x84\xa9\xed\xd6\x5e\x13\xe9\xd2\x4a\x2a\x6e\x70"+ , vecCiphertext =+ "\x39\x1c\xc3\x28\xd4\x84\xa4\xf4\x64\x06\x18\x1b\xcd\x62\xef\xd9\xb3\xee\x19\x7d\x05" } ] vectors256 :: [Vector AES256] vectors256 = [ Vector- { vecPlaintext = ""- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x07\xf5\xf4\x16\x9b\xbf\x55\xa8\x40\x0c\xd4\x7e\xa6\xfd\x40\x0f"+ { vecPlaintext = ""+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x07\xf5\xf4\x16\x9b\xbf\x55\xa8\x40\x0c\xd4\x7e\xa6\xfd\x40\x0f" , vecCiphertext = "" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x84\x31\x22\x13\x0f\x73\x64\xb7\x61\xe0\xb9\x74\x27\xe3\xdf\x28"+ { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x84\x31\x22\x13\x0f\x73\x64\xb7\x61\xe0\xb9\x74\x27\xe3\xdf\x28" , vecCiphertext = "\xc2\xef\x32\x8e\x5c\x71\xc8\x3b" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x8c\xa5\x0d\xa9\xae\x65\x59\xe4\x8f\xd1\x0f\x6e\x5c\x9c\xa1\x7e"+ { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x8c\xa5\x0d\xa9\xae\x65\x59\xe4\x8f\xd1\x0f\x6e\x5c\x9c\xa1\x7e" , vecCiphertext = "\x9a\xab\x2a\xeb\x3f\xaa\x0a\x34\xae\xa8\xe2\xb1" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xc9\xea\xc6\xfa\x70\x09\x42\x70\x2e\x90\x86\x23\x83\xc6\xc3\x66"- , vecCiphertext = "\x85\xa0\x1b\x63\x02\x5b\xa1\x9b\x7f\xd3\xdd\xfc\x03\x3b\x3e\x76"+ { vecPlaintext =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xc9\xea\xc6\xfa\x70\x09\x42\x70\x2e\x90\x86\x23\x83\xc6\xc3\x66"+ , vecCiphertext =+ "\x85\xa0\x1b\x63\x02\x5b\xa1\x9b\x7f\xd3\xdd\xfc\x03\x3b\x3e\x76" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xe8\x19\xe6\x3a\xbc\xd0\x20\xb0\x06\xa9\x76\x39\x76\x32\xeb\x5d"- , vecCiphertext = "\x4a\x6a\x9d\xb4\xc8\xc6\x54\x92\x01\xb9\xed\xb5\x30\x06\xcb\xa8\x21\xec\x9c\xf8\x50\x94\x8a\x7c\x86\xc6\x8a\xc7\x53\x9d\x02\x7f"+ { vecPlaintext =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xe8\x19\xe6\x3a\xbc\xd0\x20\xb0\x06\xa9\x76\x39\x76\x32\xeb\x5d"+ , vecCiphertext =+ "\x4a\x6a\x9d\xb4\xc8\xc6\x54\x92\x01\xb9\xed\xb5\x30\x06\xcb\xa8\x21\xec\x9c\xf8\x50\x94\x8a\x7c\x86\xc6\x8a\xc7\x53\x9d\x02\x7f" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x79\x0b\xc9\x68\x80\xa9\x9b\xa8\x04\xbd\x12\xc0\xe6\xa2\x2c\xc4"- , vecCiphertext = "\xc0\x0d\x12\x18\x93\xa9\xfa\x60\x3f\x48\xcc\xc1\xca\x3c\x57\xce\x74\x99\x24\x5e\xa0\x04\x6d\xb1\x6c\x53\xc7\xc6\x6f\xe7\x17\xe3\x9c\xf6\xc7\x48\x83\x7b\x61\xf6\xee\x3a\xdc\xee\x17\x53\x4e\xd5"+ { vecPlaintext =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x79\x0b\xc9\x68\x80\xa9\x9b\xa8\x04\xbd\x12\xc0\xe6\xa2\x2c\xc4"+ , vecCiphertext =+ "\xc0\x0d\x12\x18\x93\xa9\xfa\x60\x3f\x48\xcc\xc1\xca\x3c\x57\xce\x74\x99\x24\x5e\xa0\x04\x6d\xb1\x6c\x53\xc7\xc6\x6f\xe7\x17\xe3\x9c\xf6\xc7\x48\x83\x7b\x61\xf6\xee\x3a\xdc\xee\x17\x53\x4e\xd5" } , Vector- { vecPlaintext = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x11\x28\x64\xc2\x69\xfc\x0d\x9d\x88\xc6\x1f\xa4\x7e\x39\xaa\x08"- , vecCiphertext = "\xc2\xd5\x16\x0a\x1f\x86\x83\x83\x49\x10\xac\xda\xfc\x41\xfb\xb1\x63\x2d\x4a\x35\x3e\x8b\x90\x5e\xc9\xa5\x49\x9a\xc3\x4f\x96\xc7\xe1\x04\x9e\xb0\x80\x88\x38\x91\xa4\xdb\x8c\xaa\xa1\xf9\x9d\xd0\x04\xd8\x04\x87\x54\x07\x35\x23\x4e\x37\x44\x51\x2c\x6f\x90\xce"+ { vecPlaintext =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x11\x28\x64\xc2\x69\xfc\x0d\x9d\x88\xc6\x1f\xa4\x7e\x39\xaa\x08"+ , vecCiphertext =+ "\xc2\xd5\x16\x0a\x1f\x86\x83\x83\x49\x10\xac\xda\xfc\x41\xfb\xb1\x63\x2d\x4a\x35\x3e\x8b\x90\x5e\xc9\xa5\x49\x9a\xc3\x4f\x96\xc7\xe1\x04\x9e\xb0\x80\x88\x38\x91\xa4\xdb\x8c\xaa\xa1\xf9\x9d\xd0\x04\xd8\x04\x87\x54\x07\x35\x23\x4e\x37\x44\x51\x2c\x6f\x90\xce" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x91\x21\x3f\x26\x7e\x3b\x45\x2f\x02\xd0\x1a\xe3\x3e\x4e\xc8\x54"+ { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x91\x21\x3f\x26\x7e\x3b\x45\x2f\x02\xd0\x1a\xe3\x3e\x4e\xc8\x54" , vecCiphertext = "\x1d\xe2\x29\x67\x23\x7a\x81\x32" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xc1\xa4\xa1\x9a\xe8\x00\x94\x1c\xcd\xc5\x7c\xc8\x41\x3c\x27\x7f"+ { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xc1\xa4\xa1\x9a\xe8\x00\x94\x1c\xcd\xc5\x7c\xc8\x41\x3c\x27\x7f" , vecCiphertext = "\x16\x3d\x6f\x9c\xc1\xb3\x46\xcd\x45\x3a\x2e\x4c" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xb2\x92\xd2\x8f\xf6\x11\x89\xe8\xe4\x9f\x38\x75\xef\x91\xaf\xf7"- , vecCiphertext = "\xc9\x15\x45\x82\x3c\xc2\x4f\x17\xdb\xb0\xe9\xe8\x07\xd5\xec\x17"+ { vecPlaintext =+ "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xb2\x92\xd2\x8f\xf6\x11\x89\xe8\xe4\x9f\x38\x75\xef\x91\xaf\xf7"+ , vecCiphertext =+ "\xc9\x15\x45\x82\x3c\xc2\x4f\x17\xdb\xb0\xe9\xe8\x07\xd5\xec\x17" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xae\xa1\xba\xd1\x27\x02\xe1\x96\x56\x04\x37\x4a\xab\x96\xdb\xbc"- , vecCiphertext = "\x07\xda\xd3\x64\xbf\xc2\xb9\xda\x89\x11\x6d\x7b\xef\x6d\xaa\xaf\x6f\x25\x55\x10\xaa\x65\x4f\x92\x0a\xc8\x1b\x94\xe8\xba\xd3\x65"+ { vecPlaintext =+ "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xae\xa1\xba\xd1\x27\x02\xe1\x96\x56\x04\x37\x4a\xab\x96\xdb\xbc"+ , vecCiphertext =+ "\x07\xda\xd3\x64\xbf\xc2\xb9\xda\x89\x11\x6d\x7b\xef\x6d\xaa\xaf\x6f\x25\x55\x10\xaa\x65\x4f\x92\x0a\xc8\x1b\x94\xe8\xba\xd3\x65" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x03\x33\x27\x42\xb2\x28\xc6\x47\x17\x36\x16\xcf\xd4\x4c\x54\xeb"- , vecCiphertext = "\xc6\x7a\x1f\x0f\x56\x7a\x51\x98\xaa\x1f\xcc\x8e\x3f\x21\x31\x43\x36\xf7\xf5\x1c\xa8\xb1\xaf\x61\xfe\xac\x35\xa8\x64\x16\xfa\x47\xfb\xca\x3b\x5f\x74\x9c\xdf\x56\x45\x27\xf2\x31\x4f\x42\xfe\x25"+ { vecPlaintext =+ "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x03\x33\x27\x42\xb2\x28\xc6\x47\x17\x36\x16\xcf\xd4\x4c\x54\xeb"+ , vecCiphertext =+ "\xc6\x7a\x1f\x0f\x56\x7a\x51\x98\xaa\x1f\xcc\x8e\x3f\x21\x31\x43\x36\xf7\xf5\x1c\xa8\xb1\xaf\x61\xfe\xac\x35\xa8\x64\x16\xfa\x47\xfb\xca\x3b\x5f\x74\x9c\xdf\x56\x45\x27\xf2\x31\x4f\x42\xfe\x25" } , Vector- { vecPlaintext = "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = "\x01"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x5b\xde\x02\x85\x03\x7c\x5d\xe8\x1e\x5b\x57\x0a\x04\x9b\x62\xa0"- , vecCiphertext = "\x67\xfd\x45\xe1\x26\xbf\xb9\xa7\x99\x30\xc4\x3a\xad\x2d\x36\x96\x7d\x3f\x0e\x4d\x21\x7c\x1e\x55\x1f\x59\x72\x78\x70\xbe\xef\xc9\x8c\xb9\x33\xa8\xfc\xe9\xde\x88\x7b\x1e\x40\x79\x99\x88\xdb\x1f\xc3\xf9\x18\x80\xed\x40\x5b\x2d\xd2\x98\x31\x88\x58\x46\x7c\x89"+ { vecPlaintext =+ "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = "\x01"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x5b\xde\x02\x85\x03\x7c\x5d\xe8\x1e\x5b\x57\x0a\x04\x9b\x62\xa0"+ , vecCiphertext =+ "\x67\xfd\x45\xe1\x26\xbf\xb9\xa7\x99\x30\xc4\x3a\xad\x2d\x36\x96\x7d\x3f\x0e\x4d\x21\x7c\x1e\x55\x1f\x59\x72\x78\x70\xbe\xef\xc9\x8c\xb9\x33\xa8\xfc\xe9\xde\x88\x7b\x1e\x40\x79\x99\x88\xdb\x1f\xc3\xf9\x18\x80\xed\x40\x5b\x2d\xd2\x98\x31\x88\x58\x46\x7c\x89" } , Vector- { vecPlaintext = "\x02\x00\x00\x00"- , vecAAD = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\x18\x35\xe5\x17\x74\x1d\xfd\xdc\xcf\xa0\x7f\xa4\x66\x1b\x74\xcf"+ { vecPlaintext = "\x02\x00\x00\x00"+ , vecAAD = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\x18\x35\xe5\x17\x74\x1d\xfd\xdc\xcf\xa0\x7f\xa4\x66\x1b\x74\xcf" , vecCiphertext = "\x22\xb3\xf4\xcd" } , Vector- { vecPlaintext = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00"- , vecAAD = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xb8\x79\xad\x97\x6d\x82\x42\xac\xc1\x88\xab\x59\xca\xbf\xe3\x07"- , vecCiphertext = "\x43\xdd\x01\x63\xcd\xb4\x8f\x9f\xe3\x21\x2b\xf6\x1b\x20\x19\x76\x06\x7f\x34\x2b"+ { vecPlaintext =+ "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00"+ , vecAAD =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xb8\x79\xad\x97\x6d\x82\x42\xac\xc1\x88\xab\x59\xca\xbf\xe3\x07"+ , vecCiphertext =+ "\x43\xdd\x01\x63\xcd\xb4\x8f\x9f\xe3\x21\x2b\xf6\x1b\x20\x19\x76\x06\x7f\x34\x2b" } , Vector- { vecPlaintext = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00"- , vecAAD = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00"- , vecKey = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xcf\xcd\xf5\x04\x21\x12\xaa\x29\x68\x5c\x91\x2f\xc2\x05\x65\x43"- , vecCiphertext = "\x46\x24\x01\x72\x4b\x5c\xe6\x58\x8d\x5a\x54\xaa\xe5\x37\x55\x13\xa0\x75"+ { vecPlaintext =+ "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00"+ , vecAAD =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00"+ , vecKey =+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xcf\xcd\xf5\x04\x21\x12\xaa\x29\x68\x5c\x91\x2f\xc2\x05\x65\x43"+ , vecCiphertext =+ "\x46\x24\x01\x72\x4b\x5c\xe6\x58\x8d\x5a\x54\xaa\xe5\x37\x55\x13\xa0\x75" } , Vector- { vecPlaintext = ""- , vecAAD = ""- , vecKey = "\xe6\x60\x21\xd5\xeb\x8e\x4f\x40\x66\xd4\xad\xb9\xc3\x35\x60\xe4\xf4\x6e\x44\xbb\x3d\xa0\x01\x5c\x94\xf7\x08\x87\x36\x86\x42\x00"- , vecNonce = "\xe0\xea\xf5\x28\x4d\x88\x4a\x0e\x77\xd3\x16\x46"- , vecTag = "\x16\x9f\xbb\x2f\xbf\x38\x9a\x99\x5f\x63\x90\xaf\x22\x22\x8a\x62"+ { vecPlaintext = ""+ , vecAAD = ""+ , vecKey =+ "\xe6\x60\x21\xd5\xeb\x8e\x4f\x40\x66\xd4\xad\xb9\xc3\x35\x60\xe4\xf4\x6e\x44\xbb\x3d\xa0\x01\x5c\x94\xf7\x08\x87\x36\x86\x42\x00"+ , vecNonce = "\xe0\xea\xf5\x28\x4d\x88\x4a\x0e\x77\xd3\x16\x46"+ , vecTag =+ "\x16\x9f\xbb\x2f\xbf\x38\x9a\x99\x5f\x63\x90\xaf\x22\x22\x8a\x62" , vecCiphertext = "" } , Vector- { vecPlaintext = "\x67\x1f\xdd"- , vecAAD = "\x4f\xbd\xc6\x6f\x14"- , vecKey = "\xba\xe8\xe3\x7f\xc8\x34\x41\xb1\x60\x34\x56\x6b\x7a\x80\x6c\x46\xbb\x91\xc3\xc5\xae\xdb\x64\xa6\xc5\x90\xbc\x84\xd1\xa5\xe2\x69"- , vecNonce = "\xe4\xb4\x78\x01\xaf\xc0\x57\x7e\x34\x69\x9b\x9e"- , vecTag = "\x93\xda\x9b\xb8\x13\x33\xae\xe0\xc7\x85\xb2\x40\xd3\x19\x71\x9d"+ { vecPlaintext = "\x67\x1f\xdd"+ , vecAAD = "\x4f\xbd\xc6\x6f\x14"+ , vecKey =+ "\xba\xe8\xe3\x7f\xc8\x34\x41\xb1\x60\x34\x56\x6b\x7a\x80\x6c\x46\xbb\x91\xc3\xc5\xae\xdb\x64\xa6\xc5\x90\xbc\x84\xd1\xa5\xe2\x69"+ , vecNonce = "\xe4\xb4\x78\x01\xaf\xc0\x57\x7e\x34\x69\x9b\x9e"+ , vecTag =+ "\x93\xda\x9b\xb8\x13\x33\xae\xe0\xc7\x85\xb2\x40\xd3\x19\x71\x9d" , vecCiphertext = "\x0e\xac\xcb" } , Vector- { vecPlaintext = "\x19\x54\x95\x86\x0f\x04"- , vecAAD = "\x67\x87\xf3\xea\x22\xc1\x27\xaa\xf1\x95"- , vecKey = "\x65\x45\xfc\x88\x0c\x94\xa9\x51\x98\x87\x42\x96\xd5\xcc\x1f\xd1\x61\x32\x0b\x69\x20\xce\x07\x78\x7f\x86\x74\x3b\x27\x5d\x1a\xb3"- , vecNonce = "\x2f\x6d\x1f\x04\x34\xd8\x84\x8c\x11\x77\x44\x1f"- , vecTag = "\x6b\x62\xb8\x4d\xc4\x0c\x84\x63\x6a\x5e\xc1\x20\x20\xec\x8c\x2c"+ { vecPlaintext = "\x19\x54\x95\x86\x0f\x04"+ , vecAAD = "\x67\x87\xf3\xea\x22\xc1\x27\xaa\xf1\x95"+ , vecKey =+ "\x65\x45\xfc\x88\x0c\x94\xa9\x51\x98\x87\x42\x96\xd5\xcc\x1f\xd1\x61\x32\x0b\x69\x20\xce\x07\x78\x7f\x86\x74\x3b\x27\x5d\x1a\xb3"+ , vecNonce = "\x2f\x6d\x1f\x04\x34\xd8\x84\x8c\x11\x77\x44\x1f"+ , vecTag =+ "\x6b\x62\xb8\x4d\xc4\x0c\x84\x63\x6a\x5e\xc1\x20\x20\xec\x8c\x2c" , vecCiphertext = "\xa2\x54\xda\xd4\xf3\xf9" } , Vector- { vecPlaintext = "\xc9\x88\x2e\x53\x86\xfd\x9f\x92\xec"- , vecAAD = "\x48\x9c\x8f\xde\x2b\xe2\xcf\x97\xe7\x4e\x93\x2d\x4e\xd8\x7d"- , vecKey = "\xd1\x89\x47\x28\xb3\xfe\xd1\x47\x3c\x52\x8b\x84\x26\xa5\x82\x99\x59\x29\xa1\x49\x9e\x9a\xd8\x78\x0c\x8d\x63\xd0\xab\x41\x49\xc0"- , vecNonce = "\x9f\x57\x2c\x61\x4b\x47\x45\x91\x44\x74\xe7\xc7"- , vecTag = "\xc0\xfd\x3d\xc6\x62\x8d\xfe\x55\xeb\xb0\xb9\xfb\x22\x95\xc8\xc2"+ { vecPlaintext = "\xc9\x88\x2e\x53\x86\xfd\x9f\x92\xec"+ , vecAAD = "\x48\x9c\x8f\xde\x2b\xe2\xcf\x97\xe7\x4e\x93\x2d\x4e\xd8\x7d"+ , vecKey =+ "\xd1\x89\x47\x28\xb3\xfe\xd1\x47\x3c\x52\x8b\x84\x26\xa5\x82\x99\x59\x29\xa1\x49\x9e\x9a\xd8\x78\x0c\x8d\x63\xd0\xab\x41\x49\xc0"+ , vecNonce = "\x9f\x57\x2c\x61\x4b\x47\x45\x91\x44\x74\xe7\xc7"+ , vecTag =+ "\xc0\xfd\x3d\xc6\x62\x8d\xfe\x55\xeb\xb0\xb9\xfb\x22\x95\xc8\xc2" , vecCiphertext = "\x0d\xf9\xe3\x08\x67\x82\x44\xc4\x4b" } , Vector- { vecPlaintext = "\x1d\xb2\x31\x6f\xd5\x68\x37\x8d\xa1\x07\xb5\x2b"- , vecAAD = "\x0d\xa5\x52\x10\xcc\x1c\x1b\x0a\xbd\xe3\xb2\xf2\x04\xd1\xe9\xf8\xb0\x6b\xc4\x7f"- , vecKey = "\xa4\x41\x02\x95\x2e\xf9\x4b\x02\xb8\x05\x24\x9b\xac\x80\xe6\xf6\x14\x55\xbf\xac\x83\x08\xa2\xd4\x0d\x8c\x84\x51\x17\x80\x82\x35"- , vecNonce = "\x5c\x9e\x94\x0f\xea\x2f\x58\x29\x50\xa7\x0d\x5a"- , vecTag = "\x40\x40\x99\xc2\x58\x7f\x64\x97\x9f\x21\x82\x67\x06\xd4\x97\xd5"+ { vecPlaintext = "\x1d\xb2\x31\x6f\xd5\x68\x37\x8d\xa1\x07\xb5\x2b"+ , vecAAD =+ "\x0d\xa5\x52\x10\xcc\x1c\x1b\x0a\xbd\xe3\xb2\xf2\x04\xd1\xe9\xf8\xb0\x6b\xc4\x7f"+ , vecKey =+ "\xa4\x41\x02\x95\x2e\xf9\x4b\x02\xb8\x05\x24\x9b\xac\x80\xe6\xf6\x14\x55\xbf\xac\x83\x08\xa2\xd4\x0d\x8c\x84\x51\x17\x80\x82\x35"+ , vecNonce = "\x5c\x9e\x94\x0f\xea\x2f\x58\x29\x50\xa7\x0d\x5a"+ , vecTag =+ "\x40\x40\x99\xc2\x58\x7f\x64\x97\x9f\x21\x82\x67\x06\xd4\x97\xd5" , vecCiphertext = "\x8d\xbe\xb9\xf7\x25\x5b\xf5\x76\x9d\xd5\x66\x92" } , Vector- { vecPlaintext = "\x21\x70\x2d\xe0\xde\x18\xba\xa9\xc9\x59\x62\x91\xb0\x84\x66"- , vecAAD = "\xf3\x7d\xe2\x1c\x7f\xf9\x01\xcf\xe8\xa6\x96\x15\xa9\x3f\xdf\x7a\x98\xca\xd4\x81\x79\x62\x45\x70\x9f"- , vecKey = "\x97\x45\xb3\xd1\xae\x06\x55\x6f\xb6\xaa\x78\x90\xbe\xbc\x18\xfe\x6b\x3d\xb4\xda\x3d\x57\xaa\x94\x84\x2b\x98\x03\xa9\x6e\x07\xfb"- , vecNonce = "\x6d\xe7\x18\x60\xf7\x62\xeb\xfb\xd0\x82\x84\xe4"- , vecTag = "\xb3\x08\x0d\x28\xf6\xeb\xb5\xd3\x64\x8c\xe9\x7b\xd5\xba\x67\xfd"+ { vecPlaintext = "\x21\x70\x2d\xe0\xde\x18\xba\xa9\xc9\x59\x62\x91\xb0\x84\x66"+ , vecAAD =+ "\xf3\x7d\xe2\x1c\x7f\xf9\x01\xcf\xe8\xa6\x96\x15\xa9\x3f\xdf\x7a\x98\xca\xd4\x81\x79\x62\x45\x70\x9f"+ , vecKey =+ "\x97\x45\xb3\xd1\xae\x06\x55\x6f\xb6\xaa\x78\x90\xbe\xbc\x18\xfe\x6b\x3d\xb4\xda\x3d\x57\xaa\x94\x84\x2b\x98\x03\xa9\x6e\x07\xfb"+ , vecNonce = "\x6d\xe7\x18\x60\xf7\x62\xeb\xfb\xd0\x82\x84\xe4"+ , vecTag =+ "\xb3\x08\x0d\x28\xf6\xeb\xb5\xd3\x64\x8c\xe9\x7b\xd5\xba\x67\xfd" , vecCiphertext = "\x79\x35\x76\xdf\xa5\xc0\xf8\x87\x29\xa7\xed\x3c\x2f\x1b\xff" } , Vector- { vecPlaintext = "\xb2\x02\xb3\x70\xef\x97\x68\xec\x65\x61\xc4\xfe\x6b\x7e\x72\x96\xfa\x85"- , vecAAD = "\x9c\x21\x59\x05\x8b\x1f\x0f\xe9\x14\x33\xa5\xbd\xc2\x0e\x21\x4e\xab\x7f\xec\xef\x44\x54\xa1\x0e\xf0\x65\x7d\xf2\x1a\xc7"- , vecKey = "\xb1\x88\x53\xf6\x8d\x83\x36\x40\xe4\x2a\x3c\x02\xc2\x5b\x64\x86\x9e\x14\x6d\x7b\x23\x39\x87\xbd\xdf\xc2\x40\x87\x1d\x75\x76\xf7"- , vecNonce = "\x02\x8e\xc6\xeb\x5e\xa7\xe2\x98\x34\x2a\x94\xd4"- , vecTag = "\x45\x4f\xc2\xa1\x54\xfe\xa9\x1f\x83\x63\xa3\x9f\xec\x7d\x0a\x49"- , vecCiphertext = "\x85\x7e\x16\xa6\x49\x15\xa7\x87\x63\x76\x87\xdb\x4a\x95\x19\x63\x5c\xdd"+ { vecPlaintext =+ "\xb2\x02\xb3\x70\xef\x97\x68\xec\x65\x61\xc4\xfe\x6b\x7e\x72\x96\xfa\x85"+ , vecAAD =+ "\x9c\x21\x59\x05\x8b\x1f\x0f\xe9\x14\x33\xa5\xbd\xc2\x0e\x21\x4e\xab\x7f\xec\xef\x44\x54\xa1\x0e\xf0\x65\x7d\xf2\x1a\xc7"+ , vecKey =+ "\xb1\x88\x53\xf6\x8d\x83\x36\x40\xe4\x2a\x3c\x02\xc2\x5b\x64\x86\x9e\x14\x6d\x7b\x23\x39\x87\xbd\xdf\xc2\x40\x87\x1d\x75\x76\xf7"+ , vecNonce = "\x02\x8e\xc6\xeb\x5e\xa7\xe2\x98\x34\x2a\x94\xd4"+ , vecTag =+ "\x45\x4f\xc2\xa1\x54\xfe\xa9\x1f\x83\x63\xa3\x9f\xec\x7d\x0a\x49"+ , vecCiphertext =+ "\x85\x7e\x16\xa6\x49\x15\xa7\x87\x63\x76\x87\xdb\x4a\x95\x19\x63\x5c\xdd" } , Vector- { vecPlaintext = "\xce\xd5\x32\xce\x41\x59\xb0\x35\x27\x7d\x4d\xfb\xb7\xdb\x62\x96\x8b\x13\xcd\x4e\xec"- , vecAAD = "\x73\x43\x20\xcc\xc9\xd9\xbb\xbb\x19\xcb\x81\xb2\xaf\x4e\xcb\xc3\xe7\x28\x34\x32\x1f\x7a\xa0\xf7\x0b\x72\x82\xb4\xf3\x3d\xf2\x3f\x16\x75\x41"- , vecKey = "\x3c\x53\x5d\xe1\x92\xea\xed\x38\x22\xa2\xfb\xbe\x2c\xa9\xdf\xc8\x82\x55\xe1\x4a\x66\x1b\x8a\xa8\x2c\xc5\x42\x36\x09\x3b\xbc\x23"- , vecNonce = "\x68\x80\x89\xe5\x55\x40\xdb\x18\x72\x50\x4e\x1c"- , vecTag = "\x9d\x6c\x70\x29\x67\x5b\x89\xea\xf4\xba\x1d\xed\x1a\x28\x65\x94"- , vecCiphertext = "\x62\x66\x60\xc2\x6e\xa6\x61\x2f\xb1\x7a\xd9\x1e\x8e\x76\x76\x39\xed\xd6\xc9\xfa\xee"+ { vecPlaintext =+ "\xce\xd5\x32\xce\x41\x59\xb0\x35\x27\x7d\x4d\xfb\xb7\xdb\x62\x96\x8b\x13\xcd\x4e\xec"+ , vecAAD =+ "\x73\x43\x20\xcc\xc9\xd9\xbb\xbb\x19\xcb\x81\xb2\xaf\x4e\xcb\xc3\xe7\x28\x34\x32\x1f\x7a\xa0\xf7\x0b\x72\x82\xb4\xf3\x3d\xf2\x3f\x16\x75\x41"+ , vecKey =+ "\x3c\x53\x5d\xe1\x92\xea\xed\x38\x22\xa2\xfb\xbe\x2c\xa9\xdf\xc8\x82\x55\xe1\x4a\x66\x1b\x8a\xa8\x2c\xc5\x42\x36\x09\x3b\xbc\x23"+ , vecNonce = "\x68\x80\x89\xe5\x55\x40\xdb\x18\x72\x50\x4e\x1c"+ , vecTag =+ "\x9d\x6c\x70\x29\x67\x5b\x89\xea\xf4\xba\x1d\xed\x1a\x28\x65\x94"+ , vecCiphertext =+ "\x62\x66\x60\xc2\x6e\xa6\x61\x2f\xb1\x7a\xd9\x1e\x8e\x76\x76\x39\xed\xd6\xc9\xfa\xee" } ] vectorsWrap256 :: [Vector AES256] vectorsWrap256 = [ Vector- { vecPlaintext = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4d\xb9\x23\xdc\x79\x3e\xe6\x49\x7c\x76\xdc\xc0\x3a\x98\xe1\x08"- , vecAAD = ""- , vecKey = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecCiphertext = "\xf3\xf8\x0f\x2c\xf0\xcb\x2d\xd9\xc5\x98\x4f\xcd\xa9\x08\x45\x6c\xc5\x37\x70\x3b\x5b\xa7\x03\x24\xa6\x79\x3a\x7b\xf2\x18\xd3\xea"+ { vecPlaintext =+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4d\xb9\x23\xdc\x79\x3e\xe6\x49\x7c\x76\xdc\xc0\x3a\x98\xe1\x08"+ , vecAAD = ""+ , vecKey =+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecCiphertext =+ "\xf3\xf8\x0f\x2c\xf0\xcb\x2d\xd9\xc5\x98\x4f\xcd\xa9\x08\x45\x6c\xc5\x37\x70\x3b\x5b\xa7\x03\x24\xa6\x79\x3a\x7b\xf2\x18\xd3\xea" } , Vector- { vecPlaintext = "\xeb\x36\x40\x27\x7c\x7f\xfd\x13\x03\xc7\xa5\x42\xd0\x2d\x3e\x4c\x00\x00\x00\x00\x00\x00\x00\x00"- , vecAAD = ""- , vecKey = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecNonce = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecTag = "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"- , vecCiphertext = "\x18\xce\x4f\x0b\x8c\xb4\xd0\xca\xc6\x5f\xea\x8f\x79\x25\x7b\x20\x88\x8e\x53\xe7\x22\x99\xe5\x6d"+ { vecPlaintext =+ "\xeb\x36\x40\x27\x7c\x7f\xfd\x13\x03\xc7\xa5\x42\xd0\x2d\x3e\x4c\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecAAD = ""+ , vecKey =+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecNonce = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecTag =+ "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+ , vecCiphertext =+ "\x18\xce\x4f\x0b\x8c\xb4\xd0\xca\xc6\x5f\xea\x8f\x79\x25\x7b\x20\x88\x8e\x53\xe7\x22\x99\xe5\x6d" } ] @@ -442,27 +607,32 @@ makeEncryptionTest i vec@Vector{..} = testCase (show i) $ (t, vecCiphertext) @=? encrypt (vecCipher vec) n vecAAD vecPlaintext- where t = AuthTag (B.convert vecTag)- n = throwCryptoError (nonce vecNonce)+ where+ t = AuthTag (B.convert vecTag)+ n = throwCryptoError (nonce vecNonce) makeDecryptionTest :: BlockCipher128 aes => Int -> Vector aes -> TestTree makeDecryptionTest i vec@Vector{..} = testCase (show i) $ Just vecPlaintext @=? decrypt (vecCipher vec) n vecAAD vecCiphertext t- where t = AuthTag (B.convert vecTag)- n = throwCryptoError (nonce vecNonce)+ where+ t = AuthTag (B.convert vecTag)+ n = throwCryptoError (nonce vecNonce) -katTests :: TestName- -> (forall c . BlockCipher128 c => Int -> Vector c -> TestTree)- -> TestTree-katTests name makeTest = testGroup name- [ testGroup "AES128" $ zipWith makeTest [1..] vectors128- , testGroup "AES256" $ zipWith makeTest [1..] vectors256- , testGroup "CounterWrap" $ zipWith makeTest [1..] vectorsWrap256- ]+katTests+ :: TestName+ -> (forall c. BlockCipher128 c => Int -> Vector c -> TestTree)+ -> TestTree+katTests name makeTest =+ testGroup+ name+ [ testGroup "AES128" $ zipWith makeTest [1 ..] vectors128+ , testGroup "AES256" $ zipWith makeTest [1 ..] vectors256+ , testGroup "CounterWrap" $ zipWith makeTest [1 ..] vectorsWrap256+ ] newtype Key c = Key ByteString- deriving (Show,Eq)+ deriving (Show, Eq) instance Arbitrary (Key AES128) where arbitrary = Key <$> arbitraryBS 16@@ -473,22 +643,31 @@ instance Arbitrary Nonce where arbitrary = throwCryptoError . nonce <$> arbitraryBS 12 -encDecTest :: BlockCipher128 c- => Proxy c -> Key c -> Nonce- -> ArbitraryBS0_2901 -> ArbitraryBS0_2901 -> Property+encDecTest+ :: BlockCipher128 c+ => Proxy c+ -> Key c+ -> Nonce+ -> ArbitraryBS0_2901+ -> ArbitraryBS0_2901+ -> Property encDecTest prx (Key key) iv (ArbitraryBS0_2901 aad) (ArbitraryBS0_2901 input) = let c = throwCryptoError (cipherInit key) `asProxyTypeOf` prx (tag, ciphertext) = encrypt c iv aad input in decrypt c iv aad ciphertext tag === Just input tests :: TestTree-tests = testGroup "AES-GCM-SIV"- [ testGroup "KATs"- [ katTests "encrypt" makeEncryptionTest- , katTests "decrypt" makeDecryptionTest- ]- , testGroup "properties"- [ testProperty "AES128" $ encDecTest (Proxy :: Proxy AES128)- , testProperty "AES256" $ encDecTest (Proxy :: Proxy AES256)+tests =+ testGroup+ "AES-GCM-SIV"+ [ testGroup+ "KATs"+ [ katTests "encrypt" makeEncryptionTest+ , katTests "decrypt" makeDecryptionTest+ ]+ , testGroup+ "properties"+ [ testProperty "AES128" $ encDecTest (Proxy :: Proxy AES128)+ , testProperty "AES256" $ encDecTest (Proxy :: Proxy AES256)+ ] ]- ]
tests/KAT_AFIS.hs view
@@ -1,31 +1,35 @@-{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE OverloadedStrings #-}+ module KAT_AFIS (tests) where import Imports +import qualified Crypto.Data.AFIS as AFIS import Crypto.Hash import Crypto.Random-import qualified Crypto.Data.AFIS as AFIS import qualified Data.ByteString as B -mergeVec :: [ (Int, SHA1, B.ByteString, B.ByteString) ]+mergeVec :: [(Int, SHA1, B.ByteString, B.ByteString)] mergeVec =- [ (3- , 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- , 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"- )+ [+ ( 3+ , 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+ , 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 = zipWith toProp mergeVec [(0 :: Int)..]- where toProp (nbExpands, hashAlg, expected, dat) i =- testCase ("merge " ++ show i) (expected @=? AFIS.merge hashAlg nbExpands dat)+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 @@ -33,12 +37,19 @@ show (AFISParams dat expand _ _) = "data: " ++ show dat ++ " expanded: " ++ show expand instance Arbitrary AFISParams where- arbitrary = AFISParams <$> arbitraryBSof 3 46 <*> choose (2,2) <*> elements [SHA1] <*> arbitrary+ arbitrary =+ AFISParams+ <$> arbitraryBSof 3 46+ <*> choose (2, 2)+ <*> elements [SHA1]+ <*> 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))- ]+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))+ ]
tests/KAT_Argon2.hs view
@@ -1,29 +1,34 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_Argon2 (tests) where -import Crypto.Error+import Crypto.Error import qualified Crypto.KDF.Argon2 as Argon2 import qualified Data.ByteString as B-import Imports+import Imports data KDFVector = KDFVector- { kdfPass :: ByteString- , kdfSalt :: ByteString- , kdfOptions :: Argon2.Options- , kdfResult :: ByteString+ { kdfPass :: ByteString+ , kdfSalt :: ByteString+ , kdfOptions :: Argon2.Options+ , kdfResult :: ByteString } argon2i_13 :: Argon2.TimeCost -> Argon2.MemoryCost -> Argon2.Options-argon2i_13 iters memory = Argon2.Options- { Argon2.iterations = iters- , Argon2.memory = memory- , Argon2.parallelism = 1- , Argon2.variant = Argon2.Argon2i- , Argon2.version = Argon2.Version13- }+argon2i_13 iters memory =+ Argon2.Options+ { Argon2.iterations = iters+ , Argon2.memory = memory+ , Argon2.parallelism = 1+ , Argon2.variant = Argon2.Argon2i+ , Argon2.version = Argon2.Version13+ } vectors =- [ KDFVector "password" "somesalt" (argon2i_13 2 65536)+ [ KDFVector+ "password"+ "somesalt"+ (argon2i_13 2 65536) "\xc1\x62\x88\x32\x14\x7d\x97\x20\xc5\xbd\x1c\xfd\x61\x36\x70\x78\x72\x9f\x6d\xfb\x6f\x8f\xea\x9f\xf9\x81\x58\xe0\xd7\x81\x6e\xd0" ] @@ -31,12 +36,17 @@ kdfTests = zipWith toKDFTest is vectors where toKDFTest i v =- testCase (show i)- (CryptoPassed (kdfResult v) @=? Argon2.hash (kdfOptions v) (kdfPass v) (kdfSalt v) (B.length $ kdfResult v))+ testCase+ (show i)+ ( CryptoPassed (kdfResult v)+ @=? Argon2.hash (kdfOptions v) (kdfPass v) (kdfSalt v) (B.length $ kdfResult v)+ ) is :: [Int]- is = [1..]+ is = [1 ..] -tests = testGroup "Argon2"- [ testGroup "KATs" kdfTests- ]+tests =+ testGroup+ "Argon2"+ [ testGroup "KATs" kdfTests+ ]
tests/KAT_Blake2.hs view
@@ -1,20 +1,20 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-}+ module KAT_Blake2 (tests) where -import Crypto.Hash (digestFromByteString)-import Crypto.Hash.Algorithms+import Crypto.Hash (digestFromByteString)+import Crypto.Hash.Algorithms import qualified Crypto.MAC.KeyedBlake2 as KB import qualified Data.ByteString as B import Imports - data MACVector hash = MACVector { macMessage :: ByteString- , macKey :: ByteString+ , macKey :: ByteString , macResult :: KB.KeyedBlake2 hash } @@ -24,87 +24,114 @@ digest :: KB.HashBlake2 hash => ByteString -> KB.KeyedBlake2 hash digest = maybe (error "cannot get digest") KB.KeyedBlake2 . digestFromByteString - -- From: https://github.com/BLAKE2/BLAKE2/blob/master/testvectors/ vectorsBlake2bKAT :: [MACVector (Blake2b 512)] vectorsBlake2bKAT = [ MACVector { macMessage = ""- , macKey = fixedKey- , macResult = digest "\x10\xeb\xb6\x77\x00\xb1\x86\x8e\xfb\x44\x17\x98\x7a\xcf\x46\x90\xae\x9d\x97\x2f\xb7\xa5\x90\xc2\xf0\x28\x71\x79\x9a\xaa\x47\x86\xb5\xe9\x96\xe8\xf0\xf4\xeb\x98\x1f\xc2\x14\xb0\x05\xf4\x2d\x2f\xf4\x23\x34\x99\x39\x16\x53\xdf\x7a\xef\xcb\xc1\x3f\xc5\x15\x68"+ , macKey = fixedKey+ , macResult =+ digest+ "\x10\xeb\xb6\x77\x00\xb1\x86\x8e\xfb\x44\x17\x98\x7a\xcf\x46\x90\xae\x9d\x97\x2f\xb7\xa5\x90\xc2\xf0\x28\x71\x79\x9a\xaa\x47\x86\xb5\xe9\x96\xe8\xf0\xf4\xeb\x98\x1f\xc2\x14\xb0\x05\xf4\x2d\x2f\xf4\x23\x34\x99\x39\x16\x53\xdf\x7a\xef\xcb\xc1\x3f\xc5\x15\x68" } , MACVector { macMessage = "\x00"- , macKey = fixedKey- , macResult = digest "\x96\x1f\x6d\xd1\xe4\xdd\x30\xf6\x39\x01\x69\x0c\x51\x2e\x78\xe4\xb4\x5e\x47\x42\xed\x19\x7c\x3c\x5e\x45\xc5\x49\xfd\x25\xf2\xe4\x18\x7b\x0b\xc9\xfe\x30\x49\x2b\x16\xb0\xd0\xbc\x4e\xf9\xb0\xf3\x4c\x70\x03\xfa\xc0\x9a\x5e\xf1\x53\x2e\x69\x43\x02\x34\xce\xbd"+ , macKey = fixedKey+ , macResult =+ digest+ "\x96\x1f\x6d\xd1\xe4\xdd\x30\xf6\x39\x01\x69\x0c\x51\x2e\x78\xe4\xb4\x5e\x47\x42\xed\x19\x7c\x3c\x5e\x45\xc5\x49\xfd\x25\xf2\xe4\x18\x7b\x0b\xc9\xfe\x30\x49\x2b\x16\xb0\xd0\xbc\x4e\xf9\xb0\xf3\x4c\x70\x03\xfa\xc0\x9a\x5e\xf1\x53\x2e\x69\x43\x02\x34\xce\xbd" } , MACVector- { macMessage = B.pack [ 0x00 .. 0xfe ]- , macKey = fixedKey- , macResult = digest "\x14\x27\x09\xd6\x2e\x28\xfc\xcc\xd0\xaf\x97\xfa\xd0\xf8\x46\x5b\x97\x1e\x82\x20\x1d\xc5\x10\x70\xfa\xa0\x37\x2a\xa4\x3e\x92\x48\x4b\xe1\xc1\xe7\x3b\xa1\x09\x06\xd5\xd1\x85\x3d\xb6\xa4\x10\x6e\x0a\x7b\xf9\x80\x0d\x37\x3d\x6d\xee\x2d\x46\xd6\x2e\xf2\xa4\x61"+ { macMessage = B.pack [0x00 .. 0xfe]+ , macKey = fixedKey+ , macResult =+ digest+ "\x14\x27\x09\xd6\x2e\x28\xfc\xcc\xd0\xaf\x97\xfa\xd0\xf8\x46\x5b\x97\x1e\x82\x20\x1d\xc5\x10\x70\xfa\xa0\x37\x2a\xa4\x3e\x92\x48\x4b\xe1\xc1\xe7\x3b\xa1\x09\x06\xd5\xd1\x85\x3d\xb6\xa4\x10\x6e\x0a\x7b\xf9\x80\x0d\x37\x3d\x6d\xee\x2d\x46\xd6\x2e\xf2\xa4\x61" } ]- where fixedKey = B.pack [ 0x00 .. 0x3f ]+ where+ fixedKey = B.pack [0x00 .. 0x3f] vectorsBlake2bpKAT :: [MACVector (Blake2bp 512)] vectorsBlake2bpKAT = [ MACVector { macMessage = ""- , macKey = fixedKey- , macResult = digest "\x9d\x94\x61\x07\x3e\x4e\xb6\x40\xa2\x55\x35\x7b\x83\x9f\x39\x4b\x83\x8c\x6f\xf5\x7c\x9b\x68\x6a\x3f\x76\x10\x7c\x10\x66\x72\x8f\x3c\x99\x56\xbd\x78\x5c\xbc\x3b\xf7\x9d\xc2\xab\x57\x8c\x5a\x0c\x06\x3b\x9d\x9c\x40\x58\x48\xde\x1d\xbe\x82\x1c\xd0\x5c\x94\x0a"+ , macKey = fixedKey+ , macResult =+ digest+ "\x9d\x94\x61\x07\x3e\x4e\xb6\x40\xa2\x55\x35\x7b\x83\x9f\x39\x4b\x83\x8c\x6f\xf5\x7c\x9b\x68\x6a\x3f\x76\x10\x7c\x10\x66\x72\x8f\x3c\x99\x56\xbd\x78\x5c\xbc\x3b\xf7\x9d\xc2\xab\x57\x8c\x5a\x0c\x06\x3b\x9d\x9c\x40\x58\x48\xde\x1d\xbe\x82\x1c\xd0\x5c\x94\x0a" } , MACVector { macMessage = "\x00"- , macKey = fixedKey- , macResult = digest "\xff\x8e\x90\xa3\x7b\x94\x62\x39\x32\xc5\x9f\x75\x59\xf2\x60\x35\x02\x9c\x37\x67\x32\xcb\x14\xd4\x16\x02\x00\x1c\xbb\x73\xad\xb7\x92\x93\xa2\xdb\xda\x5f\x60\x70\x30\x25\x14\x4d\x15\x8e\x27\x35\x52\x95\x96\x25\x1c\x73\xc0\x34\x5c\xa6\xfc\xcb\x1f\xb1\xe9\x7e"+ , macKey = fixedKey+ , macResult =+ digest+ "\xff\x8e\x90\xa3\x7b\x94\x62\x39\x32\xc5\x9f\x75\x59\xf2\x60\x35\x02\x9c\x37\x67\x32\xcb\x14\xd4\x16\x02\x00\x1c\xbb\x73\xad\xb7\x92\x93\xa2\xdb\xda\x5f\x60\x70\x30\x25\x14\x4d\x15\x8e\x27\x35\x52\x95\x96\x25\x1c\x73\xc0\x34\x5c\xa6\xfc\xcb\x1f\xb1\xe9\x7e" } , MACVector- { macMessage = B.pack [ 0x00 .. 0xfe ]- , macKey = fixedKey- , macResult = digest "\x96\xfb\xcb\xb6\x0b\xd3\x13\xb8\x84\x50\x33\xe5\xbc\x05\x8a\x38\x02\x74\x38\x57\x2d\x7e\x79\x57\xf3\x68\x4f\x62\x68\xaa\xdd\x3a\xd0\x8d\x21\x76\x7e\xd6\x87\x86\x85\x33\x1b\xa9\x85\x71\x48\x7e\x12\x47\x0a\xad\x66\x93\x26\x71\x6e\x46\x66\x7f\x69\xf8\xd7\xe8"+ { macMessage = B.pack [0x00 .. 0xfe]+ , macKey = fixedKey+ , macResult =+ digest+ "\x96\xfb\xcb\xb6\x0b\xd3\x13\xb8\x84\x50\x33\xe5\xbc\x05\x8a\x38\x02\x74\x38\x57\x2d\x7e\x79\x57\xf3\x68\x4f\x62\x68\xaa\xdd\x3a\xd0\x8d\x21\x76\x7e\xd6\x87\x86\x85\x33\x1b\xa9\x85\x71\x48\x7e\x12\x47\x0a\xad\x66\x93\x26\x71\x6e\x46\x66\x7f\x69\xf8\xd7\xe8" } ]- where fixedKey = B.pack [ 0x00 .. 0x3f ]+ where+ fixedKey = B.pack [0x00 .. 0x3f] vectorsBlake2sKAT :: [MACVector (Blake2s 256)] vectorsBlake2sKAT = [ MACVector { macMessage = ""- , macKey = fixedKey- , macResult = digest "\x48\xa8\x99\x7d\xa4\x07\x87\x6b\x3d\x79\xc0\xd9\x23\x25\xad\x3b\x89\xcb\xb7\x54\xd8\x6a\xb7\x1a\xee\x04\x7a\xd3\x45\xfd\x2c\x49"+ , macKey = fixedKey+ , macResult =+ digest+ "\x48\xa8\x99\x7d\xa4\x07\x87\x6b\x3d\x79\xc0\xd9\x23\x25\xad\x3b\x89\xcb\xb7\x54\xd8\x6a\xb7\x1a\xee\x04\x7a\xd3\x45\xfd\x2c\x49" } , MACVector { macMessage = "\x00"- , macKey = fixedKey- , macResult = digest "\x40\xd1\x5f\xee\x7c\x32\x88\x30\x16\x6a\xc3\xf9\x18\x65\x0f\x80\x7e\x7e\x01\xe1\x77\x25\x8c\xdc\x0a\x39\xb1\x1f\x59\x80\x66\xf1"+ , macKey = fixedKey+ , macResult =+ digest+ "\x40\xd1\x5f\xee\x7c\x32\x88\x30\x16\x6a\xc3\xf9\x18\x65\x0f\x80\x7e\x7e\x01\xe1\x77\x25\x8c\xdc\x0a\x39\xb1\x1f\x59\x80\x66\xf1" } , MACVector- { macMessage = B.pack [ 0x00 .. 0xfe ]- , macKey = fixedKey- , macResult = digest "\x3f\xb7\x35\x06\x1a\xbc\x51\x9d\xfe\x97\x9e\x54\xc1\xee\x5b\xfa\xd0\xa9\xd8\x58\xb3\x31\x5b\xad\x34\xbd\xe9\x99\xef\xd7\x24\xdd"+ { macMessage = B.pack [0x00 .. 0xfe]+ , macKey = fixedKey+ , macResult =+ digest+ "\x3f\xb7\x35\x06\x1a\xbc\x51\x9d\xfe\x97\x9e\x54\xc1\xee\x5b\xfa\xd0\xa9\xd8\x58\xb3\x31\x5b\xad\x34\xbd\xe9\x99\xef\xd7\x24\xdd" } ]- where fixedKey = B.pack [ 0x00 .. 0x1f ]+ where+ fixedKey = B.pack [0x00 .. 0x1f] vectorsBlake2spKAT :: [MACVector (Blake2sp 256)] vectorsBlake2spKAT = [ MACVector { macMessage = ""- , macKey = fixedKey- , macResult = digest "\x71\x5c\xb1\x38\x95\xae\xb6\x78\xf6\x12\x41\x60\xbf\xf2\x14\x65\xb3\x0f\x4f\x68\x74\x19\x3f\xc8\x51\xb4\x62\x10\x43\xf0\x9c\xc6"+ , macKey = fixedKey+ , macResult =+ digest+ "\x71\x5c\xb1\x38\x95\xae\xb6\x78\xf6\x12\x41\x60\xbf\xf2\x14\x65\xb3\x0f\x4f\x68\x74\x19\x3f\xc8\x51\xb4\x62\x10\x43\xf0\x9c\xc6" } , MACVector { macMessage = "\x00"- , macKey = fixedKey- , macResult = digest "\x40\x57\x8f\xfa\x52\xbf\x51\xae\x18\x66\xf4\x28\x4d\x3a\x15\x7f\xc1\xbc\xd3\x6a\xc1\x3c\xbd\xcb\x03\x77\xe4\xd0\xcd\x0b\x66\x03"+ , macKey = fixedKey+ , macResult =+ digest+ "\x40\x57\x8f\xfa\x52\xbf\x51\xae\x18\x66\xf4\x28\x4d\x3a\x15\x7f\xc1\xbc\xd3\x6a\xc1\x3c\xbd\xcb\x03\x77\xe4\xd0\xcd\x0b\x66\x03" } , MACVector- { macMessage = B.pack [ 0x00 .. 0xfe ]- , macKey = fixedKey- , macResult = digest "\x0c\x8a\x36\x59\x7d\x74\x61\xc6\x3a\x94\x73\x28\x21\xc9\x41\x85\x6c\x66\x83\x76\x60\x6c\x86\xa5\x2d\xe0\xee\x41\x04\xc6\x15\xdb"+ { macMessage = B.pack [0x00 .. 0xfe]+ , macKey = fixedKey+ , macResult =+ digest+ "\x0c\x8a\x36\x59\x7d\x74\x61\xc6\x3a\x94\x73\x28\x21\xc9\x41\x85\x6c\x66\x83\x76\x60\x6c\x86\xa5\x2d\xe0\xee\x41\x04\xc6\x15\xdb" } ]- where fixedKey = B.pack [ 0x00 .. 0x1f ]+ where+ fixedKey = B.pack [0x00 .. 0x1f] macTests :: [TestTree] macTests =@@ -113,16 +140,20 @@ , testGroup "Blake2s_512" (concatMap toMACTest $ zip is vectorsBlake2sKAT) , testGroup "Blake2sp_512" (concatMap toMACTest $ zip is vectorsBlake2spKAT) ]- where toMACTest (i, MACVector{..}) =- [ testCase (show i) (macResult @=? KB.keyedBlake2 macKey macMessage)- , testCase ("incr-" ++ show i) (macResult @=?- KB.finalize (KB.update (KB.initialize macKey) macMessage))- ]- is :: [Int]- is = [1..]+ where+ toMACTest (i, MACVector{..}) =+ [ testCase (show i) (macResult @=? KB.keyedBlake2 macKey macMessage)+ , testCase+ ("incr-" ++ show i)+ ( macResult+ @=? KB.finalize (KB.update (KB.initialize macKey) macMessage)+ )+ ]+ is :: [Int]+ is = [1 ..] data MacIncremental a = MacIncremental ByteString ByteString (KB.KeyedBlake2 a)- deriving (Show,Eq)+ deriving (Show, Eq) instance KB.HashBlake2 a => Arbitrary (MacIncremental a) where arbitrary = do@@ -130,13 +161,14 @@ msg <- arbitraryBSof 1 99 return $ MacIncremental key msg (KB.keyedBlake2 key msg) -data MacIncrementalList a = MacIncrementalList ByteString [ByteString] (KB.KeyedBlake2 a)- deriving (Show,Eq)+data MacIncrementalList a+ = MacIncrementalList ByteString [ByteString] (KB.KeyedBlake2 a)+ deriving (Show, Eq) instance KB.HashBlake2 a => Arbitrary (MacIncrementalList a) where arbitrary = do key <- arbitraryBSof 32 64- msgs <- choose (1,20) >>= \n -> replicateM n (arbitraryBSof 1 99)+ msgs <- choose (1, 20) >>= \n -> replicateM n (arbitraryBSof 1 99) return $ MacIncrementalList key msgs (KB.keyedBlake2 key (B.concat msgs)) macIncrementalTests :: [TestTree]@@ -147,20 +179,25 @@ , testIncrProperties "Blake2sp_256" (Blake2sp :: Blake2sp 256) ] where- testIncrProperties :: KB.HashBlake2 a => TestName -> a -> TestTree- testIncrProperties name a = testGroup name+ testIncrProperties :: KB.HashBlake2 a => TestName -> a -> TestTree+ testIncrProperties name a =+ testGroup+ name [ testProperty "list-one" (prop_inc0 a) , testProperty "list-multi" (prop_inc1 a) ] - prop_inc0 :: KB.HashBlake2 a => a -> MacIncremental a -> Bool- prop_inc0 _ (MacIncremental secret msg result) =- result `assertEq` KB.finalize (KB.update (KB.initialize secret) msg)+ prop_inc0 :: KB.HashBlake2 a => a -> MacIncremental a -> Bool+ prop_inc0 _ (MacIncremental secret msg result) =+ result `assertEq` KB.finalize (KB.update (KB.initialize secret) msg) - prop_inc1 :: KB.HashBlake2 a => a -> MacIncrementalList a -> Bool- prop_inc1 _ (MacIncrementalList secret msgs result) =- result `assertEq` KB.finalize (foldl' KB.update (KB.initialize secret) msgs)+ prop_inc1 :: KB.HashBlake2 a => a -> MacIncrementalList a -> Bool+ prop_inc1 _ (MacIncrementalList secret msgs result) =+ result `assertEq` KB.finalize (foldl' KB.update (KB.initialize secret) msgs) -tests = testGroup "Blake2"- [ testGroup "KATs" macTests- , testGroup "properties" macIncrementalTests ]+tests =+ testGroup+ "Blake2"+ [ testGroup "KATs" macTests+ , testGroup "properties" macIncrementalTests+ ]
tests/KAT_Blowfish.hs view
@@ -1,47 +1,151 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_Blowfish where +import BlockCipher import Crypto.Cipher.Blowfish import Imports ()-import BlockCipher -vectors_ecb = -- key plaintext cipher- [ KAT_ECB "\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00" "\x4E\xF9\x97\x45\x61\x98\xDD\x78"- , KAT_ECB "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\x51\x86\x6F\xD5\xB8\x5E\xCB\x8A"- , KAT_ECB "\x30\x00\x00\x00\x00\x00\x00\x00" "\x10\x00\x00\x00\x00\x00\x00\x01" "\x7D\x85\x6F\x9A\x61\x30\x63\xF2"- , KAT_ECB "\x11\x11\x11\x11\x11\x11\x11\x11" "\x11\x11\x11\x11\x11\x11\x11\x11" "\x24\x66\xDD\x87\x8B\x96\x3C\x9D"- , KAT_ECB "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\x11\x11\x11\x11\x11\x11\x11\x11" "\x61\xF9\xC3\x80\x22\x81\xB0\x96"- , KAT_ECB "\x11\x11\x11\x11\x11\x11\x11\x11" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\x7D\x0C\xC6\x30\xAF\xDA\x1E\xC7"- , KAT_ECB "\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00" "\x4E\xF9\x97\x45\x61\x98\xDD\x78"- , KAT_ECB "\xFE\xDC\xBA\x98\x76\x54\x32\x10" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\x0A\xCE\xAB\x0F\xC6\xA0\xA2\x8D"- , KAT_ECB "\x7C\xA1\x10\x45\x4A\x1A\x6E\x57" "\x01\xA1\xD6\xD0\x39\x77\x67\x42" "\x59\xC6\x82\x45\xEB\x05\x28\x2B"- , KAT_ECB "\x01\x31\xD9\x61\x9D\xC1\x37\x6E" "\x5C\xD5\x4C\xA8\x3D\xEF\x57\xDA" "\xB1\xB8\xCC\x0B\x25\x0F\x09\xA0"- , KAT_ECB "\x07\xA1\x13\x3E\x4A\x0B\x26\x86" "\x02\x48\xD4\x38\x06\xF6\x71\x72" "\x17\x30\xE5\x77\x8B\xEA\x1D\xA4"- , KAT_ECB "\x38\x49\x67\x4C\x26\x02\x31\x9E" "\x51\x45\x4B\x58\x2D\xDF\x44\x0A" "\xA2\x5E\x78\x56\xCF\x26\x51\xEB"- , KAT_ECB "\x04\xB9\x15\xBA\x43\xFE\xB5\xB6" "\x42\xFD\x44\x30\x59\x57\x7F\xA2" "\x35\x38\x82\xB1\x09\xCE\x8F\x1A"- , KAT_ECB "\x01\x13\xB9\x70\xFD\x34\xF2\xCE" "\x05\x9B\x5E\x08\x51\xCF\x14\x3A" "\x48\xF4\xD0\x88\x4C\x37\x99\x18"- , KAT_ECB "\x01\x70\xF1\x75\x46\x8F\xB5\xE6" "\x07\x56\xD8\xE0\x77\x47\x61\xD2" "\x43\x21\x93\xB7\x89\x51\xFC\x98"- , KAT_ECB "\x43\x29\x7F\xAD\x38\xE3\x73\xFE" "\x76\x25\x14\xB8\x29\xBF\x48\x6A" "\x13\xF0\x41\x54\xD6\x9D\x1A\xE5"- , KAT_ECB "\x07\xA7\x13\x70\x45\xDA\x2A\x16" "\x3B\xDD\x11\x90\x49\x37\x28\x02" "\x2E\xED\xDA\x93\xFF\xD3\x9C\x79"- , KAT_ECB "\x04\x68\x91\x04\xC2\xFD\x3B\x2F" "\x26\x95\x5F\x68\x35\xAF\x60\x9A" "\xD8\x87\xE0\x39\x3C\x2D\xA6\xE3"- , KAT_ECB "\x37\xD0\x6B\xB5\x16\xCB\x75\x46" "\x16\x4D\x5E\x40\x4F\x27\x52\x32" "\x5F\x99\xD0\x4F\x5B\x16\x39\x69"- , KAT_ECB "\x1F\x08\x26\x0D\x1A\xC2\x46\x5E" "\x6B\x05\x6E\x18\x75\x9F\x5C\xCA" "\x4A\x05\x7A\x3B\x24\xD3\x97\x7B"- , KAT_ECB "\x58\x40\x23\x64\x1A\xBA\x61\x76" "\x00\x4B\xD6\xEF\x09\x17\x60\x62" "\x45\x20\x31\xC1\xE4\xFA\xDA\x8E"- , KAT_ECB "\x02\x58\x16\x16\x46\x29\xB0\x07" "\x48\x0D\x39\x00\x6E\xE7\x62\xF2" "\x75\x55\xAE\x39\xF5\x9B\x87\xBD"- , KAT_ECB "\x49\x79\x3E\xBC\x79\xB3\x25\x8F" "\x43\x75\x40\xC8\x69\x8F\x3C\xFA" "\x53\xC5\x5F\x9C\xB4\x9F\xC0\x19"- , KAT_ECB "\x4F\xB0\x5E\x15\x15\xAB\x73\xA7" "\x07\x2D\x43\xA0\x77\x07\x52\x92" "\x7A\x8E\x7B\xFA\x93\x7E\x89\xA3"- , KAT_ECB "\x49\xE9\x5D\x6D\x4C\xA2\x29\xBF" "\x02\xFE\x55\x77\x81\x17\xF1\x2A" "\xCF\x9C\x5D\x7A\x49\x86\xAD\xB5"- , KAT_ECB "\x01\x83\x10\xDC\x40\x9B\x26\xD6" "\x1D\x9D\x5C\x50\x18\xF7\x28\xC2" "\xD1\xAB\xB2\x90\x65\x8B\xC7\x78"- , KAT_ECB "\x1C\x58\x7F\x1C\x13\x92\x4F\xEF" "\x30\x55\x32\x28\x6D\x6F\x29\x5A" "\x55\xCB\x37\x74\xD1\x3E\xF2\x01"- , KAT_ECB "\x01\x01\x01\x01\x01\x01\x01\x01" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\xFA\x34\xEC\x48\x47\xB2\x68\xB2"- , KAT_ECB "\x1F\x1F\x1F\x1F\x0E\x0E\x0E\x0E" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\xA7\x90\x79\x51\x08\xEA\x3C\xAE"- , KAT_ECB "\xE0\xFE\xE0\xFE\xF1\xFE\xF1\xFE" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\xC3\x9E\x07\x2D\x9F\xAC\x63\x1D"- , KAT_ECB "\x00\x00\x00\x00\x00\x00\x00\x00" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\x01\x49\x33\xE0\xCD\xAF\xF6\xE4"- , KAT_ECB "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\x00\x00\x00\x00\x00\x00\x00\x00" "\xF2\x1E\x9A\x77\xB7\x1C\x49\xBC"- , KAT_ECB "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\x00\x00\x00\x00\x00\x00\x00\x00" "\x24\x59\x46\x88\x57\x54\x36\x9A"- , KAT_ECB "\xFE\xDC\xBA\x98\x76\x54\x32\x10" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\x6B\x5C\x5A\x9C\x5D\x9E\x0A\x5A"+vectors_ecb =+ -- key plaintext cipher+ [ KAT_ECB+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\x4E\xF9\x97\x45\x61\x98\xDD\x78"+ , KAT_ECB+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"+ "\x51\x86\x6F\xD5\xB8\x5E\xCB\x8A"+ , KAT_ECB+ "\x30\x00\x00\x00\x00\x00\x00\x00"+ "\x10\x00\x00\x00\x00\x00\x00\x01"+ "\x7D\x85\x6F\x9A\x61\x30\x63\xF2"+ , KAT_ECB+ "\x11\x11\x11\x11\x11\x11\x11\x11"+ "\x11\x11\x11\x11\x11\x11\x11\x11"+ "\x24\x66\xDD\x87\x8B\x96\x3C\x9D"+ , KAT_ECB+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\x11\x11\x11\x11\x11\x11\x11\x11"+ "\x61\xF9\xC3\x80\x22\x81\xB0\x96"+ , KAT_ECB+ "\x11\x11\x11\x11\x11\x11\x11\x11"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\x7D\x0C\xC6\x30\xAF\xDA\x1E\xC7"+ , KAT_ECB+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\x4E\xF9\x97\x45\x61\x98\xDD\x78"+ , KAT_ECB+ "\xFE\xDC\xBA\x98\x76\x54\x32\x10"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\x0A\xCE\xAB\x0F\xC6\xA0\xA2\x8D"+ , KAT_ECB+ "\x7C\xA1\x10\x45\x4A\x1A\x6E\x57"+ "\x01\xA1\xD6\xD0\x39\x77\x67\x42"+ "\x59\xC6\x82\x45\xEB\x05\x28\x2B"+ , KAT_ECB+ "\x01\x31\xD9\x61\x9D\xC1\x37\x6E"+ "\x5C\xD5\x4C\xA8\x3D\xEF\x57\xDA"+ "\xB1\xB8\xCC\x0B\x25\x0F\x09\xA0"+ , KAT_ECB+ "\x07\xA1\x13\x3E\x4A\x0B\x26\x86"+ "\x02\x48\xD4\x38\x06\xF6\x71\x72"+ "\x17\x30\xE5\x77\x8B\xEA\x1D\xA4"+ , KAT_ECB+ "\x38\x49\x67\x4C\x26\x02\x31\x9E"+ "\x51\x45\x4B\x58\x2D\xDF\x44\x0A"+ "\xA2\x5E\x78\x56\xCF\x26\x51\xEB"+ , KAT_ECB+ "\x04\xB9\x15\xBA\x43\xFE\xB5\xB6"+ "\x42\xFD\x44\x30\x59\x57\x7F\xA2"+ "\x35\x38\x82\xB1\x09\xCE\x8F\x1A"+ , KAT_ECB+ "\x01\x13\xB9\x70\xFD\x34\xF2\xCE"+ "\x05\x9B\x5E\x08\x51\xCF\x14\x3A"+ "\x48\xF4\xD0\x88\x4C\x37\x99\x18"+ , KAT_ECB+ "\x01\x70\xF1\x75\x46\x8F\xB5\xE6"+ "\x07\x56\xD8\xE0\x77\x47\x61\xD2"+ "\x43\x21\x93\xB7\x89\x51\xFC\x98"+ , KAT_ECB+ "\x43\x29\x7F\xAD\x38\xE3\x73\xFE"+ "\x76\x25\x14\xB8\x29\xBF\x48\x6A"+ "\x13\xF0\x41\x54\xD6\x9D\x1A\xE5"+ , KAT_ECB+ "\x07\xA7\x13\x70\x45\xDA\x2A\x16"+ "\x3B\xDD\x11\x90\x49\x37\x28\x02"+ "\x2E\xED\xDA\x93\xFF\xD3\x9C\x79"+ , KAT_ECB+ "\x04\x68\x91\x04\xC2\xFD\x3B\x2F"+ "\x26\x95\x5F\x68\x35\xAF\x60\x9A"+ "\xD8\x87\xE0\x39\x3C\x2D\xA6\xE3"+ , KAT_ECB+ "\x37\xD0\x6B\xB5\x16\xCB\x75\x46"+ "\x16\x4D\x5E\x40\x4F\x27\x52\x32"+ "\x5F\x99\xD0\x4F\x5B\x16\x39\x69"+ , KAT_ECB+ "\x1F\x08\x26\x0D\x1A\xC2\x46\x5E"+ "\x6B\x05\x6E\x18\x75\x9F\x5C\xCA"+ "\x4A\x05\x7A\x3B\x24\xD3\x97\x7B"+ , KAT_ECB+ "\x58\x40\x23\x64\x1A\xBA\x61\x76"+ "\x00\x4B\xD6\xEF\x09\x17\x60\x62"+ "\x45\x20\x31\xC1\xE4\xFA\xDA\x8E"+ , KAT_ECB+ "\x02\x58\x16\x16\x46\x29\xB0\x07"+ "\x48\x0D\x39\x00\x6E\xE7\x62\xF2"+ "\x75\x55\xAE\x39\xF5\x9B\x87\xBD"+ , KAT_ECB+ "\x49\x79\x3E\xBC\x79\xB3\x25\x8F"+ "\x43\x75\x40\xC8\x69\x8F\x3C\xFA"+ "\x53\xC5\x5F\x9C\xB4\x9F\xC0\x19"+ , KAT_ECB+ "\x4F\xB0\x5E\x15\x15\xAB\x73\xA7"+ "\x07\x2D\x43\xA0\x77\x07\x52\x92"+ "\x7A\x8E\x7B\xFA\x93\x7E\x89\xA3"+ , KAT_ECB+ "\x49\xE9\x5D\x6D\x4C\xA2\x29\xBF"+ "\x02\xFE\x55\x77\x81\x17\xF1\x2A"+ "\xCF\x9C\x5D\x7A\x49\x86\xAD\xB5"+ , KAT_ECB+ "\x01\x83\x10\xDC\x40\x9B\x26\xD6"+ "\x1D\x9D\x5C\x50\x18\xF7\x28\xC2"+ "\xD1\xAB\xB2\x90\x65\x8B\xC7\x78"+ , KAT_ECB+ "\x1C\x58\x7F\x1C\x13\x92\x4F\xEF"+ "\x30\x55\x32\x28\x6D\x6F\x29\x5A"+ "\x55\xCB\x37\x74\xD1\x3E\xF2\x01"+ , KAT_ECB+ "\x01\x01\x01\x01\x01\x01\x01\x01"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\xFA\x34\xEC\x48\x47\xB2\x68\xB2"+ , KAT_ECB+ "\x1F\x1F\x1F\x1F\x0E\x0E\x0E\x0E"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\xA7\x90\x79\x51\x08\xEA\x3C\xAE"+ , KAT_ECB+ "\xE0\xFE\xE0\xFE\xF1\xFE\xF1\xFE"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\xC3\x9E\x07\x2D\x9F\xAC\x63\x1D"+ , KAT_ECB+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"+ "\x01\x49\x33\xE0\xCD\xAF\xF6\xE4"+ , KAT_ECB+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\xF2\x1E\x9A\x77\xB7\x1C\x49\xBC"+ , KAT_ECB+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\x24\x59\x46\x88\x57\x54\x36\x9A"+ , KAT_ECB+ "\xFE\xDC\xBA\x98\x76\x54\x32\x10"+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"+ "\x6B\x5C\x5A\x9C\x5D\x9E\x0A\x5A" ] -kats = defaultKATs { kat_ECB = vectors_ecb }+kats = defaultKATs{kat_ECB = vectors_ecb} tests = testBlockCipher kats (undefined :: Blowfish64)
tests/KAT_CAST5.hs view
@@ -1,15 +1,26 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_CAST5 (tests) where import BlockCipher import qualified Crypto.Cipher.CAST5 as CAST5 -vectors_ecb = -- key plaintext ciphertext- [ KAT_ECB "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\x23\x8B\x4F\xE5\x84\x7E\x44\xB2"- , KAT_ECB "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\xEB\x6A\x71\x1A\x2C\x02\x27\x1B"- , KAT_ECB "\x01\x23\x45\x67\x12" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\x7A\xC8\x16\xD1\x6E\x9B\x30\x2E"+vectors_ecb =+ -- key plaintext ciphertext+ [ KAT_ECB+ "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\x23\x8B\x4F\xE5\x84\x7E\x44\xB2"+ , KAT_ECB+ "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\xEB\x6A\x71\x1A\x2C\x02\x27\x1B"+ , KAT_ECB+ "\x01\x23\x45\x67\x12"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\x7A\xC8\x16\xD1\x6E\x9B\x30\x2E" ] -kats = defaultKATs { kat_ECB = vectors_ecb }+kats = defaultKATs{kat_ECB = vectors_ecb} tests = testBlockCipher kats (undefined :: CAST5.CAST5)
tests/KAT_CMAC.hs view
@@ -1,26 +1,31 @@- module KAT_CMAC (tests) where +import Crypto.Cipher.AES (AES128, AES192, AES256)+import Crypto.Cipher.TripleDES (DES_EDE2, DES_EDE3)+import Crypto.Cipher.Types (+ BlockCipher,+ Cipher,+ blockSize,+ cipherInit,+ ecbEncrypt,+ )+import Crypto.Error (eitherCryptoError) import qualified Crypto.MAC.CMAC as CMAC-import Crypto.Cipher.Types (Cipher, cipherInit, BlockCipher, ecbEncrypt, blockSize)-import Crypto.Error (eitherCryptoError)-import Crypto.Cipher.AES (AES128, AES192, AES256)-import Crypto.Cipher.TripleDES (DES_EDE3, DES_EDE2) -import Imports+import Imports -import Data.Char (digitToInt)-import qualified Data.ByteString as BS import qualified Data.ByteArray as B-+import qualified Data.ByteString as BS+import Data.Char (digitToInt) hxs :: String -> ByteString-hxs = BS.pack . rec' where+hxs = BS.pack . rec'+ where dtoW8 = fromIntegral . digitToInt- rec' (' ':xs) = rec' xs- rec' (x:y:xs) = dtoW8 x * 16 + dtoW8 y : rec' xs- rec' [_] = error "hxs: invalid hex pattern."- rec' [] = []+ rec' (' ' : xs) = rec' xs+ rec' (x : y : xs) = dtoW8 x * 16 + dtoW8 y : rec' xs+ rec' [_] = error "hxs: invalid hex pattern."+ rec' [] = [] unsafeCipher :: Cipher k => ByteString -> k unsafeCipher = either (error . show) id . eitherCryptoError . cipherInit@@ -36,11 +41,11 @@ msg512 :: ByteString msg512 =- hxs $- "6bc1bee2 2e409f96 e93d7e11 7393172a" ++- "ae2d8a57 1e03ac9c 9eb76fac 45af8e51" ++- "30c81c46 a35ce411 e5fbc119 1a0a52ef" ++- "f69f2445 df4f9b17 ad2b417b e66c3710"+ hxs $+ "6bc1bee2 2e409f96 e93d7e11 7393172a"+ ++ "ae2d8a57 1e03ac9c 9eb76fac 45af8e51"+ ++ "30c81c46 a35ce411 e5fbc119 1a0a52ef"+ ++ "f69f2445 df4f9b17 ad2b417b e66c3710" msg320 :: ByteString msg320 = BS.take 40 msg512@@ -65,146 +70,148 @@ gAES128 :: TestTree gAES128 =- igroup "aes128"- [ ecb0 aes128key @?= hxs "7df76b0c 1ab899b3 3e42f047 b91b546f"- , aes128k1 @?= hxs "fbeed618 35713366 7c85e08f 7236a8de"- , aes128k2 @?= hxs "f7ddac30 6ae266cc f90bc11e e46d513b"-- , bsCMAC aes128key msg0- @?= hxs "bb1d6929 e9593728 7fa37d12 9b756746"- , bsCMAC aes128key msg128- @?= hxs "070a16b4 6b4d4144 f79bdd9d d04a287c"- , bsCMAC aes128key msg320- @?= hxs "dfa66747 de9ae630 30ca3261 1497c827"- , bsCMAC aes128key msg512- @?= hxs "51f0bebf 7e3b9d92 fc497417 79363cfe"- ]+ igroup+ "aes128"+ [ ecb0 aes128key @?= hxs "7df76b0c 1ab899b3 3e42f047 b91b546f"+ , aes128k1 @?= hxs "fbeed618 35713366 7c85e08f 7236a8de"+ , aes128k2 @?= hxs "f7ddac30 6ae266cc f90bc11e e46d513b"+ , bsCMAC aes128key msg0+ @?= hxs "bb1d6929 e9593728 7fa37d12 9b756746"+ , bsCMAC aes128key msg128+ @?= hxs "070a16b4 6b4d4144 f79bdd9d d04a287c"+ , bsCMAC aes128key msg320+ @?= hxs "dfa66747 de9ae630 30ca3261 1497c827"+ , bsCMAC aes128key msg512+ @?= hxs "51f0bebf 7e3b9d92 fc497417 79363cfe"+ ] where aes128key :: AES128 aes128key =- unsafeCipher $ hxs- "2b7e1516 28aed2a6 abf71588 09cf4f3c"+ unsafeCipher $+ hxs+ "2b7e1516 28aed2a6 abf71588 09cf4f3c" aes128k1, aes128k2 :: ByteString (aes128k1, aes128k2) = CMAC.subKeys aes128key - gAES192 :: TestTree gAES192 =- igroup "aes192"- [ ecb0 aes192key @?= hxs "22452d8e 49a8a593 9f7321ce ea6d514b"- , aes192k1 @?= hxs "448a5b1c 93514b27 3ee6439d d4daa296"- , aes192k2 @?= hxs "8914b639 26a2964e 7dcc873b a9b5452c"-- , bsCMAC aes192key msg0- @?= hxs "d17ddf46 adaacde5 31cac483 de7a9367"- , bsCMAC aes192key msg128- @?= hxs "9e99a7bf 31e71090 0662f65e 617c5184"- , bsCMAC aes192key msg320- @?= hxs "8a1de5be 2eb31aad 089a82e6 ee908b0e"- , bsCMAC aes192key msg512- @?= hxs "a1d5df0e ed790f79 4d775896 59f39a11"- ]+ igroup+ "aes192"+ [ ecb0 aes192key @?= hxs "22452d8e 49a8a593 9f7321ce ea6d514b"+ , aes192k1 @?= hxs "448a5b1c 93514b27 3ee6439d d4daa296"+ , aes192k2 @?= hxs "8914b639 26a2964e 7dcc873b a9b5452c"+ , bsCMAC aes192key msg0+ @?= hxs "d17ddf46 adaacde5 31cac483 de7a9367"+ , bsCMAC aes192key msg128+ @?= hxs "9e99a7bf 31e71090 0662f65e 617c5184"+ , bsCMAC aes192key msg320+ @?= hxs "8a1de5be 2eb31aad 089a82e6 ee908b0e"+ , bsCMAC aes192key msg512+ @?= hxs "a1d5df0e ed790f79 4d775896 59f39a11"+ ] where aes192key :: AES192 aes192key = unsafeCipher . hxs $- "8e73b0f7 da0e6452 c810f32b 809079e5" ++- "62f8ead2 522c6b7b"+ "8e73b0f7 da0e6452 c810f32b 809079e5"+ ++ "62f8ead2 522c6b7b" aes192k1, aes192k2 :: ByteString (aes192k1, aes192k2) = CMAC.subKeys aes192key gAES256 :: TestTree gAES256 =- igroup "aes256"- [ ecb0 aes256key @?= hxs "e568f681 94cf76d6 174d4cc0 4310a854"- , aes256k1 @?= hxs "cad1ed03 299eedac 2e9a9980 8621502f"- , aes256k2 @?= hxs "95a3da06 533ddb58 5d353301 0c42a0d9"-- , bsCMAC aes256key msg0- @?= hxs "028962f6 1b7bf89e fc6b551f 4667d983"- , bsCMAC aes256key msg128- @?= hxs "28a7023f 452e8f82 bd4bf28d 8c37c35c"- , bsCMAC aes256key msg320- @?= hxs "aaf3d8f1 de5640c2 32f5b169 b9c911e6"- , bsCMAC aes256key msg512- @?= hxs "e1992190 549f6ed5 696a2c05 6c315410"- ]+ igroup+ "aes256"+ [ ecb0 aes256key @?= hxs "e568f681 94cf76d6 174d4cc0 4310a854"+ , aes256k1 @?= hxs "cad1ed03 299eedac 2e9a9980 8621502f"+ , aes256k2 @?= hxs "95a3da06 533ddb58 5d353301 0c42a0d9"+ , bsCMAC aes256key msg0+ @?= hxs "028962f6 1b7bf89e fc6b551f 4667d983"+ , bsCMAC aes256key msg128+ @?= hxs "28a7023f 452e8f82 bd4bf28d 8c37c35c"+ , bsCMAC aes256key msg320+ @?= hxs "aaf3d8f1 de5640c2 32f5b169 b9c911e6"+ , bsCMAC aes256key msg512+ @?= hxs "e1992190 549f6ed5 696a2c05 6c315410"+ ] where aes256key :: AES256 aes256key = unsafeCipher . hxs $- "603deb10 15ca71be 2b73aef0 857d7781" ++- "1f352c07 3b6108d7 2d9810a3 0914dff4"+ "603deb10 15ca71be 2b73aef0 857d7781"+ ++ "1f352c07 3b6108d7 2d9810a3 0914dff4" aes256k1, aes256k2 :: ByteString (aes256k1, aes256k2) = CMAC.subKeys aes256key gTDEA3 :: TestTree gTDEA3 =- igroup "Three Key TDEA"- [ ecb0 tdea3key @?= hxs "c8cc74e9 8a7329a2"- , tdea3k1 @?= hxs "9198e9d3 14e6535f"- , tdea3k2 @?= hxs "2331d3a6 29cca6a5"-- , bsCMAC tdea3key msg0- @?= hxs "b7a688e1 22ffaf95"- , bsCMAC tdea3key msg64- @?= hxs "8e8f2931 36283797"- , bsCMAC tdea3key msg160- @?= hxs "743ddbe0 ce2dc2ed"- , bsCMAC tdea3key msg256- @?= hxs "33e6b109 2400eae5"- ]+ igroup+ "Three Key TDEA"+ [ ecb0 tdea3key @?= hxs "c8cc74e9 8a7329a2"+ , tdea3k1 @?= hxs "9198e9d3 14e6535f"+ , tdea3k2 @?= hxs "2331d3a6 29cca6a5"+ , bsCMAC tdea3key msg0+ @?= hxs "b7a688e1 22ffaf95"+ , bsCMAC tdea3key msg64+ @?= hxs "8e8f2931 36283797"+ , bsCMAC tdea3key msg160+ @?= hxs "743ddbe0 ce2dc2ed"+ , bsCMAC tdea3key msg256+ @?= hxs "33e6b109 2400eae5"+ ] where tdea3key :: DES_EDE3 tdea3key = unsafeCipher . hxs $- "8aa83bf8 cbda1062" ++- "0bc1bf19 fbb6cd58" ++- "bc313d4a 371ca8b5"+ "8aa83bf8 cbda1062"+ ++ "0bc1bf19 fbb6cd58"+ ++ "bc313d4a 371ca8b5" tdea3k1, tdea3k2 :: ByteString (tdea3k1, tdea3k2) = CMAC.subKeys tdea3key gTDEA2 :: TestTree gTDEA2 =- igroup "Two Key TDEA"- [ ecb0 tdea2key @?= hxs "c7679b9f 6b8d7d7a"- , tdea2k1 @?= hxs "8ecf373e d71afaef"- , tdea2k2 @?= hxs "1d9e6e7d ae35f5c5"-- , bsCMAC tdea2key msg0- @?= hxs "bd2ebf9a 3ba00361"- , bsCMAC tdea2key msg64- @?= hxs "4ff2ab81 3c53ce83"- , bsCMAC tdea2key msg160- @?= hxs "62dd1b47 1902bd4e"- , bsCMAC tdea2key msg256- @?= hxs "31b1e431 dabc4eb8"- ]+ igroup+ "Two Key TDEA"+ [ ecb0 tdea2key @?= hxs "c7679b9f 6b8d7d7a"+ , tdea2k1 @?= hxs "8ecf373e d71afaef"+ , tdea2k2 @?= hxs "1d9e6e7d ae35f5c5"+ , bsCMAC tdea2key msg0+ @?= hxs "bd2ebf9a 3ba00361"+ , bsCMAC tdea2key msg64+ @?= hxs "4ff2ab81 3c53ce83"+ , bsCMAC tdea2key msg160+ @?= hxs "62dd1b47 1902bd4e"+ , bsCMAC tdea2key msg256+ @?= hxs "31b1e431 dabc4eb8"+ ] where tdea2key :: DES_EDE2 tdea2key =- unsafeCipher . hxs $- "4cf15134 a2850dd5" ++- "8a3d10ba 80570d38"+ unsafeCipher . hxs $+ "4cf15134 a2850dd5"+ ++ "8a3d10ba 80570d38" tdea2k1, tdea2k2 :: ByteString (tdea2k1, tdea2k2) = CMAC.subKeys tdea2key igroup :: TestName -> [Assertion] -> TestTree-igroup nm = testGroup nm . zipWith (flip ($)) [1..] . map icase+igroup nm = testGroup nm . zipWith (flip ($)) [1 ..] . map icase where icase c i = testCase (show (i :: Int)) c nistVectors :: TestTree nistVectors =- testGroup "KAT - NIST test vectors"- [ gAES128, gAES192, gAES256, gTDEA3, gTDEA2 ]+ testGroup+ "KAT - NIST test vectors"+ [gAES128, gAES192, gAES256, gTDEA3, gTDEA2] tests :: TestTree tests =- testGroup "CMAC"- [ nistVectors ]+ testGroup+ "CMAC"+ [nistVectors]
tests/KAT_Camellia.hs view
@@ -2,33 +2,246 @@ {-# LANGUAGE ViewPatterns #-} {-# OPTIONS_GHC -fno-warn-unused-binds #-} {-# OPTIONS_GHC -fno-warn-unused-matches #-}+ module KAT_Camellia (tests) where -import Imports () import BlockCipher+import Imports () -import qualified Data.ByteString as B import Crypto.Cipher.Camellia+import qualified Data.ByteString as B vectors_camellia128 =- [ KAT_ECB (B.replicate 16 0) (B.replicate 16 0) (B.pack [0x3d,0x02,0x80,0x25,0xb1,0x56,0x32,0x7c,0x17,0xf7,0x62,0xc1,0xf2,0xcb,0xca,0x71])- , KAT_ECB (B.pack [0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10])- (B.pack [0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10])- (B.pack [0x67,0x67,0x31,0x38,0x54,0x96,0x69,0x73,0x08,0x57,0x06,0x56,0x48,0xea,0xbe,0x43])+ [ KAT_ECB+ (B.replicate 16 0)+ (B.replicate 16 0)+ ( B.pack+ [ 0x3d+ , 0x02+ , 0x80+ , 0x25+ , 0xb1+ , 0x56+ , 0x32+ , 0x7c+ , 0x17+ , 0xf7+ , 0x62+ , 0xc1+ , 0xf2+ , 0xcb+ , 0xca+ , 0x71+ ]+ )+ , KAT_ECB+ ( B.pack+ [ 0x01+ , 0x23+ , 0x45+ , 0x67+ , 0x89+ , 0xab+ , 0xcd+ , 0xef+ , 0xfe+ , 0xdc+ , 0xba+ , 0x98+ , 0x76+ , 0x54+ , 0x32+ , 0x10+ ]+ )+ ( B.pack+ [ 0x01+ , 0x23+ , 0x45+ , 0x67+ , 0x89+ , 0xab+ , 0xcd+ , 0xef+ , 0xfe+ , 0xdc+ , 0xba+ , 0x98+ , 0x76+ , 0x54+ , 0x32+ , 0x10+ ]+ )+ ( B.pack+ [ 0x67+ , 0x67+ , 0x31+ , 0x38+ , 0x54+ , 0x96+ , 0x69+ , 0x73+ , 0x08+ , 0x57+ , 0x06+ , 0x56+ , 0x48+ , 0xea+ , 0xbe+ , 0x43+ ]+ ) ] vectors_camellia192 =- [ KAT_ECB (B.pack [0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77]) (B.pack [0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10]) (B.pack [0xb4,0x99,0x34,0x01,0xb3,0xe9,0x96,0xf8,0x4e,0xe5,0xce,0xe7,0xd7,0x9b,0x09,0xb9])+ [ KAT_ECB+ ( B.pack+ [ 0x01+ , 0x23+ , 0x45+ , 0x67+ , 0x89+ , 0xab+ , 0xcd+ , 0xef+ , 0xfe+ , 0xdc+ , 0xba+ , 0x98+ , 0x76+ , 0x54+ , 0x32+ , 0x10+ , 0x00+ , 0x11+ , 0x22+ , 0x33+ , 0x44+ , 0x55+ , 0x66+ , 0x77+ ]+ )+ ( B.pack+ [ 0x01+ , 0x23+ , 0x45+ , 0x67+ , 0x89+ , 0xab+ , 0xcd+ , 0xef+ , 0xfe+ , 0xdc+ , 0xba+ , 0x98+ , 0x76+ , 0x54+ , 0x32+ , 0x10+ ]+ )+ ( B.pack+ [ 0xb4+ , 0x99+ , 0x34+ , 0x01+ , 0xb3+ , 0xe9+ , 0x96+ , 0xf8+ , 0x4e+ , 0xe5+ , 0xce+ , 0xe7+ , 0xd7+ , 0x9b+ , 0x09+ , 0xb9+ ]+ ) ] vectors_camellia256 =- [ KAT_ECB (B.pack [0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10 ,0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff])- (B.pack [0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10])- (B.pack [0x9a,0xcc,0x23,0x7d,0xff,0x16,0xd7,0x6c,0x20,0xef,0x7c,0x91,0x9e,0x3a,0x75,0x09])+ [ KAT_ECB+ ( B.pack+ [ 0x01+ , 0x23+ , 0x45+ , 0x67+ , 0x89+ , 0xab+ , 0xcd+ , 0xef+ , 0xfe+ , 0xdc+ , 0xba+ , 0x98+ , 0x76+ , 0x54+ , 0x32+ , 0x10+ , 0x00+ , 0x11+ , 0x22+ , 0x33+ , 0x44+ , 0x55+ , 0x66+ , 0x77+ , 0x88+ , 0x99+ , 0xaa+ , 0xbb+ , 0xcc+ , 0xdd+ , 0xee+ , 0xff+ ]+ )+ ( B.pack+ [ 0x01+ , 0x23+ , 0x45+ , 0x67+ , 0x89+ , 0xab+ , 0xcd+ , 0xef+ , 0xfe+ , 0xdc+ , 0xba+ , 0x98+ , 0x76+ , 0x54+ , 0x32+ , 0x10+ ]+ )+ ( B.pack+ [ 0x9a+ , 0xcc+ , 0x23+ , 0x7d+ , 0xff+ , 0x16+ , 0xd7+ , 0x6c+ , 0x20+ , 0xef+ , 0x7c+ , 0x91+ , 0x9e+ , 0x3a+ , 0x75+ , 0x09+ ]+ ) ] -kats128 = defaultKATs { kat_ECB = vectors_camellia128 }-kats192 = defaultKATs { kat_ECB = vectors_camellia192 }-kats256 = defaultKATs { kat_ECB = vectors_camellia256 }+kats128 = defaultKATs{kat_ECB = vectors_camellia128}+kats192 = defaultKATs{kat_ECB = vectors_camellia192}+kats256 = defaultKATs{kat_ECB = vectors_camellia256} tests = testBlockCipher kats128 (undefined :: Camellia128)
tests/KAT_Curve25519.hs view
@@ -1,25 +1,50 @@ {-# LANGUAGE OverloadedStrings #-}-module KAT_Curve25519 ( tests ) where -import Crypto.Error+module KAT_Curve25519 (tests) where++import Crypto.Error import qualified Crypto.PubKey.Curve25519 as Curve25519-import Data.ByteArray as B-import Imports+import Data.ByteArray as B+import Imports -alicePrivate = throwCryptoError $ Curve25519.secretKey ("\x77\x07\x6d\x0a\x73\x18\xa5\x7d\x3c\x16\xc1\x72\x51\xb2\x66\x45\xdf\x4c\x2f\x87\xeb\xc0\x99\x2a\xb1\x77\xfb\xa5\x1d\xb9\x2c\x2a" :: ByteString)-alicePublic = throwCryptoError $ Curve25519.publicKey ("\x85\x20\xf0\x09\x89\x30\xa7\x54\x74\x8b\x7d\xdc\xb4\x3e\xf7\x5a\x0d\xbf\x3a\x0d\x26\x38\x1a\xf4\xeb\xa4\xa9\x8e\xaa\x9b\x4e\x6a" :: ByteString)-bobPrivate = throwCryptoError $ Curve25519.secretKey ("\x5d\xab\x08\x7e\x62\x4a\x8a\x4b\x79\xe1\x7f\x8b\x83\x80\x0e\xe6\x6f\x3b\xb1\x29\x26\x18\xb6\xfd\x1c\x2f\x8b\x27\xff\x88\xe0\xeb" :: ByteString)-bobPublic = throwCryptoError $ Curve25519.publicKey ("\xde\x9e\xdb\x7d\x7b\x7d\xc1\xb4\xd3\x5b\x61\xc2\xec\xe4\x35\x37\x3f\x83\x43\xc8\x5b\x78\x67\x4d\xad\xfc\x7e\x14\x6f\x88\x2b\x4f" :: ByteString)-aliceMultBob = "\x4a\x5d\x9d\x5b\xa4\xce\x2d\xe1\x72\x8e\x3b\xf4\x80\x35\x0f\x25\xe0\x7e\x21\xc9\x47\xd1\x9e\x33\x76\xf0\x9b\x3c\x1e\x16\x17\x42" :: ByteString+alicePrivate =+ throwCryptoError $+ Curve25519.secretKey+ ( "\x77\x07\x6d\x0a\x73\x18\xa5\x7d\x3c\x16\xc1\x72\x51\xb2\x66\x45\xdf\x4c\x2f\x87\xeb\xc0\x99\x2a\xb1\x77\xfb\xa5\x1d\xb9\x2c\x2a"+ :: ByteString+ )+alicePublic =+ throwCryptoError $+ Curve25519.publicKey+ ( "\x85\x20\xf0\x09\x89\x30\xa7\x54\x74\x8b\x7d\xdc\xb4\x3e\xf7\x5a\x0d\xbf\x3a\x0d\x26\x38\x1a\xf4\xeb\xa4\xa9\x8e\xaa\x9b\x4e\x6a"+ :: ByteString+ )+bobPrivate =+ throwCryptoError $+ Curve25519.secretKey+ ( "\x5d\xab\x08\x7e\x62\x4a\x8a\x4b\x79\xe1\x7f\x8b\x83\x80\x0e\xe6\x6f\x3b\xb1\x29\x26\x18\xb6\xfd\x1c\x2f\x8b\x27\xff\x88\xe0\xeb"+ :: ByteString+ )+bobPublic =+ throwCryptoError $+ Curve25519.publicKey+ ( "\xde\x9e\xdb\x7d\x7b\x7d\xc1\xb4\xd3\x5b\x61\xc2\xec\xe4\x35\x37\x3f\x83\x43\xc8\x5b\x78\x67\x4d\xad\xfc\x7e\x14\x6f\x88\x2b\x4f"+ :: ByteString+ )+aliceMultBob =+ "\x4a\x5d\x9d\x5b\xa4\xce\x2d\xe1\x72\x8e\x3b\xf4\x80\x35\x0f\x25\xe0\x7e\x21\xc9\x47\xd1\x9e\x33\x76\xf0\x9b\x3c\x1e\x16\x17\x42"+ :: ByteString katTests :: [TestTree] katTests = [ testCase "0" (aliceMultBob @=? B.convert (Curve25519.dh alicePublic bobPrivate)) , testCase "1" (aliceMultBob @=? B.convert (Curve25519.dh bobPublic alicePrivate))- , testCase "2" (alicePublic @=? Curve25519.toPublic alicePrivate)- , testCase "3" (bobPublic @=? Curve25519.toPublic bobPrivate)+ , testCase "2" (alicePublic @=? Curve25519.toPublic alicePrivate)+ , testCase "3" (bobPublic @=? Curve25519.toPublic bobPrivate) ] -tests = testGroup "Curve25519"- [ testGroup "KATs" katTests- ]+tests =+ testGroup+ "Curve25519"+ [ testGroup "KATs" katTests+ ]
tests/KAT_Curve448.hs view
@@ -1,25 +1,50 @@ {-# LANGUAGE OverloadedStrings #-}-module KAT_Curve448 ( tests ) where -import Crypto.Error+module KAT_Curve448 (tests) where++import Crypto.Error import qualified Crypto.PubKey.Curve448 as Curve448-import Data.ByteArray as B-import Imports+import Data.ByteArray as B+import Imports -alicePrivate = throwCryptoError $ Curve448.secretKey ("\x9a\x8f\x49\x25\xd1\x51\x9f\x57\x75\xcf\x46\xb0\x4b\x58\x00\xd4\xee\x9e\xe8\xba\xe8\xbc\x55\x65\xd4\x98\xc2\x8d\xd9\xc9\xba\xf5\x74\xa9\x41\x97\x44\x89\x73\x91\x00\x63\x82\xa6\xf1\x27\xab\x1d\x9a\xc2\xd8\xc0\xa5\x98\x72\x6b" :: ByteString)-alicePublic = throwCryptoError $ Curve448.publicKey ("\x9b\x08\xf7\xcc\x31\xb7\xe3\xe6\x7d\x22\xd5\xae\xa1\x21\x07\x4a\x27\x3b\xd2\xb8\x3d\xe0\x9c\x63\xfa\xa7\x3d\x2c\x22\xc5\xd9\xbb\xc8\x36\x64\x72\x41\xd9\x53\xd4\x0c\x5b\x12\xda\x88\x12\x0d\x53\x17\x7f\x80\xe5\x32\xc4\x1f\xa0" :: ByteString)-bobPrivate = throwCryptoError $ Curve448.secretKey ("\x1c\x30\x6a\x7a\xc2\xa0\xe2\xe0\x99\x0b\x29\x44\x70\xcb\xa3\x39\xe6\x45\x37\x72\xb0\x75\x81\x1d\x8f\xad\x0d\x1d\x69\x27\xc1\x20\xbb\x5e\xe8\x97\x2b\x0d\x3e\x21\x37\x4c\x9c\x92\x1b\x09\xd1\xb0\x36\x6f\x10\xb6\x51\x73\x99\x2d" :: ByteString)-bobPublic = throwCryptoError $ Curve448.publicKey ("\x3e\xb7\xa8\x29\xb0\xcd\x20\xf5\xbc\xfc\x0b\x59\x9b\x6f\xec\xcf\x6d\xa4\x62\x71\x07\xbd\xb0\xd4\xf3\x45\xb4\x30\x27\xd8\xb9\x72\xfc\x3e\x34\xfb\x42\x32\xa1\x3c\xa7\x06\xdc\xb5\x7a\xec\x3d\xae\x07\xbd\xc1\xc6\x7b\xf3\x36\x09" :: ByteString)-aliceMultBob = "\x07\xff\xf4\x18\x1a\xc6\xcc\x95\xec\x1c\x16\xa9\x4a\x0f\x74\xd1\x2d\xa2\x32\xce\x40\xa7\x75\x52\x28\x1d\x28\x2b\xb6\x0c\x0b\x56\xfd\x24\x64\xc3\x35\x54\x39\x36\x52\x1c\x24\x40\x30\x85\xd5\x9a\x44\x9a\x50\x37\x51\x4a\x87\x9d" :: ByteString+alicePrivate =+ throwCryptoError $+ Curve448.secretKey+ ( "\x9a\x8f\x49\x25\xd1\x51\x9f\x57\x75\xcf\x46\xb0\x4b\x58\x00\xd4\xee\x9e\xe8\xba\xe8\xbc\x55\x65\xd4\x98\xc2\x8d\xd9\xc9\xba\xf5\x74\xa9\x41\x97\x44\x89\x73\x91\x00\x63\x82\xa6\xf1\x27\xab\x1d\x9a\xc2\xd8\xc0\xa5\x98\x72\x6b"+ :: ByteString+ )+alicePublic =+ throwCryptoError $+ Curve448.publicKey+ ( "\x9b\x08\xf7\xcc\x31\xb7\xe3\xe6\x7d\x22\xd5\xae\xa1\x21\x07\x4a\x27\x3b\xd2\xb8\x3d\xe0\x9c\x63\xfa\xa7\x3d\x2c\x22\xc5\xd9\xbb\xc8\x36\x64\x72\x41\xd9\x53\xd4\x0c\x5b\x12\xda\x88\x12\x0d\x53\x17\x7f\x80\xe5\x32\xc4\x1f\xa0"+ :: ByteString+ )+bobPrivate =+ throwCryptoError $+ Curve448.secretKey+ ( "\x1c\x30\x6a\x7a\xc2\xa0\xe2\xe0\x99\x0b\x29\x44\x70\xcb\xa3\x39\xe6\x45\x37\x72\xb0\x75\x81\x1d\x8f\xad\x0d\x1d\x69\x27\xc1\x20\xbb\x5e\xe8\x97\x2b\x0d\x3e\x21\x37\x4c\x9c\x92\x1b\x09\xd1\xb0\x36\x6f\x10\xb6\x51\x73\x99\x2d"+ :: ByteString+ )+bobPublic =+ throwCryptoError $+ Curve448.publicKey+ ( "\x3e\xb7\xa8\x29\xb0\xcd\x20\xf5\xbc\xfc\x0b\x59\x9b\x6f\xec\xcf\x6d\xa4\x62\x71\x07\xbd\xb0\xd4\xf3\x45\xb4\x30\x27\xd8\xb9\x72\xfc\x3e\x34\xfb\x42\x32\xa1\x3c\xa7\x06\xdc\xb5\x7a\xec\x3d\xae\x07\xbd\xc1\xc6\x7b\xf3\x36\x09"+ :: ByteString+ )+aliceMultBob =+ "\x07\xff\xf4\x18\x1a\xc6\xcc\x95\xec\x1c\x16\xa9\x4a\x0f\x74\xd1\x2d\xa2\x32\xce\x40\xa7\x75\x52\x28\x1d\x28\x2b\xb6\x0c\x0b\x56\xfd\x24\x64\xc3\x35\x54\x39\x36\x52\x1c\x24\x40\x30\x85\xd5\x9a\x44\x9a\x50\x37\x51\x4a\x87\x9d"+ :: ByteString katTests :: [TestTree] katTests = [ testCase "0" (aliceMultBob @=? B.convert (Curve448.dh alicePublic bobPrivate)) , testCase "1" (aliceMultBob @=? B.convert (Curve448.dh bobPublic alicePrivate))- , testCase "2" (alicePublic @=? Curve448.toPublic alicePrivate)- , testCase "3" (bobPublic @=? Curve448.toPublic bobPrivate)+ , testCase "2" (alicePublic @=? Curve448.toPublic alicePrivate)+ , testCase "3" (bobPublic @=? Curve448.toPublic bobPrivate) ] -tests = testGroup "Curve448"- [ testGroup "KATs" katTests- ]+tests =+ testGroup+ "Curve448"+ [ testGroup "KATs" katTests+ ]
tests/KAT_DES.hs view
@@ -1,49 +1,154 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ViewPatterns #-}+ module KAT_DES (tests) where -import Imports import BlockCipher import qualified Crypto.Cipher.DES as DES+import Imports -vectors_ecb = -- key plaintext ciphertext- [ KAT_ECB "\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00" "\x8C\xA6\x4D\xE9\xC1\xB1\x23\xA7"- , KAT_ECB "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\x73\x59\xB2\x16\x3E\x4E\xDC\x58"- , KAT_ECB "\x30\x00\x00\x00\x00\x00\x00\x00" "\x10\x00\x00\x00\x00\x00\x00\x01" "\x95\x8E\x6E\x62\x7A\x05\x55\x7B"- , KAT_ECB "\x11\x11\x11\x11\x11\x11\x11\x11" "\x11\x11\x11\x11\x11\x11\x11\x11" "\xF4\x03\x79\xAB\x9E\x0E\xC5\x33"- , KAT_ECB "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\x11\x11\x11\x11\x11\x11\x11\x11" "\x17\x66\x8D\xFC\x72\x92\x53\x2D"- , KAT_ECB "\x11\x11\x11\x11\x11\x11\x11\x11" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\x8A\x5A\xE1\xF8\x1A\xB8\xF2\xDD"- , KAT_ECB "\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00" "\x8C\xA6\x4D\xE9\xC1\xB1\x23\xA7"- , KAT_ECB "\xFE\xDC\xBA\x98\x76\x54\x32\x10" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\xED\x39\xD9\x50\xFA\x74\xBC\xC4"- , KAT_ECB "\x7C\xA1\x10\x45\x4A\x1A\x6E\x57" "\x01\xA1\xD6\xD0\x39\x77\x67\x42" "\x69\x0F\x5B\x0D\x9A\x26\x93\x9B"- , KAT_ECB "\x01\x31\xD9\x61\x9D\xC1\x37\x6E" "\x5C\xD5\x4C\xA8\x3D\xEF\x57\xDA" "\x7A\x38\x9D\x10\x35\x4B\xD2\x71"- , KAT_ECB "\x07\xA1\x13\x3E\x4A\x0B\x26\x86" "\x02\x48\xD4\x38\x06\xF6\x71\x72" "\x86\x8E\xBB\x51\xCA\xB4\x59\x9A"- , KAT_ECB "\x38\x49\x67\x4C\x26\x02\x31\x9E" "\x51\x45\x4B\x58\x2D\xDF\x44\x0A" "\x71\x78\x87\x6E\x01\xF1\x9B\x2A"- , KAT_ECB "\x04\xB9\x15\xBA\x43\xFE\xB5\xB6" "\x42\xFD\x44\x30\x59\x57\x7F\xA2" "\xAF\x37\xFB\x42\x1F\x8C\x40\x95"- , KAT_ECB "\x01\x13\xB9\x70\xFD\x34\xF2\xCE" "\x05\x9B\x5E\x08\x51\xCF\x14\x3A" "\x86\xA5\x60\xF1\x0E\xC6\xD8\x5B"- , KAT_ECB "\x01\x70\xF1\x75\x46\x8F\xB5\xE6" "\x07\x56\xD8\xE0\x77\x47\x61\xD2" "\x0C\xD3\xDA\x02\x00\x21\xDC\x09"- , KAT_ECB "\x43\x29\x7F\xAD\x38\xE3\x73\xFE" "\x76\x25\x14\xB8\x29\xBF\x48\x6A" "\xEA\x67\x6B\x2C\xB7\xDB\x2B\x7A"- , KAT_ECB "\x07\xA7\x13\x70\x45\xDA\x2A\x16" "\x3B\xDD\x11\x90\x49\x37\x28\x02" "\xDF\xD6\x4A\x81\x5C\xAF\x1A\x0F"- , KAT_ECB "\x04\x68\x91\x04\xC2\xFD\x3B\x2F" "\x26\x95\x5F\x68\x35\xAF\x60\x9A" "\x5C\x51\x3C\x9C\x48\x86\xC0\x88"- , KAT_ECB "\x37\xD0\x6B\xB5\x16\xCB\x75\x46" "\x16\x4D\x5E\x40\x4F\x27\x52\x32" "\x0A\x2A\xEE\xAE\x3F\xF4\xAB\x77"- , KAT_ECB "\x1F\x08\x26\x0D\x1A\xC2\x46\x5E" "\x6B\x05\x6E\x18\x75\x9F\x5C\xCA" "\xEF\x1B\xF0\x3E\x5D\xFA\x57\x5A"- , KAT_ECB "\x58\x40\x23\x64\x1A\xBA\x61\x76" "\x00\x4B\xD6\xEF\x09\x17\x60\x62" "\x88\xBF\x0D\xB6\xD7\x0D\xEE\x56"- , KAT_ECB "\x02\x58\x16\x16\x46\x29\xB0\x07" "\x48\x0D\x39\x00\x6E\xE7\x62\xF2" "\xA1\xF9\x91\x55\x41\x02\x0B\x56"- , KAT_ECB "\x49\x79\x3E\xBC\x79\xB3\x25\x8F" "\x43\x75\x40\xC8\x69\x8F\x3C\xFA" "\x6F\xBF\x1C\xAF\xCF\xFD\x05\x56"- , KAT_ECB "\x4F\xB0\x5E\x15\x15\xAB\x73\xA7" "\x07\x2D\x43\xA0\x77\x07\x52\x92" "\x2F\x22\xE4\x9B\xAB\x7C\xA1\xAC"- , KAT_ECB "\x49\xE9\x5D\x6D\x4C\xA2\x29\xBF" "\x02\xFE\x55\x77\x81\x17\xF1\x2A" "\x5A\x6B\x61\x2C\xC2\x6C\xCE\x4A"- , KAT_ECB "\x01\x83\x10\xDC\x40\x9B\x26\xD6" "\x1D\x9D\x5C\x50\x18\xF7\x28\xC2" "\x5F\x4C\x03\x8E\xD1\x2B\x2E\x41"- , KAT_ECB "\x1C\x58\x7F\x1C\x13\x92\x4F\xEF" "\x30\x55\x32\x28\x6D\x6F\x29\x5A" "\x63\xFA\xC0\xD0\x34\xD9\xF7\x93"- , KAT_ECB "\x01\x01\x01\x01\x01\x01\x01\x01" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\x61\x7B\x3A\x0C\xE8\xF0\x71\x00"- , KAT_ECB "\x1F\x1F\x1F\x1F\x0E\x0E\x0E\x0E" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\xDB\x95\x86\x05\xF8\xC8\xC6\x06"- , KAT_ECB "\xE0\xFE\xE0\xFE\xF1\xFE\xF1\xFE" "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\xED\xBF\xD1\xC6\x6C\x29\xCC\xC7"- , KAT_ECB "\x00\x00\x00\x00\x00\x00\x00\x00" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\x35\x55\x50\xB2\x15\x0E\x24\x51"- , KAT_ECB "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\x00\x00\x00\x00\x00\x00\x00\x00" "\xCA\xAA\xAF\x4D\xEA\xF1\xDB\xAE"- , KAT_ECB "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\x00\x00\x00\x00\x00\x00\x00\x00" "\xD5\xD4\x4F\xF7\x20\x68\x3D\x0D"- , KAT_ECB "\xFE\xDC\xBA\x98\x76\x54\x32\x10" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\x2A\x2B\xB0\x08\xDF\x97\xC2\xF2"+vectors_ecb =+ -- key plaintext ciphertext+ [ KAT_ECB+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\x8C\xA6\x4D\xE9\xC1\xB1\x23\xA7"+ , KAT_ECB+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"+ "\x73\x59\xB2\x16\x3E\x4E\xDC\x58"+ , KAT_ECB+ "\x30\x00\x00\x00\x00\x00\x00\x00"+ "\x10\x00\x00\x00\x00\x00\x00\x01"+ "\x95\x8E\x6E\x62\x7A\x05\x55\x7B"+ , KAT_ECB+ "\x11\x11\x11\x11\x11\x11\x11\x11"+ "\x11\x11\x11\x11\x11\x11\x11\x11"+ "\xF4\x03\x79\xAB\x9E\x0E\xC5\x33"+ , KAT_ECB+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\x11\x11\x11\x11\x11\x11\x11\x11"+ "\x17\x66\x8D\xFC\x72\x92\x53\x2D"+ , KAT_ECB+ "\x11\x11\x11\x11\x11\x11\x11\x11"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\x8A\x5A\xE1\xF8\x1A\xB8\xF2\xDD"+ , KAT_ECB+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\x8C\xA6\x4D\xE9\xC1\xB1\x23\xA7"+ , KAT_ECB+ "\xFE\xDC\xBA\x98\x76\x54\x32\x10"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\xED\x39\xD9\x50\xFA\x74\xBC\xC4"+ , KAT_ECB+ "\x7C\xA1\x10\x45\x4A\x1A\x6E\x57"+ "\x01\xA1\xD6\xD0\x39\x77\x67\x42"+ "\x69\x0F\x5B\x0D\x9A\x26\x93\x9B"+ , KAT_ECB+ "\x01\x31\xD9\x61\x9D\xC1\x37\x6E"+ "\x5C\xD5\x4C\xA8\x3D\xEF\x57\xDA"+ "\x7A\x38\x9D\x10\x35\x4B\xD2\x71"+ , KAT_ECB+ "\x07\xA1\x13\x3E\x4A\x0B\x26\x86"+ "\x02\x48\xD4\x38\x06\xF6\x71\x72"+ "\x86\x8E\xBB\x51\xCA\xB4\x59\x9A"+ , KAT_ECB+ "\x38\x49\x67\x4C\x26\x02\x31\x9E"+ "\x51\x45\x4B\x58\x2D\xDF\x44\x0A"+ "\x71\x78\x87\x6E\x01\xF1\x9B\x2A"+ , KAT_ECB+ "\x04\xB9\x15\xBA\x43\xFE\xB5\xB6"+ "\x42\xFD\x44\x30\x59\x57\x7F\xA2"+ "\xAF\x37\xFB\x42\x1F\x8C\x40\x95"+ , KAT_ECB+ "\x01\x13\xB9\x70\xFD\x34\xF2\xCE"+ "\x05\x9B\x5E\x08\x51\xCF\x14\x3A"+ "\x86\xA5\x60\xF1\x0E\xC6\xD8\x5B"+ , KAT_ECB+ "\x01\x70\xF1\x75\x46\x8F\xB5\xE6"+ "\x07\x56\xD8\xE0\x77\x47\x61\xD2"+ "\x0C\xD3\xDA\x02\x00\x21\xDC\x09"+ , KAT_ECB+ "\x43\x29\x7F\xAD\x38\xE3\x73\xFE"+ "\x76\x25\x14\xB8\x29\xBF\x48\x6A"+ "\xEA\x67\x6B\x2C\xB7\xDB\x2B\x7A"+ , KAT_ECB+ "\x07\xA7\x13\x70\x45\xDA\x2A\x16"+ "\x3B\xDD\x11\x90\x49\x37\x28\x02"+ "\xDF\xD6\x4A\x81\x5C\xAF\x1A\x0F"+ , KAT_ECB+ "\x04\x68\x91\x04\xC2\xFD\x3B\x2F"+ "\x26\x95\x5F\x68\x35\xAF\x60\x9A"+ "\x5C\x51\x3C\x9C\x48\x86\xC0\x88"+ , KAT_ECB+ "\x37\xD0\x6B\xB5\x16\xCB\x75\x46"+ "\x16\x4D\x5E\x40\x4F\x27\x52\x32"+ "\x0A\x2A\xEE\xAE\x3F\xF4\xAB\x77"+ , KAT_ECB+ "\x1F\x08\x26\x0D\x1A\xC2\x46\x5E"+ "\x6B\x05\x6E\x18\x75\x9F\x5C\xCA"+ "\xEF\x1B\xF0\x3E\x5D\xFA\x57\x5A"+ , KAT_ECB+ "\x58\x40\x23\x64\x1A\xBA\x61\x76"+ "\x00\x4B\xD6\xEF\x09\x17\x60\x62"+ "\x88\xBF\x0D\xB6\xD7\x0D\xEE\x56"+ , KAT_ECB+ "\x02\x58\x16\x16\x46\x29\xB0\x07"+ "\x48\x0D\x39\x00\x6E\xE7\x62\xF2"+ "\xA1\xF9\x91\x55\x41\x02\x0B\x56"+ , KAT_ECB+ "\x49\x79\x3E\xBC\x79\xB3\x25\x8F"+ "\x43\x75\x40\xC8\x69\x8F\x3C\xFA"+ "\x6F\xBF\x1C\xAF\xCF\xFD\x05\x56"+ , KAT_ECB+ "\x4F\xB0\x5E\x15\x15\xAB\x73\xA7"+ "\x07\x2D\x43\xA0\x77\x07\x52\x92"+ "\x2F\x22\xE4\x9B\xAB\x7C\xA1\xAC"+ , KAT_ECB+ "\x49\xE9\x5D\x6D\x4C\xA2\x29\xBF"+ "\x02\xFE\x55\x77\x81\x17\xF1\x2A"+ "\x5A\x6B\x61\x2C\xC2\x6C\xCE\x4A"+ , KAT_ECB+ "\x01\x83\x10\xDC\x40\x9B\x26\xD6"+ "\x1D\x9D\x5C\x50\x18\xF7\x28\xC2"+ "\x5F\x4C\x03\x8E\xD1\x2B\x2E\x41"+ , KAT_ECB+ "\x1C\x58\x7F\x1C\x13\x92\x4F\xEF"+ "\x30\x55\x32\x28\x6D\x6F\x29\x5A"+ "\x63\xFA\xC0\xD0\x34\xD9\xF7\x93"+ , KAT_ECB+ "\x01\x01\x01\x01\x01\x01\x01\x01"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\x61\x7B\x3A\x0C\xE8\xF0\x71\x00"+ , KAT_ECB+ "\x1F\x1F\x1F\x1F\x0E\x0E\x0E\x0E"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\xDB\x95\x86\x05\xF8\xC8\xC6\x06"+ , KAT_ECB+ "\xE0\xFE\xE0\xFE\xF1\xFE\xF1\xFE"+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\xED\xBF\xD1\xC6\x6C\x29\xCC\xC7"+ , KAT_ECB+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"+ "\x35\x55\x50\xB2\x15\x0E\x24\x51"+ , KAT_ECB+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\xCA\xAA\xAF\x4D\xEA\xF1\xDB\xAE"+ , KAT_ECB+ "\x01\x23\x45\x67\x89\xAB\xCD\xEF"+ "\x00\x00\x00\x00\x00\x00\x00\x00"+ "\xD5\xD4\x4F\xF7\x20\x68\x3D\x0D"+ , KAT_ECB+ "\xFE\xDC\xBA\x98\x76\x54\x32\x10"+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"+ "\x2A\x2B\xB0\x08\xDF\x97\xC2\xF2" ] -kats = defaultKATs { kat_ECB = vectors_ecb }+kats = defaultKATs{kat_ECB = vectors_ecb} -tests = localOption (QuickCheckTests 5)- $ testBlockCipher kats (undefined :: DES.DES)+tests =+ localOption (QuickCheckTests 5) $+ testBlockCipher kats (undefined :: DES.DES)
tests/KAT_Ed25519.hs view
@@ -1,72 +1,91 @@-{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE BangPatterns #-} {-# LANGUAGE OverloadedStrings #-}-module KAT_Ed25519 ( tests ) where -import Crypto.Error+module KAT_Ed25519 (tests) where++import Crypto.Error import qualified Crypto.PubKey.Ed25519 as Ed25519-import Imports+import Imports data Vec = Vec { vecSec :: ByteString , vecPub :: ByteString , vecMsg :: ByteString , vecSig :: ByteString- } deriving (Show,Eq)+ }+ deriving (Show, Eq) vectors = [ Vec- { vecSec = "\x9d\x61\xb1\x9d\xef\xfd\x5a\x60\xba\x84\x4a\xf4\x92\xec\x2c\xc4\x44\x49\xc5\x69\x7b\x32\x69\x19\x70\x3b\xac\x03\x1c\xae\x7f\x60"- , vecPub = "\xd7\x5a\x98\x01\x82\xb1\x0a\xb7\xd5\x4b\xfe\xd3\xc9\x64\x07\x3a\x0e\xe1\x72\xf3\xda\xa6\x23\x25\xaf\x02\x1a\x68\xf7\x07\x51\x1a"+ { vecSec =+ "\x9d\x61\xb1\x9d\xef\xfd\x5a\x60\xba\x84\x4a\xf4\x92\xec\x2c\xc4\x44\x49\xc5\x69\x7b\x32\x69\x19\x70\x3b\xac\x03\x1c\xae\x7f\x60"+ , vecPub =+ "\xd7\x5a\x98\x01\x82\xb1\x0a\xb7\xd5\x4b\xfe\xd3\xc9\x64\x07\x3a\x0e\xe1\x72\xf3\xda\xa6\x23\x25\xaf\x02\x1a\x68\xf7\x07\x51\x1a" , vecMsg = ""- , vecSig = "\xe5\x56\x43\x00\xc3\x60\xac\x72\x90\x86\xe2\xcc\x80\x6e\x82\x8a\x84\x87\x7f\x1e\xb8\xe5\xd9\x74\xd8\x73\xe0\x65\x22\x49\x01\x55\x5f\xb8\x82\x15\x90\xa3\x3b\xac\xc6\x1e\x39\x70\x1c\xf9\xb4\x6b\xd2\x5b\xf5\xf0\x59\x5b\xbe\x24\x65\x51\x41\x43\x8e\x7a\x10\x0b"+ , vecSig =+ "\xe5\x56\x43\x00\xc3\x60\xac\x72\x90\x86\xe2\xcc\x80\x6e\x82\x8a\x84\x87\x7f\x1e\xb8\xe5\xd9\x74\xd8\x73\xe0\x65\x22\x49\x01\x55\x5f\xb8\x82\x15\x90\xa3\x3b\xac\xc6\x1e\x39\x70\x1c\xf9\xb4\x6b\xd2\x5b\xf5\xf0\x59\x5b\xbe\x24\x65\x51\x41\x43\x8e\x7a\x10\x0b" } , Vec- { vecSec = "\x4c\xcd\x08\x9b\x28\xff\x96\xda\x9d\xb6\xc3\x46\xec\x11\x4e\x0f\x5b\x8a\x31\x9f\x35\xab\xa6\x24\xda\x8c\xf6\xed\x4f\xb8\xa6\xfb"- , vecPub = "\x3d\x40\x17\xc3\xe8\x43\x89\x5a\x92\xb7\x0a\xa7\x4d\x1b\x7e\xbc\x9c\x98\x2c\xcf\x2e\xc4\x96\x8c\xc0\xcd\x55\xf1\x2a\xf4\x66\x0c"+ { vecSec =+ "\x4c\xcd\x08\x9b\x28\xff\x96\xda\x9d\xb6\xc3\x46\xec\x11\x4e\x0f\x5b\x8a\x31\x9f\x35\xab\xa6\x24\xda\x8c\xf6\xed\x4f\xb8\xa6\xfb"+ , vecPub =+ "\x3d\x40\x17\xc3\xe8\x43\x89\x5a\x92\xb7\x0a\xa7\x4d\x1b\x7e\xbc\x9c\x98\x2c\xcf\x2e\xc4\x96\x8c\xc0\xcd\x55\xf1\x2a\xf4\x66\x0c" , vecMsg = "\x72"- , vecSig = "\x92\xa0\x09\xa9\xf0\xd4\xca\xb8\x72\x0e\x82\x0b\x5f\x64\x25\x40\xa2\xb2\x7b\x54\x16\x50\x3f\x8f\xb3\x76\x22\x23\xeb\xdb\x69\xda\x08\x5a\xc1\xe4\x3e\x15\x99\x6e\x45\x8f\x36\x13\xd0\xf1\x1d\x8c\x38\x7b\x2e\xae\xb4\x30\x2a\xee\xb0\x0d\x29\x16\x12\xbb\x0c\x00"+ , vecSig =+ "\x92\xa0\x09\xa9\xf0\xd4\xca\xb8\x72\x0e\x82\x0b\x5f\x64\x25\x40\xa2\xb2\x7b\x54\x16\x50\x3f\x8f\xb3\x76\x22\x23\xeb\xdb\x69\xda\x08\x5a\xc1\xe4\x3e\x15\x99\x6e\x45\x8f\x36\x13\xd0\xf1\x1d\x8c\x38\x7b\x2e\xae\xb4\x30\x2a\xee\xb0\x0d\x29\x16\x12\xbb\x0c\x00" } , Vec- { vecSec = "\xc5\xaa\x8d\xf4\x3f\x9f\x83\x7b\xed\xb7\x44\x2f\x31\xdc\xb7\xb1\x66\xd3\x85\x35\x07\x6f\x09\x4b\x85\xce\x3a\x2e\x0b\x44\x58\xf7"- , vecPub = "\xfc\x51\xcd\x8e\x62\x18\xa1\xa3\x8d\xa4\x7e\xd0\x02\x30\xf0\x58\x08\x16\xed\x13\xba\x33\x03\xac\x5d\xeb\x91\x15\x48\x90\x80\x25"+ { vecSec =+ "\xc5\xaa\x8d\xf4\x3f\x9f\x83\x7b\xed\xb7\x44\x2f\x31\xdc\xb7\xb1\x66\xd3\x85\x35\x07\x6f\x09\x4b\x85\xce\x3a\x2e\x0b\x44\x58\xf7"+ , vecPub =+ "\xfc\x51\xcd\x8e\x62\x18\xa1\xa3\x8d\xa4\x7e\xd0\x02\x30\xf0\x58\x08\x16\xed\x13\xba\x33\x03\xac\x5d\xeb\x91\x15\x48\x90\x80\x25" , vecMsg = "\xaf\x82"- , vecSig = "\x62\x91\xd6\x57\xde\xec\x24\x02\x48\x27\xe6\x9c\x3a\xbe\x01\xa3\x0c\xe5\x48\xa2\x84\x74\x3a\x44\x5e\x36\x80\xd7\xdb\x5a\xc3\xac\x18\xff\x9b\x53\x8d\x16\xf2\x90\xae\x67\xf7\x60\x98\x4d\xc6\x59\x4a\x7c\x15\xe9\x71\x6e\xd2\x8d\xc0\x27\xbe\xce\xea\x1e\xc4\x0a"+ , vecSig =+ "\x62\x91\xd6\x57\xde\xec\x24\x02\x48\x27\xe6\x9c\x3a\xbe\x01\xa3\x0c\xe5\x48\xa2\x84\x74\x3a\x44\x5e\x36\x80\xd7\xdb\x5a\xc3\xac\x18\xff\x9b\x53\x8d\x16\xf2\x90\xae\x67\xf7\x60\x98\x4d\xc6\x59\x4a\x7c\x15\xe9\x71\x6e\xd2\x8d\xc0\x27\xbe\xce\xea\x1e\xc4\x0a" } , Vec- { vecSec = "\xf5\xe5\x76\x7c\xf1\x53\x31\x95\x17\x63\x0f\x22\x68\x76\xb8\x6c\x81\x60\xcc\x58\x3b\xc0\x13\x74\x4c\x6b\xf2\x55\xf5\xcc\x0e\xe5"- , vecPub = "\x27\x81\x17\xfc\x14\x4c\x72\x34\x0f\x67\xd0\xf2\x31\x6e\x83\x86\xce\xff\xbf\x2b\x24\x28\xc9\xc5\x1f\xef\x7c\x59\x7f\x1d\x42\x6e"- , vecMsg = "\x08\xb8\xb2\xb7\x33\x42\x42\x43\x76\x0f\xe4\x26\xa4\xb5\x49\x08\x63\x21\x10\xa6\x6c\x2f\x65\x91\xea\xbd\x33\x45\xe3\xe4\xeb\x98\xfa\x6e\x26\x4b\xf0\x9e\xfe\x12\xee\x50\xf8\xf5\x4e\x9f\x77\xb1\xe3\x55\xf6\xc5\x05\x44\xe2\x3f\xb1\x43\x3d\xdf\x73\xbe\x84\xd8\x79\xde\x7c\x00\x46\xdc\x49\x96\xd9\xe7\x73\xf4\xbc\x9e\xfe\x57\x38\x82\x9a\xdb\x26\xc8\x1b\x37\xc9\x3a\x1b\x27\x0b\x20\x32\x9d\x65\x86\x75\xfc\x6e\xa5\x34\xe0\x81\x0a\x44\x32\x82\x6b\xf5\x8c\x94\x1e\xfb\x65\xd5\x7a\x33\x8b\xbd\x2e\x26\x64\x0f\x89\xff\xbc\x1a\x85\x8e\xfc\xb8\x55\x0e\xe3\xa5\xe1\x99\x8b\xd1\x77\xe9\x3a\x73\x63\xc3\x44\xfe\x6b\x19\x9e\xe5\xd0\x2e\x82\xd5\x22\xc4\xfe\xba\x15\x45\x2f\x80\x28\x8a\x82\x1a\x57\x91\x16\xec\x6d\xad\x2b\x3b\x31\x0d\xa9\x03\x40\x1a\xa6\x21\x00\xab\x5d\x1a\x36\x55\x3e\x06\x20\x3b\x33\x89\x0c\xc9\xb8\x32\xf7\x9e\xf8\x05\x60\xcc\xb9\xa3\x9c\xe7\x67\x96\x7e\xd6\x28\xc6\xad\x57\x3c\xb1\x16\xdb\xef\xef\xd7\x54\x99\xda\x96\xbd\x68\xa8\xa9\x7b\x92\x8a\x8b\xbc\x10\x3b\x66\x21\xfc\xde\x2b\xec\xa1\x23\x1d\x20\x6b\xe6\xcd\x9e\xc7\xaf\xf6\xf6\xc9\x4f\xcd\x72\x04\xed\x34\x55\xc6\x8c\x83\xf4\xa4\x1d\xa4\xaf\x2b\x74\xef\x5c\x53\xf1\xd8\xac\x70\xbd\xcb\x7e\xd1\x85\xce\x81\xbd\x84\x35\x9d\x44\x25\x4d\x95\x62\x9e\x98\x55\xa9\x4a\x7c\x19\x58\xd1\xf8\xad\xa5\xd0\x53\x2e\xd8\xa5\xaa\x3f\xb2\xd1\x7b\xa7\x0e\xb6\x24\x8e\x59\x4e\x1a\x22\x97\xac\xbb\xb3\x9d\x50\x2f\x1a\x8c\x6e\xb6\xf1\xce\x22\xb3\xde\x1a\x1f\x40\xcc\x24\x55\x41\x19\xa8\x31\xa9\xaa\xd6\x07\x9c\xad\x88\x42\x5d\xe6\xbd\xe1\xa9\x18\x7e\xbb\x60\x92\xcf\x67\xbf\x2b\x13\xfd\x65\xf2\x70\x88\xd7\x8b\x7e\x88\x3c\x87\x59\xd2\xc4\xf5\xc6\x5a\xdb\x75\x53\x87\x8a\xd5\x75\xf9\xfa\xd8\x78\xe8\x0a\x0c\x9b\xa6\x3b\xcb\xcc\x27\x32\xe6\x94\x85\xbb\xc9\xc9\x0b\xfb\xd6\x24\x81\xd9\x08\x9b\xec\xcf\x80\xcf\xe2\xdf\x16\xa2\xcf\x65\xbd\x92\xdd\x59\x7b\x07\x07\xe0\x91\x7a\xf4\x8b\xbb\x75\xfe\xd4\x13\xd2\x38\xf5\x55\x5a\x7a\x56\x9d\x80\xc3\x41\x4a\x8d\x08\x59\xdc\x65\xa4\x61\x28\xba\xb2\x7a\xf8\x7a\x71\x31\x4f\x31\x8c\x78\x2b\x23\xeb\xfe\x80\x8b\x82\xb0\xce\x26\x40\x1d\x2e\x22\xf0\x4d\x83\xd1\x25\x5d\xc5\x1a\xdd\xd3\xb7\x5a\x2b\x1a\xe0\x78\x45\x04\xdf\x54\x3a\xf8\x96\x9b\xe3\xea\x70\x82\xff\x7f\xc9\x88\x8c\x14\x4d\xa2\xaf\x58\x42\x9e\xc9\x60\x31\xdb\xca\xd3\xda\xd9\xaf\x0d\xcb\xaa\xaf\x26\x8c\xb8\xfc\xff\xea\xd9\x4f\x3c\x7c\xa4\x95\xe0\x56\xa9\xb4\x7a\xcd\xb7\x51\xfb\x73\xe6\x66\xc6\xc6\x55\xad\xe8\x29\x72\x97\xd0\x7a\xd1\xba\x5e\x43\xf1\xbc\xa3\x23\x01\x65\x13\x39\xe2\x29\x04\xcc\x8c\x42\xf5\x8c\x30\xc0\x4a\xaf\xdb\x03\x8d\xda\x08\x47\xdd\x98\x8d\xcd\xa6\xf3\xbf\xd1\x5c\x4b\x4c\x45\x25\x00\x4a\xa0\x6e\xef\xf8\xca\x61\x78\x3a\xac\xec\x57\xfb\x3d\x1f\x92\xb0\xfe\x2f\xd1\xa8\x5f\x67\x24\x51\x7b\x65\xe6\x14\xad\x68\x08\xd6\xf6\xee\x34\xdf\xf7\x31\x0f\xdc\x82\xae\xbf\xd9\x04\xb0\x1e\x1d\xc5\x4b\x29\x27\x09\x4b\x2d\xb6\x8d\x6f\x90\x3b\x68\x40\x1a\xde\xbf\x5a\x7e\x08\xd7\x8f\xf4\xef\x5d\x63\x65\x3a\x65\x04\x0c\xf9\xbf\xd4\xac\xa7\x98\x4a\x74\xd3\x71\x45\x98\x67\x80\xfc\x0b\x16\xac\x45\x16\x49\xde\x61\x88\xa7\xdb\xdf\x19\x1f\x64\xb5\xfc\x5e\x2a\xb4\x7b\x57\xf7\xf7\x27\x6c\xd4\x19\xc1\x7a\x3c\xa8\xe1\xb9\x39\xae\x49\xe4\x88\xac\xba\x6b\x96\x56\x10\xb5\x48\x01\x09\xc8\xb1\x7b\x80\xe1\xb7\xb7\x50\xdf\xc7\x59\x8d\x5d\x50\x11\xfd\x2d\xcc\x56\x00\xa3\x2e\xf5\xb5\x2a\x1e\xcc\x82\x0e\x30\x8a\xa3\x42\x72\x1a\xac\x09\x43\xbf\x66\x86\xb6\x4b\x25\x79\x37\x65\x04\xcc\xc4\x93\xd9\x7e\x6a\xed\x3f\xb0\xf9\xcd\x71\xa4\x3d\xd4\x97\xf0\x1f\x17\xc0\xe2\xcb\x37\x97\xaa\x2a\x2f\x25\x66\x56\x16\x8e\x6c\x49\x6a\xfc\x5f\xb9\x32\x46\xf6\xb1\x11\x63\x98\xa3\x46\xf1\xa6\x41\xf3\xb0\x41\xe9\x89\xf7\x91\x4f\x90\xcc\x2c\x7f\xff\x35\x78\x76\xe5\x06\xb5\x0d\x33\x4b\xa7\x7c\x22\x5b\xc3\x07\xba\x53\x71\x52\xf3\xf1\x61\x0e\x4e\xaf\xe5\x95\xf6\xd9\xd9\x0d\x11\xfa\xa9\x33\xa1\x5e\xf1\x36\x95\x46\x86\x8a\x7f\x3a\x45\xa9\x67\x68\xd4\x0f\xd9\xd0\x34\x12\xc0\x91\xc6\x31\x5c\xf4\xfd\xe7\xcb\x68\x60\x69\x37\x38\x0d\xb2\xea\xaa\x70\x7b\x4c\x41\x85\xc3\x2e\xdd\xcd\xd3\x06\x70\x5e\x4d\xc1\xff\xc8\x72\xee\xee\x47\x5a\x64\xdf\xac\x86\xab\xa4\x1c\x06\x18\x98\x3f\x87\x41\xc5\xef\x68\xd3\xa1\x01\xe8\xa3\xb8\xca\xc6\x0c\x90\x5c\x15\xfc\x91\x08\x40\xb9\x4c\x00\xa0\xb9\xd0"- , vecSig = "\x0a\xab\x4c\x90\x05\x01\xb3\xe2\x4d\x7c\xdf\x46\x63\x32\x6a\x3a\x87\xdf\x5e\x48\x43\xb2\xcb\xdb\x67\xcb\xf6\xe4\x60\xfe\xc3\x50\xaa\x53\x71\xb1\x50\x8f\x9f\x45\x28\xec\xea\x23\xc4\x36\xd9\x4b\x5e\x8f\xcd\x4f\x68\x1e\x30\xa6\xac\x00\xa9\x70\x4a\x18\x8a\x03"+ { vecSec =+ "\xf5\xe5\x76\x7c\xf1\x53\x31\x95\x17\x63\x0f\x22\x68\x76\xb8\x6c\x81\x60\xcc\x58\x3b\xc0\x13\x74\x4c\x6b\xf2\x55\xf5\xcc\x0e\xe5"+ , vecPub =+ "\x27\x81\x17\xfc\x14\x4c\x72\x34\x0f\x67\xd0\xf2\x31\x6e\x83\x86\xce\xff\xbf\x2b\x24\x28\xc9\xc5\x1f\xef\x7c\x59\x7f\x1d\x42\x6e"+ , vecMsg =+ "\x08\xb8\xb2\xb7\x33\x42\x42\x43\x76\x0f\xe4\x26\xa4\xb5\x49\x08\x63\x21\x10\xa6\x6c\x2f\x65\x91\xea\xbd\x33\x45\xe3\xe4\xeb\x98\xfa\x6e\x26\x4b\xf0\x9e\xfe\x12\xee\x50\xf8\xf5\x4e\x9f\x77\xb1\xe3\x55\xf6\xc5\x05\x44\xe2\x3f\xb1\x43\x3d\xdf\x73\xbe\x84\xd8\x79\xde\x7c\x00\x46\xdc\x49\x96\xd9\xe7\x73\xf4\xbc\x9e\xfe\x57\x38\x82\x9a\xdb\x26\xc8\x1b\x37\xc9\x3a\x1b\x27\x0b\x20\x32\x9d\x65\x86\x75\xfc\x6e\xa5\x34\xe0\x81\x0a\x44\x32\x82\x6b\xf5\x8c\x94\x1e\xfb\x65\xd5\x7a\x33\x8b\xbd\x2e\x26\x64\x0f\x89\xff\xbc\x1a\x85\x8e\xfc\xb8\x55\x0e\xe3\xa5\xe1\x99\x8b\xd1\x77\xe9\x3a\x73\x63\xc3\x44\xfe\x6b\x19\x9e\xe5\xd0\x2e\x82\xd5\x22\xc4\xfe\xba\x15\x45\x2f\x80\x28\x8a\x82\x1a\x57\x91\x16\xec\x6d\xad\x2b\x3b\x31\x0d\xa9\x03\x40\x1a\xa6\x21\x00\xab\x5d\x1a\x36\x55\x3e\x06\x20\x3b\x33\x89\x0c\xc9\xb8\x32\xf7\x9e\xf8\x05\x60\xcc\xb9\xa3\x9c\xe7\x67\x96\x7e\xd6\x28\xc6\xad\x57\x3c\xb1\x16\xdb\xef\xef\xd7\x54\x99\xda\x96\xbd\x68\xa8\xa9\x7b\x92\x8a\x8b\xbc\x10\x3b\x66\x21\xfc\xde\x2b\xec\xa1\x23\x1d\x20\x6b\xe6\xcd\x9e\xc7\xaf\xf6\xf6\xc9\x4f\xcd\x72\x04\xed\x34\x55\xc6\x8c\x83\xf4\xa4\x1d\xa4\xaf\x2b\x74\xef\x5c\x53\xf1\xd8\xac\x70\xbd\xcb\x7e\xd1\x85\xce\x81\xbd\x84\x35\x9d\x44\x25\x4d\x95\x62\x9e\x98\x55\xa9\x4a\x7c\x19\x58\xd1\xf8\xad\xa5\xd0\x53\x2e\xd8\xa5\xaa\x3f\xb2\xd1\x7b\xa7\x0e\xb6\x24\x8e\x59\x4e\x1a\x22\x97\xac\xbb\xb3\x9d\x50\x2f\x1a\x8c\x6e\xb6\xf1\xce\x22\xb3\xde\x1a\x1f\x40\xcc\x24\x55\x41\x19\xa8\x31\xa9\xaa\xd6\x07\x9c\xad\x88\x42\x5d\xe6\xbd\xe1\xa9\x18\x7e\xbb\x60\x92\xcf\x67\xbf\x2b\x13\xfd\x65\xf2\x70\x88\xd7\x8b\x7e\x88\x3c\x87\x59\xd2\xc4\xf5\xc6\x5a\xdb\x75\x53\x87\x8a\xd5\x75\xf9\xfa\xd8\x78\xe8\x0a\x0c\x9b\xa6\x3b\xcb\xcc\x27\x32\xe6\x94\x85\xbb\xc9\xc9\x0b\xfb\xd6\x24\x81\xd9\x08\x9b\xec\xcf\x80\xcf\xe2\xdf\x16\xa2\xcf\x65\xbd\x92\xdd\x59\x7b\x07\x07\xe0\x91\x7a\xf4\x8b\xbb\x75\xfe\xd4\x13\xd2\x38\xf5\x55\x5a\x7a\x56\x9d\x80\xc3\x41\x4a\x8d\x08\x59\xdc\x65\xa4\x61\x28\xba\xb2\x7a\xf8\x7a\x71\x31\x4f\x31\x8c\x78\x2b\x23\xeb\xfe\x80\x8b\x82\xb0\xce\x26\x40\x1d\x2e\x22\xf0\x4d\x83\xd1\x25\x5d\xc5\x1a\xdd\xd3\xb7\x5a\x2b\x1a\xe0\x78\x45\x04\xdf\x54\x3a\xf8\x96\x9b\xe3\xea\x70\x82\xff\x7f\xc9\x88\x8c\x14\x4d\xa2\xaf\x58\x42\x9e\xc9\x60\x31\xdb\xca\xd3\xda\xd9\xaf\x0d\xcb\xaa\xaf\x26\x8c\xb8\xfc\xff\xea\xd9\x4f\x3c\x7c\xa4\x95\xe0\x56\xa9\xb4\x7a\xcd\xb7\x51\xfb\x73\xe6\x66\xc6\xc6\x55\xad\xe8\x29\x72\x97\xd0\x7a\xd1\xba\x5e\x43\xf1\xbc\xa3\x23\x01\x65\x13\x39\xe2\x29\x04\xcc\x8c\x42\xf5\x8c\x30\xc0\x4a\xaf\xdb\x03\x8d\xda\x08\x47\xdd\x98\x8d\xcd\xa6\xf3\xbf\xd1\x5c\x4b\x4c\x45\x25\x00\x4a\xa0\x6e\xef\xf8\xca\x61\x78\x3a\xac\xec\x57\xfb\x3d\x1f\x92\xb0\xfe\x2f\xd1\xa8\x5f\x67\x24\x51\x7b\x65\xe6\x14\xad\x68\x08\xd6\xf6\xee\x34\xdf\xf7\x31\x0f\xdc\x82\xae\xbf\xd9\x04\xb0\x1e\x1d\xc5\x4b\x29\x27\x09\x4b\x2d\xb6\x8d\x6f\x90\x3b\x68\x40\x1a\xde\xbf\x5a\x7e\x08\xd7\x8f\xf4\xef\x5d\x63\x65\x3a\x65\x04\x0c\xf9\xbf\xd4\xac\xa7\x98\x4a\x74\xd3\x71\x45\x98\x67\x80\xfc\x0b\x16\xac\x45\x16\x49\xde\x61\x88\xa7\xdb\xdf\x19\x1f\x64\xb5\xfc\x5e\x2a\xb4\x7b\x57\xf7\xf7\x27\x6c\xd4\x19\xc1\x7a\x3c\xa8\xe1\xb9\x39\xae\x49\xe4\x88\xac\xba\x6b\x96\x56\x10\xb5\x48\x01\x09\xc8\xb1\x7b\x80\xe1\xb7\xb7\x50\xdf\xc7\x59\x8d\x5d\x50\x11\xfd\x2d\xcc\x56\x00\xa3\x2e\xf5\xb5\x2a\x1e\xcc\x82\x0e\x30\x8a\xa3\x42\x72\x1a\xac\x09\x43\xbf\x66\x86\xb6\x4b\x25\x79\x37\x65\x04\xcc\xc4\x93\xd9\x7e\x6a\xed\x3f\xb0\xf9\xcd\x71\xa4\x3d\xd4\x97\xf0\x1f\x17\xc0\xe2\xcb\x37\x97\xaa\x2a\x2f\x25\x66\x56\x16\x8e\x6c\x49\x6a\xfc\x5f\xb9\x32\x46\xf6\xb1\x11\x63\x98\xa3\x46\xf1\xa6\x41\xf3\xb0\x41\xe9\x89\xf7\x91\x4f\x90\xcc\x2c\x7f\xff\x35\x78\x76\xe5\x06\xb5\x0d\x33\x4b\xa7\x7c\x22\x5b\xc3\x07\xba\x53\x71\x52\xf3\xf1\x61\x0e\x4e\xaf\xe5\x95\xf6\xd9\xd9\x0d\x11\xfa\xa9\x33\xa1\x5e\xf1\x36\x95\x46\x86\x8a\x7f\x3a\x45\xa9\x67\x68\xd4\x0f\xd9\xd0\x34\x12\xc0\x91\xc6\x31\x5c\xf4\xfd\xe7\xcb\x68\x60\x69\x37\x38\x0d\xb2\xea\xaa\x70\x7b\x4c\x41\x85\xc3\x2e\xdd\xcd\xd3\x06\x70\x5e\x4d\xc1\xff\xc8\x72\xee\xee\x47\x5a\x64\xdf\xac\x86\xab\xa4\x1c\x06\x18\x98\x3f\x87\x41\xc5\xef\x68\xd3\xa1\x01\xe8\xa3\xb8\xca\xc6\x0c\x90\x5c\x15\xfc\x91\x08\x40\xb9\x4c\x00\xa0\xb9\xd0"+ , vecSig =+ "\x0a\xab\x4c\x90\x05\x01\xb3\xe2\x4d\x7c\xdf\x46\x63\x32\x6a\x3a\x87\xdf\x5e\x48\x43\xb2\xcb\xdb\x67\xcb\xf6\xe4\x60\xfe\xc3\x50\xaa\x53\x71\xb1\x50\x8f\x9f\x45\x28\xec\xea\x23\xc4\x36\xd9\x4b\x5e\x8f\xcd\x4f\x68\x1e\x30\xa6\xac\x00\xa9\x70\x4a\x18\x8a\x03" } , Vec- { vecSec = "\x83\x3f\xe6\x24\x09\x23\x7b\x9d\x62\xec\x77\x58\x75\x20\x91\x1e\x9a\x75\x9c\xec\x1d\x19\x75\x5b\x7d\xa9\x01\xb9\x6d\xca\x3d\x42"- , vecPub = "\xec\x17\x2b\x93\xad\x5e\x56\x3b\xf4\x93\x2c\x70\xe1\x24\x50\x34\xc3\x54\x67\xef\x2e\xfd\x4d\x64\xeb\xf8\x19\x68\x34\x67\xe2\xbf"- , vecMsg = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f"- , vecSig = "\xdc\x2a\x44\x59\xe7\x36\x96\x33\xa5\x2b\x1b\xf2\x77\x83\x9a\x00\x20\x10\x09\xa3\xef\xbf\x3e\xcb\x69\xbe\xa2\x18\x6c\x26\xb5\x89\x09\x35\x1f\xc9\xac\x90\xb3\xec\xfd\xfb\xc7\xc6\x64\x31\xe0\x30\x3d\xca\x17\x9c\x13\x8a\xc1\x7a\xd9\xbe\xf1\x17\x73\x31\xa7\x04"+ { vecSec =+ "\x83\x3f\xe6\x24\x09\x23\x7b\x9d\x62\xec\x77\x58\x75\x20\x91\x1e\x9a\x75\x9c\xec\x1d\x19\x75\x5b\x7d\xa9\x01\xb9\x6d\xca\x3d\x42"+ , vecPub =+ "\xec\x17\x2b\x93\xad\x5e\x56\x3b\xf4\x93\x2c\x70\xe1\x24\x50\x34\xc3\x54\x67\xef\x2e\xfd\x4d\x64\xeb\xf8\x19\x68\x34\x67\xe2\xbf"+ , vecMsg =+ "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f"+ , vecSig =+ "\xdc\x2a\x44\x59\xe7\x36\x96\x33\xa5\x2b\x1b\xf2\x77\x83\x9a\x00\x20\x10\x09\xa3\xef\xbf\x3e\xcb\x69\xbe\xa2\x18\x6c\x26\xb5\x89\x09\x35\x1f\xc9\xac\x90\xb3\xec\xfd\xfb\xc7\xc6\x64\x31\xe0\x30\x3d\xca\x17\x9c\x13\x8a\xc1\x7a\xd9\xbe\xf1\x17\x73\x31\xa7\x04" } ] - doPublicKeyTest i vec = testCase (show i) (pub @=? Ed25519.toPublic sec) where- !pub = throwCryptoError $ Ed25519.publicKey (vecPub vec)- !sec = throwCryptoError $ Ed25519.secretKey (vecSec vec)+ !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)) where- !sig = throwCryptoError $ Ed25519.signature (vecSig vec)- !pub = throwCryptoError $ Ed25519.publicKey (vecPub vec)- !sec = throwCryptoError $ Ed25519.secretKey (vecSec vec)+ !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) where- !sig = throwCryptoError $ Ed25519.signature (vecSig vec)- !pub = throwCryptoError $ Ed25519.publicKey (vecPub vec)-+ !sig = throwCryptoError $ Ed25519.signature (vecSig vec)+ !pub = throwCryptoError $ Ed25519.publicKey (vecPub vec) -tests = testGroup "Ed25519"- [ testCase "gen secretkey" (Ed25519.generateSecretKey *> pure ())- , testGroup "gen publickey" $ zipWith doPublicKeyTest [katZero..] vectors- , testGroup "gen signature" $ zipWith doSignatureTest [katZero..] vectors- , testGroup "verify sig" $ zipWith doVerifyTest [katZero..] vectors- ]+tests =+ testGroup+ "Ed25519"+ [ testCase "gen secretkey" (Ed25519.generateSecretKey *> pure ())+ , testGroup "gen publickey" $ zipWith doPublicKeyTest [katZero ..] vectors+ , testGroup "gen signature" $ zipWith doSignatureTest [katZero ..] vectors+ , testGroup "verify sig" $ zipWith doVerifyTest [katZero ..] vectors+ ]
tests/KAT_Ed448.hs view
@@ -1,90 +1,119 @@-{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE BangPatterns #-}-module KAT_Ed448 ( tests ) where+{-# LANGUAGE OverloadedStrings #-} -import Crypto.Error+module KAT_Ed448 (tests) where++import Crypto.Error import qualified Crypto.PubKey.Ed448 as Ed448-import Imports+import Imports data Vec = Vec { vecSec :: ByteString , vecPub :: ByteString , vecMsg :: ByteString , vecSig :: ByteString- } deriving (Show,Eq)+ }+ deriving (Show, Eq) vectors = [ Vec- { vecSec = "\x6c\x82\xa5\x62\xcb\x80\x8d\x10\xd6\x32\xbe\x89\xc8\x51\x3e\xbf\x6c\x92\x9f\x34\xdd\xfa\x8c\x9f\x63\xc9\x96\x0e\xf6\xe3\x48\xa3\x52\x8c\x8a\x3f\xcc\x2f\x04\x4e\x39\xa3\xfc\x5b\x94\x49\x2f\x8f\x03\x2e\x75\x49\xa2\x00\x98\xf9\x5b"- , vecPub = "\x5f\xd7\x44\x9b\x59\xb4\x61\xfd\x2c\xe7\x87\xec\x61\x6a\xd4\x6a\x1d\xa1\x34\x24\x85\xa7\x0e\x1f\x8a\x0e\xa7\x5d\x80\xe9\x67\x78\xed\xf1\x24\x76\x9b\x46\xc7\x06\x1b\xd6\x78\x3d\xf1\xe5\x0f\x6c\xd1\xfa\x1a\xbe\xaf\xe8\x25\x61\x80"+ { vecSec =+ "\x6c\x82\xa5\x62\xcb\x80\x8d\x10\xd6\x32\xbe\x89\xc8\x51\x3e\xbf\x6c\x92\x9f\x34\xdd\xfa\x8c\x9f\x63\xc9\x96\x0e\xf6\xe3\x48\xa3\x52\x8c\x8a\x3f\xcc\x2f\x04\x4e\x39\xa3\xfc\x5b\x94\x49\x2f\x8f\x03\x2e\x75\x49\xa2\x00\x98\xf9\x5b"+ , vecPub =+ "\x5f\xd7\x44\x9b\x59\xb4\x61\xfd\x2c\xe7\x87\xec\x61\x6a\xd4\x6a\x1d\xa1\x34\x24\x85\xa7\x0e\x1f\x8a\x0e\xa7\x5d\x80\xe9\x67\x78\xed\xf1\x24\x76\x9b\x46\xc7\x06\x1b\xd6\x78\x3d\xf1\xe5\x0f\x6c\xd1\xfa\x1a\xbe\xaf\xe8\x25\x61\x80" , vecMsg = ""- , vecSig = "\x53\x3a\x37\xf6\xbb\xe4\x57\x25\x1f\x02\x3c\x0d\x88\xf9\x76\xae\x2d\xfb\x50\x4a\x84\x3e\x34\xd2\x07\x4f\xd8\x23\xd4\x1a\x59\x1f\x2b\x23\x3f\x03\x4f\x62\x82\x81\xf2\xfd\x7a\x22\xdd\xd4\x7d\x78\x28\xc5\x9b\xd0\xa2\x1b\xfd\x39\x80\xff\x0d\x20\x28\xd4\xb1\x8a\x9d\xf6\x3e\x00\x6c\x5d\x1c\x2d\x34\x5b\x92\x5d\x8d\xc0\x0b\x41\x04\x85\x2d\xb9\x9a\xc5\xc7\xcd\xda\x85\x30\xa1\x13\xa0\xf4\xdb\xb6\x11\x49\xf0\x5a\x73\x63\x26\x8c\x71\xd9\x58\x08\xff\x2e\x65\x26\x00"+ , vecSig =+ "\x53\x3a\x37\xf6\xbb\xe4\x57\x25\x1f\x02\x3c\x0d\x88\xf9\x76\xae\x2d\xfb\x50\x4a\x84\x3e\x34\xd2\x07\x4f\xd8\x23\xd4\x1a\x59\x1f\x2b\x23\x3f\x03\x4f\x62\x82\x81\xf2\xfd\x7a\x22\xdd\xd4\x7d\x78\x28\xc5\x9b\xd0\xa2\x1b\xfd\x39\x80\xff\x0d\x20\x28\xd4\xb1\x8a\x9d\xf6\x3e\x00\x6c\x5d\x1c\x2d\x34\x5b\x92\x5d\x8d\xc0\x0b\x41\x04\x85\x2d\xb9\x9a\xc5\xc7\xcd\xda\x85\x30\xa1\x13\xa0\xf4\xdb\xb6\x11\x49\xf0\x5a\x73\x63\x26\x8c\x71\xd9\x58\x08\xff\x2e\x65\x26\x00" } , Vec- { vecSec = "\xc4\xea\xb0\x5d\x35\x70\x07\xc6\x32\xf3\xdb\xb4\x84\x89\x92\x4d\x55\x2b\x08\xfe\x0c\x35\x3a\x0d\x4a\x1f\x00\xac\xda\x2c\x46\x3a\xfb\xea\x67\xc5\xe8\xd2\x87\x7c\x5e\x3b\xc3\x97\xa6\x59\x94\x9e\xf8\x02\x1e\x95\x4e\x0a\x12\x27\x4e"- , vecPub = "\x43\xba\x28\xf4\x30\xcd\xff\x45\x6a\xe5\x31\x54\x5f\x7e\xcd\x0a\xc8\x34\xa5\x5d\x93\x58\xc0\x37\x2b\xfa\x0c\x6c\x67\x98\xc0\x86\x6a\xea\x01\xeb\x00\x74\x28\x02\xb8\x43\x8e\xa4\xcb\x82\x16\x9c\x23\x51\x60\x62\x7b\x4c\x3a\x94\x80"+ { vecSec =+ "\xc4\xea\xb0\x5d\x35\x70\x07\xc6\x32\xf3\xdb\xb4\x84\x89\x92\x4d\x55\x2b\x08\xfe\x0c\x35\x3a\x0d\x4a\x1f\x00\xac\xda\x2c\x46\x3a\xfb\xea\x67\xc5\xe8\xd2\x87\x7c\x5e\x3b\xc3\x97\xa6\x59\x94\x9e\xf8\x02\x1e\x95\x4e\x0a\x12\x27\x4e"+ , vecPub =+ "\x43\xba\x28\xf4\x30\xcd\xff\x45\x6a\xe5\x31\x54\x5f\x7e\xcd\x0a\xc8\x34\xa5\x5d\x93\x58\xc0\x37\x2b\xfa\x0c\x6c\x67\x98\xc0\x86\x6a\xea\x01\xeb\x00\x74\x28\x02\xb8\x43\x8e\xa4\xcb\x82\x16\x9c\x23\x51\x60\x62\x7b\x4c\x3a\x94\x80" , vecMsg = "\x03"- , vecSig = "\x26\xb8\xf9\x17\x27\xbd\x62\x89\x7a\xf1\x5e\x41\xeb\x43\xc3\x77\xef\xb9\xc6\x10\xd4\x8f\x23\x35\xcb\x0b\xd0\x08\x78\x10\xf4\x35\x25\x41\xb1\x43\xc4\xb9\x81\xb7\xe1\x8f\x62\xde\x8c\xcd\xf6\x33\xfc\x1b\xf0\x37\xab\x7c\xd7\x79\x80\x5e\x0d\xbc\xc0\xaa\xe1\xcb\xce\xe1\xaf\xb2\xe0\x27\xdf\x36\xbc\x04\xdc\xec\xbf\x15\x43\x36\xc1\x9f\x0a\xf7\xe0\xa6\x47\x29\x05\xe7\x99\xf1\x95\x3d\x2a\x0f\xf3\x34\x8a\xb2\x1a\xa4\xad\xaf\xd1\xd2\x34\x44\x1c\xf8\x07\xc0\x3a\x00"+ , vecSig =+ "\x26\xb8\xf9\x17\x27\xbd\x62\x89\x7a\xf1\x5e\x41\xeb\x43\xc3\x77\xef\xb9\xc6\x10\xd4\x8f\x23\x35\xcb\x0b\xd0\x08\x78\x10\xf4\x35\x25\x41\xb1\x43\xc4\xb9\x81\xb7\xe1\x8f\x62\xde\x8c\xcd\xf6\x33\xfc\x1b\xf0\x37\xab\x7c\xd7\x79\x80\x5e\x0d\xbc\xc0\xaa\xe1\xcb\xce\xe1\xaf\xb2\xe0\x27\xdf\x36\xbc\x04\xdc\xec\xbf\x15\x43\x36\xc1\x9f\x0a\xf7\xe0\xa6\x47\x29\x05\xe7\x99\xf1\x95\x3d\x2a\x0f\xf3\x34\x8a\xb2\x1a\xa4\xad\xaf\xd1\xd2\x34\x44\x1c\xf8\x07\xc0\x3a\x00" } , Vec- { vecSec = "\xcd\x23\xd2\x4f\x71\x42\x74\xe7\x44\x34\x32\x37\xb9\x32\x90\xf5\x11\xf6\x42\x5f\x98\xe6\x44\x59\xff\x20\x3e\x89\x85\x08\x3f\xfd\xf6\x05\x00\x55\x3a\xbc\x0e\x05\xcd\x02\x18\x4b\xdb\x89\xc4\xcc\xd6\x7e\x18\x79\x51\x26\x7e\xb3\x28"- , vecPub = "\xdc\xea\x9e\x78\xf3\x5a\x1b\xf3\x49\x9a\x83\x1b\x10\xb8\x6c\x90\xaa\xc0\x1c\xd8\x4b\x67\xa0\x10\x9b\x55\xa3\x6e\x93\x28\xb1\xe3\x65\xfc\xe1\x61\xd7\x1c\xe7\x13\x1a\x54\x3e\xa4\xcb\x5f\x7e\x9f\x1d\x8b\x00\x69\x64\x47\x00\x14\x00"+ { vecSec =+ "\xcd\x23\xd2\x4f\x71\x42\x74\xe7\x44\x34\x32\x37\xb9\x32\x90\xf5\x11\xf6\x42\x5f\x98\xe6\x44\x59\xff\x20\x3e\x89\x85\x08\x3f\xfd\xf6\x05\x00\x55\x3a\xbc\x0e\x05\xcd\x02\x18\x4b\xdb\x89\xc4\xcc\xd6\x7e\x18\x79\x51\x26\x7e\xb3\x28"+ , vecPub =+ "\xdc\xea\x9e\x78\xf3\x5a\x1b\xf3\x49\x9a\x83\x1b\x10\xb8\x6c\x90\xaa\xc0\x1c\xd8\x4b\x67\xa0\x10\x9b\x55\xa3\x6e\x93\x28\xb1\xe3\x65\xfc\xe1\x61\xd7\x1c\xe7\x13\x1a\x54\x3e\xa4\xcb\x5f\x7e\x9f\x1d\x8b\x00\x69\x64\x47\x00\x14\x00" , vecMsg = "\x0c\x3e\x54\x40\x74\xec\x63\xb0\x26\x5e\x0c"- , vecSig = "\x1f\x0a\x88\x88\xce\x25\xe8\xd4\x58\xa2\x11\x30\x87\x9b\x84\x0a\x90\x89\xd9\x99\xaa\xba\x03\x9e\xaf\x3e\x3a\xfa\x09\x0a\x09\xd3\x89\xdb\xa8\x2c\x4f\xf2\xae\x8a\xc5\xcd\xfb\x7c\x55\xe9\x4d\x5d\x96\x1a\x29\xfe\x01\x09\x94\x1e\x00\xb8\xdb\xde\xea\x6d\x3b\x05\x10\x68\xdf\x72\x54\xc0\xcd\xc1\x29\xcb\xe6\x2d\xb2\xdc\x95\x7d\xbb\x47\xb5\x1f\xd3\xf2\x13\xfb\x86\x98\xf0\x64\x77\x42\x50\xa5\x02\x89\x61\xc9\xbf\x8f\xfd\x97\x3f\xe5\xd5\xc2\x06\x49\x2b\x14\x0e\x00"+ , vecSig =+ "\x1f\x0a\x88\x88\xce\x25\xe8\xd4\x58\xa2\x11\x30\x87\x9b\x84\x0a\x90\x89\xd9\x99\xaa\xba\x03\x9e\xaf\x3e\x3a\xfa\x09\x0a\x09\xd3\x89\xdb\xa8\x2c\x4f\xf2\xae\x8a\xc5\xcd\xfb\x7c\x55\xe9\x4d\x5d\x96\x1a\x29\xfe\x01\x09\x94\x1e\x00\xb8\xdb\xde\xea\x6d\x3b\x05\x10\x68\xdf\x72\x54\xc0\xcd\xc1\x29\xcb\xe6\x2d\xb2\xdc\x95\x7d\xbb\x47\xb5\x1f\xd3\xf2\x13\xfb\x86\x98\xf0\x64\x77\x42\x50\xa5\x02\x89\x61\xc9\xbf\x8f\xfd\x97\x3f\xe5\xd5\xc2\x06\x49\x2b\x14\x0e\x00" } , Vec- { vecSec = "\x25\x8c\xdd\x4a\xda\x32\xed\x9c\x9f\xf5\x4e\x63\x75\x6a\xe5\x82\xfb\x8f\xab\x2a\xc7\x21\xf2\xc8\xe6\x76\xa7\x27\x68\x51\x3d\x93\x9f\x63\xdd\xdb\x55\x60\x91\x33\xf2\x9a\xdf\x86\xec\x99\x29\xdc\xcb\x52\xc1\xc5\xfd\x2f\xf7\xe2\x1b"- , vecPub = "\x3b\xa1\x6d\xa0\xc6\xf2\xcc\x1f\x30\x18\x77\x40\x75\x6f\x5e\x79\x8d\x6b\xc5\xfc\x01\x5d\x7c\x63\xcc\x95\x10\xee\x3f\xd4\x4a\xdc\x24\xd8\xe9\x68\xb6\xe4\x6e\x6f\x94\xd1\x9b\x94\x53\x61\x72\x6b\xd7\x5e\x14\x9e\xf0\x98\x17\xf5\x80"+ { vecSec =+ "\x25\x8c\xdd\x4a\xda\x32\xed\x9c\x9f\xf5\x4e\x63\x75\x6a\xe5\x82\xfb\x8f\xab\x2a\xc7\x21\xf2\xc8\xe6\x76\xa7\x27\x68\x51\x3d\x93\x9f\x63\xdd\xdb\x55\x60\x91\x33\xf2\x9a\xdf\x86\xec\x99\x29\xdc\xcb\x52\xc1\xc5\xfd\x2f\xf7\xe2\x1b"+ , vecPub =+ "\x3b\xa1\x6d\xa0\xc6\xf2\xcc\x1f\x30\x18\x77\x40\x75\x6f\x5e\x79\x8d\x6b\xc5\xfc\x01\x5d\x7c\x63\xcc\x95\x10\xee\x3f\xd4\x4a\xdc\x24\xd8\xe9\x68\xb6\xe4\x6e\x6f\x94\xd1\x9b\x94\x53\x61\x72\x6b\xd7\x5e\x14\x9e\xf0\x98\x17\xf5\x80" , vecMsg = "\x64\xa6\x5f\x3c\xde\xdc\xdd\x66\x81\x1e\x29\x15"- , vecSig = "\x7e\xee\xab\x7c\x4e\x50\xfb\x79\x9b\x41\x8e\xe5\xe3\x19\x7f\xf6\xbf\x15\xd4\x3a\x14\xc3\x43\x89\xb5\x9d\xd1\xa7\xb1\xb8\x5b\x4a\xe9\x04\x38\xac\xa6\x34\xbe\xa4\x5e\x3a\x26\x95\xf1\x27\x0f\x07\xfd\xcd\xf7\xc6\x2b\x8e\xfe\xaf\x00\xb4\x5c\x2c\x96\xba\x45\x7e\xb1\xa8\xbf\x07\x5a\x3d\xb2\x8e\x5c\x24\xf6\xb9\x23\xed\x4a\xd7\x47\xc3\xc9\xe0\x3c\x70\x79\xef\xb8\x7c\xb1\x10\xd3\xa9\x98\x61\xe7\x20\x03\xcb\xae\x6d\x6b\x8b\x82\x7e\x4e\x6c\x14\x30\x64\xff\x3c\x00"+ , vecSig =+ "\x7e\xee\xab\x7c\x4e\x50\xfb\x79\x9b\x41\x8e\xe5\xe3\x19\x7f\xf6\xbf\x15\xd4\x3a\x14\xc3\x43\x89\xb5\x9d\xd1\xa7\xb1\xb8\x5b\x4a\xe9\x04\x38\xac\xa6\x34\xbe\xa4\x5e\x3a\x26\x95\xf1\x27\x0f\x07\xfd\xcd\xf7\xc6\x2b\x8e\xfe\xaf\x00\xb4\x5c\x2c\x96\xba\x45\x7e\xb1\xa8\xbf\x07\x5a\x3d\xb2\x8e\x5c\x24\xf6\xb9\x23\xed\x4a\xd7\x47\xc3\xc9\xe0\x3c\x70\x79\xef\xb8\x7c\xb1\x10\xd3\xa9\x98\x61\xe7\x20\x03\xcb\xae\x6d\x6b\x8b\x82\x7e\x4e\x6c\x14\x30\x64\xff\x3c\x00" } , Vec- { vecSec = "\x7e\xf4\xe8\x45\x44\x23\x67\x52\xfb\xb5\x6b\x8f\x31\xa2\x3a\x10\xe4\x28\x14\xf5\xf5\x5c\xa0\x37\xcd\xcc\x11\xc6\x4c\x9a\x3b\x29\x49\xc1\xbb\x60\x70\x03\x14\x61\x17\x32\xa6\xc2\xfe\xa9\x8e\xeb\xc0\x26\x6a\x11\xa9\x39\x70\x10\x0e"- , vecPub = "\xb3\xda\x07\x9b\x0a\xa4\x93\xa5\x77\x20\x29\xf0\x46\x7b\xae\xbe\xe5\xa8\x11\x2d\x9d\x3a\x22\x53\x23\x61\xda\x29\x4f\x7b\xb3\x81\x5c\x5d\xc5\x9e\x17\x6b\x4d\x9f\x38\x1c\xa0\x93\x8e\x13\xc6\xc0\x7b\x17\x4b\xe6\x5d\xfa\x57\x8e\x80"+ { vecSec =+ "\x7e\xf4\xe8\x45\x44\x23\x67\x52\xfb\xb5\x6b\x8f\x31\xa2\x3a\x10\xe4\x28\x14\xf5\xf5\x5c\xa0\x37\xcd\xcc\x11\xc6\x4c\x9a\x3b\x29\x49\xc1\xbb\x60\x70\x03\x14\x61\x17\x32\xa6\xc2\xfe\xa9\x8e\xeb\xc0\x26\x6a\x11\xa9\x39\x70\x10\x0e"+ , vecPub =+ "\xb3\xda\x07\x9b\x0a\xa4\x93\xa5\x77\x20\x29\xf0\x46\x7b\xae\xbe\xe5\xa8\x11\x2d\x9d\x3a\x22\x53\x23\x61\xda\x29\x4f\x7b\xb3\x81\x5c\x5d\xc5\x9e\x17\x6b\x4d\x9f\x38\x1c\xa0\x93\x8e\x13\xc6\xc0\x7b\x17\x4b\xe6\x5d\xfa\x57\x8e\x80" , vecMsg = "\x64\xa6\x5f\x3c\xde\xdc\xdd\x66\x81\x1e\x29\x15\xe7"- , vecSig = "\x6a\x12\x06\x6f\x55\x33\x1b\x6c\x22\xac\xd5\xd5\xbf\xc5\xd7\x12\x28\xfb\xda\x80\xae\x8d\xec\x26\xbd\xd3\x06\x74\x3c\x50\x27\xcb\x48\x90\x81\x0c\x16\x2c\x02\x74\x68\x67\x5e\xcf\x64\x5a\x83\x17\x6c\x0d\x73\x23\xa2\xcc\xde\x2d\x80\xef\xe5\xa1\x26\x8e\x8a\xca\x1d\x6f\xbc\x19\x4d\x3f\x77\xc4\x49\x86\xeb\x4a\xb4\x17\x79\x19\xad\x8b\xec\x33\xeb\x47\xbb\xb5\xfc\x6e\x28\x19\x6f\xd1\xca\xf5\x6b\x4e\x7e\x0b\xa5\x51\x92\x34\xd0\x47\x15\x5a\xc7\x27\xa1\x05\x31\x00"+ , vecSig =+ "\x6a\x12\x06\x6f\x55\x33\x1b\x6c\x22\xac\xd5\xd5\xbf\xc5\xd7\x12\x28\xfb\xda\x80\xae\x8d\xec\x26\xbd\xd3\x06\x74\x3c\x50\x27\xcb\x48\x90\x81\x0c\x16\x2c\x02\x74\x68\x67\x5e\xcf\x64\x5a\x83\x17\x6c\x0d\x73\x23\xa2\xcc\xde\x2d\x80\xef\xe5\xa1\x26\x8e\x8a\xca\x1d\x6f\xbc\x19\x4d\x3f\x77\xc4\x49\x86\xeb\x4a\xb4\x17\x79\x19\xad\x8b\xec\x33\xeb\x47\xbb\xb5\xfc\x6e\x28\x19\x6f\xd1\xca\xf5\x6b\x4e\x7e\x0b\xa5\x51\x92\x34\xd0\x47\x15\x5a\xc7\x27\xa1\x05\x31\x00" } , Vec- { vecSec = "\xd6\x5d\xf3\x41\xad\x13\xe0\x08\x56\x76\x88\xba\xed\xda\x8e\x9d\xcd\xc1\x7d\xc0\x24\x97\x4e\xa5\xb4\x22\x7b\x65\x30\xe3\x39\xbf\xf2\x1f\x99\xe6\x8c\xa6\x96\x8f\x3c\xca\x6d\xfe\x0f\xb9\xf4\xfa\xb4\xfa\x13\x5d\x55\x42\xea\x3f\x01"- , vecPub = "\xdf\x97\x05\xf5\x8e\xdb\xab\x80\x2c\x7f\x83\x63\xcf\xe5\x56\x0a\xb1\xc6\x13\x2c\x20\xa9\xf1\xdd\x16\x34\x83\xa2\x6f\x8a\xc5\x3a\x39\xd6\x80\x8b\xf4\xa1\xdf\xbd\x26\x1b\x09\x9b\xb0\x3b\x3f\xb5\x09\x06\xcb\x28\xbd\x8a\x08\x1f\x00"- , vecMsg = "\xbd\x0f\x6a\x37\x47\xcd\x56\x1b\xdd\xdf\x46\x40\xa3\x32\x46\x1a\x4a\x30\xa1\x2a\x43\x4c\xd0\xbf\x40\xd7\x66\xd9\xc6\xd4\x58\xe5\x51\x22\x04\xa3\x0c\x17\xd1\xf5\x0b\x50\x79\x63\x1f\x64\xeb\x31\x12\x18\x2d\xa3\x00\x58\x35\x46\x11\x13\x71\x8d\x1a\x5e\xf9\x44"- , vecSig = "\x55\x4b\xc2\x48\x08\x60\xb4\x9e\xab\x85\x32\xd2\xa5\x33\xb7\xd5\x78\xef\x47\x3e\xeb\x58\xc9\x8b\xb2\xd0\xe1\xce\x48\x8a\x98\xb1\x8d\xfd\xe9\xb9\xb9\x07\x75\xe6\x7f\x47\xd4\xa1\xc3\x48\x20\x58\xef\xc9\xf4\x0d\x2c\xa0\x33\xa0\x80\x1b\x63\xd4\x5b\x3b\x72\x2e\xf5\x52\xba\xd3\xb4\xcc\xb6\x67\xda\x35\x01\x92\xb6\x1c\x50\x8c\xf7\xb6\xb5\xad\xad\xc2\xc8\xd9\xa4\x46\xef\x00\x3f\xb0\x5c\xba\x5f\x30\xe8\x8e\x36\xec\x27\x03\xb3\x49\xca\x22\x9c\x26\x70\x83\x39\x00"+ { vecSec =+ "\xd6\x5d\xf3\x41\xad\x13\xe0\x08\x56\x76\x88\xba\xed\xda\x8e\x9d\xcd\xc1\x7d\xc0\x24\x97\x4e\xa5\xb4\x22\x7b\x65\x30\xe3\x39\xbf\xf2\x1f\x99\xe6\x8c\xa6\x96\x8f\x3c\xca\x6d\xfe\x0f\xb9\xf4\xfa\xb4\xfa\x13\x5d\x55\x42\xea\x3f\x01"+ , vecPub =+ "\xdf\x97\x05\xf5\x8e\xdb\xab\x80\x2c\x7f\x83\x63\xcf\xe5\x56\x0a\xb1\xc6\x13\x2c\x20\xa9\xf1\xdd\x16\x34\x83\xa2\x6f\x8a\xc5\x3a\x39\xd6\x80\x8b\xf4\xa1\xdf\xbd\x26\x1b\x09\x9b\xb0\x3b\x3f\xb5\x09\x06\xcb\x28\xbd\x8a\x08\x1f\x00"+ , vecMsg =+ "\xbd\x0f\x6a\x37\x47\xcd\x56\x1b\xdd\xdf\x46\x40\xa3\x32\x46\x1a\x4a\x30\xa1\x2a\x43\x4c\xd0\xbf\x40\xd7\x66\xd9\xc6\xd4\x58\xe5\x51\x22\x04\xa3\x0c\x17\xd1\xf5\x0b\x50\x79\x63\x1f\x64\xeb\x31\x12\x18\x2d\xa3\x00\x58\x35\x46\x11\x13\x71\x8d\x1a\x5e\xf9\x44"+ , vecSig =+ "\x55\x4b\xc2\x48\x08\x60\xb4\x9e\xab\x85\x32\xd2\xa5\x33\xb7\xd5\x78\xef\x47\x3e\xeb\x58\xc9\x8b\xb2\xd0\xe1\xce\x48\x8a\x98\xb1\x8d\xfd\xe9\xb9\xb9\x07\x75\xe6\x7f\x47\xd4\xa1\xc3\x48\x20\x58\xef\xc9\xf4\x0d\x2c\xa0\x33\xa0\x80\x1b\x63\xd4\x5b\x3b\x72\x2e\xf5\x52\xba\xd3\xb4\xcc\xb6\x67\xda\x35\x01\x92\xb6\x1c\x50\x8c\xf7\xb6\xb5\xad\xad\xc2\xc8\xd9\xa4\x46\xef\x00\x3f\xb0\x5c\xba\x5f\x30\xe8\x8e\x36\xec\x27\x03\xb3\x49\xca\x22\x9c\x26\x70\x83\x39\x00" } , Vec- { vecSec = "\x2e\xc5\xfe\x3c\x17\x04\x5a\xbd\xb1\x36\xa5\xe6\xa9\x13\xe3\x2a\xb7\x5a\xe6\x8b\x53\xd2\xfc\x14\x9b\x77\xe5\x04\x13\x2d\x37\x56\x9b\x7e\x76\x6b\xa7\x4a\x19\xbd\x61\x62\x34\x3a\x21\xc8\x59\x0a\xa9\xce\xbc\xa9\x01\x4c\x63\x6d\xf5"- , vecPub = "\x79\x75\x6f\x01\x4d\xcf\xe2\x07\x9f\x5d\xd9\xe7\x18\xbe\x41\x71\xe2\xef\x24\x86\xa0\x8f\x25\x18\x6f\x6b\xff\x43\xa9\x93\x6b\x9b\xfe\x12\x40\x2b\x08\xae\x65\x79\x8a\x3d\x81\xe2\x2e\x9e\xc8\x0e\x76\x90\x86\x2e\xf3\xd4\xed\x3a\x00"- , vecMsg = "\x15\x77\x75\x32\xb0\xbd\xd0\xd1\x38\x9f\x63\x6c\x5f\x6b\x9b\xa7\x34\xc9\x0a\xf5\x72\x87\x7e\x2d\x27\x2d\xd0\x78\xaa\x1e\x56\x7c\xfa\x80\xe1\x29\x28\xbb\x54\x23\x30\xe8\x40\x9f\x31\x74\x50\x41\x07\xec\xd5\xef\xac\x61\xae\x75\x04\xda\xbe\x2a\x60\x2e\xde\x89\xe5\xcc\xa6\x25\x7a\x7c\x77\xe2\x7a\x70\x2b\x3a\xe3\x9f\xc7\x69\xfc\x54\xf2\x39\x5a\xe6\xa1\x17\x8c\xab\x47\x38\xe5\x43\x07\x2f\xc1\xc1\x77\xfe\x71\xe9\x2e\x25\xbf\x03\xe4\xec\xb7\x2f\x47\xb6\x4d\x04\x65\xaa\xea\x4c\x7f\xad\x37\x25\x36\xc8\xba\x51\x6a\x60\x39\xc3\xc2\xa3\x9f\x0e\x4d\x83\x2b\xe4\x32\xdf\xa9\xa7\x06\xa6\xe5\xc7\xe1\x9f\x39\x79\x64\xca\x42\x58\x00\x2f\x7c\x05\x41\xb5\x90\x31\x6d\xbc\x56\x22\xb6\xb2\xa6\xfe\x7a\x4a\xbf\xfd\x96\x10\x5e\xca\x76\xea\x7b\x98\x81\x6a\xf0\x74\x8c\x10\xdf\x04\x8c\xe0\x12\xd9\x01\x01\x5a\x51\xf1\x89\xf3\x88\x81\x45\xc0\x36\x50\xaa\x23\xce\x89\x4c\x3b\xd8\x89\xe0\x30\xd5\x65\x07\x1c\x59\xf4\x09\xa9\x98\x1b\x51\x87\x8f\xd6\xfc\x11\x06\x24\xdc\xbc\xde\x0b\xf7\xa6\x9c\xcc\xe3\x8f\xab\xdf\x86\xf3\xbe\xf6\x04\x48\x19\xde\x11"- , vecSig = "\xc6\x50\xdd\xbb\x06\x01\xc1\x9c\xa1\x14\x39\xe1\x64\x0d\xd9\x31\xf4\x3c\x51\x8e\xa5\xbe\xa7\x0d\x3d\xcd\xe5\xf4\x19\x1f\xe5\x3f\x00\xcf\x96\x65\x46\xb7\x2b\xcc\x7d\x58\xbe\x2b\x9b\xad\xef\x28\x74\x39\x54\xe3\xa4\x4a\x23\xf8\x80\xe8\xd4\xf1\xcf\xce\x2d\x7a\x61\x45\x2d\x26\xda\x05\x89\x6f\x0a\x50\xda\x66\xa2\x39\xa8\xa1\x88\xb6\xd8\x25\xb3\x30\x5a\xd7\x7b\x73\xfb\xac\x08\x36\xec\xc6\x09\x87\xfd\x08\x52\x7c\x1a\x8e\x80\xd5\x82\x3e\x65\xca\xfe\x2a\x3d\x00"+ { vecSec =+ "\x2e\xc5\xfe\x3c\x17\x04\x5a\xbd\xb1\x36\xa5\xe6\xa9\x13\xe3\x2a\xb7\x5a\xe6\x8b\x53\xd2\xfc\x14\x9b\x77\xe5\x04\x13\x2d\x37\x56\x9b\x7e\x76\x6b\xa7\x4a\x19\xbd\x61\x62\x34\x3a\x21\xc8\x59\x0a\xa9\xce\xbc\xa9\x01\x4c\x63\x6d\xf5"+ , vecPub =+ "\x79\x75\x6f\x01\x4d\xcf\xe2\x07\x9f\x5d\xd9\xe7\x18\xbe\x41\x71\xe2\xef\x24\x86\xa0\x8f\x25\x18\x6f\x6b\xff\x43\xa9\x93\x6b\x9b\xfe\x12\x40\x2b\x08\xae\x65\x79\x8a\x3d\x81\xe2\x2e\x9e\xc8\x0e\x76\x90\x86\x2e\xf3\xd4\xed\x3a\x00"+ , vecMsg =+ "\x15\x77\x75\x32\xb0\xbd\xd0\xd1\x38\x9f\x63\x6c\x5f\x6b\x9b\xa7\x34\xc9\x0a\xf5\x72\x87\x7e\x2d\x27\x2d\xd0\x78\xaa\x1e\x56\x7c\xfa\x80\xe1\x29\x28\xbb\x54\x23\x30\xe8\x40\x9f\x31\x74\x50\x41\x07\xec\xd5\xef\xac\x61\xae\x75\x04\xda\xbe\x2a\x60\x2e\xde\x89\xe5\xcc\xa6\x25\x7a\x7c\x77\xe2\x7a\x70\x2b\x3a\xe3\x9f\xc7\x69\xfc\x54\xf2\x39\x5a\xe6\xa1\x17\x8c\xab\x47\x38\xe5\x43\x07\x2f\xc1\xc1\x77\xfe\x71\xe9\x2e\x25\xbf\x03\xe4\xec\xb7\x2f\x47\xb6\x4d\x04\x65\xaa\xea\x4c\x7f\xad\x37\x25\x36\xc8\xba\x51\x6a\x60\x39\xc3\xc2\xa3\x9f\x0e\x4d\x83\x2b\xe4\x32\xdf\xa9\xa7\x06\xa6\xe5\xc7\xe1\x9f\x39\x79\x64\xca\x42\x58\x00\x2f\x7c\x05\x41\xb5\x90\x31\x6d\xbc\x56\x22\xb6\xb2\xa6\xfe\x7a\x4a\xbf\xfd\x96\x10\x5e\xca\x76\xea\x7b\x98\x81\x6a\xf0\x74\x8c\x10\xdf\x04\x8c\xe0\x12\xd9\x01\x01\x5a\x51\xf1\x89\xf3\x88\x81\x45\xc0\x36\x50\xaa\x23\xce\x89\x4c\x3b\xd8\x89\xe0\x30\xd5\x65\x07\x1c\x59\xf4\x09\xa9\x98\x1b\x51\x87\x8f\xd6\xfc\x11\x06\x24\xdc\xbc\xde\x0b\xf7\xa6\x9c\xcc\xe3\x8f\xab\xdf\x86\xf3\xbe\xf6\x04\x48\x19\xde\x11"+ , vecSig =+ "\xc6\x50\xdd\xbb\x06\x01\xc1\x9c\xa1\x14\x39\xe1\x64\x0d\xd9\x31\xf4\x3c\x51\x8e\xa5\xbe\xa7\x0d\x3d\xcd\xe5\xf4\x19\x1f\xe5\x3f\x00\xcf\x96\x65\x46\xb7\x2b\xcc\x7d\x58\xbe\x2b\x9b\xad\xef\x28\x74\x39\x54\xe3\xa4\x4a\x23\xf8\x80\xe8\xd4\xf1\xcf\xce\x2d\x7a\x61\x45\x2d\x26\xda\x05\x89\x6f\x0a\x50\xda\x66\xa2\x39\xa8\xa1\x88\xb6\xd8\x25\xb3\x30\x5a\xd7\x7b\x73\xfb\xac\x08\x36\xec\xc6\x09\x87\xfd\x08\x52\x7c\x1a\x8e\x80\xd5\x82\x3e\x65\xca\xfe\x2a\x3d\x00" } , Vec- { vecSec = "\x87\x2d\x09\x37\x80\xf5\xd3\x73\x0d\xf7\xc2\x12\x66\x4b\x37\xb8\xa0\xf2\x4f\x56\x81\x0d\xaa\x83\x82\xcd\x4f\xa3\xf7\x76\x34\xec\x44\xdc\x54\xf1\xc2\xed\x9b\xea\x86\xfa\xfb\x76\x32\xd8\xbe\x19\x9e\xa1\x65\xf5\xad\x55\xdd\x9c\xe8"- , vecPub = "\xa8\x1b\x2e\x8a\x70\xa5\xac\x94\xff\xdb\xcc\x9b\xad\xfc\x3f\xeb\x08\x01\xf2\x58\x57\x8b\xb1\x14\xad\x44\xec\xe1\xec\x0e\x79\x9d\xa0\x8e\xff\xb8\x1c\x5d\x68\x5c\x0c\x56\xf6\x4e\xec\xae\xf8\xcd\xf1\x1c\xc3\x87\x37\x83\x8c\xf4\x00"- , vecMsg = "\x6d\xdf\x80\x2e\x1a\xae\x49\x86\x93\x5f\x7f\x98\x1b\xa3\xf0\x35\x1d\x62\x73\xc0\xa0\xc2\x2c\x9c\x0e\x83\x39\x16\x8e\x67\x54\x12\xa3\xde\xbf\xaf\x43\x5e\xd6\x51\x55\x80\x07\xdb\x43\x84\xb6\x50\xfc\xc0\x7e\x3b\x58\x6a\x27\xa4\xf7\xa0\x0a\xc8\xa6\xfe\xc2\xcd\x86\xae\x4b\xf1\x57\x0c\x41\xe6\xa4\x0c\x93\x1d\xb2\x7b\x2f\xaa\x15\xa8\xce\xdd\x52\xcf\xf7\x36\x2c\x4e\x6e\x23\xda\xec\x0f\xbc\x3a\x79\xb6\x80\x6e\x31\x6e\xfc\xc7\xb6\x81\x19\xbf\x46\xbc\x76\xa2\x60\x67\xa5\x3f\x29\x6d\xaf\xdb\xdc\x11\xc7\x7f\x77\x77\xe9\x72\x66\x0c\xf4\xb6\xa9\xb3\x69\xa6\x66\x5f\x02\xe0\xcc\x9b\x6e\xdf\xad\x13\x6b\x4f\xab\xe7\x23\xd2\x81\x3d\xb3\x13\x6c\xfd\xe9\xb6\xd0\x44\x32\x2f\xee\x29\x47\x95\x2e\x03\x1b\x73\xab\x5c\x60\x33\x49\xb3\x07\xbd\xc2\x7b\xc6\xcb\x8b\x8b\xbd\x7b\xd3\x23\x21\x9b\x80\x33\xa5\x81\xb5\x9e\xad\xeb\xb0\x9b\x3c\x4f\x3d\x22\x77\xd4\xf0\x34\x36\x24\xac\xc8\x17\x80\x47\x28\xb2\x5a\xb7\x97\x17\x2b\x4c\x5c\x21\xa2\x2f\x9c\x78\x39\xd6\x43\x00\x23\x2e\xb6\x6e\x53\xf3\x1c\x72\x3f\xa3\x7f\xe3\x87\xc7\xd3\xe5\x0b\xdf\x98\x13\xa3\x0e\x5b\xb1\x2c\xf4\xcd\x93\x0c\x40\xcf\xb4\xe1\xfc\x62\x25\x92\xa4\x95\x88\x79\x44\x94\xd5\x6d\x24\xea\x4b\x40\xc8\x9f\xc0\x59\x6c\xc9\xeb\xb9\x61\xc8\xcb\x10\xad\xde\x97\x6a\x5d\x60\x2b\x1c\x3f\x85\xb9\xb9\xa0\x01\xed\x3c\x6a\x4d\x3b\x14\x37\xf5\x20\x96\xcd\x19\x56\xd0\x42\xa5\x97\xd5\x61\xa5\x96\xec\xd3\xd1\x73\x5a\x8d\x57\x0e\xa0\xec\x27\x22\x5a\x2c\x4a\xaf\xf2\x63\x06\xd1\x52\x6c\x1a\xf3\xca\x6d\x9c\xf5\xa2\xc9\x8f\x47\xe1\xc4\x6d\xb9\xa3\x32\x34\xcf\xd4\xd8\x1f\x2c\x98\x53\x8a\x09\xeb\xe7\x69\x98\xd0\xd8\xfd\x25\x99\x7c\x7d\x25\x5c\x6d\x66\xec\xe6\xfa\x56\xf1\x11\x44\x95\x0f\x02\x77\x95\xe6\x53\x00\x8f\x4b\xd7\xca\x2d\xee\x85\xd8\xe9\x0f\x3d\xc3\x15\x13\x0c\xe2\xa0\x03\x75\xa3\x18\xc7\xc3\xd9\x7b\xe2\xc8\xce\x5b\x6d\xb4\x1a\x62\x54\xff\x26\x4f\xa6\x15\x5b\xae\xe3\xb0\x77\x3c\x0f\x49\x7c\x57\x3f\x19\xbb\x4f\x42\x40\x28\x1f\x0b\x1f\x4f\x7b\xe8\x57\xa4\xe5\x9d\x41\x6c\x06\xb4\xc5\x0f\xa0\x9e\x18\x10\xdd\xc6\xb1\x46\x7b\xae\xac\x5a\x36\x68\xd1\x1b\x6e\xca\xa9\x01\x44\x00\x16\xf3\x89\xf8\x0a\xcc\x4d\xb9\x77\x02\x5e\x7f\x59\x24\x38\x8c\x7e\x34\x0a\x73\x2e\x55\x44\x40\xe7\x65\x70\xf8\xdd\x71\xb7\xd6\x40\xb3\x45\x0d\x1f\xd5\xf0\x41\x0a\x18\xf9\xa3\x49\x4f\x70\x7c\x71\x7b\x79\xb4\xbf\x75\xc9\x84\x00\xb0\x96\xb2\x16\x53\xb5\xd2\x17\xcf\x35\x65\xc9\x59\x74\x56\xf7\x07\x03\x49\x7a\x07\x87\x63\x82\x9b\xc0\x1b\xb1\xcb\xc8\xfa\x04\xea\xdc\x9a\x6e\x3f\x66\x99\x58\x7a\x9e\x75\xc9\x4e\x5b\xab\x00\x36\xe0\xb2\xe7\x11\x39\x2c\xff\x00\x47\xd0\xd6\xb0\x5b\xd2\xa5\x88\xbc\x10\x97\x18\x95\x42\x59\xf1\xd8\x66\x78\xa5\x79\xa3\x12\x0f\x19\xcf\xb2\x96\x3f\x17\x7a\xeb\x70\xf2\xd4\x84\x48\x26\x26\x2e\x51\xb8\x02\x71\x27\x20\x68\xef\x5b\x38\x56\xfa\x85\x35\xaa\x2a\x88\xb2\xd4\x1f\x2a\x0e\x2f\xda\x76\x24\xc2\x85\x02\x72\xac\x4a\x2f\x56\x1f\x8f\x2f\x7a\x31\x8b\xfd\x5c\xaf\x96\x96\x14\x9e\x4a\xc8\x24\xad\x34\x60\x53\x8f\xdc\x25\x42\x1b\xee\xc2\xcc\x68\x18\x16\x2d\x06\xbb\xed\x0c\x40\xa3\x87\x19\x23\x49\xdb\x67\xa1\x18\xba\xda\x6c\xd5\xab\x01\x40\xee\x27\x32\x04\xf6\x28\xaa\xd1\xc1\x35\xf7\x70\x27\x9a\x65\x1e\x24\xd8\xc1\x4d\x75\xa6\x05\x9d\x76\xb9\x6a\x6f\xd8\x57\xde\xf5\xe0\xb3\x54\xb2\x7a\xb9\x37\xa5\x81\x5d\x16\xb5\xfa\xe4\x07\xff\x18\x22\x2c\x6d\x1e\xd2\x63\xbe\x68\xc9\x5f\x32\xd9\x08\xbd\x89\x5c\xd7\x62\x07\xae\x72\x64\x87\x56\x7f\x9a\x67\xda\xd7\x9a\xbe\xc3\x16\xf6\x83\xb1\x7f\x2d\x02\xbf\x07\xe0\xac\x8b\x5b\xc6\x16\x2c\xf9\x46\x97\xb3\xc2\x7c\xd1\xfe\xa4\x9b\x27\xf2\x3b\xa2\x90\x18\x71\x96\x25\x06\x52\x0c\x39\x2d\xa8\xb6\xad\x0d\x99\xf7\x01\x3f\xbc\x06\xc2\xc1\x7a\x56\x95\x00\xc8\xa7\x69\x64\x81\xc1\xcd\x33\xe9\xb1\x4e\x40\xb8\x2e\x79\xa5\xf5\xdb\x82\x57\x1b\xa9\x7b\xae\x3a\xd3\xe0\x47\x95\x15\xbb\x0e\x2b\x0f\x3b\xfc\xd1\xfd\x33\x03\x4e\xfc\x62\x45\xed\xdd\x7e\xe2\x08\x6d\xda\xe2\x60\x0d\x8c\xa7\x3e\x21\x4e\x8c\x2b\x0b\xdb\x2b\x04\x7c\x6a\x46\x4a\x56\x2e\xd7\x7b\x73\xd2\xd8\x41\xc4\xb3\x49\x73\x55\x12\x57\x71\x3b\x75\x36\x32\xef\xba\x34\x81\x69\xab\xc9\x0a\x68\xf4\x26\x11\xa4\x01\x26\xd7\xcb\x21\xb5\x86\x95\x56\x81\x86\xf7\xe5\x69\xd2\xff\x0f\x9e\x74\x5d\x04\x87\xdd\x2e\xb9\x97\xca\xfc\x5a\xbf\x9d\xd1\x02\xe6\x2f\xf6\x6c\xba\x87"- , vecSig = "\xe3\x01\x34\x5a\x41\xa3\x9a\x4d\x72\xff\xf8\xdf\x69\xc9\x80\x75\xa0\xcc\x08\x2b\x80\x2f\xc9\xb2\xb6\xbc\x50\x3f\x92\x6b\x65\xbd\xdf\x7f\x4c\x8f\x1c\xb4\x9f\x63\x96\xaf\xc8\xa7\x0a\xbe\x6d\x8a\xef\x0d\xb4\x78\xd4\xc6\xb2\x97\x00\x76\xc6\xa0\x48\x4f\xe7\x6d\x76\xb3\xa9\x76\x25\xd7\x9f\x1c\xe2\x40\xe7\xc5\x76\x75\x0d\x29\x55\x28\x28\x6f\x71\x9b\x41\x3d\xe9\xad\xa3\xe8\xeb\x78\xed\x57\x36\x03\xce\x30\xd8\xbb\x76\x17\x85\xdc\x30\xdb\xc3\x20\x86\x9e\x1a\x00"+ { vecSec =+ "\x87\x2d\x09\x37\x80\xf5\xd3\x73\x0d\xf7\xc2\x12\x66\x4b\x37\xb8\xa0\xf2\x4f\x56\x81\x0d\xaa\x83\x82\xcd\x4f\xa3\xf7\x76\x34\xec\x44\xdc\x54\xf1\xc2\xed\x9b\xea\x86\xfa\xfb\x76\x32\xd8\xbe\x19\x9e\xa1\x65\xf5\xad\x55\xdd\x9c\xe8"+ , vecPub =+ "\xa8\x1b\x2e\x8a\x70\xa5\xac\x94\xff\xdb\xcc\x9b\xad\xfc\x3f\xeb\x08\x01\xf2\x58\x57\x8b\xb1\x14\xad\x44\xec\xe1\xec\x0e\x79\x9d\xa0\x8e\xff\xb8\x1c\x5d\x68\x5c\x0c\x56\xf6\x4e\xec\xae\xf8\xcd\xf1\x1c\xc3\x87\x37\x83\x8c\xf4\x00"+ , vecMsg =+ "\x6d\xdf\x80\x2e\x1a\xae\x49\x86\x93\x5f\x7f\x98\x1b\xa3\xf0\x35\x1d\x62\x73\xc0\xa0\xc2\x2c\x9c\x0e\x83\x39\x16\x8e\x67\x54\x12\xa3\xde\xbf\xaf\x43\x5e\xd6\x51\x55\x80\x07\xdb\x43\x84\xb6\x50\xfc\xc0\x7e\x3b\x58\x6a\x27\xa4\xf7\xa0\x0a\xc8\xa6\xfe\xc2\xcd\x86\xae\x4b\xf1\x57\x0c\x41\xe6\xa4\x0c\x93\x1d\xb2\x7b\x2f\xaa\x15\xa8\xce\xdd\x52\xcf\xf7\x36\x2c\x4e\x6e\x23\xda\xec\x0f\xbc\x3a\x79\xb6\x80\x6e\x31\x6e\xfc\xc7\xb6\x81\x19\xbf\x46\xbc\x76\xa2\x60\x67\xa5\x3f\x29\x6d\xaf\xdb\xdc\x11\xc7\x7f\x77\x77\xe9\x72\x66\x0c\xf4\xb6\xa9\xb3\x69\xa6\x66\x5f\x02\xe0\xcc\x9b\x6e\xdf\xad\x13\x6b\x4f\xab\xe7\x23\xd2\x81\x3d\xb3\x13\x6c\xfd\xe9\xb6\xd0\x44\x32\x2f\xee\x29\x47\x95\x2e\x03\x1b\x73\xab\x5c\x60\x33\x49\xb3\x07\xbd\xc2\x7b\xc6\xcb\x8b\x8b\xbd\x7b\xd3\x23\x21\x9b\x80\x33\xa5\x81\xb5\x9e\xad\xeb\xb0\x9b\x3c\x4f\x3d\x22\x77\xd4\xf0\x34\x36\x24\xac\xc8\x17\x80\x47\x28\xb2\x5a\xb7\x97\x17\x2b\x4c\x5c\x21\xa2\x2f\x9c\x78\x39\xd6\x43\x00\x23\x2e\xb6\x6e\x53\xf3\x1c\x72\x3f\xa3\x7f\xe3\x87\xc7\xd3\xe5\x0b\xdf\x98\x13\xa3\x0e\x5b\xb1\x2c\xf4\xcd\x93\x0c\x40\xcf\xb4\xe1\xfc\x62\x25\x92\xa4\x95\x88\x79\x44\x94\xd5\x6d\x24\xea\x4b\x40\xc8\x9f\xc0\x59\x6c\xc9\xeb\xb9\x61\xc8\xcb\x10\xad\xde\x97\x6a\x5d\x60\x2b\x1c\x3f\x85\xb9\xb9\xa0\x01\xed\x3c\x6a\x4d\x3b\x14\x37\xf5\x20\x96\xcd\x19\x56\xd0\x42\xa5\x97\xd5\x61\xa5\x96\xec\xd3\xd1\x73\x5a\x8d\x57\x0e\xa0\xec\x27\x22\x5a\x2c\x4a\xaf\xf2\x63\x06\xd1\x52\x6c\x1a\xf3\xca\x6d\x9c\xf5\xa2\xc9\x8f\x47\xe1\xc4\x6d\xb9\xa3\x32\x34\xcf\xd4\xd8\x1f\x2c\x98\x53\x8a\x09\xeb\xe7\x69\x98\xd0\xd8\xfd\x25\x99\x7c\x7d\x25\x5c\x6d\x66\xec\xe6\xfa\x56\xf1\x11\x44\x95\x0f\x02\x77\x95\xe6\x53\x00\x8f\x4b\xd7\xca\x2d\xee\x85\xd8\xe9\x0f\x3d\xc3\x15\x13\x0c\xe2\xa0\x03\x75\xa3\x18\xc7\xc3\xd9\x7b\xe2\xc8\xce\x5b\x6d\xb4\x1a\x62\x54\xff\x26\x4f\xa6\x15\x5b\xae\xe3\xb0\x77\x3c\x0f\x49\x7c\x57\x3f\x19\xbb\x4f\x42\x40\x28\x1f\x0b\x1f\x4f\x7b\xe8\x57\xa4\xe5\x9d\x41\x6c\x06\xb4\xc5\x0f\xa0\x9e\x18\x10\xdd\xc6\xb1\x46\x7b\xae\xac\x5a\x36\x68\xd1\x1b\x6e\xca\xa9\x01\x44\x00\x16\xf3\x89\xf8\x0a\xcc\x4d\xb9\x77\x02\x5e\x7f\x59\x24\x38\x8c\x7e\x34\x0a\x73\x2e\x55\x44\x40\xe7\x65\x70\xf8\xdd\x71\xb7\xd6\x40\xb3\x45\x0d\x1f\xd5\xf0\x41\x0a\x18\xf9\xa3\x49\x4f\x70\x7c\x71\x7b\x79\xb4\xbf\x75\xc9\x84\x00\xb0\x96\xb2\x16\x53\xb5\xd2\x17\xcf\x35\x65\xc9\x59\x74\x56\xf7\x07\x03\x49\x7a\x07\x87\x63\x82\x9b\xc0\x1b\xb1\xcb\xc8\xfa\x04\xea\xdc\x9a\x6e\x3f\x66\x99\x58\x7a\x9e\x75\xc9\x4e\x5b\xab\x00\x36\xe0\xb2\xe7\x11\x39\x2c\xff\x00\x47\xd0\xd6\xb0\x5b\xd2\xa5\x88\xbc\x10\x97\x18\x95\x42\x59\xf1\xd8\x66\x78\xa5\x79\xa3\x12\x0f\x19\xcf\xb2\x96\x3f\x17\x7a\xeb\x70\xf2\xd4\x84\x48\x26\x26\x2e\x51\xb8\x02\x71\x27\x20\x68\xef\x5b\x38\x56\xfa\x85\x35\xaa\x2a\x88\xb2\xd4\x1f\x2a\x0e\x2f\xda\x76\x24\xc2\x85\x02\x72\xac\x4a\x2f\x56\x1f\x8f\x2f\x7a\x31\x8b\xfd\x5c\xaf\x96\x96\x14\x9e\x4a\xc8\x24\xad\x34\x60\x53\x8f\xdc\x25\x42\x1b\xee\xc2\xcc\x68\x18\x16\x2d\x06\xbb\xed\x0c\x40\xa3\x87\x19\x23\x49\xdb\x67\xa1\x18\xba\xda\x6c\xd5\xab\x01\x40\xee\x27\x32\x04\xf6\x28\xaa\xd1\xc1\x35\xf7\x70\x27\x9a\x65\x1e\x24\xd8\xc1\x4d\x75\xa6\x05\x9d\x76\xb9\x6a\x6f\xd8\x57\xde\xf5\xe0\xb3\x54\xb2\x7a\xb9\x37\xa5\x81\x5d\x16\xb5\xfa\xe4\x07\xff\x18\x22\x2c\x6d\x1e\xd2\x63\xbe\x68\xc9\x5f\x32\xd9\x08\xbd\x89\x5c\xd7\x62\x07\xae\x72\x64\x87\x56\x7f\x9a\x67\xda\xd7\x9a\xbe\xc3\x16\xf6\x83\xb1\x7f\x2d\x02\xbf\x07\xe0\xac\x8b\x5b\xc6\x16\x2c\xf9\x46\x97\xb3\xc2\x7c\xd1\xfe\xa4\x9b\x27\xf2\x3b\xa2\x90\x18\x71\x96\x25\x06\x52\x0c\x39\x2d\xa8\xb6\xad\x0d\x99\xf7\x01\x3f\xbc\x06\xc2\xc1\x7a\x56\x95\x00\xc8\xa7\x69\x64\x81\xc1\xcd\x33\xe9\xb1\x4e\x40\xb8\x2e\x79\xa5\xf5\xdb\x82\x57\x1b\xa9\x7b\xae\x3a\xd3\xe0\x47\x95\x15\xbb\x0e\x2b\x0f\x3b\xfc\xd1\xfd\x33\x03\x4e\xfc\x62\x45\xed\xdd\x7e\xe2\x08\x6d\xda\xe2\x60\x0d\x8c\xa7\x3e\x21\x4e\x8c\x2b\x0b\xdb\x2b\x04\x7c\x6a\x46\x4a\x56\x2e\xd7\x7b\x73\xd2\xd8\x41\xc4\xb3\x49\x73\x55\x12\x57\x71\x3b\x75\x36\x32\xef\xba\x34\x81\x69\xab\xc9\x0a\x68\xf4\x26\x11\xa4\x01\x26\xd7\xcb\x21\xb5\x86\x95\x56\x81\x86\xf7\xe5\x69\xd2\xff\x0f\x9e\x74\x5d\x04\x87\xdd\x2e\xb9\x97\xca\xfc\x5a\xbf\x9d\xd1\x02\xe6\x2f\xf6\x6c\xba\x87"+ , vecSig =+ "\xe3\x01\x34\x5a\x41\xa3\x9a\x4d\x72\xff\xf8\xdf\x69\xc9\x80\x75\xa0\xcc\x08\x2b\x80\x2f\xc9\xb2\xb6\xbc\x50\x3f\x92\x6b\x65\xbd\xdf\x7f\x4c\x8f\x1c\xb4\x9f\x63\x96\xaf\xc8\xa7\x0a\xbe\x6d\x8a\xef\x0d\xb4\x78\xd4\xc6\xb2\x97\x00\x76\xc6\xa0\x48\x4f\xe7\x6d\x76\xb3\xa9\x76\x25\xd7\x9f\x1c\xe2\x40\xe7\xc5\x76\x75\x0d\x29\x55\x28\x28\x6f\x71\x9b\x41\x3d\xe9\xad\xa3\xe8\xeb\x78\xed\x57\x36\x03\xce\x30\xd8\xbb\x76\x17\x85\xdc\x30\xdb\xc3\x20\x86\x9e\x1a\x00" } ] - doPublicKeyTest i vec = testCase (show i) (pub @=? Ed448.toPublic sec) where- !pub = throwCryptoError $ Ed448.publicKey (vecPub vec)- !sec = throwCryptoError $ Ed448.secretKey (vecSec vec)+ !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)) where- !sig = throwCryptoError $ Ed448.signature (vecSig vec)- !pub = throwCryptoError $ Ed448.publicKey (vecPub vec)- !sec = throwCryptoError $ Ed448.secretKey (vecSec vec)+ !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) where- !sig = throwCryptoError $ Ed448.signature (vecSig vec)- !pub = throwCryptoError $ Ed448.publicKey (vecPub vec)-+ !sig = throwCryptoError $ Ed448.signature (vecSig vec)+ !pub = throwCryptoError $ Ed448.publicKey (vecPub vec) -tests = testGroup "Ed448"- [ testCase "gen secretkey" (Ed448.generateSecretKey *> pure ())- , testGroup "gen publickey" $ zipWith doPublicKeyTest [katZero..] vectors- , testGroup "gen signature" $ zipWith doSignatureTest [katZero..] vectors- , testGroup "verify sig" $ zipWith doVerifyTest [katZero..] vectors- ]+tests =+ testGroup+ "Ed448"+ [ testCase "gen secretkey" (Ed448.generateSecretKey *> pure ())+ , testGroup "gen publickey" $ zipWith doPublicKeyTest [katZero ..] vectors+ , testGroup "gen signature" $ zipWith doSignatureTest [katZero ..] vectors+ , testGroup "verify sig" $ zipWith doVerifyTest [katZero ..] vectors+ ]
tests/KAT_EdDSA.hs view
@@ -3,20 +3,23 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-}-module KAT_EdDSA ( tests ) where -import Crypto.Error-import Crypto.ECC-import Crypto.Hash.Algorithms-import Crypto.Hash.IO+module KAT_EdDSA (tests) where++import Crypto.ECC+import Crypto.Error+import Crypto.Hash.Algorithms+import Crypto.Hash.IO import qualified Crypto.PubKey.EdDSA as EdDSA-import Imports+import Imports -data Vec = forall curve hash .- ( EdDSA.EllipticCurveEdDSA curve- , HashAlgorithm hash- , HashDigestSize hash ~ EdDSA.CurveDigestSize curve- ) => Vec+data Vec+ = forall curve hash.+ ( EdDSA.EllipticCurveEdDSA curve+ , HashAlgorithm hash+ , HashDigestSize hash ~ EdDSA.CurveDigestSize curve+ ) =>+ Vec { vecPrx :: Maybe curve , vecAlg :: hash , vecSec :: ByteString@@ -29,78 +32,107 @@ [ Vec { vecPrx = Just Curve_Edwards25519 , vecAlg = SHA512- , vecSec = "\x9d\x61\xb1\x9d\xef\xfd\x5a\x60\xba\x84\x4a\xf4\x92\xec\x2c\xc4\x44\x49\xc5\x69\x7b\x32\x69\x19\x70\x3b\xac\x03\x1c\xae\x7f\x60"- , vecPub = "\xd7\x5a\x98\x01\x82\xb1\x0a\xb7\xd5\x4b\xfe\xd3\xc9\x64\x07\x3a\x0e\xe1\x72\xf3\xda\xa6\x23\x25\xaf\x02\x1a\x68\xf7\x07\x51\x1a"+ , vecSec =+ "\x9d\x61\xb1\x9d\xef\xfd\x5a\x60\xba\x84\x4a\xf4\x92\xec\x2c\xc4\x44\x49\xc5\x69\x7b\x32\x69\x19\x70\x3b\xac\x03\x1c\xae\x7f\x60"+ , vecPub =+ "\xd7\x5a\x98\x01\x82\xb1\x0a\xb7\xd5\x4b\xfe\xd3\xc9\x64\x07\x3a\x0e\xe1\x72\xf3\xda\xa6\x23\x25\xaf\x02\x1a\x68\xf7\x07\x51\x1a" , vecMsg = ""- , vecSig = "\xe5\x56\x43\x00\xc3\x60\xac\x72\x90\x86\xe2\xcc\x80\x6e\x82\x8a\x84\x87\x7f\x1e\xb8\xe5\xd9\x74\xd8\x73\xe0\x65\x22\x49\x01\x55\x5f\xb8\x82\x15\x90\xa3\x3b\xac\xc6\x1e\x39\x70\x1c\xf9\xb4\x6b\xd2\x5b\xf5\xf0\x59\x5b\xbe\x24\x65\x51\x41\x43\x8e\x7a\x10\x0b"+ , vecSig =+ "\xe5\x56\x43\x00\xc3\x60\xac\x72\x90\x86\xe2\xcc\x80\x6e\x82\x8a\x84\x87\x7f\x1e\xb8\xe5\xd9\x74\xd8\x73\xe0\x65\x22\x49\x01\x55\x5f\xb8\x82\x15\x90\xa3\x3b\xac\xc6\x1e\x39\x70\x1c\xf9\xb4\x6b\xd2\x5b\xf5\xf0\x59\x5b\xbe\x24\x65\x51\x41\x43\x8e\x7a\x10\x0b" } , Vec { vecPrx = Just Curve_Edwards25519 , vecAlg = SHA512- , vecSec = "\x4c\xcd\x08\x9b\x28\xff\x96\xda\x9d\xb6\xc3\x46\xec\x11\x4e\x0f\x5b\x8a\x31\x9f\x35\xab\xa6\x24\xda\x8c\xf6\xed\x4f\xb8\xa6\xfb"- , vecPub = "\x3d\x40\x17\xc3\xe8\x43\x89\x5a\x92\xb7\x0a\xa7\x4d\x1b\x7e\xbc\x9c\x98\x2c\xcf\x2e\xc4\x96\x8c\xc0\xcd\x55\xf1\x2a\xf4\x66\x0c"+ , vecSec =+ "\x4c\xcd\x08\x9b\x28\xff\x96\xda\x9d\xb6\xc3\x46\xec\x11\x4e\x0f\x5b\x8a\x31\x9f\x35\xab\xa6\x24\xda\x8c\xf6\xed\x4f\xb8\xa6\xfb"+ , vecPub =+ "\x3d\x40\x17\xc3\xe8\x43\x89\x5a\x92\xb7\x0a\xa7\x4d\x1b\x7e\xbc\x9c\x98\x2c\xcf\x2e\xc4\x96\x8c\xc0\xcd\x55\xf1\x2a\xf4\x66\x0c" , vecMsg = "\x72"- , vecSig = "\x92\xa0\x09\xa9\xf0\xd4\xca\xb8\x72\x0e\x82\x0b\x5f\x64\x25\x40\xa2\xb2\x7b\x54\x16\x50\x3f\x8f\xb3\x76\x22\x23\xeb\xdb\x69\xda\x08\x5a\xc1\xe4\x3e\x15\x99\x6e\x45\x8f\x36\x13\xd0\xf1\x1d\x8c\x38\x7b\x2e\xae\xb4\x30\x2a\xee\xb0\x0d\x29\x16\x12\xbb\x0c\x00"+ , vecSig =+ "\x92\xa0\x09\xa9\xf0\xd4\xca\xb8\x72\x0e\x82\x0b\x5f\x64\x25\x40\xa2\xb2\x7b\x54\x16\x50\x3f\x8f\xb3\x76\x22\x23\xeb\xdb\x69\xda\x08\x5a\xc1\xe4\x3e\x15\x99\x6e\x45\x8f\x36\x13\xd0\xf1\x1d\x8c\x38\x7b\x2e\xae\xb4\x30\x2a\xee\xb0\x0d\x29\x16\x12\xbb\x0c\x00" } , Vec { vecPrx = Just Curve_Edwards25519 , vecAlg = SHA512- , vecSec = "\xc5\xaa\x8d\xf4\x3f\x9f\x83\x7b\xed\xb7\x44\x2f\x31\xdc\xb7\xb1\x66\xd3\x85\x35\x07\x6f\x09\x4b\x85\xce\x3a\x2e\x0b\x44\x58\xf7"- , vecPub = "\xfc\x51\xcd\x8e\x62\x18\xa1\xa3\x8d\xa4\x7e\xd0\x02\x30\xf0\x58\x08\x16\xed\x13\xba\x33\x03\xac\x5d\xeb\x91\x15\x48\x90\x80\x25"+ , vecSec =+ "\xc5\xaa\x8d\xf4\x3f\x9f\x83\x7b\xed\xb7\x44\x2f\x31\xdc\xb7\xb1\x66\xd3\x85\x35\x07\x6f\x09\x4b\x85\xce\x3a\x2e\x0b\x44\x58\xf7"+ , vecPub =+ "\xfc\x51\xcd\x8e\x62\x18\xa1\xa3\x8d\xa4\x7e\xd0\x02\x30\xf0\x58\x08\x16\xed\x13\xba\x33\x03\xac\x5d\xeb\x91\x15\x48\x90\x80\x25" , vecMsg = "\xaf\x82"- , vecSig = "\x62\x91\xd6\x57\xde\xec\x24\x02\x48\x27\xe6\x9c\x3a\xbe\x01\xa3\x0c\xe5\x48\xa2\x84\x74\x3a\x44\x5e\x36\x80\xd7\xdb\x5a\xc3\xac\x18\xff\x9b\x53\x8d\x16\xf2\x90\xae\x67\xf7\x60\x98\x4d\xc6\x59\x4a\x7c\x15\xe9\x71\x6e\xd2\x8d\xc0\x27\xbe\xce\xea\x1e\xc4\x0a"+ , vecSig =+ "\x62\x91\xd6\x57\xde\xec\x24\x02\x48\x27\xe6\x9c\x3a\xbe\x01\xa3\x0c\xe5\x48\xa2\x84\x74\x3a\x44\x5e\x36\x80\xd7\xdb\x5a\xc3\xac\x18\xff\x9b\x53\x8d\x16\xf2\x90\xae\x67\xf7\x60\x98\x4d\xc6\x59\x4a\x7c\x15\xe9\x71\x6e\xd2\x8d\xc0\x27\xbe\xce\xea\x1e\xc4\x0a" } , Vec { vecPrx = Just Curve_Edwards25519 , vecAlg = SHA512- , vecSec = "\xf5\xe5\x76\x7c\xf1\x53\x31\x95\x17\x63\x0f\x22\x68\x76\xb8\x6c\x81\x60\xcc\x58\x3b\xc0\x13\x74\x4c\x6b\xf2\x55\xf5\xcc\x0e\xe5"- , vecPub = "\x27\x81\x17\xfc\x14\x4c\x72\x34\x0f\x67\xd0\xf2\x31\x6e\x83\x86\xce\xff\xbf\x2b\x24\x28\xc9\xc5\x1f\xef\x7c\x59\x7f\x1d\x42\x6e"- , vecMsg = "\x08\xb8\xb2\xb7\x33\x42\x42\x43\x76\x0f\xe4\x26\xa4\xb5\x49\x08\x63\x21\x10\xa6\x6c\x2f\x65\x91\xea\xbd\x33\x45\xe3\xe4\xeb\x98\xfa\x6e\x26\x4b\xf0\x9e\xfe\x12\xee\x50\xf8\xf5\x4e\x9f\x77\xb1\xe3\x55\xf6\xc5\x05\x44\xe2\x3f\xb1\x43\x3d\xdf\x73\xbe\x84\xd8\x79\xde\x7c\x00\x46\xdc\x49\x96\xd9\xe7\x73\xf4\xbc\x9e\xfe\x57\x38\x82\x9a\xdb\x26\xc8\x1b\x37\xc9\x3a\x1b\x27\x0b\x20\x32\x9d\x65\x86\x75\xfc\x6e\xa5\x34\xe0\x81\x0a\x44\x32\x82\x6b\xf5\x8c\x94\x1e\xfb\x65\xd5\x7a\x33\x8b\xbd\x2e\x26\x64\x0f\x89\xff\xbc\x1a\x85\x8e\xfc\xb8\x55\x0e\xe3\xa5\xe1\x99\x8b\xd1\x77\xe9\x3a\x73\x63\xc3\x44\xfe\x6b\x19\x9e\xe5\xd0\x2e\x82\xd5\x22\xc4\xfe\xba\x15\x45\x2f\x80\x28\x8a\x82\x1a\x57\x91\x16\xec\x6d\xad\x2b\x3b\x31\x0d\xa9\x03\x40\x1a\xa6\x21\x00\xab\x5d\x1a\x36\x55\x3e\x06\x20\x3b\x33\x89\x0c\xc9\xb8\x32\xf7\x9e\xf8\x05\x60\xcc\xb9\xa3\x9c\xe7\x67\x96\x7e\xd6\x28\xc6\xad\x57\x3c\xb1\x16\xdb\xef\xef\xd7\x54\x99\xda\x96\xbd\x68\xa8\xa9\x7b\x92\x8a\x8b\xbc\x10\x3b\x66\x21\xfc\xde\x2b\xec\xa1\x23\x1d\x20\x6b\xe6\xcd\x9e\xc7\xaf\xf6\xf6\xc9\x4f\xcd\x72\x04\xed\x34\x55\xc6\x8c\x83\xf4\xa4\x1d\xa4\xaf\x2b\x74\xef\x5c\x53\xf1\xd8\xac\x70\xbd\xcb\x7e\xd1\x85\xce\x81\xbd\x84\x35\x9d\x44\x25\x4d\x95\x62\x9e\x98\x55\xa9\x4a\x7c\x19\x58\xd1\xf8\xad\xa5\xd0\x53\x2e\xd8\xa5\xaa\x3f\xb2\xd1\x7b\xa7\x0e\xb6\x24\x8e\x59\x4e\x1a\x22\x97\xac\xbb\xb3\x9d\x50\x2f\x1a\x8c\x6e\xb6\xf1\xce\x22\xb3\xde\x1a\x1f\x40\xcc\x24\x55\x41\x19\xa8\x31\xa9\xaa\xd6\x07\x9c\xad\x88\x42\x5d\xe6\xbd\xe1\xa9\x18\x7e\xbb\x60\x92\xcf\x67\xbf\x2b\x13\xfd\x65\xf2\x70\x88\xd7\x8b\x7e\x88\x3c\x87\x59\xd2\xc4\xf5\xc6\x5a\xdb\x75\x53\x87\x8a\xd5\x75\xf9\xfa\xd8\x78\xe8\x0a\x0c\x9b\xa6\x3b\xcb\xcc\x27\x32\xe6\x94\x85\xbb\xc9\xc9\x0b\xfb\xd6\x24\x81\xd9\x08\x9b\xec\xcf\x80\xcf\xe2\xdf\x16\xa2\xcf\x65\xbd\x92\xdd\x59\x7b\x07\x07\xe0\x91\x7a\xf4\x8b\xbb\x75\xfe\xd4\x13\xd2\x38\xf5\x55\x5a\x7a\x56\x9d\x80\xc3\x41\x4a\x8d\x08\x59\xdc\x65\xa4\x61\x28\xba\xb2\x7a\xf8\x7a\x71\x31\x4f\x31\x8c\x78\x2b\x23\xeb\xfe\x80\x8b\x82\xb0\xce\x26\x40\x1d\x2e\x22\xf0\x4d\x83\xd1\x25\x5d\xc5\x1a\xdd\xd3\xb7\x5a\x2b\x1a\xe0\x78\x45\x04\xdf\x54\x3a\xf8\x96\x9b\xe3\xea\x70\x82\xff\x7f\xc9\x88\x8c\x14\x4d\xa2\xaf\x58\x42\x9e\xc9\x60\x31\xdb\xca\xd3\xda\xd9\xaf\x0d\xcb\xaa\xaf\x26\x8c\xb8\xfc\xff\xea\xd9\x4f\x3c\x7c\xa4\x95\xe0\x56\xa9\xb4\x7a\xcd\xb7\x51\xfb\x73\xe6\x66\xc6\xc6\x55\xad\xe8\x29\x72\x97\xd0\x7a\xd1\xba\x5e\x43\xf1\xbc\xa3\x23\x01\x65\x13\x39\xe2\x29\x04\xcc\x8c\x42\xf5\x8c\x30\xc0\x4a\xaf\xdb\x03\x8d\xda\x08\x47\xdd\x98\x8d\xcd\xa6\xf3\xbf\xd1\x5c\x4b\x4c\x45\x25\x00\x4a\xa0\x6e\xef\xf8\xca\x61\x78\x3a\xac\xec\x57\xfb\x3d\x1f\x92\xb0\xfe\x2f\xd1\xa8\x5f\x67\x24\x51\x7b\x65\xe6\x14\xad\x68\x08\xd6\xf6\xee\x34\xdf\xf7\x31\x0f\xdc\x82\xae\xbf\xd9\x04\xb0\x1e\x1d\xc5\x4b\x29\x27\x09\x4b\x2d\xb6\x8d\x6f\x90\x3b\x68\x40\x1a\xde\xbf\x5a\x7e\x08\xd7\x8f\xf4\xef\x5d\x63\x65\x3a\x65\x04\x0c\xf9\xbf\xd4\xac\xa7\x98\x4a\x74\xd3\x71\x45\x98\x67\x80\xfc\x0b\x16\xac\x45\x16\x49\xde\x61\x88\xa7\xdb\xdf\x19\x1f\x64\xb5\xfc\x5e\x2a\xb4\x7b\x57\xf7\xf7\x27\x6c\xd4\x19\xc1\x7a\x3c\xa8\xe1\xb9\x39\xae\x49\xe4\x88\xac\xba\x6b\x96\x56\x10\xb5\x48\x01\x09\xc8\xb1\x7b\x80\xe1\xb7\xb7\x50\xdf\xc7\x59\x8d\x5d\x50\x11\xfd\x2d\xcc\x56\x00\xa3\x2e\xf5\xb5\x2a\x1e\xcc\x82\x0e\x30\x8a\xa3\x42\x72\x1a\xac\x09\x43\xbf\x66\x86\xb6\x4b\x25\x79\x37\x65\x04\xcc\xc4\x93\xd9\x7e\x6a\xed\x3f\xb0\xf9\xcd\x71\xa4\x3d\xd4\x97\xf0\x1f\x17\xc0\xe2\xcb\x37\x97\xaa\x2a\x2f\x25\x66\x56\x16\x8e\x6c\x49\x6a\xfc\x5f\xb9\x32\x46\xf6\xb1\x11\x63\x98\xa3\x46\xf1\xa6\x41\xf3\xb0\x41\xe9\x89\xf7\x91\x4f\x90\xcc\x2c\x7f\xff\x35\x78\x76\xe5\x06\xb5\x0d\x33\x4b\xa7\x7c\x22\x5b\xc3\x07\xba\x53\x71\x52\xf3\xf1\x61\x0e\x4e\xaf\xe5\x95\xf6\xd9\xd9\x0d\x11\xfa\xa9\x33\xa1\x5e\xf1\x36\x95\x46\x86\x8a\x7f\x3a\x45\xa9\x67\x68\xd4\x0f\xd9\xd0\x34\x12\xc0\x91\xc6\x31\x5c\xf4\xfd\xe7\xcb\x68\x60\x69\x37\x38\x0d\xb2\xea\xaa\x70\x7b\x4c\x41\x85\xc3\x2e\xdd\xcd\xd3\x06\x70\x5e\x4d\xc1\xff\xc8\x72\xee\xee\x47\x5a\x64\xdf\xac\x86\xab\xa4\x1c\x06\x18\x98\x3f\x87\x41\xc5\xef\x68\xd3\xa1\x01\xe8\xa3\xb8\xca\xc6\x0c\x90\x5c\x15\xfc\x91\x08\x40\xb9\x4c\x00\xa0\xb9\xd0"- , vecSig = "\x0a\xab\x4c\x90\x05\x01\xb3\xe2\x4d\x7c\xdf\x46\x63\x32\x6a\x3a\x87\xdf\x5e\x48\x43\xb2\xcb\xdb\x67\xcb\xf6\xe4\x60\xfe\xc3\x50\xaa\x53\x71\xb1\x50\x8f\x9f\x45\x28\xec\xea\x23\xc4\x36\xd9\x4b\x5e\x8f\xcd\x4f\x68\x1e\x30\xa6\xac\x00\xa9\x70\x4a\x18\x8a\x03"+ , vecSec =+ "\xf5\xe5\x76\x7c\xf1\x53\x31\x95\x17\x63\x0f\x22\x68\x76\xb8\x6c\x81\x60\xcc\x58\x3b\xc0\x13\x74\x4c\x6b\xf2\x55\xf5\xcc\x0e\xe5"+ , vecPub =+ "\x27\x81\x17\xfc\x14\x4c\x72\x34\x0f\x67\xd0\xf2\x31\x6e\x83\x86\xce\xff\xbf\x2b\x24\x28\xc9\xc5\x1f\xef\x7c\x59\x7f\x1d\x42\x6e"+ , vecMsg =+ "\x08\xb8\xb2\xb7\x33\x42\x42\x43\x76\x0f\xe4\x26\xa4\xb5\x49\x08\x63\x21\x10\xa6\x6c\x2f\x65\x91\xea\xbd\x33\x45\xe3\xe4\xeb\x98\xfa\x6e\x26\x4b\xf0\x9e\xfe\x12\xee\x50\xf8\xf5\x4e\x9f\x77\xb1\xe3\x55\xf6\xc5\x05\x44\xe2\x3f\xb1\x43\x3d\xdf\x73\xbe\x84\xd8\x79\xde\x7c\x00\x46\xdc\x49\x96\xd9\xe7\x73\xf4\xbc\x9e\xfe\x57\x38\x82\x9a\xdb\x26\xc8\x1b\x37\xc9\x3a\x1b\x27\x0b\x20\x32\x9d\x65\x86\x75\xfc\x6e\xa5\x34\xe0\x81\x0a\x44\x32\x82\x6b\xf5\x8c\x94\x1e\xfb\x65\xd5\x7a\x33\x8b\xbd\x2e\x26\x64\x0f\x89\xff\xbc\x1a\x85\x8e\xfc\xb8\x55\x0e\xe3\xa5\xe1\x99\x8b\xd1\x77\xe9\x3a\x73\x63\xc3\x44\xfe\x6b\x19\x9e\xe5\xd0\x2e\x82\xd5\x22\xc4\xfe\xba\x15\x45\x2f\x80\x28\x8a\x82\x1a\x57\x91\x16\xec\x6d\xad\x2b\x3b\x31\x0d\xa9\x03\x40\x1a\xa6\x21\x00\xab\x5d\x1a\x36\x55\x3e\x06\x20\x3b\x33\x89\x0c\xc9\xb8\x32\xf7\x9e\xf8\x05\x60\xcc\xb9\xa3\x9c\xe7\x67\x96\x7e\xd6\x28\xc6\xad\x57\x3c\xb1\x16\xdb\xef\xef\xd7\x54\x99\xda\x96\xbd\x68\xa8\xa9\x7b\x92\x8a\x8b\xbc\x10\x3b\x66\x21\xfc\xde\x2b\xec\xa1\x23\x1d\x20\x6b\xe6\xcd\x9e\xc7\xaf\xf6\xf6\xc9\x4f\xcd\x72\x04\xed\x34\x55\xc6\x8c\x83\xf4\xa4\x1d\xa4\xaf\x2b\x74\xef\x5c\x53\xf1\xd8\xac\x70\xbd\xcb\x7e\xd1\x85\xce\x81\xbd\x84\x35\x9d\x44\x25\x4d\x95\x62\x9e\x98\x55\xa9\x4a\x7c\x19\x58\xd1\xf8\xad\xa5\xd0\x53\x2e\xd8\xa5\xaa\x3f\xb2\xd1\x7b\xa7\x0e\xb6\x24\x8e\x59\x4e\x1a\x22\x97\xac\xbb\xb3\x9d\x50\x2f\x1a\x8c\x6e\xb6\xf1\xce\x22\xb3\xde\x1a\x1f\x40\xcc\x24\x55\x41\x19\xa8\x31\xa9\xaa\xd6\x07\x9c\xad\x88\x42\x5d\xe6\xbd\xe1\xa9\x18\x7e\xbb\x60\x92\xcf\x67\xbf\x2b\x13\xfd\x65\xf2\x70\x88\xd7\x8b\x7e\x88\x3c\x87\x59\xd2\xc4\xf5\xc6\x5a\xdb\x75\x53\x87\x8a\xd5\x75\xf9\xfa\xd8\x78\xe8\x0a\x0c\x9b\xa6\x3b\xcb\xcc\x27\x32\xe6\x94\x85\xbb\xc9\xc9\x0b\xfb\xd6\x24\x81\xd9\x08\x9b\xec\xcf\x80\xcf\xe2\xdf\x16\xa2\xcf\x65\xbd\x92\xdd\x59\x7b\x07\x07\xe0\x91\x7a\xf4\x8b\xbb\x75\xfe\xd4\x13\xd2\x38\xf5\x55\x5a\x7a\x56\x9d\x80\xc3\x41\x4a\x8d\x08\x59\xdc\x65\xa4\x61\x28\xba\xb2\x7a\xf8\x7a\x71\x31\x4f\x31\x8c\x78\x2b\x23\xeb\xfe\x80\x8b\x82\xb0\xce\x26\x40\x1d\x2e\x22\xf0\x4d\x83\xd1\x25\x5d\xc5\x1a\xdd\xd3\xb7\x5a\x2b\x1a\xe0\x78\x45\x04\xdf\x54\x3a\xf8\x96\x9b\xe3\xea\x70\x82\xff\x7f\xc9\x88\x8c\x14\x4d\xa2\xaf\x58\x42\x9e\xc9\x60\x31\xdb\xca\xd3\xda\xd9\xaf\x0d\xcb\xaa\xaf\x26\x8c\xb8\xfc\xff\xea\xd9\x4f\x3c\x7c\xa4\x95\xe0\x56\xa9\xb4\x7a\xcd\xb7\x51\xfb\x73\xe6\x66\xc6\xc6\x55\xad\xe8\x29\x72\x97\xd0\x7a\xd1\xba\x5e\x43\xf1\xbc\xa3\x23\x01\x65\x13\x39\xe2\x29\x04\xcc\x8c\x42\xf5\x8c\x30\xc0\x4a\xaf\xdb\x03\x8d\xda\x08\x47\xdd\x98\x8d\xcd\xa6\xf3\xbf\xd1\x5c\x4b\x4c\x45\x25\x00\x4a\xa0\x6e\xef\xf8\xca\x61\x78\x3a\xac\xec\x57\xfb\x3d\x1f\x92\xb0\xfe\x2f\xd1\xa8\x5f\x67\x24\x51\x7b\x65\xe6\x14\xad\x68\x08\xd6\xf6\xee\x34\xdf\xf7\x31\x0f\xdc\x82\xae\xbf\xd9\x04\xb0\x1e\x1d\xc5\x4b\x29\x27\x09\x4b\x2d\xb6\x8d\x6f\x90\x3b\x68\x40\x1a\xde\xbf\x5a\x7e\x08\xd7\x8f\xf4\xef\x5d\x63\x65\x3a\x65\x04\x0c\xf9\xbf\xd4\xac\xa7\x98\x4a\x74\xd3\x71\x45\x98\x67\x80\xfc\x0b\x16\xac\x45\x16\x49\xde\x61\x88\xa7\xdb\xdf\x19\x1f\x64\xb5\xfc\x5e\x2a\xb4\x7b\x57\xf7\xf7\x27\x6c\xd4\x19\xc1\x7a\x3c\xa8\xe1\xb9\x39\xae\x49\xe4\x88\xac\xba\x6b\x96\x56\x10\xb5\x48\x01\x09\xc8\xb1\x7b\x80\xe1\xb7\xb7\x50\xdf\xc7\x59\x8d\x5d\x50\x11\xfd\x2d\xcc\x56\x00\xa3\x2e\xf5\xb5\x2a\x1e\xcc\x82\x0e\x30\x8a\xa3\x42\x72\x1a\xac\x09\x43\xbf\x66\x86\xb6\x4b\x25\x79\x37\x65\x04\xcc\xc4\x93\xd9\x7e\x6a\xed\x3f\xb0\xf9\xcd\x71\xa4\x3d\xd4\x97\xf0\x1f\x17\xc0\xe2\xcb\x37\x97\xaa\x2a\x2f\x25\x66\x56\x16\x8e\x6c\x49\x6a\xfc\x5f\xb9\x32\x46\xf6\xb1\x11\x63\x98\xa3\x46\xf1\xa6\x41\xf3\xb0\x41\xe9\x89\xf7\x91\x4f\x90\xcc\x2c\x7f\xff\x35\x78\x76\xe5\x06\xb5\x0d\x33\x4b\xa7\x7c\x22\x5b\xc3\x07\xba\x53\x71\x52\xf3\xf1\x61\x0e\x4e\xaf\xe5\x95\xf6\xd9\xd9\x0d\x11\xfa\xa9\x33\xa1\x5e\xf1\x36\x95\x46\x86\x8a\x7f\x3a\x45\xa9\x67\x68\xd4\x0f\xd9\xd0\x34\x12\xc0\x91\xc6\x31\x5c\xf4\xfd\xe7\xcb\x68\x60\x69\x37\x38\x0d\xb2\xea\xaa\x70\x7b\x4c\x41\x85\xc3\x2e\xdd\xcd\xd3\x06\x70\x5e\x4d\xc1\xff\xc8\x72\xee\xee\x47\x5a\x64\xdf\xac\x86\xab\xa4\x1c\x06\x18\x98\x3f\x87\x41\xc5\xef\x68\xd3\xa1\x01\xe8\xa3\xb8\xca\xc6\x0c\x90\x5c\x15\xfc\x91\x08\x40\xb9\x4c\x00\xa0\xb9\xd0"+ , vecSig =+ "\x0a\xab\x4c\x90\x05\x01\xb3\xe2\x4d\x7c\xdf\x46\x63\x32\x6a\x3a\x87\xdf\x5e\x48\x43\xb2\xcb\xdb\x67\xcb\xf6\xe4\x60\xfe\xc3\x50\xaa\x53\x71\xb1\x50\x8f\x9f\x45\x28\xec\xea\x23\xc4\x36\xd9\x4b\x5e\x8f\xcd\x4f\x68\x1e\x30\xa6\xac\x00\xa9\x70\x4a\x18\x8a\x03" } , Vec { vecPrx = Just Curve_Edwards25519 , vecAlg = SHA512- , vecSec = "\x83\x3f\xe6\x24\x09\x23\x7b\x9d\x62\xec\x77\x58\x75\x20\x91\x1e\x9a\x75\x9c\xec\x1d\x19\x75\x5b\x7d\xa9\x01\xb9\x6d\xca\x3d\x42"- , vecPub = "\xec\x17\x2b\x93\xad\x5e\x56\x3b\xf4\x93\x2c\x70\xe1\x24\x50\x34\xc3\x54\x67\xef\x2e\xfd\x4d\x64\xeb\xf8\x19\x68\x34\x67\xe2\xbf"- , vecMsg = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f"- , vecSig = "\xdc\x2a\x44\x59\xe7\x36\x96\x33\xa5\x2b\x1b\xf2\x77\x83\x9a\x00\x20\x10\x09\xa3\xef\xbf\x3e\xcb\x69\xbe\xa2\x18\x6c\x26\xb5\x89\x09\x35\x1f\xc9\xac\x90\xb3\xec\xfd\xfb\xc7\xc6\x64\x31\xe0\x30\x3d\xca\x17\x9c\x13\x8a\xc1\x7a\xd9\xbe\xf1\x17\x73\x31\xa7\x04"+ , vecSec =+ "\x83\x3f\xe6\x24\x09\x23\x7b\x9d\x62\xec\x77\x58\x75\x20\x91\x1e\x9a\x75\x9c\xec\x1d\x19\x75\x5b\x7d\xa9\x01\xb9\x6d\xca\x3d\x42"+ , vecPub =+ "\xec\x17\x2b\x93\xad\x5e\x56\x3b\xf4\x93\x2c\x70\xe1\x24\x50\x34\xc3\x54\x67\xef\x2e\xfd\x4d\x64\xeb\xf8\x19\x68\x34\x67\xe2\xbf"+ , vecMsg =+ "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f"+ , vecSig =+ "\xdc\x2a\x44\x59\xe7\x36\x96\x33\xa5\x2b\x1b\xf2\x77\x83\x9a\x00\x20\x10\x09\xa3\xef\xbf\x3e\xcb\x69\xbe\xa2\x18\x6c\x26\xb5\x89\x09\x35\x1f\xc9\xac\x90\xb3\xec\xfd\xfb\xc7\xc6\x64\x31\xe0\x30\x3d\xca\x17\x9c\x13\x8a\xc1\x7a\xd9\xbe\xf1\x17\x73\x31\xa7\x04" } , Vec { vecPrx = Just Curve_Edwards25519 , vecAlg = Blake2b_512- , vecSec = "\x9d\x61\xb1\x9d\xef\xfd\x5a\x60\xba\x84\x4a\xf4\x92\xec\x2c\xc4\x44\x49\xc5\x69\x7b\x32\x69\x19\x70\x3b\xac\x03\x1c\xae\x7f\x60"- , vecPub = "\x78\xe6\x5b\xf3\x0f\x89\x3d\x32\xfc\x57\xef\x05\x1c\x34\x1b\xde\xde\x24\x25\x44\xfc\x2a\x21\x12\xf0\xfa\x2c\x7a\xfd\xeb\xc0\x2f"+ , vecSec =+ "\x9d\x61\xb1\x9d\xef\xfd\x5a\x60\xba\x84\x4a\xf4\x92\xec\x2c\xc4\x44\x49\xc5\x69\x7b\x32\x69\x19\x70\x3b\xac\x03\x1c\xae\x7f\x60"+ , vecPub =+ "\x78\xe6\x5b\xf3\x0f\x89\x3d\x32\xfc\x57\xef\x05\x1c\x34\x1b\xde\xde\x24\x25\x44\xfc\x2a\x21\x12\xf0\xfa\x2c\x7a\xfd\xeb\xc0\x2f" , vecMsg = ""- , vecSig = "\x99\xa5\x23\xbd\x46\x16\xc8\x16\x11\x44\xd6\xa9\x9d\x3c\x32\x40\x0c\xb4\xa3\x26\xf4\xd7\x9e\x30\x73\x40\xf6\xaf\xa1\x17\x50\xa0\x08\x5d\x7d\x84\x62\x6b\xc9\xe4\xb1\x53\xfc\x0e\x39\x6d\x15\xce\x44\xc3\x9b\xae\x45\x33\x80\x4d\xb1\xfe\x5b\x52\xf2\xb1\xb8\x05"+ , vecSig =+ "\x99\xa5\x23\xbd\x46\x16\xc8\x16\x11\x44\xd6\xa9\x9d\x3c\x32\x40\x0c\xb4\xa3\x26\xf4\xd7\x9e\x30\x73\x40\xf6\xaf\xa1\x17\x50\xa0\x08\x5d\x7d\x84\x62\x6b\xc9\xe4\xb1\x53\xfc\x0e\x39\x6d\x15\xce\x44\xc3\x9b\xae\x45\x33\x80\x4d\xb1\xfe\x5b\x52\xf2\xb1\xb8\x05" } , Vec { vecPrx = Just Curve_Edwards25519 , vecAlg = Blake2b_512- , vecSec = "\x4c\xcd\x08\x9b\x28\xff\x96\xda\x9d\xb6\xc3\x46\xec\x11\x4e\x0f\x5b\x8a\x31\x9f\x35\xab\xa6\x24\xda\x8c\xf6\xed\x4f\xb8\xa6\xfb"- , vecPub = "\x5e\x71\x39\x2d\x91\xe6\xa5\x8f\xed\xeb\x08\x50\x36\x4f\x56\xcd\x15\x8a\x60\x44\x75\x57\xd7\x89\x03\x89\xc9\xb3\xd4\x57\x6d\x4d"+ , vecSec =+ "\x4c\xcd\x08\x9b\x28\xff\x96\xda\x9d\xb6\xc3\x46\xec\x11\x4e\x0f\x5b\x8a\x31\x9f\x35\xab\xa6\x24\xda\x8c\xf6\xed\x4f\xb8\xa6\xfb"+ , vecPub =+ "\x5e\x71\x39\x2d\x91\xe6\xa5\x8f\xed\xeb\x08\x50\x36\x4f\x56\xcd\x15\x8a\x60\x44\x75\x57\xd7\x89\x03\x89\xc9\xb3\xd4\x57\x6d\x4d" , vecMsg = "\x72"- , vecSig = "\x6d\xa7\x5e\x15\xb5\x70\x7f\x4d\xe5\xa1\x53\xc4\x8a\x5d\x83\x9f\xb8\x50\x74\xc3\x8a\xeb\x62\x85\x97\x7f\x03\xa1\x39\x77\x59\x7f\x97\x60\x69\xfd\xb9\x03\xf1\x83\x47\x4a\xaa\x5e\xd0\xcf\xe8\x78\xba\x8e\xf8\x68\xc5\xe4\x7c\xa3\xf9\x6c\xcf\xb3\xa8\x9b\x2a\x06"+ , vecSig =+ "\x6d\xa7\x5e\x15\xb5\x70\x7f\x4d\xe5\xa1\x53\xc4\x8a\x5d\x83\x9f\xb8\x50\x74\xc3\x8a\xeb\x62\x85\x97\x7f\x03\xa1\x39\x77\x59\x7f\x97\x60\x69\xfd\xb9\x03\xf1\x83\x47\x4a\xaa\x5e\xd0\xcf\xe8\x78\xba\x8e\xf8\x68\xc5\xe4\x7c\xa3\xf9\x6c\xcf\xb3\xa8\x9b\x2a\x06" } , Vec { vecPrx = Just Curve_Edwards25519 , vecAlg = Blake2b_512- , vecSec = "\xc5\xaa\x8d\xf4\x3f\x9f\x83\x7b\xed\xb7\x44\x2f\x31\xdc\xb7\xb1\x66\xd3\x85\x35\x07\x6f\x09\x4b\x85\xce\x3a\x2e\x0b\x44\x58\xf7"- , vecPub = "\x8d\x53\xca\x70\xf0\xea\xb2\x3b\x91\x78\x34\x57\x85\xfc\xdb\x69\xed\x67\x23\xf8\x14\x8f\x7e\x33\x9e\x88\x65\x37\x00\xb7\x18\xda"+ , vecSec =+ "\xc5\xaa\x8d\xf4\x3f\x9f\x83\x7b\xed\xb7\x44\x2f\x31\xdc\xb7\xb1\x66\xd3\x85\x35\x07\x6f\x09\x4b\x85\xce\x3a\x2e\x0b\x44\x58\xf7"+ , vecPub =+ "\x8d\x53\xca\x70\xf0\xea\xb2\x3b\x91\x78\x34\x57\x85\xfc\xdb\x69\xed\x67\x23\xf8\x14\x8f\x7e\x33\x9e\x88\x65\x37\x00\xb7\x18\xda" , vecMsg = "\xaf\x82"- , vecSig = "\x7c\xc3\xc1\x38\x52\xbd\x12\xab\xf3\xce\x4c\xa8\xca\x28\x36\xcb\xf8\x6d\xa9\x6c\x46\x34\xc5\x0d\xf3\xfb\x80\xdc\x80\x9e\x29\xdb\x0e\x10\x9c\x36\x13\x53\x40\x7c\x12\x36\xa9\x04\xf6\x36\x86\x8a\xa3\x39\x77\xa9\x9d\x3f\x84\x45\x98\xdb\x15\x38\xb4\x29\x52\x03"+ , vecSig =+ "\x7c\xc3\xc1\x38\x52\xbd\x12\xab\xf3\xce\x4c\xa8\xca\x28\x36\xcb\xf8\x6d\xa9\x6c\x46\x34\xc5\x0d\xf3\xfb\x80\xdc\x80\x9e\x29\xdb\x0e\x10\x9c\x36\x13\x53\x40\x7c\x12\x36\xa9\x04\xf6\x36\x86\x8a\xa3\x39\x77\xa9\x9d\x3f\x84\x45\x98\xdb\x15\x38\xb4\x29\x52\x03" } , Vec { vecPrx = Just Curve_Edwards25519 , vecAlg = Blake2b_512- , vecSec = "\xf5\xe5\x76\x7c\xf1\x53\x31\x95\x17\x63\x0f\x22\x68\x76\xb8\x6c\x81\x60\xcc\x58\x3b\xc0\x13\x74\x4c\x6b\xf2\x55\xf5\xcc\x0e\xe5"- , vecPub = "\x9e\x3c\xa4\x9b\xb2\xd9\xe3\x6b\x8f\x0c\x94\x4a\x7b\x1c\x29\x26\x45\xda\x87\xce\x6f\xa6\xb4\x28\x86\xe5\xd7\xc8\x68\x33\xa7\x14"- , vecMsg = "\x08\xb8\xb2\xb7\x33\x42\x42\x43\x76\x0f\xe4\x26\xa4\xb5\x49\x08\x63\x21\x10\xa6\x6c\x2f\x65\x91\xea\xbd\x33\x45\xe3\xe4\xeb\x98\xfa\x6e\x26\x4b\xf0\x9e\xfe\x12\xee\x50\xf8\xf5\x4e\x9f\x77\xb1\xe3\x55\xf6\xc5\x05\x44\xe2\x3f\xb1\x43\x3d\xdf\x73\xbe\x84\xd8\x79\xde\x7c\x00\x46\xdc\x49\x96\xd9\xe7\x73\xf4\xbc\x9e\xfe\x57\x38\x82\x9a\xdb\x26\xc8\x1b\x37\xc9\x3a\x1b\x27\x0b\x20\x32\x9d\x65\x86\x75\xfc\x6e\xa5\x34\xe0\x81\x0a\x44\x32\x82\x6b\xf5\x8c\x94\x1e\xfb\x65\xd5\x7a\x33\x8b\xbd\x2e\x26\x64\x0f\x89\xff\xbc\x1a\x85\x8e\xfc\xb8\x55\x0e\xe3\xa5\xe1\x99\x8b\xd1\x77\xe9\x3a\x73\x63\xc3\x44\xfe\x6b\x19\x9e\xe5\xd0\x2e\x82\xd5\x22\xc4\xfe\xba\x15\x45\x2f\x80\x28\x8a\x82\x1a\x57\x91\x16\xec\x6d\xad\x2b\x3b\x31\x0d\xa9\x03\x40\x1a\xa6\x21\x00\xab\x5d\x1a\x36\x55\x3e\x06\x20\x3b\x33\x89\x0c\xc9\xb8\x32\xf7\x9e\xf8\x05\x60\xcc\xb9\xa3\x9c\xe7\x67\x96\x7e\xd6\x28\xc6\xad\x57\x3c\xb1\x16\xdb\xef\xef\xd7\x54\x99\xda\x96\xbd\x68\xa8\xa9\x7b\x92\x8a\x8b\xbc\x10\x3b\x66\x21\xfc\xde\x2b\xec\xa1\x23\x1d\x20\x6b\xe6\xcd\x9e\xc7\xaf\xf6\xf6\xc9\x4f\xcd\x72\x04\xed\x34\x55\xc6\x8c\x83\xf4\xa4\x1d\xa4\xaf\x2b\x74\xef\x5c\x53\xf1\xd8\xac\x70\xbd\xcb\x7e\xd1\x85\xce\x81\xbd\x84\x35\x9d\x44\x25\x4d\x95\x62\x9e\x98\x55\xa9\x4a\x7c\x19\x58\xd1\xf8\xad\xa5\xd0\x53\x2e\xd8\xa5\xaa\x3f\xb2\xd1\x7b\xa7\x0e\xb6\x24\x8e\x59\x4e\x1a\x22\x97\xac\xbb\xb3\x9d\x50\x2f\x1a\x8c\x6e\xb6\xf1\xce\x22\xb3\xde\x1a\x1f\x40\xcc\x24\x55\x41\x19\xa8\x31\xa9\xaa\xd6\x07\x9c\xad\x88\x42\x5d\xe6\xbd\xe1\xa9\x18\x7e\xbb\x60\x92\xcf\x67\xbf\x2b\x13\xfd\x65\xf2\x70\x88\xd7\x8b\x7e\x88\x3c\x87\x59\xd2\xc4\xf5\xc6\x5a\xdb\x75\x53\x87\x8a\xd5\x75\xf9\xfa\xd8\x78\xe8\x0a\x0c\x9b\xa6\x3b\xcb\xcc\x27\x32\xe6\x94\x85\xbb\xc9\xc9\x0b\xfb\xd6\x24\x81\xd9\x08\x9b\xec\xcf\x80\xcf\xe2\xdf\x16\xa2\xcf\x65\xbd\x92\xdd\x59\x7b\x07\x07\xe0\x91\x7a\xf4\x8b\xbb\x75\xfe\xd4\x13\xd2\x38\xf5\x55\x5a\x7a\x56\x9d\x80\xc3\x41\x4a\x8d\x08\x59\xdc\x65\xa4\x61\x28\xba\xb2\x7a\xf8\x7a\x71\x31\x4f\x31\x8c\x78\x2b\x23\xeb\xfe\x80\x8b\x82\xb0\xce\x26\x40\x1d\x2e\x22\xf0\x4d\x83\xd1\x25\x5d\xc5\x1a\xdd\xd3\xb7\x5a\x2b\x1a\xe0\x78\x45\x04\xdf\x54\x3a\xf8\x96\x9b\xe3\xea\x70\x82\xff\x7f\xc9\x88\x8c\x14\x4d\xa2\xaf\x58\x42\x9e\xc9\x60\x31\xdb\xca\xd3\xda\xd9\xaf\x0d\xcb\xaa\xaf\x26\x8c\xb8\xfc\xff\xea\xd9\x4f\x3c\x7c\xa4\x95\xe0\x56\xa9\xb4\x7a\xcd\xb7\x51\xfb\x73\xe6\x66\xc6\xc6\x55\xad\xe8\x29\x72\x97\xd0\x7a\xd1\xba\x5e\x43\xf1\xbc\xa3\x23\x01\x65\x13\x39\xe2\x29\x04\xcc\x8c\x42\xf5\x8c\x30\xc0\x4a\xaf\xdb\x03\x8d\xda\x08\x47\xdd\x98\x8d\xcd\xa6\xf3\xbf\xd1\x5c\x4b\x4c\x45\x25\x00\x4a\xa0\x6e\xef\xf8\xca\x61\x78\x3a\xac\xec\x57\xfb\x3d\x1f\x92\xb0\xfe\x2f\xd1\xa8\x5f\x67\x24\x51\x7b\x65\xe6\x14\xad\x68\x08\xd6\xf6\xee\x34\xdf\xf7\x31\x0f\xdc\x82\xae\xbf\xd9\x04\xb0\x1e\x1d\xc5\x4b\x29\x27\x09\x4b\x2d\xb6\x8d\x6f\x90\x3b\x68\x40\x1a\xde\xbf\x5a\x7e\x08\xd7\x8f\xf4\xef\x5d\x63\x65\x3a\x65\x04\x0c\xf9\xbf\xd4\xac\xa7\x98\x4a\x74\xd3\x71\x45\x98\x67\x80\xfc\x0b\x16\xac\x45\x16\x49\xde\x61\x88\xa7\xdb\xdf\x19\x1f\x64\xb5\xfc\x5e\x2a\xb4\x7b\x57\xf7\xf7\x27\x6c\xd4\x19\xc1\x7a\x3c\xa8\xe1\xb9\x39\xae\x49\xe4\x88\xac\xba\x6b\x96\x56\x10\xb5\x48\x01\x09\xc8\xb1\x7b\x80\xe1\xb7\xb7\x50\xdf\xc7\x59\x8d\x5d\x50\x11\xfd\x2d\xcc\x56\x00\xa3\x2e\xf5\xb5\x2a\x1e\xcc\x82\x0e\x30\x8a\xa3\x42\x72\x1a\xac\x09\x43\xbf\x66\x86\xb6\x4b\x25\x79\x37\x65\x04\xcc\xc4\x93\xd9\x7e\x6a\xed\x3f\xb0\xf9\xcd\x71\xa4\x3d\xd4\x97\xf0\x1f\x17\xc0\xe2\xcb\x37\x97\xaa\x2a\x2f\x25\x66\x56\x16\x8e\x6c\x49\x6a\xfc\x5f\xb9\x32\x46\xf6\xb1\x11\x63\x98\xa3\x46\xf1\xa6\x41\xf3\xb0\x41\xe9\x89\xf7\x91\x4f\x90\xcc\x2c\x7f\xff\x35\x78\x76\xe5\x06\xb5\x0d\x33\x4b\xa7\x7c\x22\x5b\xc3\x07\xba\x53\x71\x52\xf3\xf1\x61\x0e\x4e\xaf\xe5\x95\xf6\xd9\xd9\x0d\x11\xfa\xa9\x33\xa1\x5e\xf1\x36\x95\x46\x86\x8a\x7f\x3a\x45\xa9\x67\x68\xd4\x0f\xd9\xd0\x34\x12\xc0\x91\xc6\x31\x5c\xf4\xfd\xe7\xcb\x68\x60\x69\x37\x38\x0d\xb2\xea\xaa\x70\x7b\x4c\x41\x85\xc3\x2e\xdd\xcd\xd3\x06\x70\x5e\x4d\xc1\xff\xc8\x72\xee\xee\x47\x5a\x64\xdf\xac\x86\xab\xa4\x1c\x06\x18\x98\x3f\x87\x41\xc5\xef\x68\xd3\xa1\x01\xe8\xa3\xb8\xca\xc6\x0c\x90\x5c\x15\xfc\x91\x08\x40\xb9\x4c\x00\xa0\xb9\xd0"- , vecSig = "\xd0\x39\x65\xac\x31\x6a\x20\xf5\xa4\x7a\xb2\xd6\x18\x5e\xb3\xf0\xae\xea\x9c\x2e\xb8\xab\xe9\x22\xe9\x6d\x31\x7b\x3b\xd0\xef\x02\xe8\xd4\x7f\xd9\x23\x84\xe2\x86\x15\xeb\x33\x14\xad\xbc\x71\xc4\x67\x59\x96\x09\x9e\x48\x4c\xeb\x16\x28\x47\xc4\x0c\x32\x44\x0e"+ , vecSec =+ "\xf5\xe5\x76\x7c\xf1\x53\x31\x95\x17\x63\x0f\x22\x68\x76\xb8\x6c\x81\x60\xcc\x58\x3b\xc0\x13\x74\x4c\x6b\xf2\x55\xf5\xcc\x0e\xe5"+ , vecPub =+ "\x9e\x3c\xa4\x9b\xb2\xd9\xe3\x6b\x8f\x0c\x94\x4a\x7b\x1c\x29\x26\x45\xda\x87\xce\x6f\xa6\xb4\x28\x86\xe5\xd7\xc8\x68\x33\xa7\x14"+ , vecMsg =+ "\x08\xb8\xb2\xb7\x33\x42\x42\x43\x76\x0f\xe4\x26\xa4\xb5\x49\x08\x63\x21\x10\xa6\x6c\x2f\x65\x91\xea\xbd\x33\x45\xe3\xe4\xeb\x98\xfa\x6e\x26\x4b\xf0\x9e\xfe\x12\xee\x50\xf8\xf5\x4e\x9f\x77\xb1\xe3\x55\xf6\xc5\x05\x44\xe2\x3f\xb1\x43\x3d\xdf\x73\xbe\x84\xd8\x79\xde\x7c\x00\x46\xdc\x49\x96\xd9\xe7\x73\xf4\xbc\x9e\xfe\x57\x38\x82\x9a\xdb\x26\xc8\x1b\x37\xc9\x3a\x1b\x27\x0b\x20\x32\x9d\x65\x86\x75\xfc\x6e\xa5\x34\xe0\x81\x0a\x44\x32\x82\x6b\xf5\x8c\x94\x1e\xfb\x65\xd5\x7a\x33\x8b\xbd\x2e\x26\x64\x0f\x89\xff\xbc\x1a\x85\x8e\xfc\xb8\x55\x0e\xe3\xa5\xe1\x99\x8b\xd1\x77\xe9\x3a\x73\x63\xc3\x44\xfe\x6b\x19\x9e\xe5\xd0\x2e\x82\xd5\x22\xc4\xfe\xba\x15\x45\x2f\x80\x28\x8a\x82\x1a\x57\x91\x16\xec\x6d\xad\x2b\x3b\x31\x0d\xa9\x03\x40\x1a\xa6\x21\x00\xab\x5d\x1a\x36\x55\x3e\x06\x20\x3b\x33\x89\x0c\xc9\xb8\x32\xf7\x9e\xf8\x05\x60\xcc\xb9\xa3\x9c\xe7\x67\x96\x7e\xd6\x28\xc6\xad\x57\x3c\xb1\x16\xdb\xef\xef\xd7\x54\x99\xda\x96\xbd\x68\xa8\xa9\x7b\x92\x8a\x8b\xbc\x10\x3b\x66\x21\xfc\xde\x2b\xec\xa1\x23\x1d\x20\x6b\xe6\xcd\x9e\xc7\xaf\xf6\xf6\xc9\x4f\xcd\x72\x04\xed\x34\x55\xc6\x8c\x83\xf4\xa4\x1d\xa4\xaf\x2b\x74\xef\x5c\x53\xf1\xd8\xac\x70\xbd\xcb\x7e\xd1\x85\xce\x81\xbd\x84\x35\x9d\x44\x25\x4d\x95\x62\x9e\x98\x55\xa9\x4a\x7c\x19\x58\xd1\xf8\xad\xa5\xd0\x53\x2e\xd8\xa5\xaa\x3f\xb2\xd1\x7b\xa7\x0e\xb6\x24\x8e\x59\x4e\x1a\x22\x97\xac\xbb\xb3\x9d\x50\x2f\x1a\x8c\x6e\xb6\xf1\xce\x22\xb3\xde\x1a\x1f\x40\xcc\x24\x55\x41\x19\xa8\x31\xa9\xaa\xd6\x07\x9c\xad\x88\x42\x5d\xe6\xbd\xe1\xa9\x18\x7e\xbb\x60\x92\xcf\x67\xbf\x2b\x13\xfd\x65\xf2\x70\x88\xd7\x8b\x7e\x88\x3c\x87\x59\xd2\xc4\xf5\xc6\x5a\xdb\x75\x53\x87\x8a\xd5\x75\xf9\xfa\xd8\x78\xe8\x0a\x0c\x9b\xa6\x3b\xcb\xcc\x27\x32\xe6\x94\x85\xbb\xc9\xc9\x0b\xfb\xd6\x24\x81\xd9\x08\x9b\xec\xcf\x80\xcf\xe2\xdf\x16\xa2\xcf\x65\xbd\x92\xdd\x59\x7b\x07\x07\xe0\x91\x7a\xf4\x8b\xbb\x75\xfe\xd4\x13\xd2\x38\xf5\x55\x5a\x7a\x56\x9d\x80\xc3\x41\x4a\x8d\x08\x59\xdc\x65\xa4\x61\x28\xba\xb2\x7a\xf8\x7a\x71\x31\x4f\x31\x8c\x78\x2b\x23\xeb\xfe\x80\x8b\x82\xb0\xce\x26\x40\x1d\x2e\x22\xf0\x4d\x83\xd1\x25\x5d\xc5\x1a\xdd\xd3\xb7\x5a\x2b\x1a\xe0\x78\x45\x04\xdf\x54\x3a\xf8\x96\x9b\xe3\xea\x70\x82\xff\x7f\xc9\x88\x8c\x14\x4d\xa2\xaf\x58\x42\x9e\xc9\x60\x31\xdb\xca\xd3\xda\xd9\xaf\x0d\xcb\xaa\xaf\x26\x8c\xb8\xfc\xff\xea\xd9\x4f\x3c\x7c\xa4\x95\xe0\x56\xa9\xb4\x7a\xcd\xb7\x51\xfb\x73\xe6\x66\xc6\xc6\x55\xad\xe8\x29\x72\x97\xd0\x7a\xd1\xba\x5e\x43\xf1\xbc\xa3\x23\x01\x65\x13\x39\xe2\x29\x04\xcc\x8c\x42\xf5\x8c\x30\xc0\x4a\xaf\xdb\x03\x8d\xda\x08\x47\xdd\x98\x8d\xcd\xa6\xf3\xbf\xd1\x5c\x4b\x4c\x45\x25\x00\x4a\xa0\x6e\xef\xf8\xca\x61\x78\x3a\xac\xec\x57\xfb\x3d\x1f\x92\xb0\xfe\x2f\xd1\xa8\x5f\x67\x24\x51\x7b\x65\xe6\x14\xad\x68\x08\xd6\xf6\xee\x34\xdf\xf7\x31\x0f\xdc\x82\xae\xbf\xd9\x04\xb0\x1e\x1d\xc5\x4b\x29\x27\x09\x4b\x2d\xb6\x8d\x6f\x90\x3b\x68\x40\x1a\xde\xbf\x5a\x7e\x08\xd7\x8f\xf4\xef\x5d\x63\x65\x3a\x65\x04\x0c\xf9\xbf\xd4\xac\xa7\x98\x4a\x74\xd3\x71\x45\x98\x67\x80\xfc\x0b\x16\xac\x45\x16\x49\xde\x61\x88\xa7\xdb\xdf\x19\x1f\x64\xb5\xfc\x5e\x2a\xb4\x7b\x57\xf7\xf7\x27\x6c\xd4\x19\xc1\x7a\x3c\xa8\xe1\xb9\x39\xae\x49\xe4\x88\xac\xba\x6b\x96\x56\x10\xb5\x48\x01\x09\xc8\xb1\x7b\x80\xe1\xb7\xb7\x50\xdf\xc7\x59\x8d\x5d\x50\x11\xfd\x2d\xcc\x56\x00\xa3\x2e\xf5\xb5\x2a\x1e\xcc\x82\x0e\x30\x8a\xa3\x42\x72\x1a\xac\x09\x43\xbf\x66\x86\xb6\x4b\x25\x79\x37\x65\x04\xcc\xc4\x93\xd9\x7e\x6a\xed\x3f\xb0\xf9\xcd\x71\xa4\x3d\xd4\x97\xf0\x1f\x17\xc0\xe2\xcb\x37\x97\xaa\x2a\x2f\x25\x66\x56\x16\x8e\x6c\x49\x6a\xfc\x5f\xb9\x32\x46\xf6\xb1\x11\x63\x98\xa3\x46\xf1\xa6\x41\xf3\xb0\x41\xe9\x89\xf7\x91\x4f\x90\xcc\x2c\x7f\xff\x35\x78\x76\xe5\x06\xb5\x0d\x33\x4b\xa7\x7c\x22\x5b\xc3\x07\xba\x53\x71\x52\xf3\xf1\x61\x0e\x4e\xaf\xe5\x95\xf6\xd9\xd9\x0d\x11\xfa\xa9\x33\xa1\x5e\xf1\x36\x95\x46\x86\x8a\x7f\x3a\x45\xa9\x67\x68\xd4\x0f\xd9\xd0\x34\x12\xc0\x91\xc6\x31\x5c\xf4\xfd\xe7\xcb\x68\x60\x69\x37\x38\x0d\xb2\xea\xaa\x70\x7b\x4c\x41\x85\xc3\x2e\xdd\xcd\xd3\x06\x70\x5e\x4d\xc1\xff\xc8\x72\xee\xee\x47\x5a\x64\xdf\xac\x86\xab\xa4\x1c\x06\x18\x98\x3f\x87\x41\xc5\xef\x68\xd3\xa1\x01\xe8\xa3\xb8\xca\xc6\x0c\x90\x5c\x15\xfc\x91\x08\x40\xb9\x4c\x00\xa0\xb9\xd0"+ , vecSig =+ "\xd0\x39\x65\xac\x31\x6a\x20\xf5\xa4\x7a\xb2\xd6\x18\x5e\xb3\xf0\xae\xea\x9c\x2e\xb8\xab\xe9\x22\xe9\x6d\x31\x7b\x3b\xd0\xef\x02\xe8\xd4\x7f\xd9\x23\x84\xe2\x86\x15\xeb\x33\x14\xad\xbc\x71\xc4\x67\x59\x96\x09\x9e\x48\x4c\xeb\x16\x28\x47\xc4\x0c\x32\x44\x0e" } ] - doPublicKeyTest :: Int -> Vec -> TestTree doPublicKeyTest i Vec{..} = testCase (show i) (pub @=? EdDSA.toPublic vecPrx vecAlg sec)@@ -123,9 +155,10 @@ !sig = throwCryptoError $ EdDSA.signature vecPrx vecAlg vecSig !pub = throwCryptoError $ EdDSA.publicKey vecPrx vecAlg vecPub --tests = testGroup "EdDSA"- [ testGroup "gen publickey" $ zipWith doPublicKeyTest [katZero..] vectors- , testGroup "gen signature" $ zipWith doSignatureTest [katZero..] vectors- , testGroup "verify sig" $ zipWith doVerifyTest [katZero..] vectors- ]+tests =+ testGroup+ "EdDSA"+ [ testGroup "gen publickey" $ zipWith doPublicKeyTest [katZero ..] vectors+ , testGroup "gen signature" $ zipWith doSignatureTest [katZero ..] vectors+ , testGroup "verify sig" $ zipWith doVerifyTest [katZero ..] vectors+ ]
tests/KAT_HKDF.hs view
@@ -1,17 +1,17 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_HKDF (tests) where +import Crypto.Hash (HashAlgorithm, SHA256 (..)) import qualified Crypto.KDF.HKDF as HKDF-import Crypto.Hash (SHA256(..), HashAlgorithm) import qualified Data.ByteString as B import Imports - data KDFVector hash = KDFVector- { kdfIKM :: ByteString- , kdfSalt :: ByteString- , kdfInfo :: ByteString+ { kdfIKM :: ByteString+ , kdfSalt :: ByteString+ , kdfInfo :: ByteString , kdfResult :: ByteString } @@ -19,33 +19,369 @@ sha256KDFVectors = [ KDFVector "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"- (B.pack [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c])+ ( B.pack+ [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c]+ ) "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9" "\x3c\xb2\x5f\x25\xfa\xac\xd5\x7a\x90\x43\x4f\x64\xd0\x36\x2f\x2a\x2d\x2d\x0a\x90\xcf\x1a\x5a\x4c\x5d\xb0\x2d\x56\xec\xc4\xc5\xbf\x34\x00\x72\x08\xd5\xb8\x87\x18\x58\x65" , KDFVector- (B.pack [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f])- (B.pack [0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf])- (B.pack [0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff])- (B.pack [0xb1,0x1e,0x39,0x8d,0xc8,0x03,0x27,0xa1,0xc8,0xe7,0xf7,0x8c,0x59,0x6a,0x49,0x34,0x4f,0x01,0x2e,0xda,0x2d,0x4e,0xfa,0xd8,0xa0,0x50,0xcc,0x4c,0x19,0xaf,0xa9,0x7c,0x59,0x04,0x5a,0x99,0xca,0xc7,0x82,0x72,0x71,0xcb,0x41,0xc6,0x5e,0x59,0x0e,0x09,0xda,0x32,0x75,0x60,0x0c,0x2f,0x09,0xb8,0x36,0x77,0x93,0xa9,0xac,0xa3,0xdb,0x71,0xcc,0x30,0xc5,0x81,0x79,0xec,0x3e,0x87,0xc1,0x4c,0x01,0xd5,0xc1,0xf3,0x43,0x4f,0x1d,0x87])+ ( B.pack+ [ 0x00+ , 0x01+ , 0x02+ , 0x03+ , 0x04+ , 0x05+ , 0x06+ , 0x07+ , 0x08+ , 0x09+ , 0x0a+ , 0x0b+ , 0x0c+ , 0x0d+ , 0x0e+ , 0x0f+ , 0x10+ , 0x11+ , 0x12+ , 0x13+ , 0x14+ , 0x15+ , 0x16+ , 0x17+ , 0x18+ , 0x19+ , 0x1a+ , 0x1b+ , 0x1c+ , 0x1d+ , 0x1e+ , 0x1f+ , 0x20+ , 0x21+ , 0x22+ , 0x23+ , 0x24+ , 0x25+ , 0x26+ , 0x27+ , 0x28+ , 0x29+ , 0x2a+ , 0x2b+ , 0x2c+ , 0x2d+ , 0x2e+ , 0x2f+ , 0x30+ , 0x31+ , 0x32+ , 0x33+ , 0x34+ , 0x35+ , 0x36+ , 0x37+ , 0x38+ , 0x39+ , 0x3a+ , 0x3b+ , 0x3c+ , 0x3d+ , 0x3e+ , 0x3f+ , 0x40+ , 0x41+ , 0x42+ , 0x43+ , 0x44+ , 0x45+ , 0x46+ , 0x47+ , 0x48+ , 0x49+ , 0x4a+ , 0x4b+ , 0x4c+ , 0x4d+ , 0x4e+ , 0x4f+ ]+ )+ ( B.pack+ [ 0x60+ , 0x61+ , 0x62+ , 0x63+ , 0x64+ , 0x65+ , 0x66+ , 0x67+ , 0x68+ , 0x69+ , 0x6a+ , 0x6b+ , 0x6c+ , 0x6d+ , 0x6e+ , 0x6f+ , 0x70+ , 0x71+ , 0x72+ , 0x73+ , 0x74+ , 0x75+ , 0x76+ , 0x77+ , 0x78+ , 0x79+ , 0x7a+ , 0x7b+ , 0x7c+ , 0x7d+ , 0x7e+ , 0x7f+ , 0x80+ , 0x81+ , 0x82+ , 0x83+ , 0x84+ , 0x85+ , 0x86+ , 0x87+ , 0x88+ , 0x89+ , 0x8a+ , 0x8b+ , 0x8c+ , 0x8d+ , 0x8e+ , 0x8f+ , 0x90+ , 0x91+ , 0x92+ , 0x93+ , 0x94+ , 0x95+ , 0x96+ , 0x97+ , 0x98+ , 0x99+ , 0x9a+ , 0x9b+ , 0x9c+ , 0x9d+ , 0x9e+ , 0x9f+ , 0xa0+ , 0xa1+ , 0xa2+ , 0xa3+ , 0xa4+ , 0xa5+ , 0xa6+ , 0xa7+ , 0xa8+ , 0xa9+ , 0xaa+ , 0xab+ , 0xac+ , 0xad+ , 0xae+ , 0xaf+ ]+ )+ ( B.pack+ [ 0xb0+ , 0xb1+ , 0xb2+ , 0xb3+ , 0xb4+ , 0xb5+ , 0xb6+ , 0xb7+ , 0xb8+ , 0xb9+ , 0xba+ , 0xbb+ , 0xbc+ , 0xbd+ , 0xbe+ , 0xbf+ , 0xc0+ , 0xc1+ , 0xc2+ , 0xc3+ , 0xc4+ , 0xc5+ , 0xc6+ , 0xc7+ , 0xc8+ , 0xc9+ , 0xca+ , 0xcb+ , 0xcc+ , 0xcd+ , 0xce+ , 0xcf+ , 0xd0+ , 0xd1+ , 0xd2+ , 0xd3+ , 0xd4+ , 0xd5+ , 0xd6+ , 0xd7+ , 0xd8+ , 0xd9+ , 0xda+ , 0xdb+ , 0xdc+ , 0xdd+ , 0xde+ , 0xdf+ , 0xe0+ , 0xe1+ , 0xe2+ , 0xe3+ , 0xe4+ , 0xe5+ , 0xe6+ , 0xe7+ , 0xe8+ , 0xe9+ , 0xea+ , 0xeb+ , 0xec+ , 0xed+ , 0xee+ , 0xef+ , 0xf0+ , 0xf1+ , 0xf2+ , 0xf3+ , 0xf4+ , 0xf5+ , 0xf6+ , 0xf7+ , 0xf8+ , 0xf9+ , 0xfa+ , 0xfb+ , 0xfc+ , 0xfd+ , 0xfe+ , 0xff+ ]+ )+ ( B.pack+ [ 0xb1+ , 0x1e+ , 0x39+ , 0x8d+ , 0xc8+ , 0x03+ , 0x27+ , 0xa1+ , 0xc8+ , 0xe7+ , 0xf7+ , 0x8c+ , 0x59+ , 0x6a+ , 0x49+ , 0x34+ , 0x4f+ , 0x01+ , 0x2e+ , 0xda+ , 0x2d+ , 0x4e+ , 0xfa+ , 0xd8+ , 0xa0+ , 0x50+ , 0xcc+ , 0x4c+ , 0x19+ , 0xaf+ , 0xa9+ , 0x7c+ , 0x59+ , 0x04+ , 0x5a+ , 0x99+ , 0xca+ , 0xc7+ , 0x82+ , 0x72+ , 0x71+ , 0xcb+ , 0x41+ , 0xc6+ , 0x5e+ , 0x59+ , 0x0e+ , 0x09+ , 0xda+ , 0x32+ , 0x75+ , 0x60+ , 0x0c+ , 0x2f+ , 0x09+ , 0xb8+ , 0x36+ , 0x77+ , 0x93+ , 0xa9+ , 0xac+ , 0xa3+ , 0xdb+ , 0x71+ , 0xcc+ , 0x30+ , 0xc5+ , 0x81+ , 0x79+ , 0xec+ , 0x3e+ , 0x87+ , 0xc1+ , 0x4c+ , 0x01+ , 0xd5+ , 0xc1+ , 0xf3+ , 0x43+ , 0x4f+ , 0x1d+ , 0x87+ ]+ ) ] kdfTests :: [TestTree] kdfTests = [ testGroup "sha256" $ concatMap toKDFTest $ zip is sha256KDFVectors ]- where toKDFTest (i, kdfVector) =- [ testCase (show i) (t HKDF.extract kdfVector)- ]-- t :: HashAlgorithm a => (ByteString -> ByteString -> HKDF.PRK a) -> KDFVector a -> Assertion- t ext v =- let prk = ext (kdfSalt v) (kdfIKM v)- in kdfResult v @=? HKDF.expand prk (kdfInfo v) (B.length $ kdfResult v)+ where+ toKDFTest (i, kdfVector) =+ [ testCase (show i) (t HKDF.extract kdfVector)+ ] - is :: [Int]- is = [1..]+ t+ :: HashAlgorithm a+ => (ByteString -> ByteString -> HKDF.PRK a) -> KDFVector a -> Assertion+ t ext v =+ let prk = ext (kdfSalt v) (kdfIKM v)+ in kdfResult v @=? HKDF.expand prk (kdfInfo v) (B.length $ kdfResult v) + is :: [Int]+ is = [1 ..] -tests = testGroup "HKDF"- [ testGroup "KATs" kdfTests- ]+tests =+ testGroup+ "HKDF"+ [ testGroup "KATs" kdfTests+ ]
tests/KAT_HMAC.hs view
@@ -1,11 +1,23 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_HMAC (tests) where +import Crypto.Hash (+ HashAlgorithm,+ Keccak_224 (..),+ Keccak_256 (..),+ Keccak_384 (..),+ Keccak_512 (..),+ MD5 (..),+ SHA1 (..),+ SHA256 (..),+ SHA3_224 (..),+ SHA3_256 (..),+ SHA3_384 (..),+ SHA3_512 (..),+ digestFromByteString,+ ) import qualified Crypto.MAC.HMAC as HMAC-import Crypto.Hash (MD5(..), SHA1(..), SHA256(..)- , Keccak_224(..), Keccak_256(..), Keccak_384(..), Keccak_512(..)- , SHA3_224(..), SHA3_256(..), SHA3_384(..), SHA3_512(..)- , HashAlgorithm, digestFromByteString) import qualified Data.ByteString as B import Imports@@ -27,69 +39,96 @@ md5MACVectors :: [MACVector MD5] md5MACVectors =- [ MACVector B.empty B.empty $ digest "\x74\xe6\xf7\x29\x8a\x9c\x2d\x16\x89\x35\xf5\x8c\x00\x1b\xad\x88"- , MACVector "key" v1 $ digest "\x80\x07\x07\x13\x46\x3e\x77\x49\xb9\x0c\x2d\xc2\x49\x11\xe2\x75"+ [ MACVector B.empty B.empty $+ digest "\x74\xe6\xf7\x29\x8a\x9c\x2d\x16\x89\x35\xf5\x8c\x00\x1b\xad\x88"+ , MACVector "key" v1 $+ digest "\x80\x07\x07\x13\x46\x3e\x77\x49\xb9\x0c\x2d\xc2\x49\x11\xe2\x75" ] sha1MACVectors :: [MACVector SHA1] sha1MACVectors =- [ MACVector B.empty B.empty $ digest "\xfb\xdb\x1d\x1b\x18\xaa\x6c\x08\x32\x4b\x7d\x64\xb7\x1f\xb7\x63\x70\x69\x0e\x1d"- , MACVector "key" v1 $ digest "\xde\x7c\x9b\x85\xb8\xb7\x8a\xa6\xbc\x8a\x7a\x36\xf7\x0a\x90\x70\x1c\x9d\xb4\xd9"+ [ MACVector B.empty B.empty $+ digest+ "\xfb\xdb\x1d\x1b\x18\xaa\x6c\x08\x32\x4b\x7d\x64\xb7\x1f\xb7\x63\x70\x69\x0e\x1d"+ , MACVector "key" v1 $+ digest+ "\xde\x7c\x9b\x85\xb8\xb7\x8a\xa6\xbc\x8a\x7a\x36\xf7\x0a\x90\x70\x1c\x9d\xb4\xd9" ] sha256MACVectors :: [MACVector SHA256] sha256MACVectors =- [ MACVector B.empty B.empty $ digest "\xb6\x13\x67\x9a\x08\x14\xd9\xec\x77\x2f\x95\xd7\x78\xc3\x5f\xc5\xff\x16\x97\xc4\x93\x71\x56\x53\xc6\xc7\x12\x14\x42\x92\xc5\xad"- , MACVector "key" v1 $ digest "\xf7\xbc\x83\xf4\x30\x53\x84\x24\xb1\x32\x98\xe6\xaa\x6f\xb1\x43\xef\x4d\x59\xa1\x49\x46\x17\x59\x97\x47\x9d\xbc\x2d\x1a\x3c\xd8"+ [ MACVector B.empty B.empty $+ digest+ "\xb6\x13\x67\x9a\x08\x14\xd9\xec\x77\x2f\x95\xd7\x78\xc3\x5f\xc5\xff\x16\x97\xc4\x93\x71\x56\x53\xc6\xc7\x12\x14\x42\x92\xc5\xad"+ , MACVector "key" v1 $+ digest+ "\xf7\xbc\x83\xf4\x30\x53\x84\x24\xb1\x32\x98\xe6\xaa\x6f\xb1\x43\xef\x4d\x59\xa1\x49\x46\x17\x59\x97\x47\x9d\xbc\x2d\x1a\x3c\xd8" ] keccak_key1 = "\x4a\x65\x66\x65"-keccak_data1 = "\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20\x6e\x6f\x74\x68\x69\x6e\x67\x3f"+keccak_data1 =+ "\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20\x6e\x6f\x74\x68\x69\x6e\x67\x3f" keccak_224_MAC_Vectors :: [MACVector Keccak_224] keccak_224_MAC_Vectors =- [ MACVector keccak_key1 keccak_data1 $ digest "\xe8\x24\xfe\xc9\x6c\x07\x4f\x22\xf9\x92\x35\xbb\x94\x2d\xa1\x98\x26\x64\xab\x69\x2c\xa8\x50\x10\x53\xcb\xd4\x14"+ [ MACVector keccak_key1 keccak_data1 $+ digest+ "\xe8\x24\xfe\xc9\x6c\x07\x4f\x22\xf9\x92\x35\xbb\x94\x2d\xa1\x98\x26\x64\xab\x69\x2c\xa8\x50\x10\x53\xcb\xd4\x14" ] keccak_256_MAC_Vectors :: [MACVector Keccak_256] keccak_256_MAC_Vectors =- [ MACVector keccak_key1 keccak_data1 $ digest "\xaa\x9a\xed\x44\x8c\x7a\xbc\x8b\x5e\x32\x6f\xfa\x6a\x01\xcd\xed\xf7\xb4\xb8\x31\x88\x14\x68\xc0\x44\xba\x8d\xd4\x56\x63\x69\xa1"+ [ MACVector keccak_key1 keccak_data1 $+ digest+ "\xaa\x9a\xed\x44\x8c\x7a\xbc\x8b\x5e\x32\x6f\xfa\x6a\x01\xcd\xed\xf7\xb4\xb8\x31\x88\x14\x68\xc0\x44\xba\x8d\xd4\x56\x63\x69\xa1" ] keccak_384_MAC_Vectors :: [MACVector Keccak_384] keccak_384_MAC_Vectors =- [ MACVector keccak_key1 keccak_data1 $ digest "\x5a\xf5\xc9\xa7\x7a\x23\xa6\xa9\x3d\x80\x64\x9e\x56\x2a\xb7\x7f\x4f\x35\x52\xe3\xc5\xca\xff\xd9\x3b\xdf\x8b\x3c\xfc\x69\x20\xe3\x02\x3f\xc2\x67\x75\xd9\xdf\x1f\x3c\x94\x61\x31\x46\xad\x2c\x9d"+ [ MACVector keccak_key1 keccak_data1 $+ digest+ "\x5a\xf5\xc9\xa7\x7a\x23\xa6\xa9\x3d\x80\x64\x9e\x56\x2a\xb7\x7f\x4f\x35\x52\xe3\xc5\xca\xff\xd9\x3b\xdf\x8b\x3c\xfc\x69\x20\xe3\x02\x3f\xc2\x67\x75\xd9\xdf\x1f\x3c\x94\x61\x31\x46\xad\x2c\x9d" ] keccak_512_MAC_Vectors :: [MACVector Keccak_512] keccak_512_MAC_Vectors =- [ MACVector keccak_key1 keccak_data1 $ digest "\xc2\x96\x2e\x5b\xbe\x12\x38\x00\x78\x52\xf7\x9d\x81\x4d\xbb\xec\xd4\x68\x2e\x6f\x09\x7d\x37\xa3\x63\x58\x7c\x03\xbf\xa2\xeb\x08\x59\xd8\xd9\xc7\x01\xe0\x4c\xec\xec\xfd\x3d\xd7\xbf\xd4\x38\xf2\x0b\x8b\x64\x8e\x01\xbf\x8c\x11\xd2\x68\x24\xb9\x6c\xeb\xbd\xcb"+ [ MACVector keccak_key1 keccak_data1 $+ digest+ "\xc2\x96\x2e\x5b\xbe\x12\x38\x00\x78\x52\xf7\x9d\x81\x4d\xbb\xec\xd4\x68\x2e\x6f\x09\x7d\x37\xa3\x63\x58\x7c\x03\xbf\xa2\xeb\x08\x59\xd8\xd9\xc7\x01\xe0\x4c\xec\xec\xfd\x3d\xd7\xbf\xd4\x38\xf2\x0b\x8b\x64\x8e\x01\xbf\x8c\x11\xd2\x68\x24\xb9\x6c\xeb\xbd\xcb" ] sha3_key1 = "\x4a\x65\x66\x65"-sha3_data1 = "\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20\x6e\x6f\x74\x68\x69\x6e\x67\x3f"+sha3_data1 =+ "\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20\x6e\x6f\x74\x68\x69\x6e\x67\x3f" sha3_224_MAC_Vectors :: [MACVector SHA3_224] sha3_224_MAC_Vectors =- [ MACVector sha3_key1 sha3_data1 $ digest "\x7f\xdb\x8d\xd8\x8b\xd2\xf6\x0d\x1b\x79\x86\x34\xad\x38\x68\x11\xc2\xcf\xc8\x5b\xfa\xf5\xd5\x2b\xba\xce\x5e\x66"+ [ MACVector sha3_key1 sha3_data1 $+ digest+ "\x7f\xdb\x8d\xd8\x8b\xd2\xf6\x0d\x1b\x79\x86\x34\xad\x38\x68\x11\xc2\xcf\xc8\x5b\xfa\xf5\xd5\x2b\xba\xce\x5e\x66" ] sha3_256_MAC_Vectors :: [MACVector SHA3_256] sha3_256_MAC_Vectors =- [ MACVector sha3_key1 sha3_data1 $ digest "\xc7\xd4\x07\x2e\x78\x88\x77\xae\x35\x96\xbb\xb0\xda\x73\xb8\x87\xc9\x17\x1f\x93\x09\x5b\x29\x4a\xe8\x57\xfb\xe2\x64\x5e\x1b\xa5"+ [ MACVector sha3_key1 sha3_data1 $+ digest+ "\xc7\xd4\x07\x2e\x78\x88\x77\xae\x35\x96\xbb\xb0\xda\x73\xb8\x87\xc9\x17\x1f\x93\x09\x5b\x29\x4a\xe8\x57\xfb\xe2\x64\x5e\x1b\xa5" ] sha3_384_MAC_Vectors :: [MACVector SHA3_384] sha3_384_MAC_Vectors =- [ MACVector sha3_key1 sha3_data1 $ digest "\xf1\x10\x1f\x8c\xbf\x97\x66\xfd\x67\x64\xd2\xed\x61\x90\x3f\x21\xca\x9b\x18\xf5\x7c\xf3\xe1\xa2\x3c\xa1\x35\x08\xa9\x32\x43\xce\x48\xc0\x45\xdc\x00\x7f\x26\xa2\x1b\x3f\x5e\x0e\x9d\xf4\xc2\x0a"+ [ MACVector sha3_key1 sha3_data1 $+ digest+ "\xf1\x10\x1f\x8c\xbf\x97\x66\xfd\x67\x64\xd2\xed\x61\x90\x3f\x21\xca\x9b\x18\xf5\x7c\xf3\xe1\xa2\x3c\xa1\x35\x08\xa9\x32\x43\xce\x48\xc0\x45\xdc\x00\x7f\x26\xa2\x1b\x3f\x5e\x0e\x9d\xf4\xc2\x0a" ] sha3_512_MAC_Vectors :: [MACVector SHA3_512] sha3_512_MAC_Vectors =- [ MACVector sha3_key1 sha3_data1 $ digest "\x5a\x4b\xfe\xab\x61\x66\x42\x7c\x7a\x36\x47\xb7\x47\x29\x2b\x83\x84\x53\x7c\xdb\x89\xaf\xb3\xbf\x56\x65\xe4\xc5\xe7\x09\x35\x0b\x28\x7b\xae\xc9\x21\xfd\x7c\xa0\xee\x7a\x0c\x31\xd0\x22\xa9\x5e\x1f\xc9\x2b\xa9\xd7\x7d\xf8\x83\x96\x02\x75\xbe\xb4\xe6\x20\x24"+ [ MACVector sha3_key1 sha3_data1 $+ digest+ "\x5a\x4b\xfe\xab\x61\x66\x42\x7c\x7a\x36\x47\xb7\x47\x29\x2b\x83\x84\x53\x7c\xdb\x89\xaf\xb3\xbf\x56\x65\xe4\xc5\xe7\x09\x35\x0b\x28\x7b\xae\xc9\x21\xfd\x7c\xa0\xee\x7a\x0c\x31\xd0\x22\xa9\x5e\x1f\xc9\x2b\xa9\xd7\x7d\xf8\x83\x96\x02\x75\xbe\xb4\xe6\x20\x24" ] - macTests :: [TestTree] macTests = [ testGroup "md5" $ concatMap toMACTest $ zip is md5MACVectors@@ -104,16 +143,23 @@ , testGroup "sha3-384" $ concatMap toMACTest $ zip is sha3_384_MAC_Vectors , testGroup "sha3-512" $ concatMap toMACTest $ zip is sha3_512_MAC_Vectors ]- where toMACTest (i, macVector) =- [ testCase (show i) (macResult macVector @=? HMAC.hmac (macKey macVector) (macSecret macVector))- , testCase ("incr-" ++ show i) (macResult macVector @=?- HMAC.finalize (HMAC.update (HMAC.initialize (macKey macVector)) (macSecret macVector)))- ]- is :: [Int]- is = [1..]+ where+ toMACTest (i, macVector) =+ [ testCase+ (show i)+ (macResult macVector @=? HMAC.hmac (macKey macVector) (macSecret macVector))+ , testCase+ ("incr-" ++ show i)+ ( macResult macVector+ @=? HMAC.finalize+ (HMAC.update (HMAC.initialize (macKey macVector)) (macSecret macVector))+ )+ ]+ is :: [Int]+ is = [1 ..] data MacIncremental a = MacIncremental ByteString ByteString (HMAC.HMAC a)- deriving (Show,Eq)+ deriving (Show, Eq) instance HashAlgorithm a => Arbitrary (MacIncremental a) where arbitrary = do@@ -122,12 +168,12 @@ return $ MacIncremental key msg (HMAC.hmac key msg) data MacIncrementalList a = MacIncrementalList ByteString [ByteString] (HMAC.HMAC a)- deriving (Show,Eq)+ deriving (Show, Eq) instance HashAlgorithm a => Arbitrary (MacIncrementalList a) where arbitrary = do- key <- arbitraryBSof 1 89- msgs <- choose (1,20) >>= \n -> replicateM n (arbitraryBSof 1 99)+ key <- arbitraryBSof 1 89+ msgs <- choose (1, 20) >>= \n -> replicateM n (arbitraryBSof 1 99) return $ MacIncrementalList key msgs (HMAC.hmac key (B.concat msgs)) macIncrementalTests :: [TestTree]@@ -141,21 +187,26 @@ , testIncrProperties SHA3_512 ] where- --testIncrProperties :: HashAlgorithm a => a -> [Property]- testIncrProperties a = testGroup (show a)+ -- testIncrProperties :: HashAlgorithm a => a -> [Property]+ testIncrProperties a =+ testGroup+ (show a) [ testProperty "list-one" (prop_inc0 a) , testProperty "list-multi" (prop_inc1 a) ] - prop_inc0 :: HashAlgorithm a => a -> MacIncremental a -> Bool- prop_inc0 _ (MacIncremental secret msg result) =- result `assertEq` HMAC.finalize (HMAC.update (HMAC.initialize secret) msg)+ prop_inc0 :: HashAlgorithm a => a -> MacIncremental a -> Bool+ prop_inc0 _ (MacIncremental secret msg result) =+ result `assertEq` HMAC.finalize (HMAC.update (HMAC.initialize secret) msg) - prop_inc1 :: HashAlgorithm a => a -> MacIncrementalList a -> Bool- prop_inc1 _ (MacIncrementalList secret msgs result) =- result `assertEq` HMAC.finalize (foldl' HMAC.update (HMAC.initialize secret) msgs)+ prop_inc1 :: HashAlgorithm a => a -> MacIncrementalList a -> Bool+ prop_inc1 _ (MacIncrementalList secret msgs result) =+ result+ `assertEq` HMAC.finalize (foldl' HMAC.update (HMAC.initialize secret) msgs) -tests = testGroup "HMAC"- [ testGroup "KATs" macTests- , testGroup "properties" macIncrementalTests- ]+tests =+ testGroup+ "HMAC"+ [ testGroup "KATs" macTests+ , testGroup "properties" macIncrementalTests+ ]
tests/KAT_KMAC.hs view
@@ -3,10 +3,15 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-}+ module KAT_KMAC (tests) where -import Crypto.Hash (SHAKE128(..), SHAKE256(..),- HashAlgorithm, digestFromByteString)+import Crypto.Hash (+ HashAlgorithm,+ SHAKE128 (..),+ SHAKE256 (..),+ digestFromByteString,+ ) import qualified Crypto.MAC.KMAC as KMAC import qualified Data.ByteString as B@@ -15,7 +20,7 @@ data MACVector hash = MACVector { macString :: ByteString- , macKey :: ByteString+ , macKey :: ByteString , macSecret :: ByteString , macResult :: KMAC.KMAC hash }@@ -30,21 +35,27 @@ vectors128 = [ MACVector { macString = ""- , macKey = B.pack [ 0x40 .. 0x5f ]- , macSecret = B.pack [ 0x00 .. 0x03 ]- , macResult = digest "\xe5\x78\x0b\x0d\x3e\xa6\xf7\xd3\xa4\x29\xc5\x70\x6a\xa4\x3a\x00\xfa\xdb\xd7\xd4\x96\x28\x83\x9e\x31\x87\x24\x3f\x45\x6e\xe1\x4e"+ , macKey = B.pack [0x40 .. 0x5f]+ , macSecret = B.pack [0x00 .. 0x03]+ , macResult =+ digest+ "\xe5\x78\x0b\x0d\x3e\xa6\xf7\xd3\xa4\x29\xc5\x70\x6a\xa4\x3a\x00\xfa\xdb\xd7\xd4\x96\x28\x83\x9e\x31\x87\x24\x3f\x45\x6e\xe1\x4e" } , MACVector { macString = "My Tagged Application"- , macKey = B.pack [ 0x40 .. 0x5f ]- , macSecret = B.pack [ 0x00 .. 0x03 ]- , macResult = digest "\x3b\x1f\xba\x96\x3c\xd8\xb0\xb5\x9e\x8c\x1a\x6d\x71\x88\x8b\x71\x43\x65\x1a\xf8\xba\x0a\x70\x70\xc0\x97\x9e\x28\x11\x32\x4a\xa5"+ , macKey = B.pack [0x40 .. 0x5f]+ , macSecret = B.pack [0x00 .. 0x03]+ , macResult =+ digest+ "\x3b\x1f\xba\x96\x3c\xd8\xb0\xb5\x9e\x8c\x1a\x6d\x71\x88\x8b\x71\x43\x65\x1a\xf8\xba\x0a\x70\x70\xc0\x97\x9e\x28\x11\x32\x4a\xa5" } , MACVector { macString = "My Tagged Application"- , macKey = B.pack [ 0x40 .. 0x5f ]- , macSecret = B.pack [ 0x00 .. 0xc7 ]- , macResult = digest "\x1f\x5b\x4e\x6c\xca\x02\x20\x9e\x0d\xcb\x5c\xa6\x35\xb8\x9a\x15\xe2\x71\xec\xc7\x60\x07\x1d\xfd\x80\x5f\xaa\x38\xf9\x72\x92\x30"+ , macKey = B.pack [0x40 .. 0x5f]+ , macSecret = B.pack [0x00 .. 0xc7]+ , macResult =+ digest+ "\x1f\x5b\x4e\x6c\xca\x02\x20\x9e\x0d\xcb\x5c\xa6\x35\xb8\x9a\x15\xe2\x71\xec\xc7\x60\x07\x1d\xfd\x80\x5f\xaa\x38\xf9\x72\x92\x30" } ] @@ -52,21 +63,27 @@ vectors256 = [ MACVector { macString = "My Tagged Application"- , macKey = B.pack [ 0x40 .. 0x5f ]- , macSecret = B.pack [ 0x00 .. 0x03 ]- , macResult = digest "\x20\xc5\x70\xc3\x13\x46\xf7\x03\xc9\xac\x36\xc6\x1c\x03\xcb\x64\xc3\x97\x0d\x0c\xfc\x78\x7e\x9b\x79\x59\x9d\x27\x3a\x68\xd2\xf7\xf6\x9d\x4c\xc3\xde\x9d\x10\x4a\x35\x16\x89\xf2\x7c\xf6\xf5\x95\x1f\x01\x03\xf3\x3f\x4f\x24\x87\x10\x24\xd9\xc2\x77\x73\xa8\xdd"+ , macKey = B.pack [0x40 .. 0x5f]+ , macSecret = B.pack [0x00 .. 0x03]+ , macResult =+ digest+ "\x20\xc5\x70\xc3\x13\x46\xf7\x03\xc9\xac\x36\xc6\x1c\x03\xcb\x64\xc3\x97\x0d\x0c\xfc\x78\x7e\x9b\x79\x59\x9d\x27\x3a\x68\xd2\xf7\xf6\x9d\x4c\xc3\xde\x9d\x10\x4a\x35\x16\x89\xf2\x7c\xf6\xf5\x95\x1f\x01\x03\xf3\x3f\x4f\x24\x87\x10\x24\xd9\xc2\x77\x73\xa8\xdd" } , MACVector { macString = ""- , macKey = B.pack [ 0x40 .. 0x5f ]- , macSecret = B.pack [ 0x00 .. 0xc7 ]- , macResult = digest "\x75\x35\x8c\xf3\x9e\x41\x49\x4e\x94\x97\x07\x92\x7c\xee\x0a\xf2\x0a\x3f\xf5\x53\x90\x4c\x86\xb0\x8f\x21\xcc\x41\x4b\xcf\xd6\x91\x58\x9d\x27\xcf\x5e\x15\x36\x9c\xbb\xff\x8b\x9a\x4c\x2e\xb1\x78\x00\x85\x5d\x02\x35\xff\x63\x5d\xa8\x25\x33\xec\x6b\x75\x9b\x69"+ , macKey = B.pack [0x40 .. 0x5f]+ , macSecret = B.pack [0x00 .. 0xc7]+ , macResult =+ digest+ "\x75\x35\x8c\xf3\x9e\x41\x49\x4e\x94\x97\x07\x92\x7c\xee\x0a\xf2\x0a\x3f\xf5\x53\x90\x4c\x86\xb0\x8f\x21\xcc\x41\x4b\xcf\xd6\x91\x58\x9d\x27\xcf\x5e\x15\x36\x9c\xbb\xff\x8b\x9a\x4c\x2e\xb1\x78\x00\x85\x5d\x02\x35\xff\x63\x5d\xa8\x25\x33\xec\x6b\x75\x9b\x69" } , MACVector { macString = "My Tagged Application"- , macKey = B.pack [ 0x40 .. 0x5f ]- , macSecret = B.pack [ 0x00 .. 0xc7 ]- , macResult = digest "\xb5\x86\x18\xf7\x1f\x92\xe1\xd5\x6c\x1b\x8c\x55\xdd\xd7\xcd\x18\x8b\x97\xb4\xca\x4d\x99\x83\x1e\xb2\x69\x9a\x83\x7d\xa2\xe4\xd9\x70\xfb\xac\xfd\xe5\x00\x33\xae\xa5\x85\xf1\xa2\x70\x85\x10\xc3\x2d\x07\x88\x08\x01\xbd\x18\x28\x98\xfe\x47\x68\x76\xfc\x89\x65"+ , macKey = B.pack [0x40 .. 0x5f]+ , macSecret = B.pack [0x00 .. 0xc7]+ , macResult =+ digest+ "\xb5\x86\x18\xf7\x1f\x92\xe1\xd5\x6c\x1b\x8c\x55\xdd\xd7\xcd\x18\x8b\x97\xb4\xca\x4d\x99\x83\x1e\xb2\x69\x9a\x83\x7d\xa2\xe4\xd9\x70\xfb\xac\xfd\xe5\x00\x33\xae\xa5\x85\xf1\xa2\x70\x85\x10\xc3\x2d\x07\x88\x08\x01\xbd\x18\x28\x98\xfe\x47\x68\x76\xfc\x89\x65" } ] @@ -75,16 +92,20 @@ [ testGroup "SHAKE128" (concatMap toMACTest $ zip is vectors128) , testGroup "SHAKE256" (concatMap toMACTest $ zip is vectors256) ]- where toMACTest (i, MACVector{..}) =- [ testCase (show i) (macResult @=? KMAC.kmac macString macKey macSecret)- , testCase ("incr-" ++ show i) (macResult @=?- KMAC.finalize (KMAC.update (KMAC.initialize macString macKey) macSecret))- ]- is :: [Int]- is = [1..]+ where+ toMACTest (i, MACVector{..}) =+ [ testCase (show i) (macResult @=? KMAC.kmac macString macKey macSecret)+ , testCase+ ("incr-" ++ show i)+ ( macResult+ @=? KMAC.finalize (KMAC.update (KMAC.initialize macString macKey) macSecret)+ )+ ]+ is :: [Int]+ is = [1 ..] data MacIncremental a = MacIncremental ByteString ByteString ByteString (KMAC.KMAC a)- deriving (Show,Eq)+ deriving (Show, Eq) instance KMAC.HashSHAKE a => Arbitrary (MacIncremental a) where arbitrary = do@@ -93,14 +114,15 @@ msg <- arbitraryBSof 1 99 return $ MacIncremental str key msg (KMAC.kmac str key msg) -data MacIncrementalList a = MacIncrementalList ByteString ByteString [ByteString] (KMAC.KMAC a)- deriving (Show,Eq)+data MacIncrementalList a+ = MacIncrementalList ByteString ByteString [ByteString] (KMAC.KMAC a)+ deriving (Show, Eq) instance KMAC.HashSHAKE a => Arbitrary (MacIncrementalList a) where arbitrary = do- str <- arbitraryBSof 0 49- key <- arbitraryBSof 1 89- msgs <- choose (1,20) >>= \n -> replicateM n (arbitraryBSof 1 99)+ str <- arbitraryBSof 0 49+ key <- arbitraryBSof 1 89+ msgs <- choose (1, 20) >>= \n -> replicateM n (arbitraryBSof 1 99) return $ MacIncrementalList str key msgs (KMAC.kmac str key (B.concat msgs)) macIncrementalTests :: [TestTree]@@ -109,21 +131,26 @@ , testIncrProperties "SHAKE256_512" (SHAKE256 :: SHAKE256 512) ] where- testIncrProperties :: KMAC.HashSHAKE a => TestName -> a -> TestTree- testIncrProperties name a = testGroup name+ testIncrProperties :: KMAC.HashSHAKE a => TestName -> a -> TestTree+ testIncrProperties name a =+ testGroup+ name [ testProperty "list-one" (prop_inc0 a) , testProperty "list-multi" (prop_inc1 a) ] - prop_inc0 :: KMAC.HashSHAKE a => a -> MacIncremental a -> Bool- prop_inc0 _ (MacIncremental str secret msg result) =- result `assertEq` KMAC.finalize (KMAC.update (KMAC.initialize str secret) msg)+ prop_inc0 :: KMAC.HashSHAKE a => a -> MacIncremental a -> Bool+ prop_inc0 _ (MacIncremental str secret msg result) =+ result `assertEq` KMAC.finalize (KMAC.update (KMAC.initialize str secret) msg) - prop_inc1 :: KMAC.HashSHAKE a => a -> MacIncrementalList a -> Bool- prop_inc1 _ (MacIncrementalList str secret msgs result) =- result `assertEq` KMAC.finalize (foldl' KMAC.update (KMAC.initialize str secret) msgs)+ prop_inc1 :: KMAC.HashSHAKE a => a -> MacIncrementalList a -> Bool+ prop_inc1 _ (MacIncrementalList str secret msgs result) =+ result+ `assertEq` KMAC.finalize (foldl' KMAC.update (KMAC.initialize str secret) msgs) -tests = testGroup "KMAC"- [ testGroup "KATs" macTests- , testGroup "properties" macIncrementalTests- ]+tests =+ testGroup+ "KMAC"+ [ testGroup "KATs" macTests+ , testGroup "properties" macIncrementalTests+ ]
tests/KAT_MiyaguchiPreneel.hs view
@@ -1,49 +1,55 @@- module KAT_MiyaguchiPreneel (tests) where -import Crypto.Cipher.AES (AES128)-import Crypto.ConstructHash.MiyaguchiPreneel as MiyaguchiPreneel+import Crypto.Cipher.AES (AES128)+import Crypto.ConstructHash.MiyaguchiPreneel as MiyaguchiPreneel -import Imports+import Imports -import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteArray as B import Data.ByteArray.Encoding (Base (Base16), convertFromBase)-+import qualified Data.ByteString.Char8 as B8 runMP128 :: ByteString -> ByteString runMP128 s = B.convert (MiyaguchiPreneel.compute s :: MiyaguchiPreneel AES128) hxs :: String -> ByteString-hxs = either (error . ("hxs:" ++)) id . convertFromBase Base16- . B8.pack . filter (/= ' ')+hxs =+ either (error . ("hxs:" ++)) id+ . convertFromBase Base16+ . B8.pack+ . filter (/= ' ') gAES128 :: TestTree gAES128 =- igroup "aes128"- [ runMP128 B8.empty- @?= hxs "66e94bd4 ef8a2c3b 884cfa59 ca342b2e"- , runMP128 (hxs "01000000 00000000 00000000 00000000")- @?= hxs "46711816 e91d6ff0 59bbbf2b f58e0fd3"- , runMP128 (hxs "00000000 00000000 00000000 00000001")- @?= hxs "58e2fcce fa7e3061 367f1d57 a4e7455b"- , runMP128 (hxs $- "00000000 00000000 00000000 00000000" ++- "01")- @?= hxs "a5ff35ae 097adf5d 646abf5e bf4c16f4"- ]+ igroup+ "aes128"+ [ runMP128 B8.empty+ @?= hxs "66e94bd4 ef8a2c3b 884cfa59 ca342b2e"+ , runMP128 (hxs "01000000 00000000 00000000 00000000")+ @?= hxs "46711816 e91d6ff0 59bbbf2b f58e0fd3"+ , runMP128 (hxs "00000000 00000000 00000000 00000001")+ @?= hxs "58e2fcce fa7e3061 367f1d57 a4e7455b"+ , runMP128+ ( hxs $+ "00000000 00000000 00000000 00000000"+ ++ "01"+ )+ @?= hxs "a5ff35ae 097adf5d 646abf5e bf4c16f4"+ ] igroup :: TestName -> [Assertion] -> TestTree-igroup nm = testGroup nm . zipWith (flip ($)) [1..] . map icase+igroup nm = testGroup nm . zipWith (flip ($)) [1 ..] . map icase where icase c i = testCase (show (i :: Int)) c vectors :: TestTree vectors =- testGroup "KATs"- [ gAES128 ]+ testGroup+ "KATs"+ [gAES128] tests :: TestTree tests =- testGroup "MiyaguchiPreneel"- [ vectors ]+ testGroup+ "MiyaguchiPreneel"+ [vectors]
tests/KAT_OTP.hs view
@@ -1,12 +1,11 @@ {-# LANGUAGE OverloadedStrings #-} --module KAT_OTP- ( tests- )+module KAT_OTP (+ tests,+) where -import Crypto.Hash.Algorithms (SHA1(..), SHA256(..), SHA512(..))+import Crypto.Hash.Algorithms (SHA1 (..), SHA256 (..), SHA512 (..)) import Crypto.OTP import Imports @@ -29,7 +28,7 @@ -- different (see the errata, or the Java example code). totpSHA1Expected :: [(Word64, Word32)] totpSHA1Expected =- [ (59 , 94287082)+ [ (59, 94287082) , (1111111109, 07081804) , (1111111111, 14050471) , (1234567890, 89005924)@@ -39,7 +38,7 @@ totpSHA256Expected :: [(Word64, Word32)] totpSHA256Expected =- [ (59 , 46119246)+ [ (59, 46119246) , (1111111109, 68084774) , (1111111111, 67062674) , (1234567890, 91819424)@@ -49,7 +48,7 @@ totpSHA512Expected :: [(Word64, Word32)] totpSHA512Expected =- [ (59 , 90693936)+ [ (59, 90693936) , (1111111109, 25091201) , (1111111111, 99943326) , (1234567890, 93441116)@@ -57,45 +56,75 @@ , (20000000000, 47863826) ] -otpKey = "12345678901234567890" :: ByteString-totpSHA256Key = "12345678901234567890123456789012" :: ByteString-totpSHA512Key = "1234567890123456789012345678901234567890123456789012345678901234" :: ByteString+otpKey :: ByteString+otpKey = "12345678901234567890" +totpSHA256Key :: ByteString+totpSHA256Key = "12345678901234567890123456789012"++totpSHA512Key :: ByteString+totpSHA512Key =+ "1234567890123456789012345678901234567890123456789012345678901234"++makeKATs :: (Eq a, Show a) => (t -> a) -> [(t, a)] -> [TestTree] makeKATs otp expected = concatMap (makeTest otp) (zip3 is counts otps) where is :: [Int]- is = [1..]+ is = [1 ..] counts = map fst expected- otps = map snd expected+ otps = map snd expected +makeTest :: (Eq a1, Show a2, Show a1) => (t -> a1) -> (a2, t, a1) -> [TestTree] makeTest otp (i, count, password) = [ testCase (show i) (assertEqual "" password (otp count)) ] -Right totpSHA1Params = mkTOTPParams SHA1 0 30 OTP8 TwoSteps-Right totpSHA256Params = mkTOTPParams SHA256 0 30 OTP8 TwoSteps-Right totpSHA512Params = mkTOTPParams SHA512 0 30 OTP8 TwoSteps+totpSHA1Params :: TOTPParams SHA1+totpSHA1Params = case mkTOTPParams SHA1 0 30 OTP8 TwoSteps of+ Right x -> x+ _ -> error "totpSHA1Params" +totpSHA256Params :: TOTPParams SHA256+totpSHA256Params = case mkTOTPParams SHA256 0 30 OTP8 TwoSteps of+ Right x -> x+ _ -> error "totpSHA256Params"++totpSHA512Params :: TOTPParams SHA512+totpSHA512Params = case mkTOTPParams SHA512 0 30 OTP8 TwoSteps of+ Right x -> x+ _ -> error "totpSHA512Params"+ -- resynching with the expected value should just return the current counter + 1+prop_resyncExpected :: Word64 -> Word16 -> Bool prop_resyncExpected ctr window = resynchronize SHA1 OTP6 window key ctr (otp, []) == Just (ctr + 1) where key = "1234" :: ByteString otp = hotp SHA1 OTP6 key ctr --tests = testGroup "OTP"- [ testGroup "HOTP"- [ testGroup "KATs" (makeKATs (hotp SHA1 OTP6 otpKey) hotpExpected)- , testGroup "properties"- [ testProperty "resync-expected" prop_resyncExpected+tests :: TestTree+tests =+ testGroup+ "OTP"+ [ testGroup+ "HOTP"+ [ testGroup "KATs" (makeKATs (hotp SHA1 OTP6 otpKey) hotpExpected)+ , testGroup+ "properties"+ [ testProperty "resync-expected" prop_resyncExpected+ ] ]- ]- , testGroup "TOTP"- [ testGroup "KATs"- [ testGroup "SHA1" (makeKATs (totp totpSHA1Params otpKey) totpSHA1Expected)- , testGroup "SHA256" (makeKATs (totp totpSHA256Params totpSHA256Key) totpSHA256Expected)- , testGroup "SHA512" (makeKATs (totp totpSHA512Params totpSHA512Key) totpSHA512Expected)+ , testGroup+ "TOTP"+ [ testGroup+ "KATs"+ [ testGroup "SHA1" (makeKATs (totp totpSHA1Params otpKey) totpSHA1Expected)+ , testGroup+ "SHA256"+ (makeKATs (totp totpSHA256Params totpSHA256Key) totpSHA256Expected)+ , testGroup+ "SHA512"+ (makeKATs (totp totpSHA512Params totpSHA512Key) totpSHA512Expected)+ ] ] ]- ]
tests/KAT_PBKDF2.hs view
@@ -3,7 +3,7 @@ -- from <http://www.ietf.org/rfc/rfc6070.txt> module KAT_PBKDF2 (tests) where -import Crypto.Hash (SHA1(..), SHA256(..), SHA512(..))+import Crypto.Hash (SHA1 (..), SHA256 (..), SHA512 (..)) import qualified Crypto.KDF.PBKDF2 as PBKDF2 import Data.ByteString (ByteString)@@ -14,76 +14,101 @@ type VectParams = (ByteString, ByteString, Int, Int) -vectors_hmac_sha1 :: [ (VectParams, ByteString) ]+vectors_hmac_sha1 :: [(VectParams, ByteString)] vectors_hmac_sha1 = [- ( ("password","salt",2,20)+ ( ("password", "salt", 2, 20) , "\xea\x6c\x01\x4d\xc7\x2d\x6f\x8c\xcd\x1e\xd9\x2a\xce\x1d\x41\xf0\xd8\xde\x89\x57" )- , ( ("password","salt",4096,20)+ ,+ ( ("password", "salt", 4096, 20) , "\x4b\x00\x79\x01\xb7\x65\x48\x9a\xbe\xad\x49\xd9\x26\xf7\x21\xd0\x65\xa4\x29\xc1" )-- , ( ("passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt", 4096, 25)+ ,+ ( ("passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt", 4096, 25) , "\x3d\x2e\xec\x4f\xe4\x1c\x84\x9b\x80\xc8\xd8\x36\x62\xc0\xe4\x4a\x8b\x29\x1a\x96\x4c\xf2\xf0\x70\x38" )- , ( ("pass\0word", "sa\0lt", 4096, 16)+ ,+ ( ("pass\0word", "sa\0lt", 4096, 16) , "\x56\xfa\x6a\xa7\x55\x48\x09\x9d\xcc\x37\xd7\xf0\x34\x25\xe0\xc3" ) ] -vectors_hmac_sha256 :: [ (VectParams, ByteString) ]+vectors_hmac_sha256 :: [(VectParams, ByteString)] vectors_hmac_sha256 =- [ ( ("password", "salt", 2, 32)+ [+ ( ("password", "salt", 2, 32) , "\xae\x4d\x0c\x95\xaf\x6b\x46\xd3\x2d\x0a\xdf\xf9\x28\xf0\x6d\xd0\x2a\x30\x3f\x8e\xf3\xc2\x51\xdf\xd6\xe2\xd8\x5a\x95\x47\x4c\x43" )- , ( ("passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt", 4096, 40)+ ,+ ( ("passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt", 4096, 40) , "\x34\x8c\x89\xdb\xcb\xd3\x2b\x2f\x32\xd8\x14\xb8\x11\x6e\x84\xcf\x2b\x17\x34\x7e\xbc\x18\x00\x18\x1c\x4e\x2a\x1f\xb8\xdd\x53\xe1\xc6\x35\x51\x8c\x7d\xac\x47\xe9" ) ] -vectors_hmac_sha512 :: [ (VectParams, ByteString) ]+vectors_hmac_sha512 :: [(VectParams, ByteString)] vectors_hmac_sha512 =- [ ( ("password", "salt", 1, 32)+ [+ ( ("password", "salt", 1, 32) , "\x86\x7f\x70\xcf\x1a\xde\x02\xcf\xf3\x75\x25\x99\xa3\xa5\x3d\xc4\xaf\x34\xc7\xa6\x69\x81\x5a\xe5\xd5\x13\x55\x4e\x1c\x8c\xf2\x52" )- , ( ("password", "salt", 2, 32)- , "\xe1\xd9\xc1\x6a\xa6\x81\x70\x8a\x45\xf5\xc7\xc4\xe2\x15\xce\xb6\x6e\x01\x1a\x2e\x9f\x00\x40\x71\x3f\x18\xae\xfd\xb8\x66\xd5\x3c"+ ,+ ( ("password", "salt", 2, 32)+ , "\xe1\xd9\xc1\x6a\xa6\x81\x70\x8a\x45\xf5\xc7\xc4\xe2\x15\xce\xb6\x6e\x01\x1a\x2e\x9f\x00\x40\x71\x3f\x18\xae\xfd\xb8\x66\xd5\x3c" )- , ( ("password", "salt", 4096, 32)- , "\xd1\x97\xb1\xb3\x3d\xb0\x14\x3e\x01\x8b\x12\xf3\xd1\xd1\x47\x9e\x6c\xde\xbd\xcc\x97\xc5\xc0\xf8\x7f\x69\x02\xe0\x72\xf4\x57\xb5"+ ,+ ( ("password", "salt", 4096, 32)+ , "\xd1\x97\xb1\xb3\x3d\xb0\x14\x3e\x01\x8b\x12\xf3\xd1\xd1\x47\x9e\x6c\xde\xbd\xcc\x97\xc5\xc0\xf8\x7f\x69\x02\xe0\x72\xf4\x57\xb5" )- , ( ("passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt", 1, 72)+ ,+ ( ("passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt", 1, 72) , "n\x23\xf2\x76\x38\x08\x4b\x0f\x7e\xa1\x73\x4e\x0d\x98\x41\xf5\x5d\xd2\x9e\xa6\x0a\x83\x44\x66\xf3\x39\x6b\xac\x80\x1f\xac\x1e\xeb\x63\x80\x2f\x03\xa0\xb4\xac\xd7\x60\x3e\x36\x99\xc8\xb7\x44\x37\xbe\x83\xff\x01\xad\x7f\x55\xda\xc1\xef\x60\xf4\xd5\x64\x80\xc3\x5e\xe6\x8f\xd5\x2c\x69\x36" ) ] --tests = testGroup "PBKDF2"- [ testGroup "KATs-HMAC-SHA1" (katTests (PBKDF2.prfHMAC SHA1) vectors_hmac_sha1)- , testGroup "KATs-HMAC-SHA1 (fast)" (katTestFastPBKDF2_SHA1 vectors_hmac_sha1)- , testGroup "KATs-HMAC-SHA256" (katTests (PBKDF2.prfHMAC SHA256) vectors_hmac_sha256)- , testGroup "KATs-HMAC-SHA256 (fast)" (katTestFastPBKDF2_SHA256 vectors_hmac_sha256)- , testGroup "KATs-HMAC-SHA512" (katTests (PBKDF2.prfHMAC SHA512) vectors_hmac_sha512)- , testGroup "KATs-HMAC-SHA512 (fast)" (katTestFastPBKDF2_SHA512 vectors_hmac_sha512)- ]- where katTests prf = zipWith (toKatTest prf) is-- toKatTest prf i ((pass, salt, iter, dkLen), output) =- testCase (show i) (output @=? PBKDF2.generate prf (PBKDF2.Parameters iter dkLen) pass salt)+tests =+ testGroup+ "PBKDF2"+ [ testGroup "KATs-HMAC-SHA1" (katTests (PBKDF2.prfHMAC SHA1) vectors_hmac_sha1)+ , testGroup "KATs-HMAC-SHA1 (fast)" (katTestFastPBKDF2_SHA1 vectors_hmac_sha1)+ , testGroup+ "KATs-HMAC-SHA256"+ (katTests (PBKDF2.prfHMAC SHA256) vectors_hmac_sha256)+ , testGroup+ "KATs-HMAC-SHA256 (fast)"+ (katTestFastPBKDF2_SHA256 vectors_hmac_sha256)+ , testGroup+ "KATs-HMAC-SHA512"+ (katTests (PBKDF2.prfHMAC SHA512) vectors_hmac_sha512)+ , testGroup+ "KATs-HMAC-SHA512 (fast)"+ (katTestFastPBKDF2_SHA512 vectors_hmac_sha512)+ ]+ where+ katTests prf = zipWith (toKatTest prf) is - 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)+ toKatTest prf i ((pass, salt, iter, dkLen), output) =+ testCase+ (show i)+ (output @=? PBKDF2.generate prf (PBKDF2.Parameters iter dkLen) pass salt) - 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_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_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)+ 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 = 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) - is :: [Int]- is = [1..]+ is :: [Int]+ is = [1 ..]
tests/KAT_PubKey.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_PubKey (tests) where import Test.Tasty@@ -8,43 +9,49 @@ import qualified Data.ByteString as B import Data.ByteString.Char8 () -import Crypto.PubKey.MaskGenFunction import Crypto.Hash+import Crypto.PubKey.MaskGenFunction -import KAT_PubKey.OAEP-import KAT_PubKey.PSS import KAT_PubKey.DSA import KAT_PubKey.ECC import KAT_PubKey.ECDSA+import KAT_PubKey.OAEP+import qualified KAT_PubKey.P256 as P256+import KAT_PubKey.PSS import KAT_PubKey.RSA import KAT_PubKey.Rabin import Utils-import qualified KAT_PubKey.P256 as P256 -data VectorMgf = VectorMgf { seed :: ByteString- , dbMask :: ByteString- }+data VectorMgf = VectorMgf+ { seed :: ByteString+ , dbMask :: ByteString+ } doMGFTest i vmgf = testCase (show i) (dbMask vmgf @=? actual)- where actual = mgf1 SHA1 (seed vmgf) (B.length $ dbMask vmgf)+ where+ actual = mgf1 SHA1 (seed vmgf) (B.length $ dbMask vmgf) vectorsMGF = [ VectorMgf- { seed = "\xdf\x1a\x89\x6f\x9d\x8b\xc8\x16\xd9\x7c\xd7\xa2\xc4\x3b\xad\x54\x6f\xbe\x8c\xfe"- , dbMask = "\x66\xe4\x67\x2e\x83\x6a\xd1\x21\xba\x24\x4b\xed\x65\x76\xb8\x67\xd9\xa4\x47\xc2\x8a\x6e\x66\xa5\xb8\x7d\xee\x7f\xbc\x7e\x65\xaf\x50\x57\xf8\x6f\xae\x89\x84\xd9\xba\x7f\x96\x9a\xd6\xfe\x02\xa4\xd7\x5f\x74\x45\xfe\xfd\xd8\x5b\x6d\x3a\x47\x7c\x28\xd2\x4b\xa1\xe3\x75\x6f\x79\x2d\xd1\xdc\xe8\xca\x94\x44\x0e\xcb\x52\x79\xec\xd3\x18\x3a\x31\x1f\xc8\x97\x39\xa9\x66\x43\x13\x6e\x8b\x0f\x46\x5e\x87\xa4\x53\x5c\xd4\xc5\x9b\x10\x02\x8d"+ { seed =+ "\xdf\x1a\x89\x6f\x9d\x8b\xc8\x16\xd9\x7c\xd7\xa2\xc4\x3b\xad\x54\x6f\xbe\x8c\xfe"+ , dbMask =+ "\x66\xe4\x67\x2e\x83\x6a\xd1\x21\xba\x24\x4b\xed\x65\x76\xb8\x67\xd9\xa4\x47\xc2\x8a\x6e\x66\xa5\xb8\x7d\xee\x7f\xbc\x7e\x65\xaf\x50\x57\xf8\x6f\xae\x89\x84\xd9\xba\x7f\x96\x9a\xd6\xfe\x02\xa4\xd7\x5f\x74\x45\xfe\xfd\xd8\x5b\x6d\x3a\x47\x7c\x28\xd2\x4b\xa1\xe3\x75\x6f\x79\x2d\xd1\xdc\xe8\xca\x94\x44\x0e\xcb\x52\x79\xec\xd3\x18\x3a\x31\x1f\xc8\x97\x39\xa9\x66\x43\x13\x6e\x8b\x0f\x46\x5e\x87\xa4\x53\x5c\xd4\xc5\x9b\x10\x02\x8d" } ] -tests = testGroup "PubKey"- [ testGroup "MGF1" $ zipWith doMGFTest [katZero..] vectorsMGF- , rsaTests- , pssTests- , oaepTests- , dsaTests- , eccTests- , ecdsaTests- , P256.tests- , rabinTests- ]+tests =+ testGroup+ "PubKey"+ [ testGroup "MGF1" $ zipWith doMGFTest [katZero ..] vectorsMGF+ , rsaTests+ , pssTests+ , oaepTests+ , dsaTests+ , eccTests+ , ecdsaTests+ , P256.tests+ , rabinTests+ ] ---newKats = [ eccKatTests ]+-- newKats = [ eccKatTests ]
tests/KAT_PubKey/DSA.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_PubKey.DSA (dsaTests) where -import qualified Crypto.PubKey.DSA as DSA import Crypto.Hash+import qualified Crypto.PubKey.DSA as DSA import Imports @@ -18,90 +19,110 @@ vectorsSHA1 = [ VectorDSA- { msg = "\x3b\x46\x73\x6d\x55\x9b\xd4\xe0\xc2\xc1\xb2\x55\x3a\x33\xad\x3c\x6c\xf2\x3c\xac\x99\x8d\x3d\x0c\x0e\x8f\xa4\xb1\x9b\xca\x06\xf2\xf3\x86\xdb\x2d\xcf\xf9\xdc\xa4\xf4\x0a\xd8\xf5\x61\xff\xc3\x08\xb4\x6c\x5f\x31\xa7\x73\x5b\x5f\xa7\xe0\xf9\xe6\xcb\x51\x2e\x63\xd7\xee\xa0\x55\x38\xd6\x6a\x75\xcd\x0d\x42\x34\xb5\xcc\xf6\xc1\x71\x5c\xca\xaf\x9c\xdc\x0a\x22\x28\x13\x5f\x71\x6e\xe9\xbd\xee\x7f\xc1\x3e\xc2\x7a\x03\xa6\xd1\x1c\x5c\x5b\x36\x85\xf5\x19\x00\xb1\x33\x71\x53\xbc\x6c\x4e\x8f\x52\x92\x0c\x33\xfa\x37\xf4\xe7"+ { msg =+ "\x3b\x46\x73\x6d\x55\x9b\xd4\xe0\xc2\xc1\xb2\x55\x3a\x33\xad\x3c\x6c\xf2\x3c\xac\x99\x8d\x3d\x0c\x0e\x8f\xa4\xb1\x9b\xca\x06\xf2\xf3\x86\xdb\x2d\xcf\xf9\xdc\xa4\xf4\x0a\xd8\xf5\x61\xff\xc3\x08\xb4\x6c\x5f\x31\xa7\x73\x5b\x5f\xa7\xe0\xf9\xe6\xcb\x51\x2e\x63\xd7\xee\xa0\x55\x38\xd6\x6a\x75\xcd\x0d\x42\x34\xb5\xcc\xf6\xc1\x71\x5c\xca\xaf\x9c\xdc\x0a\x22\x28\x13\x5f\x71\x6e\xe9\xbd\xee\x7f\xc1\x3e\xc2\x7a\x03\xa6\xd1\x1c\x5c\x5b\x36\x85\xf5\x19\x00\xb1\x33\x71\x53\xbc\x6c\x4e\x8f\x52\x92\x0c\x33\xfa\x37\xf4\xe7" , x = 0xc53eae6d45323164c7d07af5715703744a63fc3a- , y = 0x313fd9ebca91574e1c2eebe1517c57e0c21b0209872140c5328761bbb2450b33f1b18b409ce9ab7c4cd8fda3391e8e34868357c199e16a6b2eba06d6749def791d79e95d3a4d09b24c392ad89dbf100995ae19c01062056bb14bce005e8731efde175f95b975089bdcdaea562b32786d96f5a31aedf75364008ad4fffebb970b+ , y =+ 0x313fd9ebca91574e1c2eebe1517c57e0c21b0209872140c5328761bbb2450b33f1b18b409ce9ab7c4cd8fda3391e8e34868357c199e16a6b2eba06d6749def791d79e95d3a4d09b24c392ad89dbf100995ae19c01062056bb14bce005e8731efde175f95b975089bdcdaea562b32786d96f5a31aedf75364008ad4fffebb970b , k = 0x98cbcc4969d845e2461b5f66383dd503712bbcfa , r = 0x50ed0e810e3f1c7cb6ac62332058448bd8b284c0 , s = 0xc6aded17216b46b7e4b6f2a97c1ad7cc3da83fde , pgq = dsaParams } , VectorDSA- { msg = "\xd2\xbc\xb5\x3b\x04\x4b\x3e\x2e\x4b\x61\xba\x2f\x91\xc0\x99\x5f\xb8\x3a\x6a\x97\x52\x5e\x66\x44\x1a\x3b\x48\x9d\x95\x94\x23\x8b\xc7\x40\xbd\xee\xa0\xf7\x18\xa7\x69\xc9\x77\xe2\xde\x00\x38\x77\xb5\xd7\xdc\x25\xb1\x82\xae\x53\x3d\xb3\x3e\x78\xf2\xc3\xff\x06\x45\xf2\x13\x7a\xbc\x13\x7d\x4e\x7d\x93\xcc\xf2\x4f\x60\xb1\x8a\x82\x0b\xc0\x7c\x7b\x4b\x5f\xe0\x8b\x4f\x9e\x7d\x21\xb2\x56\xc1\x8f\x3b\x9d\x49\xac\xc4\xf9\x3e\x2c\xe6\xf3\x75\x4c\x78\x07\x75\x7d\x2e\x11\x76\x04\x26\x12\xcb\x32\xfc\x3f\x4f\x70\x70\x0e\x25"+ { msg =+ "\xd2\xbc\xb5\x3b\x04\x4b\x3e\x2e\x4b\x61\xba\x2f\x91\xc0\x99\x5f\xb8\x3a\x6a\x97\x52\x5e\x66\x44\x1a\x3b\x48\x9d\x95\x94\x23\x8b\xc7\x40\xbd\xee\xa0\xf7\x18\xa7\x69\xc9\x77\xe2\xde\x00\x38\x77\xb5\xd7\xdc\x25\xb1\x82\xae\x53\x3d\xb3\x3e\x78\xf2\xc3\xff\x06\x45\xf2\x13\x7a\xbc\x13\x7d\x4e\x7d\x93\xcc\xf2\x4f\x60\xb1\x8a\x82\x0b\xc0\x7c\x7b\x4b\x5f\xe0\x8b\x4f\x9e\x7d\x21\xb2\x56\xc1\x8f\x3b\x9d\x49\xac\xc4\xf9\x3e\x2c\xe6\xf3\x75\x4c\x78\x07\x75\x7d\x2e\x11\x76\x04\x26\x12\xcb\x32\xfc\x3f\x4f\x70\x70\x0e\x25" , x = 0xe65131d73470f6ad2e5878bdc9bef536faf78831- , y = 0x29bdd759aaa62d4bf16b4861c81cf42eac2e1637b9ecba512bdbc13ac12a80ae8de2526b899ae5e4a231aef884197c944c732693a634d7659abc6975a773f8d3cd5a361fe2492386a3c09aaef12e4a7e73ad7dfc3637f7b093f2c40d6223a195c136adf2ea3fbf8704a675aa7817aa7ec7f9adfb2854d4e05c3ce7f76560313b+ , y =+ 0x29bdd759aaa62d4bf16b4861c81cf42eac2e1637b9ecba512bdbc13ac12a80ae8de2526b899ae5e4a231aef884197c944c732693a634d7659abc6975a773f8d3cd5a361fe2492386a3c09aaef12e4a7e73ad7dfc3637f7b093f2c40d6223a195c136adf2ea3fbf8704a675aa7817aa7ec7f9adfb2854d4e05c3ce7f76560313b , k = 0x87256a64e98cf5be1034ecfa766f9d25d1ac7ceb , r = 0xa26c00b5750a2d27fe7435b93476b35438b4d8ab , s = 0x61c9bfcb2938755afa7dad1d1e07c6288617bf70 , pgq = dsaParams } , VectorDSA- { msg = "\xd5\x43\x1e\x6b\x16\xfd\xae\x31\x48\x17\x42\xbd\x39\x47\x58\xbe\xb8\xe2\x4f\x31\x94\x7e\x19\xb7\xea\x7b\x45\x85\x21\x88\x22\x70\xc1\xf4\x31\x92\xaa\x05\x0f\x44\x85\x14\x5a\xf8\xf3\xf9\xc5\x14\x2d\x68\xb8\x50\x18\xd2\xec\x9c\xb7\xa3\x7b\xa1\x2e\xd2\x3e\x73\xb9\x5f\xd6\x80\xfb\xa3\xc6\x12\x65\xe9\xf5\xa0\xa0\x27\xd7\x0f\xad\x0c\x8a\xa0\x8a\x3c\xbf\xbe\x99\x01\x8d\x00\x45\x38\x61\x73\xe5\xfa\xe2\x25\xfa\xeb\xe0\xce\xf5\xdd\x45\x91\x0f\x40\x0a\x86\xc2\xbe\x4e\x15\x25\x2a\x16\xde\x41\x20\xa2\x67\xbe\x2b\x59\x4d"+ { msg =+ "\xd5\x43\x1e\x6b\x16\xfd\xae\x31\x48\x17\x42\xbd\x39\x47\x58\xbe\xb8\xe2\x4f\x31\x94\x7e\x19\xb7\xea\x7b\x45\x85\x21\x88\x22\x70\xc1\xf4\x31\x92\xaa\x05\x0f\x44\x85\x14\x5a\xf8\xf3\xf9\xc5\x14\x2d\x68\xb8\x50\x18\xd2\xec\x9c\xb7\xa3\x7b\xa1\x2e\xd2\x3e\x73\xb9\x5f\xd6\x80\xfb\xa3\xc6\x12\x65\xe9\xf5\xa0\xa0\x27\xd7\x0f\xad\x0c\x8a\xa0\x8a\x3c\xbf\xbe\x99\x01\x8d\x00\x45\x38\x61\x73\xe5\xfa\xe2\x25\xfa\xeb\xe0\xce\xf5\xdd\x45\x91\x0f\x40\x0a\x86\xc2\xbe\x4e\x15\x25\x2a\x16\xde\x41\x20\xa2\x67\xbe\x2b\x59\x4d" , x = 0x20bcabc6d9347a6e79b8e498c60c44a19c73258c- , y = 0x23b4f404aa3c575e550bb320fdb1a085cd396a10e5ebc6771da62f037cab19eacd67d8222b6344038c4f7af45f5e62b55480cbe2111154ca9697ca76d87b56944138084e74c6f90a05cf43660dff8b8b3fabfcab3f0e4416775fdf40055864be102b4587392e77752ed2aeb182ee4f70be4a291dbe77b84a44ee34007957b1e0+ , y =+ 0x23b4f404aa3c575e550bb320fdb1a085cd396a10e5ebc6771da62f037cab19eacd67d8222b6344038c4f7af45f5e62b55480cbe2111154ca9697ca76d87b56944138084e74c6f90a05cf43660dff8b8b3fabfcab3f0e4416775fdf40055864be102b4587392e77752ed2aeb182ee4f70be4a291dbe77b84a44ee34007957b1e0 , k = 0x7d9bcfc9225432de9860f605a38d389e291ca750 , r = 0x3f0a4ad32f0816821b8affb518e9b599f35d57c2 , s = 0xea06638f2b2fc9d1dfe99c2a492806b497e2b0ea , pgq = dsaParams } , VectorDSA- { msg = "\x85\x66\x2b\x69\x75\x50\xe4\x91\x5c\x29\xe3\x38\xb6\x24\xb9\x12\x84\x5d\x6d\x1a\x92\x0d\x9e\x4c\x16\x04\xdd\x47\xd6\x92\xbc\x7c\x0f\xfb\x95\xae\x61\x4e\x85\x2b\xeb\xaf\x15\x73\x75\x8a\xd0\x1c\x71\x3c\xac\x0b\x47\x6e\x2f\x12\x17\x45\xa3\xcf\xee\xff\xb2\x44\x1f\xf6\xab\xfb\x9b\xbe\xb9\x8a\xa6\x34\xca\x6f\xf5\x41\x94\x7d\xcc\x99\x27\x65\x9d\x44\xf9\x5c\x5f\xf9\x17\x0f\xdc\x3c\x86\x47\x3c\xb6\x01\xba\x31\xb4\x87\xfe\x59\x36\xba\xc5\xd9\xc6\x32\xcb\xcc\x3d\xb0\x62\x46\xba\x01\xc5\x5a\x03\x8d\x79\x7f\xe3\xf6\xc3"+ { msg =+ "\x85\x66\x2b\x69\x75\x50\xe4\x91\x5c\x29\xe3\x38\xb6\x24\xb9\x12\x84\x5d\x6d\x1a\x92\x0d\x9e\x4c\x16\x04\xdd\x47\xd6\x92\xbc\x7c\x0f\xfb\x95\xae\x61\x4e\x85\x2b\xeb\xaf\x15\x73\x75\x8a\xd0\x1c\x71\x3c\xac\x0b\x47\x6e\x2f\x12\x17\x45\xa3\xcf\xee\xff\xb2\x44\x1f\xf6\xab\xfb\x9b\xbe\xb9\x8a\xa6\x34\xca\x6f\xf5\x41\x94\x7d\xcc\x99\x27\x65\x9d\x44\xf9\x5c\x5f\xf9\x17\x0f\xdc\x3c\x86\x47\x3c\xb6\x01\xba\x31\xb4\x87\xfe\x59\x36\xba\xc5\xd9\xc6\x32\xcb\xcc\x3d\xb0\x62\x46\xba\x01\xc5\x5a\x03\x8d\x79\x7f\xe3\xf6\xc3" , x = 0x52d1fbe687aa0702a51a5bf9566bd51bd569424c- , y = 0x6bc36cb3fa61cecc157be08639a7ca9e3de073b8a0ff23574ce5ab0a867dfd60669a56e60d1c989b3af8c8a43f5695d503e3098963990e12b63566784171058eace85c728cd4c08224c7a6efea75dca20df461013c75f40acbc23799ebee7f3361336dadc4a56f305708667bfe602b8ea75a491a5cf0c06ebd6fdc7161e10497+ , y =+ 0x6bc36cb3fa61cecc157be08639a7ca9e3de073b8a0ff23574ce5ab0a867dfd60669a56e60d1c989b3af8c8a43f5695d503e3098963990e12b63566784171058eace85c728cd4c08224c7a6efea75dca20df461013c75f40acbc23799ebee7f3361336dadc4a56f305708667bfe602b8ea75a491a5cf0c06ebd6fdc7161e10497 , k = 0x960c211891c090d05454646ebac1bfe1f381e82b , r = 0x3bc29dee96957050ba438d1b3e17b02c1725d229 , s = 0x0af879cf846c434e08fb6c63782f4d03e0d88865 , pgq = dsaParams } , VectorDSA- { msg = "\x87\xb6\xe7\x5b\x9f\x8e\x99\xc4\xdd\x62\xad\xb6\x93\xdd\x58\x90\xed\xff\x1b\xd0\x02\x8f\x4e\xf8\x49\xdf\x0f\x1d\x2c\xe6\xb1\x81\xfc\x3a\x55\xae\xa6\xd0\xa1\xf0\xae\xca\xb8\xed\x9e\x24\x8a\x00\xe9\x6b\xe7\x94\xa7\xcf\xba\x12\x46\xef\xb7\x10\xef\x4b\x37\x47\x1c\xef\x0a\x1b\xcf\x55\xce\xbc\x8d\x5a\xd0\x71\x61\x2b\xd2\x37\xef\xed\xd5\x10\x23\x62\xdb\x07\xa1\xe2\xc7\xa6\xf1\x5e\x09\xfe\x64\xba\x42\xb6\x0a\x26\x28\xd8\x69\xae\x05\xef\x61\x1f\xe3\x8d\x9c\xe1\x5e\xee\xc9\xbb\x3d\xec\xc8\xdc\x17\x80\x9f\x3b\x6e\x95"+ { msg =+ "\x87\xb6\xe7\x5b\x9f\x8e\x99\xc4\xdd\x62\xad\xb6\x93\xdd\x58\x90\xed\xff\x1b\xd0\x02\x8f\x4e\xf8\x49\xdf\x0f\x1d\x2c\xe6\xb1\x81\xfc\x3a\x55\xae\xa6\xd0\xa1\xf0\xae\xca\xb8\xed\x9e\x24\x8a\x00\xe9\x6b\xe7\x94\xa7\xcf\xba\x12\x46\xef\xb7\x10\xef\x4b\x37\x47\x1c\xef\x0a\x1b\xcf\x55\xce\xbc\x8d\x5a\xd0\x71\x61\x2b\xd2\x37\xef\xed\xd5\x10\x23\x62\xdb\x07\xa1\xe2\xc7\xa6\xf1\x5e\x09\xfe\x64\xba\x42\xb6\x0a\x26\x28\xd8\x69\xae\x05\xef\x61\x1f\xe3\x8d\x9c\xe1\x5e\xee\xc9\xbb\x3d\xec\xc8\xdc\x17\x80\x9f\x3b\x6e\x95" , x = 0xc86a54ec5c4ec63d7332cf43ddb082a34ed6d5f5- , y = 0x014ac746d3605efcb8a2c7dae1f54682a262e27662b252c09478ce87d0aaa522d7c200043406016c0c42896d21750b15dbd57f9707ec37dcea5651781b67ad8d01f5099fe7584b353b641bb159cc717d8ceb18b66705e656f336f1214b34f0357e577ab83641969e311bf40bdcb3ffd5e0bb59419f229508d2f432cc2859ff75+ , y =+ 0x014ac746d3605efcb8a2c7dae1f54682a262e27662b252c09478ce87d0aaa522d7c200043406016c0c42896d21750b15dbd57f9707ec37dcea5651781b67ad8d01f5099fe7584b353b641bb159cc717d8ceb18b66705e656f336f1214b34f0357e577ab83641969e311bf40bdcb3ffd5e0bb59419f229508d2f432cc2859ff75 , k = 0x6c445cee68042553fbe63be61be4ddb99d8134af , r = 0x637e07a5770f3dc65e4506c68c770e5ef6b8ced3 , s = 0x7dfc6f83e24f09745e01d3f7ae0ed1474e811d47 , pgq = dsaParams } , VectorDSA- { msg = "\x22\x59\xee\xad\x2d\x6b\xbc\x76\xd4\x92\x13\xea\x0d\xc8\xb7\x35\x0a\x97\x69\x9f\x22\x34\x10\x44\xc3\x94\x07\x82\x36\x4a\xc9\xea\x68\x31\x79\xa4\x38\xa5\xea\x45\x99\x8d\xf9\x7c\x29\x72\xda\xe0\x38\x51\xf5\xbe\x23\xfa\x9f\x04\x18\x2e\x79\xdd\xb2\xb5\x6d\xc8\x65\x23\x93\xec\xb2\x7f\x3f\x3b\x7c\x8a\x8d\x76\x1a\x86\xb3\xb8\xf4\xd4\x1a\x07\xb4\xbe\x7d\x02\xfd\xde\xfc\x42\xb9\x28\x12\x4a\x5a\x45\xb9\xf4\x60\x90\x42\x20\x9b\x3a\x7f\x58\x5b\xd5\x14\xcc\x39\xc0\x0e\xff\xcc\x42\xc7\xfe\x70\xfa\x83\xed\xf8\xa3\x2b\xf4"+ { msg =+ "\x22\x59\xee\xad\x2d\x6b\xbc\x76\xd4\x92\x13\xea\x0d\xc8\xb7\x35\x0a\x97\x69\x9f\x22\x34\x10\x44\xc3\x94\x07\x82\x36\x4a\xc9\xea\x68\x31\x79\xa4\x38\xa5\xea\x45\x99\x8d\xf9\x7c\x29\x72\xda\xe0\x38\x51\xf5\xbe\x23\xfa\x9f\x04\x18\x2e\x79\xdd\xb2\xb5\x6d\xc8\x65\x23\x93\xec\xb2\x7f\x3f\x3b\x7c\x8a\x8d\x76\x1a\x86\xb3\xb8\xf4\xd4\x1a\x07\xb4\xbe\x7d\x02\xfd\xde\xfc\x42\xb9\x28\x12\x4a\x5a\x45\xb9\xf4\x60\x90\x42\x20\x9b\x3a\x7f\x58\x5b\xd5\x14\xcc\x39\xc0\x0e\xff\xcc\x42\xc7\xfe\x70\xfa\x83\xed\xf8\xa3\x2b\xf4" , x = 0xaee6f213b9903c8069387e64729a08999e5baf65- , y = 0x0fe74045d7b0d472411202831d4932396f242a9765e92be387fd81bbe38d845054528b348c03984179b8e505674cb79d88cc0d8d3e8d7392f9aa773b29c29e54a9e326406075d755c291fcedbcc577934c824af988250f64ed5685fce726cff65e92d708ae11cbfaa958ab8d8b15340a29a137b5b4357f7ed1c7a5190cbf98a4+ , y =+ 0x0fe74045d7b0d472411202831d4932396f242a9765e92be387fd81bbe38d845054528b348c03984179b8e505674cb79d88cc0d8d3e8d7392f9aa773b29c29e54a9e326406075d755c291fcedbcc577934c824af988250f64ed5685fce726cff65e92d708ae11cbfaa958ab8d8b15340a29a137b5b4357f7ed1c7a5190cbf98a4 , k = 0xe1704bae025942e2e63c6d76bab88da79640073a , r = 0x83366ba3fed93dfb38d541203ecbf81c363998e2 , s = 0x1fe299c36a1332f23bf2e10a6c6a4e0d3cdd2bf4 , pgq = dsaParams- } + } , VectorDSA- { msg = "\x21\x9e\x8d\xf5\xbf\x88\x15\x90\x43\x0e\xce\x60\x82\x50\xf7\x67\x0d\xc5\x65\x37\x24\x93\x02\x42\x9e\x28\xec\xfe\xb9\xce\xaa\xa5\x49\x10\xa6\x94\x90\xf7\x65\xf3\xdf\x82\xe8\xb0\x1c\xd7\xd7\x6e\x56\x1d\x0f\x6c\xe2\x26\xef\x3c\xf7\x52\xca\xda\x6f\xeb\xdc\x5b\xf0\x0d\x67\x94\x7f\x92\xd4\x20\x51\x6b\x9e\x37\xc9\x6c\x8f\x1f\x2d\xa0\xb0\x75\x09\x7c\x3b\xda\x75\x8a\x8d\x91\xbd\x2e\xbe\x9c\x75\xcf\x14\x7f\x25\x4c\x25\x69\x63\xb3\x3b\x67\xd0\x2b\x6a\xa0\x9e\x7d\x74\x65\xd0\x38\xe5\x01\x95\xec\xe4\x18\x9b\x41\xe7\x68"+ { msg =+ "\x21\x9e\x8d\xf5\xbf\x88\x15\x90\x43\x0e\xce\x60\x82\x50\xf7\x67\x0d\xc5\x65\x37\x24\x93\x02\x42\x9e\x28\xec\xfe\xb9\xce\xaa\xa5\x49\x10\xa6\x94\x90\xf7\x65\xf3\xdf\x82\xe8\xb0\x1c\xd7\xd7\x6e\x56\x1d\x0f\x6c\xe2\x26\xef\x3c\xf7\x52\xca\xda\x6f\xeb\xdc\x5b\xf0\x0d\x67\x94\x7f\x92\xd4\x20\x51\x6b\x9e\x37\xc9\x6c\x8f\x1f\x2d\xa0\xb0\x75\x09\x7c\x3b\xda\x75\x8a\x8d\x91\xbd\x2e\xbe\x9c\x75\xcf\x14\x7f\x25\x4c\x25\x69\x63\xb3\x3b\x67\xd0\x2b\x6a\xa0\x9e\x7d\x74\x65\xd0\x38\xe5\x01\x95\xec\xe4\x18\x9b\x41\xe7\x68" , x = 0x699f1c07aa458c6786e770b40197235fe49cf21a- , y = 0x3a41b0678ff3c4dde20fa39772bac31a2f18bae4bedec9e12ee8e02e30e556b1a136013bef96b0d30b568233dcecc71e485ed75c922afb4d0654e709bee84993792130220e3005fdb06ebdfc0e2df163b5ec424e836465acd6d92e243c86f2b94b26b8d73bd9cf722c757e0b80b0af16f185de70e8ca850b1402d126ea60f309+ , y =+ 0x3a41b0678ff3c4dde20fa39772bac31a2f18bae4bedec9e12ee8e02e30e556b1a136013bef96b0d30b568233dcecc71e485ed75c922afb4d0654e709bee84993792130220e3005fdb06ebdfc0e2df163b5ec424e836465acd6d92e243c86f2b94b26b8d73bd9cf722c757e0b80b0af16f185de70e8ca850b1402d126ea60f309 , k = 0x5bbb795bfa5fa72191fed3434a08741410367491 , r = 0x579761039ae0ddb81106bf4968e320083bbcb947 , s = 0x503ea15dbac9dedeba917fa8e9f386b93aa30353 , pgq = dsaParams- } + } , VectorDSA- { msg = "\x2d\xa7\x9d\x06\x78\x85\xeb\x3c\xcf\x5e\x29\x3a\xe3\xb1\xd8\x22\x53\x22\x20\x3a\xbb\x5a\xdf\xde\x3b\x0f\x53\xbb\xe2\x4c\x4f\xe0\x01\x54\x1e\x11\x83\xd8\x70\xa9\x97\xf1\xf9\x46\x01\x00\xb5\xd7\x11\x92\x31\x80\x15\x43\x45\x28\x7a\x02\x14\xcf\x1c\xac\x37\xb7\xa4\x7d\xfb\xb2\xa0\xe8\xce\x49\x16\xf9\x4e\xbd\x6f\xa5\x4e\x31\x5b\x7a\x8e\xb5\xb6\x3c\xd9\x54\xc5\xba\x05\xc1\xbf\x7e\x33\xa4\xe8\xa1\x51\xf3\x2d\x28\x77\xb0\x17\x29\xc1\xad\x0e\x7c\x01\xbb\x8a\xe7\x23\xc9\x95\x18\x38\x03\xe4\x56\x36\x52\x0e\xa3\x8c\xa1"+ { msg =+ "\x2d\xa7\x9d\x06\x78\x85\xeb\x3c\xcf\x5e\x29\x3a\xe3\xb1\xd8\x22\x53\x22\x20\x3a\xbb\x5a\xdf\xde\x3b\x0f\x53\xbb\xe2\x4c\x4f\xe0\x01\x54\x1e\x11\x83\xd8\x70\xa9\x97\xf1\xf9\x46\x01\x00\xb5\xd7\x11\x92\x31\x80\x15\x43\x45\x28\x7a\x02\x14\xcf\x1c\xac\x37\xb7\xa4\x7d\xfb\xb2\xa0\xe8\xce\x49\x16\xf9\x4e\xbd\x6f\xa5\x4e\x31\x5b\x7a\x8e\xb5\xb6\x3c\xd9\x54\xc5\xba\x05\xc1\xbf\x7e\x33\xa4\xe8\xa1\x51\xf3\x2d\x28\x77\xb0\x17\x29\xc1\xad\x0e\x7c\x01\xbb\x8a\xe7\x23\xc9\x95\x18\x38\x03\xe4\x56\x36\x52\x0e\xa3\x8c\xa1" , x = 0xd6e08c20c82949ddba93ea81eb2fea8c595894dc- , y = 0x56f7272210f316c51af8bfc45a421fd4e9b1043853271b7e79f40936f0adcf262a86097aa86e19e6cb5307685d863dba761342db6c973b3849b1e060aca926f41fe07323601062515ae85f3172b8f34899c621d59fa21f73d5ae97a3deb5e840b25a18fd580862fd7b1cf416c7ae9fc5842a0197fdb0c5173ff4a4f102a8cf89+ , y =+ 0x56f7272210f316c51af8bfc45a421fd4e9b1043853271b7e79f40936f0adcf262a86097aa86e19e6cb5307685d863dba761342db6c973b3849b1e060aca926f41fe07323601062515ae85f3172b8f34899c621d59fa21f73d5ae97a3deb5e840b25a18fd580862fd7b1cf416c7ae9fc5842a0197fdb0c5173ff4a4f102a8cf89 , k = 0x6d72c30d4430959800740f2770651095d0c181c2 , r = 0x5dd90d69add67a5fae138eec1aaff0229aa4afc4 , s = 0x47f39c4db2387f10762f45b80dfd027906d7ef04 , pgq = dsaParams- } + } , VectorDSA- { msg = "\xba\x30\xd8\x5b\xe3\x57\xe7\xfb\x29\xf8\xa0\x7e\x1f\x12\x7b\xaa\xa2\x4b\x2e\xe0\x27\xf6\x4c\xb5\xef\xee\xc6\xaa\xea\xbc\xc7\x34\x5c\x5d\x55\x6e\xbf\x4b\xdc\x7a\x61\xc7\x7c\x7b\x7e\xa4\x3c\x73\xba\xbc\x18\xf7\xb4\x80\x77\x22\xda\x23\x9e\x45\xdd\xf2\x49\x84\x9c\xbb\xfe\x35\x07\x11\x2e\xbf\x87\xd7\xef\x56\x0c\x2e\x7d\x39\x1e\xd8\x42\x4f\x87\x10\xce\xa4\x16\x85\x14\x3e\x30\x06\xf8\x1b\x68\xfb\xb4\xd5\xf9\x64\x4c\x7c\xd1\x0f\x70\x92\xef\x24\x39\xb8\xd1\x8c\x0d\xf6\x55\xe0\x02\x89\x37\x2a\x41\x66\x38\x5d\x64\x0c"+ { msg =+ "\xba\x30\xd8\x5b\xe3\x57\xe7\xfb\x29\xf8\xa0\x7e\x1f\x12\x7b\xaa\xa2\x4b\x2e\xe0\x27\xf6\x4c\xb5\xef\xee\xc6\xaa\xea\xbc\xc7\x34\x5c\x5d\x55\x6e\xbf\x4b\xdc\x7a\x61\xc7\x7c\x7b\x7e\xa4\x3c\x73\xba\xbc\x18\xf7\xb4\x80\x77\x22\xda\x23\x9e\x45\xdd\xf2\x49\x84\x9c\xbb\xfe\x35\x07\x11\x2e\xbf\x87\xd7\xef\x56\x0c\x2e\x7d\x39\x1e\xd8\x42\x4f\x87\x10\xce\xa4\x16\x85\x14\x3e\x30\x06\xf8\x1b\x68\xfb\xb4\xd5\xf9\x64\x4c\x7c\xd1\x0f\x70\x92\xef\x24\x39\xb8\xd1\x8c\x0d\xf6\x55\xe0\x02\x89\x37\x2a\x41\x66\x38\x5d\x64\x0c" , x = 0x50018482864c1864e9db1f04bde8dbfd3875c76d- , y = 0x0942a5b7a72ab116ead29308cf658dfe3d55d5d61afed9e3836e64237f9d6884fdd827d2d5890c9a41ae88e7a69fc9f345ade9c480c6f08cff067c183214c227236cedb6dd1283ca2a602574e8327510221d4c27b162143b7002d8c726916826265937b87be9d5ec6d7bd28fb015f84e0ab730da7a4eaf4ef3174bf0a22a6392+ , y =+ 0x0942a5b7a72ab116ead29308cf658dfe3d55d5d61afed9e3836e64237f9d6884fdd827d2d5890c9a41ae88e7a69fc9f345ade9c480c6f08cff067c183214c227236cedb6dd1283ca2a602574e8327510221d4c27b162143b7002d8c726916826265937b87be9d5ec6d7bd28fb015f84e0ab730da7a4eaf4ef3174bf0a22a6392 , k = 0xdf3a9348f37b5d2d4c9176db266ae388f1fa7e0f , r = 0x448434b214eee38bde080f8ec433e8d19b3ddf0d , s = 0x0c02e881b777923fe0ea674f2621298e00199d5f , pgq = dsaParams- } + } , VectorDSA- { msg = "\x83\x49\x9e\xfb\x06\xbb\x7f\xf0\x2f\xfb\x46\xc2\x78\xa5\xe9\x26\x30\xac\x5b\xc3\xf9\xe5\x3d\xd2\xe7\x8f\xf1\x5e\x36\x8c\x7e\x31\xaa\xd7\x7c\xf7\x71\xf3\x5f\xa0\x2d\x0b\x5f\x13\x52\x08\xa4\xaf\xdd\x86\x7b\xb2\xec\x26\xea\x2e\x7d\xd6\x4c\xde\xf2\x37\x50\x8a\x38\xb2\x7f\x39\xd8\xb2\x2d\x45\xca\xc5\xa6\x8a\x90\xb6\xea\x76\x05\x86\x45\xf6\x35\x6a\x93\x44\xd3\x6f\x00\xec\x66\x52\xea\xa4\xe9\xba\xe7\xb6\x94\xf9\xf1\xfc\x8c\x6c\x5e\x86\xfa\xdc\x7b\x27\xa2\x19\xb5\xc1\xb2\xae\x80\xa7\x25\xe5\xf6\x11\x65\xfe\x2e\xdc"+ { msg =+ "\x83\x49\x9e\xfb\x06\xbb\x7f\xf0\x2f\xfb\x46\xc2\x78\xa5\xe9\x26\x30\xac\x5b\xc3\xf9\xe5\x3d\xd2\xe7\x8f\xf1\x5e\x36\x8c\x7e\x31\xaa\xd7\x7c\xf7\x71\xf3\x5f\xa0\x2d\x0b\x5f\x13\x52\x08\xa4\xaf\xdd\x86\x7b\xb2\xec\x26\xea\x2e\x7d\xd6\x4c\xde\xf2\x37\x50\x8a\x38\xb2\x7f\x39\xd8\xb2\x2d\x45\xca\xc5\xa6\x8a\x90\xb6\xea\x76\x05\x86\x45\xf6\x35\x6a\x93\x44\xd3\x6f\x00\xec\x66\x52\xea\xa4\xe9\xba\xe7\xb6\x94\xf9\xf1\xfc\x8c\x6c\x5e\x86\xfa\xdc\x7b\x27\xa2\x19\xb5\xc1\xb2\xae\x80\xa7\x25\xe5\xf6\x11\x65\xfe\x2e\xdc" , x = 0xae56f66b0a9405b9cca54c60ec4a3bb5f8be7c3f- , y = 0xa01542c3da410dd57930ca724f0f507c4df43d553c7f69459939685941ceb95c7dcc3f175a403b359621c0d4328e98f15f330a63865baf3e7eb1604a0715e16eed64fd14b35d3a534259a6a7ddf888c4dbb5f51bbc6ed339e5bb2a239d5cfe2100ac8e2f9c16e536f25119ab435843af27dc33414a9e4602f96d7c94d6021cec+ , y =+ 0xa01542c3da410dd57930ca724f0f507c4df43d553c7f69459939685941ceb95c7dcc3f175a403b359621c0d4328e98f15f330a63865baf3e7eb1604a0715e16eed64fd14b35d3a534259a6a7ddf888c4dbb5f51bbc6ed339e5bb2a239d5cfe2100ac8e2f9c16e536f25119ab435843af27dc33414a9e4602f96d7c94d6021cec , k = 0x8857ff301ad0169d164fa269977a116e070bac17 , r = 0x8c2fab489c34672140415d41a65cef1e70192e23 , s = 0x3df86a9e2efe944a1c7ea9c30cac331d00599a0e@@ -110,7 +131,8 @@ , VectorDSA -- 1024-bit example from RFC 6979 with SHA-1 { msg = "sample" , x = 0x411602CB19A6CCC34494D79D98EF1E7ED5AF25F7- , y = 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B+ , y =+ 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B , k = 0x7BDB6B0FF756E1BB5D53583EF979082F9AD5BD5B , r = 0x2E1A0C2562B2912CAAF89186FB0F42001585DA55 , s = 0x29EFB6B0AFF2D7A68EB70CA313022253B9A88DF5@@ -119,7 +141,8 @@ , VectorDSA -- 1024-bit example from RFC 6979 with SHA-1 { msg = "test" , x = 0x411602CB19A6CCC34494D79D98EF1E7ED5AF25F7- , y = 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B+ , y =+ 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B , k = 0x5C842DF4F9E344EE09F056838B42C7A17F4A6433 , r = 0x42AB2052FD43E123F0607F115052A67DCD9C5C77 , s = 0x183916B0230D45B9931491D4C6B0BD2FB4AAF088@@ -128,7 +151,8 @@ , VectorDSA -- 2048-bit example from RFC 6979 with SHA-1 { msg = "sample" , x = 0x69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC- , y = 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF+ , y =+ 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF , k = 0x888FA6F7738A41BDC9846466ABDB8174C0338250AE50CE955CA16230F9CBD53E , r = 0x3A1B2DBD7489D6ED7E608FD036C83AF396E290DBD602408E8677DAABD6E7445A , s = 0xD26FCBA19FA3E3058FFC02CA1596CDBB6E0D20CB37B06054F7E36DED0CDBBCCF@@ -137,17 +161,22 @@ , VectorDSA -- 2048-bit example from RFC 6979 with SHA-1 { msg = "test" , x = 0x69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC- , y = 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF+ , y =+ 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF , k = 0x6EEA486F9D41A037B2C640BC5645694FF8FF4B98D066A25F76BE641CCB24BA4F , r = 0xC18270A93CFC6063F57A4DFA86024F700D980E4CF4E2CB65A504397273D98EA0 , s = 0x414F22E5F31A8B6D33295C7539C1C1BA3A6160D7D68D50AC0D3A5BEAC2884FAA , pgq = rfc6979Params2048 } ]- where -- (p,g,q)- dsaParams = DSA.Params- { DSA.params_p = 0xa8f9cd201e5e35d892f85f80e4db2599a5676a3b1d4f190330ed3256b26d0e80a0e49a8fffaaad2a24f472d2573241d4d6d6c7480c80b4c67bb4479c15ada7ea8424d2502fa01472e760241713dab025ae1b02e1703a1435f62ddf4ee4c1b664066eb22f2e3bf28bb70a2a76e4fd5ebe2d1229681b5b06439ac9c7e9d8bde283- , DSA.params_g = 0x2b3152ff6c62f14622b8f48e59f8af46883b38e79b8c74deeae9df131f8b856e3ad6c8455dab87cc0da8ac973417ce4f7878557d6cdf40b35b4a0ca3eb310c6a95d68ce284ad4e25ea28591611ee08b8444bd64b25f3f7c572410ddfb39cc728b9c936f85f419129869929cdb909a6a3a99bbe089216368171bd0ba81de4fe33+ where+ -- (p,g,q)+ dsaParams =+ DSA.Params+ { DSA.params_p =+ 0xa8f9cd201e5e35d892f85f80e4db2599a5676a3b1d4f190330ed3256b26d0e80a0e49a8fffaaad2a24f472d2573241d4d6d6c7480c80b4c67bb4479c15ada7ea8424d2502fa01472e760241713dab025ae1b02e1703a1435f62ddf4ee4c1b664066eb22f2e3bf28bb70a2a76e4fd5ebe2d1229681b5b06439ac9c7e9d8bde283+ , DSA.params_g =+ 0x2b3152ff6c62f14622b8f48e59f8af46883b38e79b8c74deeae9df131f8b856e3ad6c8455dab87cc0da8ac973417ce4f7878557d6cdf40b35b4a0ca3eb310c6a95d68ce284ad4e25ea28591611ee08b8444bd64b25f3f7c572410ddfb39cc728b9c936f85f419129869929cdb909a6a3a99bbe089216368171bd0ba81de4fe33 , DSA.params_q = 0xf85f0f83ac4df7ea0cdf8f469bfeeaea14156495 } @@ -155,7 +184,8 @@ [ VectorDSA { msg = "sample" , x = 0x411602CB19A6CCC34494D79D98EF1E7ED5AF25F7- , y = 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B+ , y =+ 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B , k = 0x562097C06782D60C3037BA7BE104774344687649 , r = 0x4BC3B686AEA70145856814A6F1BB53346F02101E , s = 0x410697B92295D994D21EDD2F4ADA85566F6F94C1@@ -164,7 +194,8 @@ , VectorDSA { msg = "test" , x = 0x411602CB19A6CCC34494D79D98EF1E7ED5AF25F7- , y = 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B+ , y =+ 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B , k = 0x4598B8EFC1A53BC8AECD58D1ABBB0C0C71E67297 , r = 0x6868E9964E36C1689F6037F91F28D5F2C30610F2 , s = 0x49CEC3ACDC83018C5BD2674ECAAD35B8CD22940F@@ -173,7 +204,8 @@ , VectorDSA { msg = "sample" , x = 0x69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC- , y = 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF+ , y =+ 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF , k = 0xBC372967702082E1AA4FCE892209F71AE4AD25A6DFD869334E6F153BD0C4D806 , r = 0xDC9F4DEADA8D8FF588E98FED0AB690FFCE858DC8C79376450EB6B76C24537E2C , s = 0xA65A9C3BC7BABE286B195D5DA68616DA8D47FA0097F36DD19F517327DC848CEC@@ -182,7 +214,8 @@ , VectorDSA { msg = "test" , x = 0x69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC- , y = 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF+ , y =+ 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF , k = 0x06BD4C05ED74719106223BE33F2D95DA6B3B541DAD7BFBD7AC508213B6DA6670 , r = 0x272ABA31572F6CC55E30BF616B7A265312018DD325BE031BE0CC82AA17870EA3 , s = 0xE9CC286A52CCE201586722D36D1E917EB96A4EBDB47932F9576AC645B3A60806@@ -194,7 +227,8 @@ [ VectorDSA { msg = "sample" , x = 0x411602CB19A6CCC34494D79D98EF1E7ED5AF25F7- , y = 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B+ , y =+ 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B , k = 0x519BA0546D0C39202A7D34D7DFA5E760B318BCFB , r = 0x81F2F5850BE5BC123C43F71A3033E9384611C545 , s = 0x4CDD914B65EB6C66A8AAAD27299BEE6B035F5E89@@ -203,7 +237,8 @@ , VectorDSA { msg = "test" , x = 0x411602CB19A6CCC34494D79D98EF1E7ED5AF25F7- , y = 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B+ , y =+ 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B , k = 0x5A67592E8128E03A417B0484410FB72C0B630E1A , r = 0x22518C127299B0F6FDC9872B282B9E70D0790812 , s = 0x6837EC18F150D55DE95B5E29BE7AF5D01E4FE160@@ -212,7 +247,8 @@ , VectorDSA { msg = "sample" , x = 0x69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC- , y = 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF+ , y =+ 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF , k = 0x8926A27C40484216F052F4427CFD5647338B7B3939BC6573AF4333569D597C52 , r = 0xEACE8BDBBE353C432A795D9EC556C6D021F7A03F42C36E9BC87E4AC7932CC809 , s = 0x7081E175455F9247B812B74583E9E94F9EA79BD640DC962533B0680793A38D53@@ -221,7 +257,8 @@ , VectorDSA { msg = "test" , x = 0x69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC- , y = 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF+ , y =+ 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF , k = 0x1D6CE6DDA1C5D37307839CD03AB0A5CBB18E60D800937D67DFB4479AAC8DEAD7 , r = 0x8190012A1969F9957D56FCCAAD223186F423398D58EF5B3CEFD5A4146A4476F0 , s = 0x7452A53F7075D417B4B013B278D1BB8BBD21863F5E7B1CEE679CF2188E1AB19E@@ -233,7 +270,8 @@ [ VectorDSA { msg = "sample" , x = 0x411602CB19A6CCC34494D79D98EF1E7ED5AF25F7- , y = 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B+ , y =+ 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B , k = 0x95897CD7BBB944AA932DBC579C1C09EB6FCFC595 , r = 0x07F2108557EE0E3921BC1774F1CA9B410B4CE65A , s = 0x54DF70456C86FAC10FAB47C1949AB83F2C6F7595@@ -242,7 +280,8 @@ , VectorDSA { msg = "test" , x = 0x411602CB19A6CCC34494D79D98EF1E7ED5AF25F7- , y = 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B+ , y =+ 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B , k = 0x220156B761F6CA5E6C9F1B9CF9C24BE25F98CD89 , r = 0x854CF929B58D73C3CBFDC421E8D5430CD6DB5E66 , s = 0x91D0E0F53E22F898D158380676A871A157CDA622@@ -251,7 +290,8 @@ , VectorDSA { msg = "sample" , x = 0x69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC- , y = 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF+ , y =+ 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF , k = 0xC345D5AB3DA0A5BCB7EC8F8FB7A7E96069E03B206371EF7D83E39068EC564920 , r = 0xB2DA945E91858834FD9BF616EBAC151EDBC4B45D27D0DD4A7F6A22739F45C00B , s = 0x19048B63D9FD6BCA1D9BAE3664E1BCB97F7276C306130969F63F38FA8319021B@@ -260,7 +300,8 @@ , VectorDSA { msg = "test" , x = 0x69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC- , y = 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF+ , y =+ 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF , k = 0x206E61F73DBE1B2DC8BE736B22B079E9DACD974DB00EEBBC5B64CAD39CF9F91C , r = 0x239E66DDBE8F8C230A3D071D601B6FFBDFB5901F94D444C6AF56F732BEB954BE , s = 0x6BD737513D5E72FE85D1C750E0F73921FE299B945AAD1C802F15C26A43D34961@@ -272,7 +313,8 @@ [ VectorDSA { msg = "sample" , x = 0x411602CB19A6CCC34494D79D98EF1E7ED5AF25F7- , y = 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B+ , y =+ 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B , k = 0x09ECE7CA27D0F5A4DD4E556C9DF1D21D28104F8B , r = 0x16C3491F9B8C3FBBDD5E7A7B667057F0D8EE8E1B , s = 0x02C36A127A7B89EDBB72E4FFBC71DABC7D4FC69C@@ -281,7 +323,8 @@ , VectorDSA { msg = "test" , x = 0x411602CB19A6CCC34494D79D98EF1E7ED5AF25F7- , y = 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B+ , y =+ 0x5DF5E01DED31D0297E274E1691C192FE5868FEF9E19A84776454B100CF16F65392195A38B90523E2542EE61871C0440CB87C322FC4B4D2EC5E1E7EC766E1BE8D4CE935437DC11C3C8FD426338933EBFE739CB3465F4D3668C5E473508253B1E682F65CBDC4FAE93C2EA212390E54905A86E2223170B44EAA7DA5DD9FFCFB7F3B , k = 0x65D2C2EEB175E370F28C75BFCDC028D22C7DBE9C , r = 0x8EA47E475BA8AC6F2D821DA3BD212D11A3DEB9A0 , s = 0x7C670C7AD72B6C050C109E1790008097125433E8@@ -290,7 +333,8 @@ , VectorDSA { msg = "sample" , x = 0x69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC- , y = 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF+ , y =+ 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF , k = 0x5A12994431785485B3F5F067221517791B85A597B7A9436995C89ED0374668FC , r = 0x2016ED092DC5FB669B8EFB3D1F31A91EECB199879BE0CF78F02BA062CB4C942E , s = 0xD0C76F84B5F091E141572A639A4FB8C230807EEA7D55C8A154A224400AFF2351@@ -299,7 +343,8 @@ , VectorDSA { msg = "test" , x = 0x69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC- , y = 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF+ , y =+ 0x667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD949F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA611728716C2E4FD53BC95B89E69949D96512E873B9C8F8DFD499CC312882561ADECB31F658E934C0C197F2C4D96B05CBAD67381E7B768891E4DA3843D24D94CDFB5126E9B8BF21E8358EE0E0A30EF13FD6A664C0DCE3731F7FB49A4845A4FD8254687972A2D382599C9BAC4E0ED7998193078913032558134976410B89D2C171D123AC35FD977219597AA7D15C1A9A428E59194F75C721EBCBCFAE44696A499AFA74E04299F132026601638CB87AB79190D4A0986315DA8EEC6561C938996BEADF , k = 0xAFF1651E4CD6036D57AA8B2A05CCF1A9D5A40166340ECBBDC55BE10B568AA0AA , r = 0x89EC4BB1400ECCFF8E7D9AA515CD1DE7803F2DAFF09693EE7FD1353E90A68307 , s = 0xC9F0BDABCC0D880BB137A994CC7F3980CE91CC10FAF529FC46565B15CEA854E1@@ -307,56 +352,83 @@ } ] -rfc6979Params1024 = DSA.Params- { DSA.params_p = 0x86F5CA03DCFEB225063FF830A0C769B9DD9D6153AD91D7CE27F787C43278B447E6533B86B18BED6E8A48B784A14C252C5BE0DBF60B86D6385BD2F12FB763ED8873ABFD3F5BA2E0A8C0A59082EAC056935E529DAF7C610467899C77ADEDFC846C881870B7B19B2B58F9BE0521A17002E3BDD6B86685EE90B3D9A1B02B782B1779- , DSA.params_g = 0x07B0F92546150B62514BB771E2A0C0CE387F03BDA6C56B505209FF25FD3C133D89BBCD97E904E09114D9A7DEFDEADFC9078EA544D2E401AEECC40BB9FBBF78FD87995A10A1C27CB7789B594BA7EFB5C4326A9FE59A070E136DB77175464ADCA417BE5DCE2F40D10A46A3A3943F26AB7FD9C0398FF8C76EE0A56826A8A88F1DBD- , DSA.params_q = 0x996F967F6C8E388D9E28D01E205FBA957A5698B1- }+rfc6979Params1024 =+ DSA.Params+ { DSA.params_p =+ 0x86F5CA03DCFEB225063FF830A0C769B9DD9D6153AD91D7CE27F787C43278B447E6533B86B18BED6E8A48B784A14C252C5BE0DBF60B86D6385BD2F12FB763ED8873ABFD3F5BA2E0A8C0A59082EAC056935E529DAF7C610467899C77ADEDFC846C881870B7B19B2B58F9BE0521A17002E3BDD6B86685EE90B3D9A1B02B782B1779+ , DSA.params_g =+ 0x07B0F92546150B62514BB771E2A0C0CE387F03BDA6C56B505209FF25FD3C133D89BBCD97E904E09114D9A7DEFDEADFC9078EA544D2E401AEECC40BB9FBBF78FD87995A10A1C27CB7789B594BA7EFB5C4326A9FE59A070E136DB77175464ADCA417BE5DCE2F40D10A46A3A3943F26AB7FD9C0398FF8C76EE0A56826A8A88F1DBD+ , DSA.params_q = 0x996F967F6C8E388D9E28D01E205FBA957A5698B1+ } -rfc6979Params2048 = DSA.Params- { DSA.params_p = 0x9DB6FB5951B66BB6FE1E140F1D2CE5502374161FD6538DF1648218642F0B5C48C8F7A41AADFA187324B87674FA1822B00F1ECF8136943D7C55757264E5A1A44FFE012E9936E00C1D3E9310B01C7D179805D3058B2A9F4BB6F9716BFE6117C6B5B3CC4D9BE341104AD4A80AD6C94E005F4B993E14F091EB51743BF33050C38DE235567E1B34C3D6A5C0CEAA1A0F368213C3D19843D0B4B09DCB9FC72D39C8DE41F1BF14D4BB4563CA28371621CAD3324B6A2D392145BEBFAC748805236F5CA2FE92B871CD8F9C36D3292B5509CA8CAA77A2ADFC7BFD77DDA6F71125A7456FEA153E433256A2261C6A06ED3693797E7995FAD5AABBCFBE3EDA2741E375404AE25B- , DSA.params_g = 0x5C7FF6B06F8F143FE8288433493E4769C4D988ACE5BE25A0E24809670716C613D7B0CEE6932F8FAA7C44D2CB24523DA53FBE4F6EC3595892D1AA58C4328A06C46A15662E7EAA703A1DECF8BBB2D05DBE2EB956C142A338661D10461C0D135472085057F3494309FFA73C611F78B32ADBB5740C361C9F35BE90997DB2014E2EF5AA61782F52ABEB8BD6432C4DD097BC5423B285DAFB60DC364E8161F4A2A35ACA3A10B1C4D203CC76A470A33AFDCBDD92959859ABD8B56E1725252D78EAC66E71BA9AE3F1DD2487199874393CD4D832186800654760E1E34C09E4D155179F9EC0DC4473F996BDCE6EED1CABED8B6F116F7AD9CF505DF0F998E34AB27514B0FFE7- , DSA.params_q = 0xF2C3119374CE76C9356990B465374A17F23F9ED35089BD969F61C6DDE9998C1F- }+rfc6979Params2048 =+ DSA.Params+ { DSA.params_p =+ 0x9DB6FB5951B66BB6FE1E140F1D2CE5502374161FD6538DF1648218642F0B5C48C8F7A41AADFA187324B87674FA1822B00F1ECF8136943D7C55757264E5A1A44FFE012E9936E00C1D3E9310B01C7D179805D3058B2A9F4BB6F9716BFE6117C6B5B3CC4D9BE341104AD4A80AD6C94E005F4B993E14F091EB51743BF33050C38DE235567E1B34C3D6A5C0CEAA1A0F368213C3D19843D0B4B09DCB9FC72D39C8DE41F1BF14D4BB4563CA28371621CAD3324B6A2D392145BEBFAC748805236F5CA2FE92B871CD8F9C36D3292B5509CA8CAA77A2ADFC7BFD77DDA6F71125A7456FEA153E433256A2261C6A06ED3693797E7995FAD5AABBCFBE3EDA2741E375404AE25B+ , DSA.params_g =+ 0x5C7FF6B06F8F143FE8288433493E4769C4D988ACE5BE25A0E24809670716C613D7B0CEE6932F8FAA7C44D2CB24523DA53FBE4F6EC3595892D1AA58C4328A06C46A15662E7EAA703A1DECF8BBB2D05DBE2EB956C142A338661D10461C0D135472085057F3494309FFA73C611F78B32ADBB5740C361C9F35BE90997DB2014E2EF5AA61782F52ABEB8BD6432C4DD097BC5423B285DAFB60DC364E8161F4A2A35ACA3A10B1C4D203CC76A470A33AFDCBDD92959859ABD8B56E1725252D78EAC66E71BA9AE3F1DD2487199874393CD4D832186800654760E1E34C09E4D155179F9EC0DC4473F996BDCE6EED1CABED8B6F116F7AD9CF505DF0F998E34AB27514B0FFE7+ , DSA.params_q =+ 0xF2C3119374CE76C9356990B465374A17F23F9ED35089BD969F61C6DDE9998C1F+ } vectorToPrivate :: VectorDSA -> DSA.PrivateKey-vectorToPrivate vector = DSA.PrivateKey- { DSA.private_x = x vector- , DSA.private_params = pgq vector- }+vectorToPrivate vector =+ DSA.PrivateKey+ { DSA.private_x = x vector+ , DSA.private_params = pgq vector+ } vectorToPublic :: VectorDSA -> DSA.PublicKey-vectorToPublic vector = DSA.PublicKey- { DSA.public_y = y vector- , DSA.public_params = pgq vector- }+vectorToPublic vector =+ DSA.PublicKey+ { DSA.public_y = y vector+ , DSA.public_params = pgq vector+ } 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)+ 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)- where actual = DSA.verify hashAlg (vectorToPublic vector) (DSA.Signature (r vector) (s vector)) (msg vector)+ where+ actual =+ DSA.verify+ hashAlg+ (vectorToPublic vector)+ (DSA.Signature (r vector) (s vector))+ (msg vector) -dsaTests = testGroup "DSA"- [ testGroup "SHA1"- [ testGroup "signature" $ zipWith (doSignatureTest SHA1) [katZero..] vectorsSHA1- , testGroup "verify" $ zipWith (doVerifyTest SHA1) [katZero..] vectorsSHA1- ]- , testGroup "SHA224"- [ testGroup "signature" $ zipWith (doSignatureTest SHA224) [katZero..] vectorsSHA224- , testGroup "verify" $ zipWith (doVerifyTest SHA224) [katZero..] vectorsSHA224- ]- , testGroup "SHA256"- [ testGroup "signature" $ zipWith (doSignatureTest SHA256) [katZero..] vectorsSHA256- , testGroup "verify" $ zipWith (doVerifyTest SHA256) [katZero..] vectorsSHA256- ]- , testGroup "SHA384"- [ testGroup "signature" $ zipWith (doSignatureTest SHA384) [katZero..] vectorsSHA384- , testGroup "verify" $ zipWith (doVerifyTest SHA384) [katZero..] vectorsSHA384- ]- , testGroup "SHA512"- [ testGroup "signature" $ zipWith (doSignatureTest SHA512) [katZero..] vectorsSHA512- , testGroup "verify" $ zipWith (doVerifyTest SHA512) [katZero..] vectorsSHA512+dsaTests =+ testGroup+ "DSA"+ [ testGroup+ "SHA1"+ [ testGroup "signature" $ zipWith (doSignatureTest SHA1) [katZero ..] vectorsSHA1+ , testGroup "verify" $ zipWith (doVerifyTest SHA1) [katZero ..] vectorsSHA1+ ]+ , testGroup+ "SHA224"+ [ testGroup "signature" $+ zipWith (doSignatureTest SHA224) [katZero ..] vectorsSHA224+ , testGroup "verify" $ zipWith (doVerifyTest SHA224) [katZero ..] vectorsSHA224+ ]+ , testGroup+ "SHA256"+ [ testGroup "signature" $+ zipWith (doSignatureTest SHA256) [katZero ..] vectorsSHA256+ , testGroup "verify" $ zipWith (doVerifyTest SHA256) [katZero ..] vectorsSHA256+ ]+ , testGroup+ "SHA384"+ [ testGroup "signature" $+ zipWith (doSignatureTest SHA384) [katZero ..] vectorsSHA384+ , testGroup "verify" $ zipWith (doVerifyTest SHA384) [katZero ..] vectorsSHA384+ ]+ , testGroup+ "SHA512"+ [ testGroup "signature" $+ zipWith (doSignatureTest SHA512) [katZero ..] vectorsSHA512+ , testGroup "verify" $ zipWith (doVerifyTest SHA512) [katZero ..] vectorsSHA512+ ] ]- ]
tests/KAT_PubKey/ECC.hs view
@@ -1,10 +1,13 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_PubKey.ECC (eccTests, eccKatTests) where import Control.Arrow (second) -import qualified Crypto.PubKey.ECC.Types as ECC+import Data.List+ import qualified Crypto.PubKey.ECC.Prim as ECC+import qualified Crypto.PubKey.ECC.Types as ECC import Test.Tasty.KAT import Test.Tasty.KAT.FileLoader@@ -12,131 +15,134 @@ import Imports instance Arbitrary ECC.Curve where- arbitrary = ECC.getCurveByName <$> elements- [ ECC.SEC_p112r1- , ECC.SEC_p112r2- , ECC.SEC_p128r1- , ECC.SEC_p128r2- , ECC.SEC_p160k1- , ECC.SEC_p160r1- , ECC.SEC_p160r2- , ECC.SEC_p192k1- , ECC.SEC_p192r1- , ECC.SEC_p224k1- , ECC.SEC_p224r1- , ECC.SEC_p256k1- , ECC.SEC_p256r1- , ECC.SEC_p384r1- , ECC.SEC_p521r1- , ECC.SEC_t113r1- , ECC.SEC_t113r2- , ECC.SEC_t131r1- , ECC.SEC_t131r2- , ECC.SEC_t163k1- , ECC.SEC_t163r1- , ECC.SEC_t163r2- , ECC.SEC_t193r1- , ECC.SEC_t193r2- , ECC.SEC_t233k1- , ECC.SEC_t233r1- , ECC.SEC_t239k1- , ECC.SEC_t283k1- , ECC.SEC_t283r1- , ECC.SEC_t409k1- , ECC.SEC_t409r1- , ECC.SEC_t571k1- , ECC.SEC_t571r1- ]+ arbitrary =+ ECC.getCurveByName+ <$> elements+ [ ECC.SEC_p112r1+ , ECC.SEC_p112r2+ , ECC.SEC_p128r1+ , ECC.SEC_p128r2+ , ECC.SEC_p160k1+ , ECC.SEC_p160r1+ , ECC.SEC_p160r2+ , ECC.SEC_p192k1+ , ECC.SEC_p192r1+ , ECC.SEC_p224k1+ , ECC.SEC_p224r1+ , ECC.SEC_p256k1+ , ECC.SEC_p256r1+ , ECC.SEC_p384r1+ , ECC.SEC_p521r1+ , ECC.SEC_t113r1+ , ECC.SEC_t113r2+ , ECC.SEC_t131r1+ , ECC.SEC_t131r2+ , ECC.SEC_t163k1+ , ECC.SEC_t163r1+ , ECC.SEC_t163r2+ , ECC.SEC_t193r1+ , ECC.SEC_t193r2+ , ECC.SEC_t233k1+ , ECC.SEC_t233r1+ , ECC.SEC_t239k1+ , ECC.SEC_t283k1+ , ECC.SEC_t283r1+ , ECC.SEC_t409k1+ , ECC.SEC_t409r1+ , ECC.SEC_t571k1+ , ECC.SEC_t571r1+ ] data VectorPoint = VectorPoint { curve :: ECC.Curve- , x :: Integer- , y :: Integer+ , x :: Integer+ , y :: Integer , valid :: Bool } +vectorsPoint :: [VectorPoint] vectorsPoint = [ VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0x491c0c4761b0a4a147b5e4ce03a531546644f5d1e3d05e57- , y = 0x6fa5addd47c5d6be3933fbff88f57a6c8ca0232c471965de+ , x = 0x491c0c4761b0a4a147b5e4ce03a531546644f5d1e3d05e57+ , y = 0x6fa5addd47c5d6be3933fbff88f57a6c8ca0232c471965de , valid = False -- point not on curve } , VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0x646c22e8aa5f7833390e0399155ac198ae42470bba4fc834- , y = 0x8d4afcfffd80e69a4d180178b37c44572495b7b267ee32a9+ , x = 0x646c22e8aa5f7833390e0399155ac198ae42470bba4fc834+ , y = 0x8d4afcfffd80e69a4d180178b37c44572495b7b267ee32a9 , valid = True } , VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0x4c6b9ea0dec92ecfff7799470be6a2277b9169daf45d54bb- , y = 0xf0eab42826704f51b26ae98036e83230becb639dd1964627+ , x = 0x4c6b9ea0dec92ecfff7799470be6a2277b9169daf45d54bb+ , y = 0xf0eab42826704f51b26ae98036e83230becb639dd1964627 , valid = False -- point not on curve }- , VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0x0673c8bb717b055c3d6f55c06acfcfb7260361ed3ec0f414- , y = 0xba8b172826eb0b854026968d2338a180450a27906f6eddea+ , x = 0x0673c8bb717b055c3d6f55c06acfcfb7260361ed3ec0f414+ , y = 0xba8b172826eb0b854026968d2338a180450a27906f6eddea , valid = True }- , VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0x82c949295156192df0b52480e38c810751ac570daec460a3- , y = 0x200057ada615c80b8ff256ce8d47f2562b74a438f1921ac3+ , x = 0x82c949295156192df0b52480e38c810751ac570daec460a3+ , y = 0x200057ada615c80b8ff256ce8d47f2562b74a438f1921ac3 , valid = False -- point not on curve }- , VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0x284fbaa76ce0faae2ca4867d01092fa1ace5724cd12c8dd0- , y = 0xe42af3dbf3206be3fcbcc3a7ccaf60c73dc29e7bb9b44fca+ , x = 0x284fbaa76ce0faae2ca4867d01092fa1ace5724cd12c8dd0+ , y = 0xe42af3dbf3206be3fcbcc3a7ccaf60c73dc29e7bb9b44fca , valid = True }- , VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0x1b574acd4fb0f60dde3e3b5f3f0e94211f95112e43cba6fd2- , y = 0xbcc1b8a770f01a22e84d7f14e44932ffe094d8e3b1e6ac26+ , x = 0x1b574acd4fb0f60dde3e3b5f3f0e94211f95112e43cba6fd2+ , y = 0xbcc1b8a770f01a22e84d7f14e44932ffe094d8e3b1e6ac26 , valid = False -- x or y out of range }- , VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0x16ba109f1f1bb44e0d05b80181c03412ea764a59601d17e9f- , y = 0x0569a843dbb4e287db420d6b9fe30cd7b5d578b052315f56+ , x = 0x16ba109f1f1bb44e0d05b80181c03412ea764a59601d17e9f+ , y = 0x0569a843dbb4e287db420d6b9fe30cd7b5d578b052315f56 , valid = False -- x or y out of range }- , VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0x1333308a7c833ede5189d25ea3525919c9bd16370d904938d- , y = 0xb10fd01d67df75ff9b726c700c1b50596c9f0766ea56f80e+ , x = 0x1333308a7c833ede5189d25ea3525919c9bd16370d904938d+ , y = 0xb10fd01d67df75ff9b726c700c1b50596c9f0766ea56f80e , valid = False -- x or y out of range } , VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0x9671ec444cff24c8a5be80b018fa505ed6109a731e88c91a- , y = 0xfe79dae23008e46bf4230c895aab261a95845a77f06d0655+ , x = 0x9671ec444cff24c8a5be80b018fa505ed6109a731e88c91a+ , y = 0xfe79dae23008e46bf4230c895aab261a95845a77f06d0655 , valid = True } , VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0x158e8b6f0b14216bc52fe8897b4305d870ede70436a96741d- , y = 0xfb3f970b19a313571a1a23be310923f85acc1cab0a157cbd+ , x = 0x158e8b6f0b14216bc52fe8897b4305d870ede70436a96741d+ , y = 0xfb3f970b19a313571a1a23be310923f85acc1cab0a157cbd , valid = False -- x or y out of range } , VectorPoint { curve = ECC.getCurveByName ECC.SEC_p192r1- , x = 0xace95b650c08f73dbb4fa7b4bbdebd6b809a25b28ed135ef- , y = 0xe9b8679404166d1329dd539ad52aad9a1b6681f5f26bb9aa+ , x = 0xace95b650c08f73dbb4fa7b4bbdebd6b809a25b28ed135ef+ , y = 0xe9b8679404166d1329dd539ad52aad9a1b6681f5f26bb9aa , valid = False -- point not on curve } ] -doPointValidTest i vector = testCase (show i) (valid vector @=? ECC.isPointValid (curve vector) (ECC.Point (x vector) (y vector)))+doPointValidTest :: Show a => a -> VectorPoint -> TestTree+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 =@@ -145,68 +151,85 @@ n = ECC.ecc_n (ECC.common_curve aCurve) pointGen = ECC.pointBaseMul aCurve <$> choose (1, n - 1) -eccTests = testGroup "ECC"- [ 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- curveGen = ECC.ecc_g . ECC.common_curve $ aCurve- p1 = ECC.pointMul aCurve r1 curveGen- p2 = ECC.pointMul aCurve r2 curveGen- pR = ECC.pointMul aCurve ((r1 + r2) `mod` curveN) curveGen- in pR `propertyEq` ECC.pointAdd aCurve p1 p2- , testProperty "point-negate-add" $ \aCurve -> do- p <- arbitraryPoint aCurve- let o = ECC.pointAdd aCurve p (ECC.pointNegate aCurve p)- return $ ECC.PointO `propertyEq` o- , testProperty "point-negate-negate" $ \aCurve -> do- p <- arbitraryPoint aCurve- return $ p `propertyEq` ECC.pointNegate aCurve (ECC.pointNegate aCurve p)- , testProperty "point-mul-mul" $ \aCurve (QAInteger n1) (QAInteger n2) -> do- p <- arbitraryPoint aCurve- let pRes = ECC.pointMul aCurve (n1 * n2) p- let pDef = ECC.pointMul aCurve n1 (ECC.pointMul aCurve n2 p)- return $ pRes `propertyEq` pDef- , testProperty "double-scalar-mult" $ \aCurve (QAInteger n1) (QAInteger n2) -> do- p1 <- arbitraryPoint aCurve- p2 <- arbitraryPoint aCurve- let pRes = ECC.pointAddTwoMuls aCurve n1 p1 n2 p2- let pDef = ECC.pointAdd aCurve (ECC.pointMul aCurve n1 p1) (ECC.pointMul aCurve n2 p2)- return $ pRes `propertyEq` pDef+eccTests :: TestTree+eccTests =+ testGroup+ "ECC"+ [ 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+ curveGen = ECC.ecc_g . ECC.common_curve $ aCurve+ p1 = ECC.pointMul aCurve r1 curveGen+ p2 = ECC.pointMul aCurve r2 curveGen+ pR = ECC.pointMul aCurve ((r1 + r2) `mod` curveN) curveGen+ in pR `propertyEq` ECC.pointAdd aCurve p1 p2+ , testProperty "point-negate-add" $ \aCurve -> do+ p <- arbitraryPoint aCurve+ let o = ECC.pointAdd aCurve p (ECC.pointNegate aCurve p)+ return $ ECC.PointO `propertyEq` o+ , testProperty "point-negate-negate" $ \aCurve -> do+ p <- arbitraryPoint aCurve+ return $ p `propertyEq` ECC.pointNegate aCurve (ECC.pointNegate aCurve p)+ , testProperty "point-mul-mul" $ \aCurve (QAInteger n1) (QAInteger n2) -> do+ p <- arbitraryPoint aCurve+ let pRes = ECC.pointMul aCurve (n1 * n2) p+ let pDef = ECC.pointMul aCurve n1 (ECC.pointMul aCurve n2 p)+ return $ pRes `propertyEq` pDef+ , testProperty "double-scalar-mult" $ \aCurve (QAInteger n1) (QAInteger n2) -> do+ p1 <- arbitraryPoint aCurve+ p2 <- arbitraryPoint aCurve+ let pRes = ECC.pointAddTwoMuls aCurve n1 p1 n2 p2+ let pDef = ECC.pointAdd aCurve (ECC.pointMul aCurve n1 p1) (ECC.pointMul aCurve n2 p2)+ return $ pRes `propertyEq` pDef+ ] ]- ] +eccKatTests :: IO TestTree eccKatTests = do- res <- testKatLoad "KATs/ECC-PKV.txt" (map (second (map toVector)) . katLoaderSimple)- return $ testKatDetailed {-Grouped-} "ECC/valid-point" res (\g vect -> do- let mCurve = ECC.getCurveByName <$> case g of- "P-192" -> Just ECC.SEC_p192r1- "P-224" -> Just ECC.SEC_p224r1- "P-256" -> Just ECC.SEC_p256r1- "P-384" -> Just ECC.SEC_p384r1- "P-521" -> Just ECC.SEC_p521r1- "B-163" -> Just ECC.SEC_t163r2- "B-233" -> Just ECC.SEC_t233r1- "B-283" -> Just ECC.SEC_t283r1- "B-409" -> Just ECC.SEC_t409r1- "B-571" -> Just ECC.SEC_t571r1- "" -> Nothing- _ -> Nothing-{-- "K-163" -> Just ECC.SEC_t163k1- "K-233" -> Just ECC.SEC_t233k1- "K-283" -> Just ECC.SEC_t283k1- "K-409" -> Just ECC.SEC_t409k1- "K-571" -> Just ECC.SEC_t571k1--}- case mCurve of- Nothing -> return True- Just c -> do- return (ECC.isPointValid c (ECC.Point (x vect) (y vect)) == valid vect)- )-- where toVector kvs =- case sequence $ map (flip lookup kvs) [ "Qx", "Qy", "Result" ] of- Just [qx,qy,res] -> VectorPoint undefined (valueHexInteger qx) (valueHexInteger qy) (head res /= 'F')- Just _ -> error ("ERROR: " ++ show kvs)- Nothing -> error ("ERROR: " ++ show kvs) -- VectorPoint undefined 0 0 True+ res <-+ testKatLoad "KATs/ECC-PKV.txt" (map (second (map toVector)) . katLoaderSimple)+ return $+ testKatDetailed {-Grouped-}+ "ECC/valid-point"+ res+ ( \g vect -> do+ let mCurve =+ ECC.getCurveByName <$> case g of+ "P-192" -> Just ECC.SEC_p192r1+ "P-224" -> Just ECC.SEC_p224r1+ "P-256" -> Just ECC.SEC_p256r1+ "P-384" -> Just ECC.SEC_p384r1+ "P-521" -> Just ECC.SEC_p521r1+ "B-163" -> Just ECC.SEC_t163r2+ "B-233" -> Just ECC.SEC_t233r1+ "B-283" -> Just ECC.SEC_t283r1+ "B-409" -> Just ECC.SEC_t409r1+ "B-571" -> Just ECC.SEC_t571r1+ "" -> Nothing+ _ -> Nothing+ {-+ "K-163" -> Just ECC.SEC_t163k1+ "K-233" -> Just ECC.SEC_t233k1+ "K-283" -> Just ECC.SEC_t283k1+ "K-409" -> Just ECC.SEC_t409k1+ "K-571" -> Just ECC.SEC_t571k1+ -}+ case mCurve of+ Nothing -> return True+ Just c -> do+ return (ECC.isPointValid c (ECC.Point (x vect) (y vect)) == valid vect)+ )+ where+ toVector kvs =+ case sequence $ map (flip lookup kvs) ["Qx", "Qy", "Result"] of+ Just [qx, qy, res] ->+ VectorPoint+ undefined+ (valueHexInteger qx)+ (valueHexInteger qy)+ ("F" `isPrefixOf` res)+ Just _ -> error ("ERROR: " ++ show kvs)+ Nothing -> error ("ERROR: " ++ show kvs) -- VectorPoint undefined 0 0 True
tests/KAT_PubKey/ECDSA.hs view
@@ -1,521 +1,1636 @@--- Test vectors for SHA1 are taken from GEC2: www.secg.org/collateral/gec2.pdf--- Test vectors for SHA224, SHA256, SHA384, SHA512 are taken from RFC 6979-{-# LANGUAGE OverloadedStrings #-}-module KAT_PubKey.ECDSA (ecdsaTests) where--import Crypto.Number.Serialize--import qualified Crypto.PubKey.ECC.ECDSA as ECDSA-import qualified Crypto.PubKey.ECC.Types as ECC-import Crypto.Hash (SHA1(..), SHA224(..), SHA256(..), SHA384(..), SHA512(..))--import Imports--data VectorECDSA = VectorECDSA- { curve :: ECC.Curve- , msg :: ByteString- , d :: Integer- , q :: ECC.Point- , k :: Integer- , r :: Integer- , s :: Integer- }--vectorsSHA1 =- [ VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p160r1- , msg = "abc"- , d = 971761939728640320549601132085879836204587084162- , q = ECC.Point 466448783855397898016055842232266600516272889280- 1110706324081757720403272427311003102474457754220- , k = 702232148019446860144825009548118511996283736794- , r = 1176954224688105769566774212902092897866168635793- , s = 299742580584132926933316745664091704165278518100- }- -- from official ECDSA KATs- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_t163k1- , msg = i2osp 0xa2c1a03fdd00521bb08fc88d20344321977aaf637ef9d5470dd7d2c8628fc8d0d1f1d3587c6b3fd02386f8c13db341b14748a9475cc63baf065df64054b27d5c2cdf0f98e3bbb81d0b5dc94f8cdb87acf75720f6163de394c8c6af360bc1acb85b923a493b7b27cc111a257e36337bd94eb0fab9d5e633befb1ae7f1b244bfaa- , d = 0x00000011f2626d90d26cb4c0379043b26e64107fc- , q = ECC.Point 0x0389fa5ad7f8304325a8c060ef7dcb83042c045bc- 0x0eefa094a5054da196943cc80509dcb9f59e5bc2e- , k = 0x0000000c3a4ff97286126dab1e5089395fcc47ebb- , r = 0x0dbe6c3a1dc851e7f2338b5c26c62b4b37bf8035c- , s = 0x1c76458135b1ff9fbd23009b8414a47996126b56a- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_t163k1- , msg = i2osp 0x67048080daaeb77d3ac31babdf8be23dbe75ceb4dfb94aa8113db5c5dcb6fe14b70f717b7b0ed0881835a66a86e6d840ffcb7d976c75ef2d1d4322fbbc86357384e24707aef88cea2c41a01a9a3d1b9e72ce650c7fdecc4f9448d3a77df6cdf13647ab295bb3132de0b1b2c402d8d2de7d452f1e003e0695de1470d1064eee16- , d = 0x00000006a3803301daee9af09bb5b6c991a4f49a4- , q = ECC.Point 0x4b500f555e857da8c299780130c5c3f48f02ee322 0x5c1c0ae25b47f06cc46fb86b12d2d8c0ba6a4bf07- , k = 0x0000002f39fbf77f3e0dc046116de692b6cf91b16- , r = 0x3d3eeda42f65d727f4a564f1415654356c6c57a6c- , s = 0x35e4d43c5f08baddf138449db1ad0b7872552b7cd- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_t163k1- , msg = i2osp 0x77e007dc2acd7248256165a4b30e98986f51a81efd926b85f74c81bc2a6d2bcd030060a844091e22fbb0ff3db5a20caaefb5d58ccdcbc27f0ff8a4d940e78f303079ec1ca5b0ca3d4ecc7580f8b34a9f0496c9e719d2ec3e1614b7644bc11179e895d2c0b58a1da204fbf0f6e509f97f983eacb6487092caf6e8e4e6b3c458b2- , d = 0x0000002e28676514bd93fea11b62db0f6e324b18d- , q = ECC.Point 0x3f9c90b71f6a1de20a2716f38ef1b5f98c757bd42 0x2ff0a5d266d447ef62d43fbca6c34c08c1ce35a40- , k = 0x00000001233ae699883e74e7f4dfb5279ff22280a- , r = 0x39de3cd2cf04145e522b8fba3f23e9218226e0860- , s = 0x2af62bfb3cfa202e2342606ee5bb0934c3b0375b6- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_t163k1- , msg = i2osp 0xfbacfcce4688748406ddf5c3495021eef8fb399865b649eb2395a04a1ab28335da2c236d306fcc59f7b65ea931cf0139571e1538ede5688958c3ac69f47a285362f5ad201f89cc735b7b465408c2c41b310fc8908d0be45054df2a7351fae36b390e842f3b5cdd9ad832940df5b2d25c2ed43ce86eaf2508bcf401ae58bb1d47- , d = 0x000000361dd088e3a6d3c910686c8dce57e5d4d8e- , q = ECC.Point 0x064f905c1da9d7e9c32d81890ae6f30dcc7839d32 0x06f1faedb6d9032016d3b681e7cf69c29d29eb27b- , k = 0x00000022f723e9f5da56d3d0837d5dca2f937395f- , r = 0x374cdc8571083fecfbd4e25e1cd69ecc66b715f2d- , s = 0x313b10949222929b2f20b15d446c27d6dcae3f086- }- ]--rfc6979_vectorsSHA224 =- [ VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p192r1- , msg = "sample"- , d = 0x6fab034934e4c0fc9ae67f5b5659a9d7d1fefd187ee09fd4- , q = ECC.Point 0xac2c77f529f91689fea0ea5efec7f210d8eea0b9e047ed56- 0x3bc723e57670bd4887ebc732c523063d0a7c957bc97c1c43- , k = 0x4381526b3fc1e7128f202e194505592f01d5ff4c5af015d8- , r = 0xa1f00dad97aeec91c95585f36200c65f3c01812aa60378f5- , s = 0xe07ec1304c7c6c9debbe980b9692668f81d4de7922a0f97a- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p192r1- , msg = "test"- , d = 0x6fab034934e4c0fc9ae67f5b5659a9d7d1fefd187ee09fd4- , q = ECC.Point 0xac2c77f529f91689fea0ea5efec7f210d8eea0b9e047ed56- 0x3bc723e57670bd4887ebc732c523063d0a7c957bc97c1c43- , k = 0xf5dc805f76ef851800700cce82e7b98d8911b7d510059fbe- , r = 0x6945a1c1d1b2206b8145548f633bb61cef04891baf26ed34- , s = 0xb7fb7fdfc339c0b9bd61a9f5a8eaf9be58fc5cba2cb15293- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p224r1- , msg = "sample"- , d = 0xf220266e1105bfe3083e03ec7a3a654651f45e37167e88600bf257c1- , q = ECC.Point 0x00cf08da5ad719e42707fa431292dea11244d64fc51610d94b130d6c- 0xeeab6f3debe455e3dbf85416f7030cbd94f34f2d6f232c69f3c1385a- , k = 0xc1d1f2f10881088301880506805feb4825fe09acb6816c36991aa06d- , r = 0x1cdfe6662dde1e4a1ec4cdedf6a1f5a2fb7fbd9145c12113e6abfd3e- , s = 0xa6694fd7718a21053f225d3f46197ca699d45006c06f871808f43ebc- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p224r1- , msg = "test"- , d = 0xf220266e1105bfe3083e03ec7a3a654651f45e37167e88600bf257c1- , q = ECC.Point 0x00cf08da5ad719e42707fa431292dea11244d64fc51610d94b130d6c- 0xeeab6f3debe455e3dbf85416f7030cbd94f34f2d6f232c69f3c1385a- , k = 0xdf8b38d40dca3e077d0ac520bf56b6d565134d9b5f2eae0d34900524- , r = 0xc441ce8e261ded634e4cf84910e4c5d1d22c5cf3b732bb204dbef019- , s = 0x902f42847a63bdc5f6046ada114953120f99442d76510150f372a3f4- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p256r1- , msg = "sample"- , d = 0xc9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721- , q = ECC.Point 0x60fed4ba255a9d31c961eb74c6356d68c049b8923b61fa6ce669622e60f29fb6- 0x7903fe1008b8bc99a41ae9e95628bc64f2f1b20c2d7e9f5177a3c294d4462299- , k = 0x103f90ee9dc52e5e7fb5132b7033c63066d194321491862059967c715985d473- , r = 0x53b2fff5d1752b2c689df257c04c40a587fababb3f6fc2702f1343af7ca9aa3f- , s = 0xb9afb64fdc03dc1a131c7d2386d11e349f070aa432a4acc918bea988bf75c74c- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p256r1- , msg = "test"- , d = 0xc9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721- , q = ECC.Point 0x60fed4ba255a9d31c961eb74c6356d68c049b8923b61fa6ce669622e60f29fb6- 0x7903fe1008b8bc99a41ae9e95628bc64f2f1b20c2d7e9f5177a3c294d4462299- , k = 0x669f4426f2688b8be0db3a6bd1989bdaefff84b649eeb84f3dd26080f667faa7- , r = 0xc37edb6f0ae79d47c3c27e962fa269bb4f441770357e114ee511f662ec34a692- , s = 0xc820053a05791e521fcaad6042d40aea1d6b1a540138558f47d0719800e18f2d- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p384r1- , msg = "sample"- , d = 0x6b9d3dad2e1b8c1c05b19875b6659f4de23c3b667bf297ba9aa47740787137d896d5724e4c70a825f872c9ea60d2edf5- , q = ECC.Point 0xec3a4e415b4e19a4568618029f427fa5da9a8bc4ae92e02e06aae5286b300c64def8f0ea9055866064a254515480bc13- 0x8015d9b72d7d57244ea8ef9ac0c621896708a59367f9dfb9f54ca84b3f1c9db1288b231c3ae0d4fe7344fd2533264720- , k = 0xa4e4d2f0e729eb786b31fc20ad5d849e304450e0ae8e3e341134a5c1afa03cab8083ee4e3c45b06a5899ea56c51b5879- , r = 0x42356e76b55a6d9b4631c865445dbe54e056d3b3431766d0509244793c3f9366450f76ee3de43f5a125333a6be060122- , s = 0x9da0c81787064021e78df658f2fbb0b042bf304665db721f077a4298b095e4834c082c03d83028efbf93a3c23940ca8d- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p384r1- , msg = "test"- , d = 0x6b9d3dad2e1b8c1c05b19875b6659f4de23c3b667bf297ba9aa47740787137d896d5724e4c70a825f872c9ea60d2edf5- , q = ECC.Point 0xec3a4e415b4e19a4568618029f427fa5da9a8bc4ae92e02e06aae5286b300c64def8f0ea9055866064a254515480bc13- 0x8015d9b72d7d57244ea8ef9ac0c621896708a59367f9dfb9f54ca84b3f1c9db1288b231c3ae0d4fe7344fd2533264720- , k = 0x18fa39db95aa5f561f30fa3591dc59c0fa3653a80daffa0b48d1a4c6dfcbff6e3d33be4dc5eb8886a8ecd093f2935726- , r = 0xe8c9d0b6ea72a0e7837fea1d14a1a9557f29faa45d3e7ee888fc5bf954b5e62464a9a817c47ff78b8c11066b24080e72- , s = 0x07041d4a7a0379ac7232ff72e6f77b6ddb8f09b16cce0ec3286b2bd43fa8c6141c53ea5abef0d8231077a04540a96b66- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p521r1- , msg = "sample"- , d = 0x0fad06daa62ba3b25d2fb40133da757205de67f5bb0018fee8c86e1b68c7e75caa896eb32f1f47c70855836a6d16fcc1466f6d8fbec67db89ec0c08b0e996b83538- , q = ECC.Point 0x1894550d0785932e00eaa23b694f213f8c3121f86dc97a04e5a7167db4e5bcd371123d46e45db6b5d5370a7f20fb633155d38ffa16d2bd761dcac474b9a2f5023a4- 0x0493101c962cd4d2fddf782285e64584139c2f91b47f87ff82354d6630f746a28a0db25741b5b34a828008b22acc23f924faafbd4d33f81ea66956dfeaa2bfdfcf5- , k = 0x121415ec2cd7726330a61f7f3fa5de14be9436019c4db8cb4041f3b54cf31be0493ee3f427fb906393d895a19c9523f3a1d54bb8702bd4aa9c99dab2597b92113f3- , r = 0x1776331cfcdf927d666e032e00cf776187bc9fdd8e69d0dabb4109ffe1b5e2a30715f4cc923a4a5e94d2503e9acfed92857b7f31d7152e0f8c00c15ff3d87e2ed2e- , s = 0x050cb5265417fe2320bbb5a122b8e1a32bd699089851128e360e620a30c7e17ba41a666af126ce100e5799b153b60528d5300d08489ca9178fb610a2006c254b41f- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p521r1- , msg = "test"- , d = 0x0fad06daa62ba3b25d2fb40133da757205de67f5bb0018fee8c86e1b68c7e75caa896eb32f1f47c70855836a6d16fcc1466f6d8fbec67db89ec0c08b0e996b83538- , q = ECC.Point 0x1894550d0785932e00eaa23b694f213f8c3121f86dc97a04e5a7167db4e5bcd371123d46e45db6b5d5370a7f20fb633155d38ffa16d2bd761dcac474b9a2f5023a4- 0x0493101c962cd4d2fddf782285e64584139c2f91b47f87ff82354d6630f746a28a0db25741b5b34a828008b22acc23f924faafbd4d33f81ea66956dfeaa2bfdfcf5- , k = 0x040d09fcf3c8a5f62cf4fb223cbbb2b9937f6b0577c27020a99602c25a01136987e452988781484edbbcf1c47e554e7fc901bc3085e5206d9f619cff07e73d6f706- , r = 0x1c7ed902e123e6815546065a2c4af977b22aa8eaddb68b2c1110e7ea44d42086bfe4a34b67ddc0e17e96536e358219b23a706c6a6e16ba77b65e1c595d43cae17fb- , s = 0x177336676304fcb343ce028b38e7b4fba76c1c1b277da18cad2a8478b2a9a9f5bec0f3ba04f35db3e4263569ec6aade8c92746e4c82f8299ae1b8f1739f8fd519a4- }- ]--rfc6979_vectorsSHA256 =- [ VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p192r1- , msg = "sample"- , d = 0x6fab034934e4c0fc9ae67f5b5659a9d7d1fefd187ee09fd4- , q = ECC.Point 0xac2c77f529f91689fea0ea5efec7f210d8eea0b9e047ed56- 0x3bc723e57670bd4887ebc732c523063d0a7c957bc97c1c43- , k = 0x32b1b6d7d42a05cb449065727a84804fb1a3e34d8f261496- , r = 0x4b0b8ce98a92866a2820e20aa6b75b56382e0f9bfd5ecb55- , s = 0xccdb006926ea9565cbadc840829d8c384e06de1f1e381b85- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p192r1- , msg = "test"- , d = 0x6fab034934e4c0fc9ae67f5b5659a9d7d1fefd187ee09fd4- , q = ECC.Point 0xac2c77f529f91689fea0ea5efec7f210d8eea0b9e047ed56- 0x3bc723e57670bd4887ebc732c523063d0a7c957bc97c1c43- , k = 0x5c4ce89cf56d9e7c77c8585339b006b97b5f0680b4306c6c- , r = 0x3a718bd8b4926c3b52ee6bbe67ef79b18cb6eb62b1ad97ae- , s = 0x5662e6848a4a19b1f1ae2f72acd4b8bbe50f1eac65d9124f- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p224r1- , msg = "sample"- , d = 0xf220266e1105bfe3083e03ec7a3a654651f45e37167e88600bf257c1- , q = ECC.Point 0x00cf08da5ad719e42707fa431292dea11244d64fc51610d94b130d6c- 0xeeab6f3debe455e3dbf85416f7030cbd94f34f2d6f232c69f3c1385a- , k = 0xad3029e0278f80643de33917ce6908c70a8ff50a411f06e41dedfcdc- , r = 0x61aa3da010e8e8406c656bc477a7a7189895e7e840cdfe8ff42307ba- , s = 0xbc814050dab5d23770879494f9e0a680dc1af7161991bde692b10101- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p224r1- , msg = "test"- , d = 0xf220266e1105bfe3083e03ec7a3a654651f45e37167e88600bf257c1- , q = ECC.Point 0x00cf08da5ad719e42707fa431292dea11244d64fc51610d94b130d6c- 0xeeab6f3debe455e3dbf85416f7030cbd94f34f2d6f232c69f3c1385a- , k = 0xff86f57924da248d6e44e8154eb69f0ae2aebaee9931d0b5a969f904- , r = 0xad04dde87b84747a243a631ea47a1ba6d1faa059149ad2440de6fba6- , s = 0x178d49b1ae90e3d8b629be3db5683915f4e8c99fdf6e666cf37adcfd- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p256r1- , msg = "sample"- , d = 0xc9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721- , q = ECC.Point 0x60fed4ba255a9d31c961eb74c6356d68c049b8923b61fa6ce669622e60f29fb6- 0x7903fe1008b8bc99a41ae9e95628bc64f2f1b20c2d7e9f5177a3c294d4462299- , k = 0xa6e3c57dd01abe90086538398355dd4c3b17aa873382b0f24d6129493d8aad60- , r = 0xefd48b2aacb6a8fd1140dd9cd45e81d69d2c877b56aaf991c34d0ea84eaf3716- , s = 0xf7cb1c942d657c41d436c7a1b6e29f65f3e900dbb9aff4064dc4ab2f843acda8- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p256r1- , msg = "test"- , d = 0xc9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721- , q = ECC.Point 0x60fed4ba255a9d31c961eb74c6356d68c049b8923b61fa6ce669622e60f29fb6- 0x7903fe1008b8bc99a41ae9e95628bc64f2f1b20c2d7e9f5177a3c294d4462299- , k = 0xd16b6ae827f17175e040871a1c7ec3500192c4c92677336ec2537acaee0008e0- , r = 0xf1abb023518351cd71d881567b1ea663ed3efcf6c5132b354f28d3b0b7d38367- , s = 0x019f4113742a2b14bd25926b49c649155f267e60d3814b4c0cc84250e46f0083- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p384r1- , msg = "sample"- , d = 0x6b9d3dad2e1b8c1c05b19875b6659f4de23c3b667bf297ba9aa47740787137d896d5724e4c70a825f872c9ea60d2edf5- , q = ECC.Point 0xec3a4e415b4e19a4568618029f427fa5da9a8bc4ae92e02e06aae5286b300c64def8f0ea9055866064a254515480bc13- 0x8015d9b72d7d57244ea8ef9ac0c621896708a59367f9dfb9f54ca84b3f1c9db1288b231c3ae0d4fe7344fd2533264720- , k = 0x180ae9f9aec5438a44bc159a1fcb277c7be54fa20e7cf404b490650a8acc414e375572342863c899f9f2edf9747a9b60- , r = 0x21b13d1e013c7fa1392d03c5f99af8b30c570c6f98d4ea8e354b63a21d3daa33bde1e888e63355d92fa2b3c36d8fb2cd- , s = 0xf3aa443fb107745bf4bd77cb3891674632068a10ca67e3d45db2266fa7d1feebefdc63eccd1ac42ec0cb8668a4fa0ab0- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p384r1- , msg = "test"- , d = 0x6b9d3dad2e1b8c1c05b19875b6659f4de23c3b667bf297ba9aa47740787137d896d5724e4c70a825f872c9ea60d2edf5- , q = ECC.Point 0xec3a4e415b4e19a4568618029f427fa5da9a8bc4ae92e02e06aae5286b300c64def8f0ea9055866064a254515480bc13- 0x8015d9b72d7d57244ea8ef9ac0c621896708a59367f9dfb9f54ca84b3f1c9db1288b231c3ae0d4fe7344fd2533264720- , k = 0x0cfac37587532347dc3389fdc98286bba8c73807285b184c83e62e26c401c0faa48dd070ba79921a3457abff2d630ad7- , r = 0x6d6defac9ab64dabafe36c6bf510352a4cc27001263638e5b16d9bb51d451559f918eedaf2293be5b475cc8f0188636b- , s = 0x2d46f3becbcc523d5f1a1256bf0c9b024d879ba9e838144c8ba6baeb4b53b47d51ab373f9845c0514eefb14024787265- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p521r1- , msg = "sample"- , d = 0x0fad06daa62ba3b25d2fb40133da757205de67f5bb0018fee8c86e1b68c7e75caa896eb32f1f47c70855836a6d16fcc1466f6d8fbec67db89ec0c08b0e996b83538- , q = ECC.Point 0x1894550d0785932e00eaa23b694f213f8c3121f86dc97a04e5a7167db4e5bcd371123d46e45db6b5d5370a7f20fb633155d38ffa16d2bd761dcac474b9a2f5023a4- 0x0493101c962cd4d2fddf782285e64584139c2f91b47f87ff82354d6630f746a28a0db25741b5b34a828008b22acc23f924faafbd4d33f81ea66956dfeaa2bfdfcf5- , k = 0x0edf38afcaaecab4383358b34d67c9f2216c8382aaea44a3dad5fdc9c32575761793fef24eb0fc276dfc4f6e3ec476752f043cf01415387470bcbd8678ed2c7e1a0- , r = 0x1511bb4d675114fe266fc4372b87682baecc01d3cc62cf2303c92b3526012659d16876e25c7c1e57648f23b73564d67f61c6f14d527d54972810421e7d87589e1a7- , s = 0x04a171143a83163d6df460aaf61522695f207a58b95c0644d87e52aa1a347916e4f7a72930b1bc06dbe22ce3f58264afd23704cbb63b29b931f7de6c9d949a7ecfc- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p521r1- , msg = "test"- , d = 0x0fad06daa62ba3b25d2fb40133da757205de67f5bb0018fee8c86e1b68c7e75caa896eb32f1f47c70855836a6d16fcc1466f6d8fbec67db89ec0c08b0e996b83538- , q = ECC.Point 0x1894550d0785932e00eaa23b694f213f8c3121f86dc97a04e5a7167db4e5bcd371123d46e45db6b5d5370a7f20fb633155d38ffa16d2bd761dcac474b9a2f5023a4- 0x0493101c962cd4d2fddf782285e64584139c2f91b47f87ff82354d6630f746a28a0db25741b5b34a828008b22acc23f924faafbd4d33f81ea66956dfeaa2bfdfcf5- , k = 0x01de74955efaabc4c4f17f8e84d881d1310b5392d7700275f82f145c61e843841af09035bf7a6210f5a431a6a9e81c9323354a9e69135d44ebd2fcaa7731b909258- , r = 0x00e871c4a14f993c6c7369501900c4bc1e9c7b0b4ba44e04868b30b41d8071042eb28c4c250411d0ce08cd197e4188ea4876f279f90b3d8d74a3c76e6f1e4656aa8- , s = 0x0cd52dbaa33b063c3a6cd8058a1fb0a46a4754b034fcc644766ca14da8ca5ca9fde00e88c1ad60ccba759025299079d7a427ec3cc5b619bfbc828e7769bcd694e86- }- ]--rfc6979_vectorsSHA384 =- [ VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p192r1- , msg = "sample"- , d = 0x6fab034934e4c0fc9ae67f5b5659a9d7d1fefd187ee09fd4- , q = ECC.Point 0xac2c77f529f91689fea0ea5efec7f210d8eea0b9e047ed56- 0x3bc723e57670bd4887ebc732c523063d0a7c957bc97c1c43- , k = 0x4730005c4fcb01834c063a7b6760096dbe284b8252ef4311- , r = 0xda63bf0b9abcf948fbb1e9167f136145f7a20426dcc287d5- , s = 0xc3aa2c960972bd7a2003a57e1c4c77f0578f8ae95e31ec5e- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p192r1- , msg = "test"- , d = 0x6fab034934e4c0fc9ae67f5b5659a9d7d1fefd187ee09fd4- , q = ECC.Point 0xac2c77f529f91689fea0ea5efec7f210d8eea0b9e047ed56- 0x3bc723e57670bd4887ebc732c523063d0a7c957bc97c1c43- , k = 0x5afefb5d3393261b828db6c91fbc68c230727b030c975693- , r = 0xb234b60b4db75a733e19280a7a6034bd6b1ee88af5332367- , s = 0x7994090b2d59bb782be57e74a44c9a1c700413f8abefe77a- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p224r1- , msg = "sample"- , d = 0xf220266e1105bfe3083e03ec7a3a654651f45e37167e88600bf257c1- , q = ECC.Point 0x00cf08da5ad719e42707fa431292dea11244d64fc51610d94b130d6c- 0xeeab6f3debe455e3dbf85416f7030cbd94f34f2d6f232c69f3c1385a- , k = 0x52b40f5a9d3d13040f494e83d3906c6079f29981035c7bd51e5cac40- , r = 0x0b115e5e36f0f9ec81f1325a5952878d745e19d7bb3eabfaba77e953- , s = 0x830f34ccdfe826ccfdc81eb4129772e20e122348a2bbd889a1b1af1d- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p224r1- , msg = "test"- , d = 0xf220266e1105bfe3083e03ec7a3a654651f45e37167e88600bf257c1- , q = ECC.Point 0x00cf08da5ad719e42707fa431292dea11244d64fc51610d94b130d6c- 0xeeab6f3debe455e3dbf85416f7030cbd94f34f2d6f232c69f3c1385a- , k = 0x7046742b839478c1b5bd31db2e862ad868e1a45c863585b5f22bdc2d- , r = 0x389b92682e399b26518a95506b52c03bc9379a9dadf3391a21fb0ea4- , s = 0x414a718ed3249ff6dbc5b50c27f71f01f070944da22ab1f78f559aab- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p256r1- , msg = "sample"- , d = 0xc9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721- , q = ECC.Point 0x60fed4ba255a9d31c961eb74c6356d68c049b8923b61fa6ce669622e60f29fb6- 0x7903fe1008b8bc99a41ae9e95628bc64f2f1b20c2d7e9f5177a3c294d4462299- , k = 0x09f634b188cefd98e7ec88b1aa9852d734d0bc272f7d2a47decc6ebeb375aad4- , r = 0x0eafea039b20e9b42309fb1d89e213057cbf973dc0cfc8f129edddc800ef7719- , s = 0x4861f0491e6998b9455193e34e7b0d284ddd7149a74b95b9261f13abde940954- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p256r1- , msg = "test"- , d = 0xc9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721- , q = ECC.Point 0x60fed4ba255a9d31c961eb74c6356d68c049b8923b61fa6ce669622e60f29fb6- 0x7903fe1008b8bc99a41ae9e95628bc64f2f1b20c2d7e9f5177a3c294d4462299- , k = 0x16aeffa357260b04b1dd199693960740066c1a8f3e8edd79070aa914d361b3b8- , r = 0x83910e8b48bb0c74244ebdf7f07a1c5413d61472bd941ef3920e623fbccebeb6- , s = 0x8ddbec54cf8cd5874883841d712142a56a8d0f218f5003cb0296b6b509619f2c- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p384r1- , msg = "sample"- , d = 0x6b9d3dad2e1b8c1c05b19875b6659f4de23c3b667bf297ba9aa47740787137d896d5724e4c70a825f872c9ea60d2edf5- , q = ECC.Point 0xec3a4e415b4e19a4568618029f427fa5da9a8bc4ae92e02e06aae5286b300c64def8f0ea9055866064a254515480bc13- 0x8015d9b72d7d57244ea8ef9ac0c621896708a59367f9dfb9f54ca84b3f1c9db1288b231c3ae0d4fe7344fd2533264720- , k = 0x94ed910d1a099dad3254e9242ae85abde4ba15168eaf0ca87a555fd56d10fbca2907e3e83ba95368623b8c4686915cf9- , r = 0x94edbb92a5ecb8aad4736e56c691916b3f88140666ce9fa73d64c4ea95ad133c81a648152e44acf96e36dd1e80fabe46- , s = 0x99ef4aeb15f178cea1fe40db2603138f130e740a19624526203b6351d0a3a94fa329c145786e679e7b82c71a38628ac8- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p384r1- , msg = "test"- , d = 0x6b9d3dad2e1b8c1c05b19875b6659f4de23c3b667bf297ba9aa47740787137d896d5724e4c70a825f872c9ea60d2edf5- , q = ECC.Point 0xec3a4e415b4e19a4568618029f427fa5da9a8bc4ae92e02e06aae5286b300c64def8f0ea9055866064a254515480bc13- 0x8015d9b72d7d57244ea8ef9ac0c621896708a59367f9dfb9f54ca84b3f1c9db1288b231c3ae0d4fe7344fd2533264720- , k = 0x015ee46a5bf88773ed9123a5ab0807962d193719503c527b031b4c2d225092ada71f4a459bc0da98adb95837db8312ea- , r = 0x8203b63d3c853e8d77227fb377bcf7b7b772e97892a80f36ab775d509d7a5feb0542a7f0812998da8f1dd3ca3cf023db- , s = 0xddd0760448d42d8a43af45af836fce4de8be06b485e9b61b827c2f13173923e06a739f040649a667bf3b828246baa5a5- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p521r1- , msg = "sample"- , d = 0x0fad06daa62ba3b25d2fb40133da757205de67f5bb0018fee8c86e1b68c7e75caa896eb32f1f47c70855836a6d16fcc1466f6d8fbec67db89ec0c08b0e996b83538- , q = ECC.Point 0x1894550d0785932e00eaa23b694f213f8c3121f86dc97a04e5a7167db4e5bcd371123d46e45db6b5d5370a7f20fb633155d38ffa16d2bd761dcac474b9a2f5023a4- 0x0493101c962cd4d2fddf782285e64584139c2f91b47f87ff82354d6630f746a28a0db25741b5b34a828008b22acc23f924faafbd4d33f81ea66956dfeaa2bfdfcf5- , k = 0x1546a108bc23a15d6f21872f7ded661fa8431ddbd922d0dcdb77cc878c8553ffad064c95a920a750ac9137e527390d2d92f153e66196966ea554d9adfcb109c4211- , r = 0x1ea842a0e17d2de4f92c15315c63ddf72685c18195c2bb95e572b9c5136ca4b4b576ad712a52be9730627d16054ba40cc0b8d3ff035b12ae75168397f5d50c67451- , s = 0x1f21a3cee066e1961025fb048bd5fe2b7924d0cd797babe0a83b66f1e35eeaf5fde143fa85dc394a7dee766523393784484bdf3e00114a1c857cde1aa203db65d61- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p521r1- , msg = "test"- , d = 0x0fad06daa62ba3b25d2fb40133da757205de67f5bb0018fee8c86e1b68c7e75caa896eb32f1f47c70855836a6d16fcc1466f6d8fbec67db89ec0c08b0e996b83538- , q = ECC.Point 0x1894550d0785932e00eaa23b694f213f8c3121f86dc97a04e5a7167db4e5bcd371123d46e45db6b5d5370a7f20fb633155d38ffa16d2bd761dcac474b9a2f5023a4- 0x0493101c962cd4d2fddf782285e64584139c2f91b47f87ff82354d6630f746a28a0db25741b5b34a828008b22acc23f924faafbd4d33f81ea66956dfeaa2bfdfcf5- , k = 0x1f1fc4a349a7da9a9e116bfdd055dc08e78252ff8e23ac276ac88b1770ae0b5dceb1ed14a4916b769a523ce1e90ba22846af11df8b300c38818f713dadd85de0c88- , r = 0x14bee21a18b6d8b3c93fab08d43e739707953244fdbe924fa926d76669e7ac8c89df62ed8975c2d8397a65a49dcc09f6b0ac62272741924d479354d74ff6075578c- , s = 0x133330865c067a0eaf72362a65e2d7bc4e461e8c8995c3b6226a21bd1aa78f0ed94fe536a0dca35534f0cd1510c41525d163fe9d74d134881e35141ed5e8e95b979- }- ]--rfc6979_vectorsSHA512 =- [ VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p192r1- , msg = "sample"- , d = 0x6fab034934e4c0fc9ae67f5b5659a9d7d1fefd187ee09fd4- , q = ECC.Point 0xac2c77f529f91689fea0ea5efec7f210d8eea0b9e047ed56- 0x3bc723e57670bd4887ebc732c523063d0a7c957bc97c1c43- , k = 0xa2ac7ab055e4f20692d49209544c203a7d1f2c0bfbc75db1- , r = 0x4d60c5ab1996bd848343b31c00850205e2ea6922dac2e4b8- , s = 0x3f6e837448f027a1bf4b34e796e32a811cbb4050908d8f67- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p192r1- , msg = "test"- , d = 0x6fab034934e4c0fc9ae67f5b5659a9d7d1fefd187ee09fd4- , q = ECC.Point 0xac2c77f529f91689fea0ea5efec7f210d8eea0b9e047ed56- 0x3bc723e57670bd4887ebc732c523063d0a7c957bc97c1c43- , k = 0x0758753a5254759c7cfbad2e2d9b0792eee44136c9480527- , r = 0xfe4f4ae86a58b6507946715934fe2d8ff9d95b6b098fe739- , s = 0x74cf5605c98fba0e1ef34d4b5a1577a7dcf59457cae52290- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p224r1- , msg = "sample"- , d = 0xf220266e1105bfe3083e03ec7a3a654651f45e37167e88600bf257c1- , q = ECC.Point 0x00cf08da5ad719e42707fa431292dea11244d64fc51610d94b130d6c- 0xeeab6f3debe455e3dbf85416f7030cbd94f34f2d6f232c69f3c1385a- , k = 0x9db103ffededf9cfdba05184f925400c1653b8501bab89cea0fbec14- , r = 0x074bd1d979d5f32bf958ddc61e4fb4872adcafeb2256497cdac30397- , s = 0xa4ceca196c3d5a1ff31027b33185dc8ee43f288b21ab342e5d8eb084- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p224r1- , msg = "test"- , d = 0xf220266e1105bfe3083e03ec7a3a654651f45e37167e88600bf257c1- , q = ECC.Point 0x00cf08da5ad719e42707fa431292dea11244d64fc51610d94b130d6c- 0xeeab6f3debe455e3dbf85416f7030cbd94f34f2d6f232c69f3c1385a- , k = 0xe39c2aa4ea6be2306c72126d40ed77bf9739bb4d6ef2bbb1dcb6169d- , r = 0x049f050477c5add858cac56208394b5a55baebbe887fdf765047c17c- , s = 0x077eb13e7005929cefa3cd0403c7cdcc077adf4e44f3c41b2f60ecff- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p256r1- , msg = "sample"- , d = 0xc9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721- , q = ECC.Point 0x60fed4ba255a9d31c961eb74c6356d68c049b8923b61fa6ce669622e60f29fb6- 0x7903fe1008b8bc99a41ae9e95628bc64f2f1b20c2d7e9f5177a3c294d4462299- , k = 0x5fa81c63109badb88c1f367b47da606da28cad69aa22c4fe6ad7df73a7173aa5- , r = 0x8496a60b5e9b47c825488827e0495b0e3fa109ec4568fd3f8d1097678eb97f00- , s = 0x2362ab1adbe2b8adf9cb9edab740ea6049c028114f2460f96554f61fae3302fe- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p256r1- , msg = "test"- , d = 0xc9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721- , q = ECC.Point 0x60fed4ba255a9d31c961eb74c6356d68c049b8923b61fa6ce669622e60f29fb6- 0x7903fe1008b8bc99a41ae9e95628bc64f2f1b20c2d7e9f5177a3c294d4462299- , k = 0x6915d11632aca3c40d5d51c08daf9c555933819548784480e93499000d9f0b7f- , r = 0x461d93f31b6540894788fd206c07cfa0cc35f46fa3c91816fff1040ad1581a04- , s = 0x39af9f15de0db8d97e72719c74820d304ce5226e32dedae67519e840d1194e55- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p384r1- , msg = "sample"- , d = 0x6b9d3dad2e1b8c1c05b19875b6659f4de23c3b667bf297ba9aa47740787137d896d5724e4c70a825f872c9ea60d2edf5- , q = ECC.Point 0xec3a4e415b4e19a4568618029f427fa5da9a8bc4ae92e02e06aae5286b300c64def8f0ea9055866064a254515480bc13- 0x8015d9b72d7d57244ea8ef9ac0c621896708a59367f9dfb9f54ca84b3f1c9db1288b231c3ae0d4fe7344fd2533264720- , k = 0x92fc3c7183a883e24216d1141f1a8976c5b0dd797dfa597e3d7b32198bd35331a4e966532593a52980d0e3aaa5e10ec3- , r = 0xed0959d5880ab2d869ae7f6c2915c6d60f96507f9cb3e047c0046861da4a799cfe30f35cc900056d7c99cd7882433709- , s = 0x512c8cceee3890a84058ce1e22dbc2198f42323ce8aca9135329f03c068e5112dc7cc3ef3446defceb01a45c2667fdd5- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p384r1- , msg = "test"- , d = 0x6b9d3dad2e1b8c1c05b19875b6659f4de23c3b667bf297ba9aa47740787137d896d5724e4c70a825f872c9ea60d2edf5- , q = ECC.Point 0xec3a4e415b4e19a4568618029f427fa5da9a8bc4ae92e02e06aae5286b300c64def8f0ea9055866064a254515480bc13- 0x8015d9b72d7d57244ea8ef9ac0c621896708a59367f9dfb9f54ca84b3f1c9db1288b231c3ae0d4fe7344fd2533264720- , k = 0x3780c4f67cb15518b6acae34c9f83568d2e12e47deab6c50a4e4ee5319d1e8ce0e2cc8a136036dc4b9c00e6888f66b6c- , r = 0xa0d5d090c9980faf3c2ce57b7ae951d31977dd11c775d314af55f76c676447d06fb6495cd21b4b6e340fc236584fb277- , s = 0x976984e59b4c77b0e8e4460dca3d9f20e07b9bb1f63beefaf576f6b2e8b224634a2092cd3792e0159ad9cee37659c736- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p521r1- , msg = "sample"- , d = 0x0fad06daa62ba3b25d2fb40133da757205de67f5bb0018fee8c86e1b68c7e75caa896eb32f1f47c70855836a6d16fcc1466f6d8fbec67db89ec0c08b0e996b83538- , q = ECC.Point 0x1894550d0785932e00eaa23b694f213f8c3121f86dc97a04e5a7167db4e5bcd371123d46e45db6b5d5370a7f20fb633155d38ffa16d2bd761dcac474b9a2f5023a4- 0x0493101c962cd4d2fddf782285e64584139c2f91b47f87ff82354d6630f746a28a0db25741b5b34a828008b22acc23f924faafbd4d33f81ea66956dfeaa2bfdfcf5- , k = 0x1dae2ea071f8110dc26882d4d5eae0621a3256fc8847fb9022e2b7d28e6f10198b1574fdd03a9053c08a1854a168aa5a57470ec97dd5ce090124ef52a2f7ecbffd3- , r = 0x0c328fafcbd79dd77850370c46325d987cb525569fb63c5d3bc53950e6d4c5f174e25a1ee9017b5d450606add152b534931d7d4e8455cc91f9b15bf05ec36e377fa- , s = 0x0617cce7cf5064806c467f678d3b4080d6f1cc50af26ca209417308281b68af282623eaa63e5b5c0723d8b8c37ff0777b1a20f8ccb1dccc43997f1ee0e44da4a67a- }- , VectorECDSA- { curve = ECC.getCurveByName ECC.SEC_p521r1- , msg = "test"- , d = 0x0fad06daa62ba3b25d2fb40133da757205de67f5bb0018fee8c86e1b68c7e75caa896eb32f1f47c70855836a6d16fcc1466f6d8fbec67db89ec0c08b0e996b83538- , q = ECC.Point 0x1894550d0785932e00eaa23b694f213f8c3121f86dc97a04e5a7167db4e5bcd371123d46e45db6b5d5370a7f20fb633155d38ffa16d2bd761dcac474b9a2f5023a4- 0x0493101c962cd4d2fddf782285e64584139c2f91b47f87ff82354d6630f746a28a0db25741b5b34a828008b22acc23f924faafbd4d33f81ea66956dfeaa2bfdfcf5- , k = 0x16200813020ec986863bedfc1b121f605c1215645018aea1a7b215a564de9eb1b38a67aa1128b80ce391c4fb71187654aaa3431027bfc7f395766ca988c964dc56d- , r = 0x13e99020abf5cee7525d16b69b229652ab6bdf2affcaef38773b4b7d08725f10cdb93482fdcc54edcee91eca4166b2a7c6265ef0ce2bd7051b7cef945babd47ee6d- , s = 0x1fbd0013c674aa79cb39849527916ce301c66ea7ce8b80682786ad60f98f7e78a19ca69eff5c57400e3b3a0ad66ce0978214d13baf4e9ac60752f7b155e2de4dce3- }- ]--vectorToPrivate :: VectorECDSA -> ECDSA.PrivateKey-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)- 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)- where actual = ECDSA.verify hashAlg (vectorToPublic vector) (ECDSA.Signature (r vector) (s vector)) (msg vector)--ecdsaTests = testGroup "ECDSA"- [ testGroup "SHA1"- [ testGroup "signature" $ zipWith (doSignatureTest SHA1) [katZero..] vectorsSHA1- , testGroup "verify" $ zipWith (doVerifyTest SHA1) [katZero..] vectorsSHA1- ]- , testGroup "SHA224"- [ testGroup "signature" $ zipWith (doSignatureTest SHA224) [katZero..] rfc6979_vectorsSHA224- , testGroup "verify" $ zipWith (doVerifyTest SHA224) [katZero..] rfc6979_vectorsSHA224- ]- , testGroup "SHA256"- [ testGroup "signature" $ zipWith (doSignatureTest SHA256) [katZero..] rfc6979_vectorsSHA256- , testGroup "verify" $ zipWith (doVerifyTest SHA256) [katZero..] rfc6979_vectorsSHA256- ]- , testGroup "SHA384"- [ testGroup "signature" $ zipWith (doSignatureTest SHA384) [katZero..] rfc6979_vectorsSHA384- , testGroup "verify" $ zipWith (doVerifyTest SHA384) [katZero..] rfc6979_vectorsSHA384- ]- , testGroup "SHA512"- [ testGroup "signature" $ zipWith (doSignatureTest SHA512) [katZero..] rfc6979_vectorsSHA512- , testGroup "verify" $ zipWith (doVerifyTest SHA512) [katZero..] rfc6979_vectorsSHA512- ]- ]+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE OverloadedStrings #-}++module KAT_PubKey.ECDSA (ecdsaTests) where++import Crypto.Hash+import Crypto.Number.Serialize+import Crypto.PubKey.ECC.ECDSA (+ PrivateKey (..),+ PublicKey (..),+ Signature (..),+ deterministicNonce,+ signWith,+ verify,+ )+import Crypto.PubKey.ECC.Generate+import Crypto.PubKey.ECC.Types+import Data.ByteString (ByteString)+import qualified Data.ByteString as B+import Test.Tasty+import Test.Tasty.HUnit+import Text.Printf++-- existential type allows storing different hash algorithms in the same value+data HashAlg = forall hash. (Show hash, HashAlgorithm hash) => HashAlg hash+instance Show HashAlg where show (HashAlg alg) = show alg++data Entry = Entry+ { curveName :: CurveName+ , privateNumber :: PrivateNumber+ , publicPoint :: PublicPoint+ , hashAlgorithm :: HashAlg+ , message :: ByteString+ , nonce :: Integer+ , signature :: Signature+ }+instance Show Entry where+ show entry =+ printf+ "%s.%s.%s"+ (show $ curveName entry)+ (show $ B.take 8 $ message entry)+ (show $ hashAlgorithm entry)++normalize :: Entry -> Entry+normalize entry+ | s <= n `div` 2 = entry+ | otherwise = entry{signature = Signature r (n - s)}+ where+ Signature r s = signature entry+ n = ecc_n $ common_curve $ getCurveByName $ curveName entry++-- taken from GEC 2: Test Vectors for SEC 1+gec2Entries :: [Entry]+gec2Entries =+ [ Entry+ { curveName = SEC_p160r1+ , privateNumber = 971761939728640320549601132085879836204587084162+ , publicPoint =+ Point+ 466448783855397898016055842232266600516272889280+ 1110706324081757720403272427311003102474457754220+ , hashAlgorithm = HashAlg SHA1+ , message = "abc"+ , nonce = 702232148019446860144825009548118511996283736794+ , signature =+ Signature+ { sign_r = 1176954224688105769566774212902092897866168635793+ , sign_s = 299742580584132926933316745664091704165278518100+ }+ }+ , Entry+ { curveName = SEC_t163k1+ , privateNumber = 0x00000011f2626d90d26cb4c0379043b26e64107fc+ , publicPoint =+ Point+ 0x0389fa5ad7f8304325a8c060ef7dcb83042c045bc+ 0x0eefa094a5054da196943cc80509dcb9f59e5bc2e+ , hashAlgorithm = HashAlg SHA1+ , message =+ i2osp+ 0xa2c1a03fdd00521bb08fc88d20344321977aaf637ef9d5470dd7d2c8628fc8d0d1f1d3587c6b3fd02386f8c13db341b14748a9475cc63baf065df64054b27d5c2cdf0f98e3bbb81d0b5dc94f8cdb87acf75720f6163de394c8c6af360bc1acb85b923a493b7b27cc111a257e36337bd94eb0fab9d5e633befb1ae7f1b244bfaa+ , nonce = 0x0000000c3a4ff97286126dab1e5089395fcc47ebb+ , signature =+ Signature+ { sign_r = 0x0dbe6c3a1dc851e7f2338b5c26c62b4b37bf8035c+ , sign_s = 0x1c76458135b1ff9fbd23009b8414a47996126b56a+ }+ }+ , Entry+ { curveName = SEC_t163k1+ , privateNumber = 0x00000006a3803301daee9af09bb5b6c991a4f49a4+ , publicPoint =+ Point+ 0x4b500f555e857da8c299780130c5c3f48f02ee322+ 0x5c1c0ae25b47f06cc46fb86b12d2d8c0ba6a4bf07+ , hashAlgorithm = HashAlg SHA1+ , message =+ i2osp+ 0x67048080daaeb77d3ac31babdf8be23dbe75ceb4dfb94aa8113db5c5dcb6fe14b70f717b7b0ed0881835a66a86e6d840ffcb7d976c75ef2d1d4322fbbc86357384e24707aef88cea2c41a01a9a3d1b9e72ce650c7fdecc4f9448d3a77df6cdf13647ab295bb3132de0b1b2c402d8d2de7d452f1e003e0695de1470d1064eee16+ , nonce = 0x0000002f39fbf77f3e0dc046116de692b6cf91b16+ , signature =+ Signature+ { sign_r = 0x3d3eeda42f65d727f4a564f1415654356c6c57a6c+ , sign_s = 0x35e4d43c5f08baddf138449db1ad0b7872552b7cd+ }+ }+ , Entry+ { curveName = SEC_t163k1+ , privateNumber = 0x0000002e28676514bd93fea11b62db0f6e324b18d+ , publicPoint =+ Point+ 0x3f9c90b71f6a1de20a2716f38ef1b5f98c757bd42+ 0x2ff0a5d266d447ef62d43fbca6c34c08c1ce35a40+ , hashAlgorithm = HashAlg SHA1+ , message =+ i2osp+ 0x77e007dc2acd7248256165a4b30e98986f51a81efd926b85f74c81bc2a6d2bcd030060a844091e22fbb0ff3db5a20caaefb5d58ccdcbc27f0ff8a4d940e78f303079ec1ca5b0ca3d4ecc7580f8b34a9f0496c9e719d2ec3e1614b7644bc11179e895d2c0b58a1da204fbf0f6e509f97f983eacb6487092caf6e8e4e6b3c458b2+ , nonce = 0x00000001233ae699883e74e7f4dfb5279ff22280a+ , signature =+ Signature+ { sign_r = 0x39de3cd2cf04145e522b8fba3f23e9218226e0860+ , sign_s = 0x2af62bfb3cfa202e2342606ee5bb0934c3b0375b6+ }+ }+ , Entry+ { curveName = SEC_t163k1+ , privateNumber = 0x000000361dd088e3a6d3c910686c8dce57e5d4d8e+ , publicPoint =+ Point+ 0x064f905c1da9d7e9c32d81890ae6f30dcc7839d32+ 0x06f1faedb6d9032016d3b681e7cf69c29d29eb27b+ , hashAlgorithm = HashAlg SHA1+ , message =+ i2osp+ 0xfbacfcce4688748406ddf5c3495021eef8fb399865b649eb2395a04a1ab28335da2c236d306fcc59f7b65ea931cf0139571e1538ede5688958c3ac69f47a285362f5ad201f89cc735b7b465408c2c41b310fc8908d0be45054df2a7351fae36b390e842f3b5cdd9ad832940df5b2d25c2ed43ce86eaf2508bcf401ae58bb1d47+ , nonce = 0x00000022f723e9f5da56d3d0837d5dca2f937395f+ , signature =+ Signature+ { sign_r = 0x374cdc8571083fecfbd4e25e1cd69ecc66b715f2d+ , sign_s = 0x313b10949222929b2f20b15d446c27d6dcae3f086+ }+ }+ ]++data EntryCurve = EntryCurve+ { ecName :: CurveName+ , ecPrivate :: PrivateNumber+ , ecPublic :: PublicPoint+ , ecMessages :: [EntryMessage]+ }+data EntryMessage = EntryMessage+ { emMessage :: ByteString+ , emHashes :: [EntryHash]+ }+data EntryHash = EntryHash+ { ehAlgorithm :: HashAlg+ , ehK :: Integer+ , ehR :: Integer+ , ehS :: Integer+ }++flatten :: [EntryCurve] -> [Entry]+flatten hierarchy = do+ entryCurve <- hierarchy+ entryMessage <- ecMessages entryCurve+ entryHash <- emHashes entryMessage+ pure $+ Entry+ { curveName = ecName entryCurve+ , privateNumber = ecPrivate entryCurve+ , publicPoint = ecPublic entryCurve+ , hashAlgorithm = ehAlgorithm entryHash+ , message = emMessage entryMessage+ , nonce = ehK entryHash+ , signature = Signature (ehR entryHash) (ehS entryHash)+ }++-- taken from RFC 6979+rfc6979Entries :: [EntryCurve]+rfc6979Entries =+ [ EntryCurve+ { ecName = SEC_p192r1+ , ecPrivate = 0x6FAB034934E4C0FC9AE67F5B5659A9D7D1FEFD187EE09FD4+ , ecPublic =+ Point+ 0xAC2C77F529F91689FEA0EA5EFEC7F210D8EEA0B9E047ED56+ 0x3BC723E57670BD4887EBC732C523063D0A7C957BC97C1C43+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x37D7CA00D2C7B0E5E412AC03BD44BA837FDD5B28CD3B0021+ , ehR = 0x98C6BD12B23EAF5E2A2045132086BE3EB8EBD62ABF6698FF+ , ehS = 0x57A22B07DEA9530F8DE9471B1DC6624472E8E2844BC25B64+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x4381526B3FC1E7128F202E194505592F01D5FF4C5AF015D8+ , ehR = 0xA1F00DAD97AEEC91C95585F36200C65F3C01812AA60378F5+ , ehS = 0xE07EC1304C7C6C9DEBBE980B9692668F81D4DE7922A0F97A+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x32B1B6D7D42A05CB449065727A84804FB1A3E34D8F261496+ , ehR = 0x4B0B8CE98A92866A2820E20AA6B75B56382E0F9BFD5ECB55+ , ehS = 0xCCDB006926EA9565CBADC840829D8C384E06DE1F1E381B85+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x4730005C4FCB01834C063A7B6760096DBE284B8252EF4311+ , ehR = 0xDA63BF0B9ABCF948FBB1E9167F136145F7A20426DCC287D5+ , ehS = 0xC3AA2C960972BD7A2003A57E1C4C77F0578F8AE95E31EC5E+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0xA2AC7AB055E4F20692D49209544C203A7D1F2C0BFBC75DB1+ , ehR = 0x4D60C5AB1996BD848343B31C00850205E2EA6922DAC2E4B8+ , ehS = 0x3F6E837448F027A1BF4B34E796E32A811CBB4050908D8F67+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0xD9CF9C3D3297D3260773A1DA7418DB5537AB8DD93DE7FA25+ , ehR = 0x0F2141A0EBBC44D2E1AF90A50EBCFCE5E197B3B7D4DE036D+ , ehS = 0xEB18BC9E1F3D7387500CB99CF5F7C157070A8961E38700B7+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0xF5DC805F76EF851800700CCE82E7B98D8911B7D510059FBE+ , ehR = 0x6945A1C1D1B2206B8145548F633BB61CEF04891BAF26ED34+ , ehS = 0xB7FB7FDFC339C0B9BD61A9F5A8EAF9BE58FC5CBA2CB15293+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x5C4CE89CF56D9E7C77C8585339B006B97B5F0680B4306C6C+ , ehR = 0x3A718BD8B4926C3B52EE6BBE67EF79B18CB6EB62B1AD97AE+ , ehS = 0x5662E6848A4A19B1F1AE2F72ACD4B8BBE50F1EAC65D9124F+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x5AFEFB5D3393261B828DB6C91FBC68C230727B030C975693+ , ehR = 0xB234B60B4DB75A733E19280A7A6034BD6B1EE88AF5332367+ , ehS = 0x7994090B2D59BB782BE57E74A44C9A1C700413F8ABEFE77A+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x0758753A5254759C7CFBAD2E2D9B0792EEE44136C9480527+ , ehR = 0xFE4F4AE86A58B6507946715934FE2D8FF9D95B6B098FE739+ , ehS = 0x74CF5605C98FBA0E1EF34D4B5A1577A7DCF59457CAE52290+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_p224r1+ , ecPrivate = 0xF220266E1105BFE3083E03EC7A3A654651F45E37167E88600BF257C1+ , ecPublic =+ Point+ 0x00CF08DA5AD719E42707FA431292DEA11244D64FC51610D94B130D6C+ 0xEEAB6F3DEBE455E3DBF85416F7030CBD94F34F2D6F232C69F3C1385A+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x7EEFADD91110D8DE6C2C470831387C50D3357F7F4D477054B8B426BC+ , ehR = 0x22226F9D40A96E19C4A301CE5B74B115303C0F3A4FD30FC257FB57AC+ , ehS = 0x66D1CDD83E3AF75605DD6E2FEFF196D30AA7ED7A2EDF7AF475403D69+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0xC1D1F2F10881088301880506805FEB4825FE09ACB6816C36991AA06D+ , ehR = 0x1CDFE6662DDE1E4A1EC4CDEDF6A1F5A2FB7FBD9145C12113E6ABFD3E+ , ehS = 0xA6694FD7718A21053F225D3F46197CA699D45006C06F871808F43EBC+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0xAD3029E0278F80643DE33917CE6908C70A8FF50A411F06E41DEDFCDC+ , ehR = 0x61AA3DA010E8E8406C656BC477A7A7189895E7E840CDFE8FF42307BA+ , ehS = 0xBC814050DAB5D23770879494F9E0A680DC1AF7161991BDE692B10101+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x52B40F5A9D3D13040F494E83D3906C6079F29981035C7BD51E5CAC40+ , ehR = 0x0B115E5E36F0F9EC81F1325A5952878D745E19D7BB3EABFABA77E953+ , ehS = 0x830F34CCDFE826CCFDC81EB4129772E20E122348A2BBD889A1B1AF1D+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x9DB103FFEDEDF9CFDBA05184F925400C1653B8501BAB89CEA0FBEC14+ , ehR = 0x074BD1D979D5F32BF958DDC61E4FB4872ADCAFEB2256497CDAC30397+ , ehS = 0xA4CECA196C3D5A1FF31027B33185DC8EE43F288B21AB342E5D8EB084+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x2519178F82C3F0E4F87ED5883A4E114E5B7A6E374043D8EFD329C253+ , ehR = 0xDEAA646EC2AF2EA8AD53ED66B2E2DDAA49A12EFD8356561451F3E21C+ , ehS = 0x95987796F6CF2062AB8135271DE56AE55366C045F6D9593F53787BD2+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0xDF8B38D40DCA3E077D0AC520BF56B6D565134D9B5F2EAE0D34900524+ , ehR = 0xC441CE8E261DED634E4CF84910E4C5D1D22C5CF3B732BB204DBEF019+ , ehS = 0x902F42847A63BDC5F6046ADA114953120F99442D76510150F372A3F4+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0xFF86F57924DA248D6E44E8154EB69F0AE2AEBAEE9931D0B5A969F904+ , ehR = 0xAD04DDE87B84747A243A631EA47A1BA6D1FAA059149AD2440DE6FBA6+ , ehS = 0x178D49B1AE90E3D8B629BE3DB5683915F4E8C99FDF6E666CF37ADCFD+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x7046742B839478C1B5BD31DB2E862AD868E1A45C863585B5F22BDC2D+ , ehR = 0x389B92682E399B26518A95506B52C03BC9379A9DADF3391A21FB0EA4+ , ehS = 0x414A718ED3249FF6DBC5B50C27F71F01F070944DA22AB1F78F559AAB+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0xE39C2AA4EA6BE2306C72126D40ED77BF9739BB4D6EF2BBB1DCB6169D+ , ehR = 0x049F050477C5ADD858CAC56208394B5A55BAEBBE887FDF765047C17C+ , ehS = 0x077EB13E7005929CEFA3CD0403C7CDCC077ADF4E44F3C41B2F60ECFF+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_p256r1+ , ecPrivate = 0xC9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721+ , ecPublic =+ Point+ 0x60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6+ 0x7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x882905F1227FD620FBF2ABF21244F0BA83D0DC3A9103DBBEE43A1FB858109DB4+ , ehR = 0x61340C88C3AAEBEB4F6D667F672CA9759A6CCAA9FA8811313039EE4A35471D32+ , ehS = 0x6D7F147DAC089441BB2E2FE8F7A3FA264B9C475098FDCF6E00D7C996E1B8B7EB+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x103F90EE9DC52E5E7FB5132B7033C63066D194321491862059967C715985D473+ , ehR = 0x53B2FFF5D1752B2C689DF257C04C40A587FABABB3F6FC2702F1343AF7CA9AA3F+ , ehS = 0xB9AFB64FDC03DC1A131C7D2386D11E349F070AA432A4ACC918BEA988BF75C74C+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0xA6E3C57DD01ABE90086538398355DD4C3B17AA873382B0F24D6129493D8AAD60+ , ehR = 0xEFD48B2AACB6A8FD1140DD9CD45E81D69D2C877B56AAF991C34D0EA84EAF3716+ , ehS = 0xF7CB1C942D657C41D436C7A1B6E29F65F3E900DBB9AFF4064DC4AB2F843ACDA8+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x09F634B188CEFD98E7EC88B1AA9852D734D0BC272F7D2A47DECC6EBEB375AAD4+ , ehR = 0x0EAFEA039B20E9B42309FB1D89E213057CBF973DC0CFC8F129EDDDC800EF7719+ , ehS = 0x4861F0491E6998B9455193E34E7B0D284DDD7149A74B95B9261F13ABDE940954+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x5FA81C63109BADB88C1F367B47DA606DA28CAD69AA22C4FE6AD7DF73A7173AA5+ , ehR = 0x8496A60B5E9B47C825488827E0495B0E3FA109EC4568FD3F8D1097678EB97F00+ , ehS = 0x2362AB1ADBE2B8ADF9CB9EDAB740EA6049C028114F2460F96554F61FAE3302FE+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x8C9520267C55D6B980DF741E56B4ADEE114D84FBFA2E62137954164028632A2E+ , ehR = 0x0CBCC86FD6ABD1D99E703E1EC50069EE5C0B4BA4B9AC60E409E8EC5910D81A89+ , ehS = 0x01B9D7B73DFAA60D5651EC4591A0136F87653E0FD780C3B1BC872FFDEAE479B1+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x669F4426F2688B8BE0DB3A6BD1989BDAEFFF84B649EEB84F3DD26080F667FAA7+ , ehR = 0xC37EDB6F0AE79D47C3C27E962FA269BB4F441770357E114EE511F662EC34A692+ , ehS = 0xC820053A05791E521FCAAD6042D40AEA1D6B1A540138558F47D0719800E18F2D+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0xD16B6AE827F17175E040871A1C7EC3500192C4C92677336EC2537ACAEE0008E0+ , ehR = 0xF1ABB023518351CD71D881567B1EA663ED3EFCF6C5132B354F28D3B0B7D38367+ , ehS = 0x019F4113742A2B14BD25926B49C649155F267E60D3814B4C0CC84250E46F0083+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x16AEFFA357260B04B1DD199693960740066C1A8F3E8EDD79070AA914D361B3B8+ , ehR = 0x83910E8B48BB0C74244EBDF7F07A1C5413D61472BD941EF3920E623FBCCEBEB6+ , ehS = 0x8DDBEC54CF8CD5874883841D712142A56A8D0F218F5003CB0296B6B509619F2C+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x6915D11632ACA3C40D5D51C08DAF9C555933819548784480E93499000D9F0B7F+ , ehR = 0x461D93F31B6540894788FD206C07CFA0CC35F46FA3C91816FFF1040AD1581A04+ , ehS = 0x39AF9F15DE0DB8D97E72719C74820D304CE5226E32DEDAE67519E840D1194E55+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_p384r1+ , ecPrivate =+ 0x6B9D3DAD2E1B8C1C05B19875B6659F4DE23C3B667BF297BA9AA47740787137D896D5724E4C70A825F872C9EA60D2EDF5+ , ecPublic =+ Point+ 0xEC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64DEF8F0EA9055866064A254515480BC13+ 0x8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1288B231C3AE0D4FE7344FD2533264720+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x4471EF7518BB2C7C20F62EAE1C387AD0C5E8E470995DB4ACF694466E6AB096630F29E5938D25106C3C340045A2DB01A7+ , ehR =+ 0xEC748D839243D6FBEF4FC5C4859A7DFFD7F3ABDDF72014540C16D73309834FA37B9BA002899F6FDA3A4A9386790D4EB2+ , ehS =+ 0xA3BCFA947BEEF4732BF247AC17F71676CB31A847B9FF0CBC9C9ED4C1A5B3FACF26F49CA031D4857570CCB5CA4424A443+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0xA4E4D2F0E729EB786B31FC20AD5D849E304450E0AE8E3E341134A5C1AFA03CAB8083EE4E3C45B06A5899EA56C51B5879+ , ehR =+ 0x42356E76B55A6D9B4631C865445DBE54E056D3B3431766D0509244793C3F9366450F76EE3DE43F5A125333A6BE060122+ , ehS =+ 0x9DA0C81787064021E78DF658F2FBB0B042BF304665DB721F077A4298B095E4834C082C03D83028EFBF93A3C23940CA8D+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x180AE9F9AEC5438A44BC159A1FCB277C7BE54FA20E7CF404B490650A8ACC414E375572342863C899F9F2EDF9747A9B60+ , ehR =+ 0x21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33BDE1E888E63355D92FA2B3C36D8FB2CD+ , ehS =+ 0xF3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEBEFDC63ECCD1AC42EC0CB8668A4FA0AB0+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x94ED910D1A099DAD3254E9242AE85ABDE4BA15168EAF0CA87A555FD56D10FBCA2907E3E83BA95368623B8C4686915CF9+ , ehR =+ 0x94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C81A648152E44ACF96E36DD1E80FABE46+ , ehS =+ 0x99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94FA329C145786E679E7B82C71A38628AC8+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x92FC3C7183A883E24216D1141F1A8976C5B0DD797DFA597E3D7B32198BD35331A4E966532593A52980D0E3AAA5E10EC3+ , ehR =+ 0xED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799CFE30F35CC900056D7C99CD7882433709+ , ehS =+ 0x512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112DC7CC3EF3446DEFCEB01A45C2667FDD5+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x66CC2C8F4D303FC962E5FF6A27BD79F84EC812DDAE58CF5243B64A4AD8094D47EC3727F3A3C186C15054492E30698497+ , ehR =+ 0x4BC35D3A50EF4E30576F58CD96CE6BF638025EE624004A1F7789A8B8E43D0678ACD9D29876DAF46638645F7F404B11C7+ , ehS =+ 0xD5A6326C494ED3FF614703878961C0FDE7B2C278F9A65FD8C4B7186201A2991695BA1C84541327E966FA7B50F7382282+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0x18FA39DB95AA5F561F30FA3591DC59C0FA3653A80DAFFA0B48D1A4C6DFCBFF6E3D33BE4DC5EB8886A8ECD093F2935726+ , ehR =+ 0xE8C9D0B6EA72A0E7837FEA1D14A1A9557F29FAA45D3E7EE888FC5BF954B5E62464A9A817C47FF78B8C11066B24080E72+ , ehS =+ 0x07041D4A7A0379AC7232FF72E6F77B6DDB8F09B16CCE0EC3286B2BD43FA8C6141C53EA5ABEF0D8231077A04540A96B66+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x0CFAC37587532347DC3389FDC98286BBA8C73807285B184C83E62E26C401C0FAA48DD070BA79921A3457ABFF2D630AD7+ , ehR =+ 0x6D6DEFAC9AB64DABAFE36C6BF510352A4CC27001263638E5B16D9BB51D451559F918EEDAF2293BE5B475CC8F0188636B+ , ehS =+ 0x2D46F3BECBCC523D5F1A1256BF0C9B024D879BA9E838144C8BA6BAEB4B53B47D51AB373F9845C0514EEFB14024787265+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x015EE46A5BF88773ED9123A5AB0807962D193719503C527B031B4C2D225092ADA71F4A459BC0DA98ADB95837DB8312EA+ , ehR =+ 0x8203B63D3C853E8D77227FB377BCF7B7B772E97892A80F36AB775D509D7A5FEB0542A7F0812998DA8F1DD3CA3CF023DB+ , ehS =+ 0xDDD0760448D42D8A43AF45AF836FCE4DE8BE06B485E9B61B827C2F13173923E06A739F040649A667BF3B828246BAA5A5+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x3780C4F67CB15518B6ACAE34C9F83568D2E12E47DEAB6C50A4E4EE5319D1E8CE0E2CC8A136036DC4B9C00E6888F66B6C+ , ehR =+ 0xA0D5D090C9980FAF3C2CE57B7AE951D31977DD11C775D314AF55F76C676447D06FB6495CD21B4B6E340FC236584FB277+ , ehS =+ 0x976984E59B4C77B0E8E4460DCA3D9F20E07B9BB1F63BEEFAF576F6B2E8B224634A2092CD3792E0159AD9CEE37659C736+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_p521r1+ , ecPrivate =+ 0x0FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75CAA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83538+ , ecPublic =+ Point+ 0x1894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD371123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F5023A4+ 0x0493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A28A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDFCF5+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x089C071B419E1C2820962321787258469511958E80582E95D8378E0C2CCDB3CB42BEDE42F50E3FA3C71F5A76724281D31D9C89F0F91FC1BE4918DB1C03A5838D0F9+ , ehR =+ 0x0343B6EC45728975EA5CBA6659BBB6062A5FF89EEA58BE3C80B619F322C87910FE092F7D45BB0F8EEE01ED3F20BABEC079D202AE677B243AB40B5431D497C55D75D+ , ehS =+ 0x0E7B0E675A9B24413D448B8CC119D2BF7B2D2DF032741C096634D6D65D0DBE3D5694625FB9E8104D3B842C1B0E2D0B98BEA19341E8676AEF66AE4EBA3D5475D5D16+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0x121415EC2CD7726330A61F7F3FA5DE14BE9436019C4DB8CB4041F3B54CF31BE0493EE3F427FB906393D895A19C9523F3A1D54BB8702BD4AA9C99DAB2597B92113F3+ , ehR =+ 0x1776331CFCDF927D666E032E00CF776187BC9FDD8E69D0DABB4109FFE1B5E2A30715F4CC923A4A5E94D2503E9ACFED92857B7F31D7152E0F8C00C15FF3D87E2ED2E+ , ehS =+ 0x050CB5265417FE2320BBB5A122B8E1A32BD699089851128E360E620A30C7E17BA41A666AF126CE100E5799B153B60528D5300D08489CA9178FB610A2006C254B41F+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x0EDF38AFCAAECAB4383358B34D67C9F2216C8382AAEA44A3DAD5FDC9C32575761793FEF24EB0FC276DFC4F6E3EC476752F043CF01415387470BCBD8678ED2C7E1A0+ , ehR =+ 0x1511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E1A7+ , ehS =+ 0x04A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7ECFC+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x1546A108BC23A15D6F21872F7DED661FA8431DDBD922D0DCDB77CC878C8553FFAD064C95A920A750AC9137E527390D2D92F153E66196966EA554D9ADFCB109C4211+ , ehR =+ 0x1EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67451+ , ehS =+ 0x1F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65D61+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x1DAE2EA071F8110DC26882D4D5EAE0621A3256FC8847FB9022E2B7D28E6F10198B1574FDD03A9053C08A1854A168AA5A57470EC97DD5CE090124EF52A2F7ECBFFD3+ , ehR =+ 0x0C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F174E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E377FA+ , ehS =+ 0x0617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF282623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A67A+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x0BB9F2BF4FE1038CCF4DABD7139A56F6FD8BB1386561BD3C6A4FC818B20DF5DDBA80795A947107A1AB9D12DAA615B1ADE4F7A9DC05E8E6311150F47F5C57CE8B222+ , ehR =+ 0x13BAD9F29ABE20DE37EBEB823C252CA0F63361284015A3BF430A46AAA80B87B0693F0694BD88AFE4E661FC33B094CD3B7963BED5A727ED8BD6A3A202ABE009D0367+ , ehS =+ 0x1E9BB81FF7944CA409AD138DBBEE228E1AFCC0C890FC78EC8604639CB0DBDC90F717A99EAD9D272855D00162EE9527567DD6A92CBD629805C0445282BBC916797FF+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0x040D09FCF3C8A5F62CF4FB223CBBB2B9937F6B0577C27020A99602C25A01136987E452988781484EDBBCF1C47E554E7FC901BC3085E5206D9F619CFF07E73D6F706+ , ehR =+ 0x1C7ED902E123E6815546065A2C4AF977B22AA8EADDB68B2C1110E7EA44D42086BFE4A34B67DDC0E17E96536E358219B23A706C6A6E16BA77B65E1C595D43CAE17FB+ , ehS =+ 0x177336676304FCB343CE028B38E7B4FBA76C1C1B277DA18CAD2A8478B2A9A9F5BEC0F3BA04F35DB3E4263569EC6AADE8C92746E4C82F8299AE1B8F1739F8FD519A4+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x01DE74955EFAABC4C4F17F8E84D881D1310B5392D7700275F82F145C61E843841AF09035BF7A6210F5A431A6A9E81C9323354A9E69135D44EBD2FCAA7731B909258+ , ehR =+ 0x00E871C4A14F993C6C7369501900C4BC1E9C7B0B4BA44E04868B30B41D8071042EB28C4C250411D0CE08CD197E4188EA4876F279F90B3D8D74A3C76E6F1E4656AA8+ , ehS =+ 0x0CD52DBAA33B063C3A6CD8058A1FB0A46A4754B034FCC644766CA14DA8CA5CA9FDE00E88C1AD60CCBA759025299079D7A427EC3CC5B619BFBC828E7769BCD694E86+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x1F1FC4A349A7DA9A9E116BFDD055DC08E78252FF8E23AC276AC88B1770AE0B5DCEB1ED14A4916B769A523CE1E90BA22846AF11DF8B300C38818F713DADD85DE0C88+ , ehR =+ 0x14BEE21A18B6D8B3C93FAB08D43E739707953244FDBE924FA926D76669E7AC8C89DF62ED8975C2D8397A65A49DCC09F6B0AC62272741924D479354D74FF6075578C+ , ehS =+ 0x133330865C067A0EAF72362A65E2D7BC4E461E8C8995C3B6226A21BD1AA78F0ED94FE536A0DCA35534F0CD1510C41525D163FE9D74D134881E35141ED5E8E95B979+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x16200813020EC986863BEDFC1B121F605C1215645018AEA1A7B215A564DE9EB1B38A67AA1128B80CE391C4FB71187654AAA3431027BFC7F395766CA988C964DC56D+ , ehR =+ 0x13E99020ABF5CEE7525D16B69B229652AB6BDF2AFFCAEF38773B4B7D08725F10CDB93482FDCC54EDCEE91ECA4166B2A7C6265EF0CE2BD7051B7CEF945BABD47EE6D+ , ehS =+ 0x1FBD0013C674AA79CB39849527916CE301C66EA7CE8B80682786AD60F98F7E78A19CA69EFF5C57400E3B3A0AD66CE0978214D13BAF4E9AC60752F7B155E2DE4DCE3+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_t163k1+ , ecPrivate = 0x09A4D6792295A7F730FC3F2B49CBC0F62E862272F+ , ecPublic =+ Point+ 0x79AEE090DB05EC252D5CB4452F356BE198A4FF96F+ 0x782E29634DDC9A31EF40386E896BAA18B53AFA5A3+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x09744429FA741D12DE2BE8316E35E84DB9E5DF1CD+ , ehR = 0x30C45B80BA0E1406C4EFBBB7000D6DE4FA465D505+ , ehS = 0x38D87DF89493522FC4CD7DE1553BD9DBBA2123011+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x323E7B28BFD64E6082F5B12110AA87BC0D6A6E159+ , ehR = 0x38A2749F7EA13BD5DA0C76C842F512D5A65FFAF32+ , ehS = 0x064F841F70112B793FD773F5606BFA5AC2A04C1E8+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x23AF4074C90A02B3FE61D286D5C87F425E6BDD81B+ , ehR = 0x113A63990598A3828C407C0F4D2438D990DF99A7F+ , ehS = 0x1313A2E03F5412DDB296A22E2C455335545672D9F+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x2132ABE0ED518487D3E4FA7FD24F8BED1F29CCFCE+ , ehR = 0x34D4DE955871BB84FEA4E7D068BA5E9A11BD8B6C4+ , ehS = 0x2BAAF4D4FD57F175C405A2F39F9755D9045C820BD+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x00BBCC2F39939388FDFE841892537EC7B1FF33AA3+ , ehR = 0x38E487F218D696A7323B891F0CCF055D895B77ADC+ , ehS = 0x0972D7721093F9B3835A5EB7F0442FA8DCAA873C4+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x14CAB9192F39C8A0EA8E81B4B87574228C99CD681+ , ehR = 0x1375BEF93F21582F601497036A7DC8014A99C2B79+ , ehS = 0x254B7F1472FFFEE9002D081BB8CE819CCE6E687F9+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x091DD986F38EB936BE053DD6ACE3419D2642ADE8D+ , ehR = 0x110F17EF209957214E35E8C2E83CBE73B3BFDEE2C+ , ehS = 0x057D5022392D359851B95DEC2444012502A5349CB+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x193649CE51F0CFF0784CFC47628F4FA854A93F7A2+ , ehR = 0x0354D5CD24F9C41F85D02E856FA2B0001C83AF53E+ , ehS = 0x020B200677731CD4FE48612A92F72A19853A82B65+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x37C73C6F8B404EC83DA17A6EBCA724B3FF1F7EEBA+ , ehR = 0x11B6A84206515495AD8DBB2E5785D6D018D75817E+ , ehS = 0x1A7D4C1E17D4030A5D748ADEA785C77A54581F6D0+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x331AD98D3186F73967B1E0B120C80B1E22EFC2988+ , ehR = 0x148934745B351F6367FF5BB56B1848A2F508902A9+ , ehS = 0x36214B19444FAB504DBA61D4D6FF2D2F9640F4837+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_t233k1+ , ecPrivate = 0x103B2142BDC2A3C3B55080D09DF1808F79336DA2399F5CA7171D1BE9B0+ , ecPublic =+ Point+ 0x0682886F36C68473C1A221720C2B12B9BE13458BA907E1C4736595779F2+ 0x1B20639B41BE0927090999B7817A3B3928D20503A39546044EC13A10309+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x273179E3E12C69591AD3DD9C7CCE3985820E3913AB6696EB14486DDBCF+ , ehR = 0x5474541C988A9A1F73899F55EF28963DFFBBF0C2B1A1EE787C6A76C6A4+ , ehS = 0x46301F9EC6624257BFC70D72186F17898EDBD0A3522560A88DD1B7D45A+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x71626A309D9CD80AD0B975D757FE6BF4B84E49F8F34C780070D7746F19+ , ehR = 0x667F2FCE3E1C497EBD8E4B7C6372A8234003FE4ED6D4515814E7E11430+ , ehS = 0x6A1C41340DAA730320DB9475F10E29A127D7AE3432F155E1F7954E1B57+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x73552F9CAC5774F74F485FA253871F2109A0C86040552EAA67DBA92DC9+ , ehR = 0x38AD9C1D2CB29906E7D63C24601AC55736B438FB14F4093D6C32F63A10+ , ehS = 0x647AAD2599C21B6EE89BE7FF957D98F684B7921DE1FD3CC82C079624F4+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x17D726A67539C609BD99E29AA3737EF247724B71455C3B6310034038C8+ , ehR = 0x0C6510F57559C36FBCFF8C7BA4B81853DC618AD0BAAB03CFFDF3FD09FD+ , ehS = 0x0AD331EE1C9B91A88BA77997235769C60AD07EE69E11F7137E17C5CF67+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x0E535C328774CDE546BE3AF5D7FCD263872F107E807435105BA2FDC166+ , ehR = 0x47C4AC1B344028CC740BA7BB9F8AA59D6390E3158153D4F2ADE4B74950+ , ehS = 0x26CE0CDE18A1B884B3EE1A879C13B42F11BB7C85F7A3745C8BECEC8E6E+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x1D8BBF5CB6EFFA270A1CDC22C81E269F0CC16E27151E0A460BA9B51AFF+ , ehR = 0x4780B2DE4BAA5613872179AD90664249842E8B96FCD5653B55DD63EED4+ , ehS = 0x6AF46BA322E21D4A88DAEC1650EF38774231276266D6A45ED6A64ECB44+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x67634D0ABA2C9BF7AE54846F26DCD166E7100654BCE6FDC96667631AA2+ , ehR = 0x61D9CC8C842DF19B3D9F4BDA0D0E14A957357ADABC239444610FB39AEA+ , ehS = 0x66432278891CB594BA8D08A0C556053D15917E53449E03C2EF88474CF6+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x2CE5AEDC155ACC0DDC5E679EBACFD21308362E5EFC05C5E99B2557A8D7+ , ehR = 0x05E4E6B4DB0E13034E7F1F2E5DBAB766D37C15AE4056C7EE607C8AC7F4+ , ehS = 0x5FC46AA489BF828B34FBAD25EC432190F161BEA8F60D3FCADB0EE3B725+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x1B4BD3903E74FD0B31E23F956C70062014DFEFEE21832032EA5352A055+ , ehR = 0x50F1EFEDFFEC1088024620280EE0D7641542E4D4B5D61DB32358FC571B+ , ehS = 0x4614EAE449927A9EB2FCC42EA3E955B43D194087719511A007EC9217A5+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x1775ED919CA491B5B014C5D5E86AF53578B5A7976378F192AF665CB705+ , ehR = 0x6FE6D0D3A953BB66BB01BC6B9EDFAD9F35E88277E5768D1B214395320F+ , ehS = 0x7C01A236E4BFF0A771050AD01EC1D24025D3130BBD9E4E81978EB3EC09+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_t283k1+ , ecPrivate =+ 0x06A0777356E87B89BA1ED3A3D845357BE332173C8F7A65BDC7DB4FAB3C4CC79ACC8194E+ , ecPublic =+ Point+ 0x25330D0A651D5A20DC6389BC02345117725640AEC3C126612CE444EDD19649BDECC03D6+ 0x505BD60A4B67182474EC4D1C668A73140F70504A68F39EFCD972487E9530E0508A76193+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x0A96F788DECAF6C9DBE24DC75ABA6EAAE85E7AB003C8D4F83CB1540625B2993BF445692+ , ehR = 0x1B66D1E33FBDB6E107A69B610995C93C744CEBAEAF623CB42737C27D60188BD1D045A68+ , ehS = 0x02E45B62C9C258643532FD536594B46C63B063946494F95DAFF8759FD552502324295C5+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x1B4C4E3B2F6B08B5991BD2BDDE277A7016DA527AD0AAE5BC61B64C5A0EE63E8B502EF61+ , ehR = 0x018CF2F371BE86BB62E02B27CDE56DDAC83CCFBB3141FC59AEE022B66AC1A60DBBD8B76+ , ehS = 0x1854E02A381295EA7F184CEE71AB7222D6974522D3B99B309B1A8025EB84118A28BF20E+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x1CEB9E8E0DFF53CE687DEB81339ACA3C98E7A657D5A9499EF779F887A934408ECBE5A38+ , ehR = 0x19E90AA3DE5FB20AED22879F92C6FED278D9C9B9293CC5E94922CD952C9DBF20DF1753A+ , ehS = 0x135AA7443B6A25D11BB64AC482E04D47902D017752882BD72527114F46CF8BB56C5A8C3+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x1460A5C41745A5763A9D548AE62F2C3630BBED71B6AA549D7F829C22442A728C5D965DA+ , ehR = 0x0F8C1CA9C221AD9907A136F787D33BA56B0495A40E86E671C940FD767EDD75EB6001A49+ , ehS = 0x1071A56915DEE89E22E511975AA09D00CDC4AA7F5054CBE83F5977EE6F8E1CC31EC43FD+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x00F3B59FCB5C1A01A1A2A0019E98C244DFF61502D6E6B9C4E957EDDCEB258EF4DBEF04A+ , ehR = 0x1D0008CF4BA4A701BEF70771934C2A4A87386155A2354140E2ED52E18553C35B47D9E50+ , ehS = 0x0D15F4FA1B7A4D41D9843578E22EF98773179103DC4FF0DD1F74A6B5642841B91056F78+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x168B5F8C0881D4026C08AC5894A2239D219FA9F4DA0600ADAA56D5A1781AF81F08A726E+ , ehR = 0x140932FA7307666A8CCB1E1A09656CC40F5932965841ABD5E8E43559D93CF2311B02767+ , ehS = 0x16A2FD46DA497E5E739DED67F426308C45C2E16528BF2A17EB5D65964FD88B770FBB9C6+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x045E13EA645CE01D9B25EA38C8A8A170E04C83BB7F231EE3152209FE10EC8B2E565536C+ , ehR = 0x0E72AF7E39CD72EF21E61964D87C838F977485FA6A7E999000AFA97A381B2445FCEE541+ , ehS = 0x1644FF7D848DA1A040F77515082C27C763B1B4BF332BCF5D08251C6B57D806319778208+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x0B585A7A68F51089691D6EDE2B43FC4451F66C10E65F134B963D4CBD4EB844B0E1469A6+ , ehR = 0x158FAEB2470B306C57764AFC8528174589008449E11DB8B36994B607A65956A59715531+ , ehS = 0x0521BC667CA1CA42B5649E78A3D76823C678B7BB3CD58D2E93CD791D53043A6F83F1FD1+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x1E88738E14482A09EE16A73D490A7FE8739DF500039538D5C4B6C8D6D7F208D6CA56760+ , ehR = 0x1CC4DC5479E0F34C4339631A45AA690580060BF0EB518184C983E0E618C3B93AAB14BBE+ , ehS = 0x0284D72FF8AFA83DE364502CBA0494BB06D40AE08F9D9746E747EA87240E589BA0683B7+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x00E5F24A223BD459653F682763C3BB322D4EE75DD89C63D4DC61518D543E76585076BBA+ , ehR = 0x1E7912517C6899732E09756B1660F6B96635D638283DF9A8A11D30E008895D7F5C9C7F3+ , ehS = 0x0887E75CBD0B7DD9DE30ED79BDB3D78E4F1121C5EAFF5946918F594F88D363644789DA7+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_t409k1+ , ecPrivate =+ 0x29C16768F01D1B8A89FDA85E2EFD73A09558B92A178A2931F359E4D70AD853E569CDAF16DAA569758FB4E73089E4525D8BBFCF+ , ecPublic =+ Point+ 0x0CF923F523FE34A6E863D8BA45FB1FE6D784C8F219C414EEF4DB8362DBBD3CA71AEB28F568668D5D7A0093E2B84F6FAD759DB42+ 0x13B1C374D5132978A1B1123EBBE9A5C54D1A9D56B09AFDB4ADE93CCD7C4D332E2916F7D4B9D18578EE3C2E2DE4D2ECE0DE63549+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x7866E5247F9A3556F983C86E81EDA696AC8489DB40A2862F278603982D304F08B2B6E1E7848534BEAF1330D37A1CF84C7994C1+ , ehR =+ 0x7192EE99EC7AFE23E02CB1F9850D1ECE620475EDA6B65D04984029408EC1E5A6476BC940D81F218FC31D979814CAC6E78340FA+ , ehS =+ 0x1DE75DE97CBE740FC79A6B5B22BC2B7832C687E6960F0B8173D5D8BE2A75AC6CA43438BAF69C669CE6D64E0FB93BC5854E0F81+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0x512340DB682C7B8EBE407BF1AA54194DFE85D49025FE0F632C9B8A06A996F2FCD0D73C752FB09D23DB8FBE50605DC25DF0745C+ , ehR =+ 0x41C8EDF39D5E4E76A04D24E6BFD4B2EC35F99CD2483478FD8B0A03E99379576EDACC4167590B7D9C387857A5130B1220CB771F+ , ehS =+ 0x659652EEAC9747BCAD58034B25362B6AA61836E1BA50E2F37630813050D43457E62EAB0F13AE197E6CFE0244F983107555E269+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x782385F18BAF5A36A588637A76DFAB05739A14163BF723A4417B74BD1469D37AC9E8CCE6AEC8FF63F37B815AAF14A876EED962+ , ehR =+ 0x49EC220D6D24980693E6D33B191532EAB4C5D924E97E305E2C1CCFE6F1EAEF96C17F6EC27D1E06191023615368628A7E0BD6A9+ , ehS =+ 0x1A4AB1DD9BAAA21F77C503E1B39E770FFD44718349D54BA4CF08F688CE89D7D7C5F7213F225944BE5F7C9BA42B8BEE382F8AF9+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x4DA637CB2E5C90E486744E45A73935DD698D4597E736DA332A06EDA8B26D5ABC6153EC2ECE14981CF3E5E023F36FFA55EEA6D7+ , ehR =+ 0x562BB99EE027644EC04E493C5E81B41F261F6BD18FB2FAE3AFEAD91FAB8DD44AFA910B13B9C79C87555225219E44E72245BB7C+ , ehS =+ 0x25BA5F28047DDDBDA7ED7E49DA31B62B20FD9C7E5B8988817BBF738B3F4DFDD2DCD06EE6DF2A1B744C850DAF952C12B9A56774+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x57055B293ECFDFE983CEF716166091E573275C53906A39EADC25C89C5EC8D7A7E5629FCFDFAD514E1348161C9A34EA1C42D58C+ , ehR =+ 0x16C7E7FB33B5577F7CF6F77762F0F2D531C6E7A3528BD2CF582498C1A48F200789E9DF7B754029DA0D7E3CE96A2DC760932606+ , ehS =+ 0x2729617EFBF80DA5D2F201AC7910D3404A992C39921C2F65F8CF4601392DFE933E6457EAFDBD13DFE160D243100378B55C290A+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x545453D8DC05D220F9A12EF322D0B855E664C72835FABE8A41211453EB8A7CFF950D80773839D0043A46852DDA5A536E02291F+ , ehR =+ 0x565648A5BAD24E747A7D7531FA9DBDFCB184ECFEFDB00A319459242B68D0989E52BED4107AED35C27D8ECA10E876ACA48006C9+ , ehS =+ 0x7420BA6FF72ECC5C92B7CA0309258B5879F26393DB22753B9EC5DF905500A04228AC08880C485E2AC8834E13E8FA44FA57BF18+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0x3C5352929D4EBE3CCE87A2DCE380F0D2B33C901E61ABC530DAF3506544AB0930AB9BFD553E51FCDA44F06CD2F49E17E07DB519+ , ehR =+ 0x251DFE54EAEC8A781ADF8A623F7F36B4ABFC7EE0AE78C8406E93B5C3932A8120AB8DFC49D8E243C7C30CB5B1E021BADBDF9CA4+ , ehS =+ 0x77854C2E72EAA6924CC0B5F6751379D132569843B1C7885978DBBAA6678967F643A50DBB06E6EA6102FFAB7766A57C3887BD22+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x251E32DEE10ED5EA4AD7370DF3EFF091E467D5531CA59DE3AA791763715E1169AB5E18C2A11CD473B0044FB45308E8542F2EB0+ , ehR =+ 0x58075FF7E8D36844EED0FC3F78B7CFFDEEF6ADE5982D5636552A081923E24841C9E37DF2C8C4BF2F2F7A174927F3B7E6A0BEB2+ , ehS =+ 0x0A737469D013A31B91E781CE201100FDE1FA488ABF2252C025C678462D715AD3078C9D049E06555CABDF37878CFB909553FF51+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x11C540EA46C5038FE28BB66E2E9E9A04C9FE9567ADF33D56745953D44C1DC8B5B92922F53A174E431C0ED8267D919329F19014+ , ehR =+ 0x1C5C88642EA216682244E46E24B7CE9AAEF9B3F97E585577D158C3CBC3C598250A53F6D46DFB1E2DD9DC302E7DA4F0CAAFF291+ , ehS =+ 0x1D3FD721C35872C74514359F88AD983E170E5DE5B31AFC0BE12E9F4AB2B2538C7797686BA955C1D042FD1F8CDC482775579F11+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x59527CE953BC09DF5E85155CAE7BB1D7F342265F41635545B06044F844ECB4FA6476E7D47420ADC8041E75460EC0A4EC760E95+ , ehR =+ 0x1A32CD7764149DF79349DBF79451F4585BB490BD63A200700D7111B45DDA414000AE1B0A69AEACBA1364DD7719968AAD123F93+ , ehS =+ 0x582AB1076CAFAE23A76244B82341AEFC4C6D8D8060A62A352C33187720C8A37F3DAC227E62758B11DF1562FD249941C1679F82+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_t571k1+ , ecPrivate =+ 0x0C16F58550D824ED7B95569D4445375D3A490BC7E0194C41A39DEB732C29396CDF1D66DE02DD1460A816606F3BEC0F32202C7BD18A32D87506466AA92032F1314ED7B19762B0D22+ , ecPublic =+ Point+ 0x6CFB0DF7541CDD4C41EF319EA88E849EFC8605D97779148082EC991C463ED32319596F9FDF4779C17CAF20EFD9BEB57E9F4ED55BFC52A2FA15CA23BC62B7BF019DB59793DD77318+ 0x1CFC91102F7759A561BD8D5B51AAAEEC7F40E659D67870361990D6DE29F6B4F7E18AE13BDE5EA5C1F77B23D676F44050C9DBFCCDD7B3756328DDA059779AAE8446FC5158A75C227+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x17F7E360B21BEAE4A757A19ACA77FB404D273F05719A86EAD9D7B3F4D5ED7B4630584BB153CF7DCD5A87CCA101BD7EA9ECA0CE5EE27CA985833560000BB52B6BBE068740A45B267+ , ehR =+ 0x0767913F96C82E38B7146A505938B79EC07E9AA3214377651BE968B52C039D3E4837B4A2DE26C481C4E1DE96F4D9DE63845D9B32E26D0D332725678E3CE57F668A5E3108FB6CEA5+ , ehS =+ 0x109F89F55FA39FF465E40EBCF869A9B1DB425AEA53AB4ECBCE3C310572F79315F5D4891461372A0C36E63871BEDDBB3BA2042C6410B67311F1A185589FF4C987DBA02F9D992B9DF+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0x0B599D068A1A00498EE0B9AD6F388521F594BD3F234E47F7A1DB6490D7B57D60B0101B36F39CC22885F78641C69411279706F0989E6991E5D5B53619E43EFB397E25E0814EF02BC+ , ehR =+ 0x010774B9F14DE6C9525131AD61531FA30987170D43782E9FB84FF0D70F093946DF75ECB69D400FE39B12D58C67C19DCE96335CEC1D9AADE004FE5B498AB8A940D46C8444348686A+ , ehS =+ 0x06DFE9AA5FEA6CF2CEDC06EE1F9FD9853D411F0B958F1C9C519C90A85F6D24C1C3435B3CDF4E207B4A67467C87B7543F6C0948DD382D24D1E48B3763EC27D4D32A0151C240CC5E0+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x0F79D53E63D89FB87F4D9E6DC5949F5D9388BCFE9EBCB4C2F7CE497814CF40E845705F8F18DBF0F860DE0B1CC4A433EF74A5741F3202E958C082E0B76E16ECD5866AA0F5F3DF300+ , ehR =+ 0x1604BE98D1A27CEC2D3FA4BD07B42799E07743071E4905D7DCE7F6992B21A27F14F55D0FE5A7810DF65CF07F2F2554658817E5A88D952282EA1B8310514C0B40FFF46F159965168+ , ehS =+ 0x18249377C654B8588475510F7B797081F68C2F8CCCE49F730353B2DA3364B1CD3E984813E11BB791824038EA367BA74583AB97A69AF2D77FA691AA694E348E15DA76F5A44EC1F40+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x0308253C022D25F8A9EBCD24459DD6596590BDEC7895618EEE8A2623A98D2A2B2E7594EE6B7AD3A39D70D68CB4ED01CB28E2129F8E2CC0CC8DC7780657E28BCD655F0BE9B7D35A2+ , ehR =+ 0x1E6D7FB237040EA1904CCBF0984B81B866DE10D8AA93B06364C4A46F6C9573FA288C8BDDCC0C6B984E6AA75B42E7BF82FF34D51DFFBD7C87FDBFAD971656185BD12E4B8372F4BF1+ , ehS =+ 0x04F94550072ADA7E8C82B7E83577DD39959577799CDABCEA60E267F36F1BEB981ABF24E722A7F031582D2CC5D80DAA7C0DEEBBE1AC5E729A6DBB34A5D645B698719FCA409FBA370+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x0C5EE7070AF55F84EBC43A0D481458CEDE1DCEBB57720A3C92F59B4941A044FECFF4F703940F3121773595E880333772ACF822F2449E17C64DA286BCD65711DD5DA44D7155BF004+ , ehR =+ 0x086C9E048EADD7D3D2908501086F3AF449A01AF6BEB2026DC381B39530BCDDBE8E854251CBD5C31E6976553813C11213E4761CB8CA2E5352240AD9FB9C635D55FAB13AE42E4EE4F+ , ehS =+ 0x09FEE0A68F322B380217FCF6ABFF15D78C432BD8DD82E18B6BA877C01C860E24410F5150A44F979920147826219766ECB4E2E11A151B6A15BB8E2E825AC95BCCA228D8A1C9D3568+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x1D056563469E933E4BE064585D84602D430983BFBFD6885A94BA484DF9A7AB031AD6AC090A433D8EEDC0A7643EA2A9BC3B6299E8ABA933B4C1F2652BB49DAEE833155C8F1319908+ , ehR =+ 0x1D055F499A3F7E3FC73D6E7D517B470879BDCB14ABC938369F23643C7B96D0242C1FF326FDAF1CCC8593612ACE982209658E73C24C9EC493B785608669DA74A5B7C9A1D8EA843BC+ , ehS =+ 0x1621376C53CFE3390A0520D2C657B1FF0EBB10E4B9C2510EDC39D04FEBAF12B8502B098A8B8F842EA6E8EB9D55CFEF94B7FF6D145AC3FFCE71BD978FEA3EF8194D4AB5293A8F3EA+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0x1DA875065B9D94DBE75C61848D69578BCC267935792624F9887B53C9AF9E43CABFC42E4C3F9A456BA89E717D24F1412F33CFD297A7A4D403B18B5438654C74D592D5022125E0C6B+ , ehR =+ 0x18709BDE4E9B73D046CE0D48842C97063DA54DCCA28DCB087168FA37DA2BF5FDBE4720EE48D49EDE4DD5BD31AC0149DB8297BD410F9BC02A11EB79B60C8EE63AF51B65267D71881+ , ehS =+ 0x12D8B9E98FBF1D264D78669E236319D8FFD8426C56AFB10C76471EE88D7F0AB1B158E685B6D93C850D47FB1D02E4B24527473DB60B8D1AEF26CEEBD3467B65A70FFDDC0DBB64D5F+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x04DDD0707E81BB56EA2D1D45D7FAFDBDD56912CAE224086802FEA1018DB306C4FB8D93338DBF6841CE6C6AB1506E9A848D2C0463E0889268843DEE4ACB552CFFCB858784ED116B2+ , ehR =+ 0x1F5BF6B044048E0E310309FFDAC825290A69634A0D3592DBEE7BE71F69E45412F766AC92E174CC99AABAA5C9C89FCB187DFDBCC7A26765DB6D9F1EEC8A6127BBDFA5801E44E3BEC+ , ehS =+ 0x1B44CBFB233BFA2A98D5E8B2F0B2C27F9494BEAA77FEB59CDE3E7AE9CB2E385BE8DA7B80D7944AA71E0654E5067E9A70E88E68833054EED49F28283F02B229123995AF37A6089F0+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x0141B53DC6E569D8C0C0718A58A5714204502FDA146E7E2133E56D19E905B79413457437095DE13CF68B5CF5C54A1F2E198A55D974FC3E507AFC0ACF95ED391C93CC79E3B3FE37C+ , ehR =+ 0x11F61A6EFAB6D83053D9C52665B3542FF3F63BD5913E527BDBA07FBAF34BC766C2EC83163C5273243AA834C75FDDD1BC8A2BEAD388CD06C4EBA1962D645EEB35E92D44E8F2E081D+ , ehS =+ 0x16BF6341876F051DF224770CC8BA0E4D48B3332568A2B014BC80827BAA89DE18D1AEBC73E3BE8F85A8008C682AAC7D5F0E9FB5ECBEFBB637E30E4A0F226D2C2AA3E569BB54AB72B+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x14842F97F263587A164B215DD0F912C588A88DC4AB6AF4C530ADC1226F16E086D62C14435E6BFAB56F019886C88922D2321914EE41A8F746AAA2B964822E4AC6F40EE2492B66824+ , ehR =+ 0x0F1E50353A39EA64CDF23081D6BB4B2A91DD73E99D3DD5A1AA1C49B4F6E34A665EAD24FD530B9103D522609A395AF3EF174C85206F67EF84835ED1632E0F6BAB718EA90DF9E2DA0+ , ehS =+ 0x0B385004D7596625028E3FDE72282DE4EDC5B4CE33C1127F21CC37527C90B7307AE7D09281B840AEBCECAA711B00718103DDB32B3E9F6A9FBC6AF23E224A73B9435F619D9C62527+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_t163r2+ , ecPrivate = 0x35318FC447D48D7E6BC93B48617DDDEDF26AA658F+ , ecPublic =+ Point+ 0x126CF562D95A1D77D387BA75A3EA3A1407F23425A+ 0x7D7CB5273C94DA8CA93049AFDA18721C24672BD71+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x0707A94C3D352E0A9FE49FB12F264992152A20004+ , ehR = 0x153FEBD179A69B6122DEBF5BC61EB947B24C93526+ , ehS = 0x37AC9C670F8CF18045049BAE7DD35553545C19E49+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x3B24C5E2C2D935314EABF57A6484289B291ADFE3F+ , ehR = 0x0A379E69C44F9C16EA3215EA39EB1A9B5D58CC955+ , ehS = 0x04BAFF5308DA2A7FE2C1742769265AD3ED1D24E74+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x3D7086A59E6981064A9CDB684653F3A81B6EC0F0B+ , ehR = 0x134E00F78FC1CB9501675D91C401DE20DDF228CDC+ , ehS = 0x373273AEC6C36CB7BAFBB1903A5F5EA6A1D50B624+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x3B1E4443443486C7251A68EF184A936F05F8B17C7+ , ehR = 0x29430B935AF8E77519B0CA4F6903B0B82E6A21A66+ , ehS = 0x1EA1415306E9353FA5AA54BC7C2581DFBB888440D+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x2EDF5CFCAC7553C17421FDF54AD1D2EF928A879D2+ , ehR = 0x0B2F177A99F9DF2D51CCAF55F015F326E4B65E7A0+ , ehS = 0x0DF1FB4487E9B120C5E970EFE48F55E406306C3A1+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x10024F5B324CBC8954BA6ADB320CD3AB9296983B4+ , ehR = 0x256D4079C6C7169B8BC92529D701776A269D56308+ , ehS = 0x341D3FFEC9F1EB6A6ACBE88E3C86A1C8FDEB8B8E1+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x34F46DE59606D56C75406BFB459537A7CC280AA62+ , ehR = 0x28ECC6F1272CE80EA59DCF32F7AC2D861BA803393+ , ehS = 0x0AD4AE2C06E60183C1567D2B82F19421FE3053CE2+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x38145E3FFCA94E4DDACC20AD6E0997BD0E3B669D2+ , ehR = 0x227DF377B3FA50F90C1CB3CDCBBDBA552C1D35104+ , ehS = 0x1F7BEAD92583FE920D353F368C1960D0E88B46A56+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x375813210ECE9C4D7AB42DDC3C55F89189CF6DFFD+ , ehR = 0x11811DAFEEA441845B6118A0DFEE8A0061231337D+ , ehS = 0x36258301865EE48C5C6F91D63F62695002AB55B57+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x25AD8B393BC1E9363600FDA1A2AB6DF40079179A3+ , ehR = 0x3B6BB95CA823BE2ED8E3972FF516EB8972D765571+ , ehS = 0x13DC6F420628969DF900C3FCC48220B38BE24A541+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_t233r1+ , ecPrivate = 0x07ADC13DD5BF34D1DDEEB50B2CE23B5F5E6D18067306D60C5F6FF11E5D3+ , ecPublic =+ Point+ 0x0FB348B3246B473AA7FBB2A01B78D61B62C4221D0F9AB55FC72DB3DF478+ 0x1162FA1F6C6ACF7FD8D19FC7D74BDD9104076E833898BC4C042A6E6BEBF+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x0A4E0B67A3A081C1B35D7BECEB5FE72A918B422B907145DB5416ED751CE+ , ehR = 0x015CC6FD78BB06E0878E71465515EA5A21A2C18E6FC77B4B158DBEB3944+ , ehS = 0x0822A4A6C2EB2DF213A5E90BF40377956365EE8C4B4A5A4E2EB9270CB6A+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x0F2B1C1E80BEB58283AAA79857F7B83BDF724120D0913606FD07F7FFB2C+ , ehR = 0x05D9920B53471148E10502AB49AB7A3F11084820A074FD89883CF51BC1A+ , ehS = 0x04D3938900C0A9AAA7080D1DFEB56CFB0FADABE4214536C7ED5117ED13A+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x034A53897B0BBDB484302E19BF3F9B34A2ABFED639D109A388DC52006B5+ , ehR = 0x0A797F3B8AEFCE7456202DF1E46CCC291EA5A49DA3D4BDDA9A4B62D5E0D+ , ehS = 0x01F6F81DA55C22DA4152134C661588F4BD6F82FDBAF0C5877096B070DC2+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x04D4670B28990BC92EEB49840B482A1FA03FE028D09F3D21F89C67ECA85+ , ehR = 0x015E85A8D46225DD7E314A1C4289731FC14DECE949349FE535D11043B85+ , ehS = 0x03F189D37F50493EFD5111A129443A662AB3C6B289129AD8C0CAC85119C+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x0DE108AAADA760A14F42C057EF81C0A31AF6B82E8FBCA8DC86E443AB549+ , ehR = 0x03B62A4BF783919098B1E42F496E65F7621F01D1D466C46940F0F132A95+ , ehS = 0x0F4BE031C6E5239E7DAA014CBBF1ED19425E49DAEB426EC9DF4C28A2E30+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x0250C5C90A4E2A3F8849FEBA87F0D0AE630AB18CBABB84F4FFFB36CEAC0+ , ehR = 0x02F1FEDC57BE203E4C8C6B8C1CEB35E13C1FCD956AB41E3BD4C8A6EFB1F+ , ehS = 0x05738EC8A8EDEA8E435EE7266AD3EDE1EEFC2CEBE2BE1D614008D5D2951+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x07BDB6A7FD080D9EC2FC84BFF9E3E15750789DC04290C84FED00E109BBD+ , ehR = 0x0CCE175124D3586BA7486F7146894C65C2A4A5A1904658E5C7F9DF5FA5D+ , ehS = 0x08804B456D847ACE5CA86D97BF79FD6335E5B17F6C0D964B5D0036C867E+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x00376886E89013F7FF4B5214D56A30D49C99F53F211A3AFE01AA2BDE12D+ , ehR = 0x035C3D6DFEEA1CFB29B93BE3FDB91A7B130951770C2690C16833A159677+ , ehS = 0x0600F7301D12AB376B56D4459774159ADB51F97E282FF384406AFD53A02+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x03726870DE75613C5E529E453F4D92631C03D08A7F63813E497D4CB3877+ , ehR = 0x061602FC8068BFD5FB86027B97455D200EC603057446CCE4D76DB8EF42C+ , ehS = 0x03396DD0D59C067BB999B422D9883736CF9311DFD6951F91033BD03CA8D+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x09CE5810F1AC68810B0DFFBB6BEEF2E0053BB937969AE7886F9D064A8C4+ , ehR = 0x07E12CB60FDD614958E8E34B3C12DDFF35D85A9C5800E31EA2CC2EF63B1+ , ehS = 0x0E8970FD99D836F3CC1C807A2C58760DE6EDAA23705A82B9CB1CE93FECC+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_t283r1+ , ecPrivate =+ 0x14510D4BC44F2D26F4553942C98073C1BD35545CEABB5CC138853C5158D2729EA408836+ , ecPublic =+ Point+ 0x17E3409A13C399F0CA8A192F028D46E3446BCFFCDF51FF8A905ED2DED786E74F9C3E8A9+ 0x47EFCBCC31C01D86D1992F7BFAC0277DBD02A6D289274099A2C0F039C8F59F318371B0E+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x277F389559667E8AE4B65DC056F8CE2872E1917E7CC59D17D485B0B98343206FBCCD441+ , ehR = 0x201E18D48C6DB3D5D097C4DCE1E25587E1501FC3CF47BDB5B4289D79E273D6A9ACB8285+ , ehS = 0x151AE05712B024CE617358260774C8CA8B0E7A7E72EF8229BF2ACE7609560CB30322C4F+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x14CC8FCFEECD6B999B4DC6084EBB06FDED0B44D5C507802CC7A5E9ECF36E69DA6AE23C6+ , ehR = 0x143E878DDFD4DF40D97B8CD638B3C4706501C2201CF7108F2FB91478C11D69473246925+ , ehS = 0x0CBF1B9717FEEA3AABB09D9654110144267098E0E1E8D0289A6211BE0EEDFDD86A3DB79+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x38C9D662188982943E080B794A4CFB0732DBA37C6F40D5B8CFADED6FF31C5452BA3F877+ , ehR = 0x29FD82497FB3E5CEF65579272138DE59E2B666B8689466572B3B69A172CEE83BE145659+ , ehS = 0x05A89D9166B40795AF0FE5958201B9C0523E500013CA12B4840EA2BC53F25F9B3CE87C0+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x21B7265DEBF90E6F988CFFDB62B121A02105226C652807CC324ED6FB119A287A72680AB+ , ehR = 0x2F00689C1BFCD2A8C7A41E0DE55AE182E6463A152828EF89FE3525139B6603294E69353+ , ehS = 0x1744514FE0A37447250C8A329EAAADA81572226CABA16F39270EE5DD03F27B1F665EB5D+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x20583259DC179D9DA8E5387E89BFF2A3090788CF1496BCABFE7D45BB120B0C811EB8980+ , ehR = 0x0DA43A9ADFAA6AD767998A054C6A8F1CF77A562924628D73C62761847AD8286E0D91B47+ , ehS = 0x1D118733AE2C88357827CAFC6F68ABC25C80C640532925E95CFE66D40F8792F3AC44C42+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK = 0x0185C57A743D5BA06193CE2AA47B07EF3D6067E5AE1A6469BCD3FC510128BA564409D82+ , ehR = 0x05A408133919F2CDCDBE5E4C14FBC706C1F71BADAFEF41F5DE4EC27272FC1CA9366FBB2+ , ehS = 0x012966272872C097FEA7BCE64FAB1A81982A773E26F6E4EF7C99969846E67CA9CBE1692+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK = 0x2E5C1F00677A0E015EC3F799FA9E9A004309DBD784640EAAF5E1CE64D3045B9FE9C1FA1+ , ehR = 0x08F3824E40C16FF1DDA8DC992776D26F4A5981AB5092956C4FDBB4F1AE0A711EEAA10E5+ , ehS = 0x0A64B91EFADB213E11483FB61C73E3EF63D3B44EEFC56EA401B99DCC60CC28E99F0F1FA+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK = 0x018A7D44F2B4341FEFE68F6BD8894960F97E08124AAB92C1FFBBE90450FCC9356C9AAA5+ , ehR = 0x3597B406F5329D11A79E887847E5EC60861CCBB19EC61F252DB7BD549C699951C182796+ , ehS = 0x0A6A100B997BC622D91701D9F5C6F6D3815517E577622DA69D3A0E8917C1CBE63ACD345+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK = 0x3C75397BA4CF1B931877076AF29F2E2F4231B117AB4B8E039F7F9704DE1BD3522F150B6+ , ehR = 0x1BB490926E5A1FDC7C5AA86D0835F9B994EDA315CA408002AF54A298728D422EBF59E4C+ , ehS = 0x36C682CFC9E2C89A782BFD3A191609D1F0C1910D5FD6981442070393159D65FBCC0A8BA+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK = 0x14E66B18441FA54C21E3492D0611D2B48E19DE3108D915FD5CA08E786327A2675F11074+ , ehR = 0x19944AA68F9778C2E3D6E240947613E6DA60EFCE9B9B2C063FF5466D72745B5A0B25BA2+ , ehS = 0x03F1567B3C5B02DF15C874F0EE22850824693D5ADC4663BAA19E384E550B1DD41F31EE6+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_t409r1+ , ecPrivate =+ 0x0494994CC325B08E7B4CE038BD9436F90B5E59A2C13C3140CD3AE07C04A01FC489F572CE0569A6DB7B8060393DE76330C624177+ , ecPublic =+ Point+ 0x1A7055961CF1DA4B9A015B18B1524EF01FDD9B93FAEFC26FB1F2F828A7227B7031925DA0AC1A8A075C3B33554B222EA859C17E7+ 0x18105C042F290736088F30AEC7AE7732A45DE47BCE0940113AB8132516D1E059B0F581FD581A9A3CB3A0AC42A1962738ADB86E6+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x042D8A2B34402757EB2CCFDDC3E6E96A7ADD3FDA547FC10A0CB77CFC720B4F9E16EEAAA2A8CC4E4A4B5DBF7D8AC4EA491859E60+ , ehR =+ 0x0D8783188E1A540E2022D389E1D35B32F56F8C2BB5636B8ABF7718806B27A713EBAE37F63ECD4B61445CEF5801B62594EF3E982+ , ehS =+ 0x03A6B4A80E204DB0DE12E7415C13C9EC091C52935658316B4A0C591216A3879154BEB1712560E346E7EF26517707435B55C3141+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0x0C933F1DC4C70838C2AD16564715ACAF545BCDD8DC203D25AF3EC63949C65CB2E68AC1F60CA7EACA2A823F4E240927AA82CEEC5+ , ehR =+ 0x0EE4F39ACC2E03CE96C3D9FCBAFA5C22C89053662F8D4117752A9B10F09ADFDA59DB061E247FE5321D6B170EE758ACE1BE4D157+ , ehS =+ 0x00A2B83265B456A430A8BF27DCC8A9488B3F126C10F0D6D64BF7B8A218FAAF20E51A295A3AE78F205E5A4A6AE224C3639F1BB34+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x08EC42D13A3909A20C41BEBD2DFED8CACCE56C7A7D1251DF43F3E9E289DAE00E239F6960924AC451E125B784CB687C7F23283FD+ , ehR =+ 0x02D8B1B31E33E74D7EB46C30FDE5AD2CA04EC8FE08FBA0E73BA5E568953AC5EA307C072942238DFC07F4A4D7C7C6A9F86436D17+ , ehS =+ 0x079F7D471E6CB73234AF7F7C381D2CE15DE35BAF8BB68393B73235B3A26EC2DF4842CE433FB492D6E074E604D4870024D42189A+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x0DA881BCE3BA851485879EF8AC585A63F1540B9198ECB8A1096D70CB25A104E2F8A96B108AE76CB49CF34491ABC70E9D2AAD450+ , ehR =+ 0x07BC638B7E7CE6FEE5E9C64A0F966D722D01BB4BC3F3A35F30D4CDDA92DFC5F7F0B4BBFE8065D9AD452FD77A1914BE3A2440C18+ , ehS =+ 0x06D904429850521B28A32CBF55C7C0FDF35DC4E0BDA2552C7BF68A171E970E6788ACC0B9521EACB4796E057C70DD9B95FED5BFB+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x0750926FFAD7FF5DE85DF7960B3A4F9E3D38CF5A049BFC89739C48D42B34FBEE03D2C047025134CC3145B60AFD22A68DF0A7FB2+ , ehR =+ 0x05D178DECAFD2D02A3DA0D8BA1C4C1D95EE083C760DF782193A9F7B4A8BE6FC5C21FD60613BCA65C063A61226E050A680B3ABD4+ , ehS =+ 0x013B7581E98F6A63FBBCB3E49BCDA60F816DB230B888506D105DC229600497C3B46588C784BE3AA9343BEF82F7C9C80AEB63C3B+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x017E167EAB1850A3B38EE66BFE2270F2F6BFDAC5E2D227D47B20E75F0719161E6C74E9F23088F0C58B1E63BC6F185AD2EF4EAE6+ , ehR =+ 0x049F54E7C10D2732B4638473053782C6919218BBEFCEC8B51640FC193E832291F05FA12371E9B448417B3290193F08EE9319195+ , ehS =+ 0x0499E267DEC84E02F6F108B10E82172C414F15B1B7364BE8BFD66ADC0C5DE23FEE3DF0D811134C25AFE0E05A6672F98889F28F1+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0x01ADEB94C19951B460A146B8275D81638C07735B38A525D76023AAF26AA8A058590E1D5B1E78AB3C91608BDA67CFFBE6FC8A6CC+ , ehR =+ 0x0B1527FFAA7DD7C7E46B628587A5BEC0539A2D04D3CF27C54841C2544E1BBDB42FDBDAAF8671A4CA86DFD619B1E3732D7BB56F2+ , ehS =+ 0x0442C68C044868DF4832C807F1EDDEBF7F5052A64B826FD03451440794063F52B022DF304F47403D4069234CA9EB4C964B37C02+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x06EBA3D58D0E0DFC406D67FC72EF0C943624CF40019D1E48C3B54CCAB0594AFD5DEE30AEBAA22E693DBCFECAD1A85D774313DAD+ , ehR =+ 0x0BB27755B991D6D31757BCBF68CB01225A38E1CFA20F775E861055DD108ED7EA455E4B96B2F6F7CD6C6EC2B3C70C3EDDEB9743B+ , ehS =+ 0x0C5BE90980E7F444B5F7A12C9E9AC7A04CA81412822DD5AD1BE7C45D5032555EA070864245CF69266871FEB8CD1B7EDC30EF6D5+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x0A45B787DB44C06DEAB846511EEDBF7BFCFD3BD2C11D965C92FC195F67328F36A2DC83C0352885DAB96B55B02FCF49DCCB0E2DA+ , ehR =+ 0x04EFEB7098772187907C87B33E0FBBA4584226C50C11E98CA7AAC6986F8D3BE044E5B52D201A410B852536527724CA5F8CE6549+ , ehS =+ 0x09574102FEB3EF87E6D66B94119F5A6062950FF4F902EA1E6BD9E2037F33FF991E31F5956C23AFE48FCDC557FD6F088C7C9B2B3+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x0B90F8A0E757E81D4EA6891766729C96A6D01F9AEDC0D334932D1F81CC4E1973A4F01C33555FF08530A5098CADB6EDAE268ABB5+ , ehR =+ 0x07E0249C68536AE2AEC2EC30090340DA49E6DC9E9EEC8F85E5AABFB234B6DA7D2E9524028CF821F21C6019770474CC40B01FAF6+ , ehS =+ 0x08125B5A03FB44AE81EA46D446130C2A415ECCA265910CA69D55F2453E16CD7B2DFA4E28C50FA8137F9C0C6CEE4CD37ABCCF6D8+ }+ ]+ }+ ]+ }+ , EntryCurve+ { ecName = SEC_t571r1+ , ecPrivate =+ 0x028A04857F24C1C082DF0D909C0E72F453F2E2340CCB071F0E389BCA2575DA19124198C57174929AD26E348CF63F78D28021EF5A9BF2D5CBEAF6B7CCB6C4DA824DD5C82CFB24E11+ , ecPublic =+ Point+ 0x4B4B3CE9377550140B62C1061763AA524814DDCEF37B00CD5CDE94F7792BB0E96758E55DA2E9FEA8FF2A8B6830AE1D57A9CA7A77FCB0836BF43EA5454CDD9FEAD5CCFE7375C6A83+ 0x4453B18F261E7A0E7570CD72F235EA750438E43946FBEBD2518B696954767AA7849C1719E18E1C51652C28CA853426F15C09AA4B579487338ABC7F33768FADD61B5A3A6443A8189+ , ecMessages =+ [ EntryMessage+ { emMessage = "sample"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x2669FAFEF848AF67D437D4A151C3C5D3F9AA8BB66EDC35F090C9118F95BA0041B0993BE2EF55DAAF36B5B3A737C40DB1F6E3D93D97B8419AD6E1BB8A5D4A0E9B2E76832D4E7B862+ , ehR =+ 0x147D3EB0EDA9F2152DFD014363D6A9CE816D7A1467D326A625FC4AB0C786E1B74DDF7CD4D0E99541391B266C704BB6B6E8DCCD27B460802E0867143727AA415555454321EFE5CB6+ , ehS =+ 0x17319571CAF533D90D2E78A64060B9C53169AB7FC908947B3EDADC54C79CCF0A7920B4C64A4EAB6282AFE9A459677CDA37FD6DD50BEF18709590FE18B923BDF74A66B189A850819+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0x2EAFAD4AC8644DEB29095BBAA88D19F31316434F1766AD4423E0B54DD2FE0C05E307758581B0DAED2902683BBC7C47B00E63E3E429BA54EA6BA3AEC33A94C9A24A6EF8E27B7677A+ , ehR =+ 0x10F4B63E79B2E54E4F4F6A2DBC786D8F4A143ECA7B2AD97810F6472AC6AE20853222854553BE1D44A7974599DB7061AE8560DF57F2675BE5F9DD94ABAF3D47F1582B318E459748B+ , ehS =+ 0x3BBEA07C6B269C2B7FE9AE4DDB118338D0C2F0022920A7F9DCFCB7489594C03B536A9900C4EA6A10410007222D3DAE1A96F291C4C9275D75D98EB290DC0EEF176037B2C7A7A39A3+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x15C2C6B7D1A070274484774E558B69FDFA193BDB7A23F27C2CD24298CE1B22A6CC9B7FB8CABFD6CF7C6B1CF3251E5A1CDDD16FBFED28DE79935BB2C631B8B8EA9CC4BCC937E669E+ , ehR =+ 0x213EF9F3B0CFC4BF996B8AF3A7E1F6CACD2B87C8C63820000800AC787F17EC99C04BCEDF29A8413CFF83142BB88A50EF8D9A086AF4EB03E97C567500C21D865714D832E03C6D054+ , ehS =+ 0x3D32322559B094E20D8935E250B6EC139AC4AAB77920812C119AF419FB62B332C8D226C6C9362AE3C1E4AABE19359B8428EA74EC8FBE83C8618C2BCCB6B43FBAA0F2CCB7D303945+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x0FEF0B68CB49453A4C6ECBF1708DBEEFC885C57FDAFB88417AAEFA5B1C35017B4B498507937ADCE2F1D9EFFA5FE8F5AEB116B804FD182A6CF1518FDB62D53F60A0FF6EB707D856B+ , ehR =+ 0x375D8F49C656A0BBD21D3F54CDA287D853C4BB1849983CD891EF6CD6BB56A62B687807C16685C2C9BCA2663C33696ACCE344C45F3910B1DF806204FF731ECB289C100EF4D1805EC+ , ehS =+ 0x1CDEC6F46DFEEE44BCE71D41C60550DC67CF98D6C91363625AC2553E4368D2DFB734A8E8C72E118A76ACDB0E58697940A0F3DF49E72894BD799450FC9E550CC04B9FF9B0380021C+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x3FF373833A06C791D7AD586AFA3990F6EF76999C35246C4AD0D519BFF180CA1880E11F2FB38B764854A0AE3BECDDB50F05AC4FCEE542F207C0A6229E2E19652F0E647B9C4882193+ , ehR =+ 0x1C26F40D940A7EAA0EB1E62991028057D91FEDA0366B606F6C434C361F04E545A6A51A435E26416F6838FFA260C617E798E946B57215284182BE55F29A355E6024FE32A47289CF0+ , ehS =+ 0x3691DE4369D921FE94EDDA67CB71FBBEC9A436787478063EB1CC778B3DCDC1C4162662752D28DEEDF6F32A269C82D1DB80C87CE4D3B662E03AC347806E3F19D18D6D4DE7358DF7E+ }+ ]+ }+ , EntryMessage+ { emMessage = "test"+ , emHashes =+ [ EntryHash+ { ehAlgorithm = HashAlg SHA1+ , ehK =+ 0x019B506FD472675A7140E429AA5510DCDDC21004206EEC1B39B28A688A8FD324138F12503A4EFB64F934840DFBA2B4797CFC18B8BD0B31BBFF3CA66A4339E4EF9D771B15279D1DC+ , ehR =+ 0x133F5414F2A9BC41466D339B79376038A64D045E5B0F792A98E5A7AA87E0AD016419E5F8D176007D5C9C10B5FD9E2E0AB8331B195797C0358BA05ECBF24ACE59C5F368A6C0997CC+ , ehS =+ 0x3D16743AE9F00F0B1A500F738719C5582550FEB64689DA241665C4CE4F328BA0E34A7EF527ED13BFA5889FD2D1D214C11EB17D6BC338E05A56F41CAFF1AF7B8D574DB62EF0D0F21+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA224+ , ehK =+ 0x333C711F8C62F205F926593220233B06228285261D34026232F6F729620C6DE12220F282F4206D223226705608688B20B8BA86D8DFE54F07A37EC48F253283AC33C3F5102C8CC3E+ , ehR =+ 0x3048E76506C5C43D92B2E33F62B33E3111CEEB87F6C7DF7C7C01E3CDA28FA5E8BE04B5B23AA03C0C70FEF8F723CBCEBFF0B7A52A3F5C8B84B741B4F6157E69A5FB0524B48F31828+ , ehS =+ 0x2C99078CCFE5C82102B8D006E3703E020C46C87C75163A2CD839C885550BA5CB501AC282D29A1C26D26773B60FBE05AAB62BFA0BA32127563D42F7669C97784C8897C22CFB4B8FA+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA256+ , ehK =+ 0x328E02CF07C7B5B6D3749D8302F1AE5BFAA8F239398459AF4A2C859C7727A8123A7FE9BE8B228413FC8DC0E9DE16AF3F8F43005107F9989A5D97A5C4455DA895E81336710A3FB2C+ , ehR =+ 0x184BC808506E11A65D628B457FDA60952803C604CC7181B59BD25AEE1411A66D12A777F3A0DC99E1190C58D0037807A95E5080FA1B2E5CCAA37B50D401CFFC3417C005AEE963469+ , ehS =+ 0x27280D45F81B19334DBDB07B7E63FE8F39AC7E9AE14DE1D2A6884D2101850289D70EE400F26ACA5E7D73F534A14568478E59D00594981ABE6A1BA18554C13EB5E03921E4DC98333+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA384+ , ehK =+ 0x2A77E29EAD9E811A9FDA0284C14CDFA1D9F8FA712DA59D530A06CDE54187E250AD1D4FB5788161938B8DE049616399C5A56B0737C9564C9D4D845A4C6A7CDFCBFF0F01A82BE672E+ , ehR =+ 0x319EE57912E7B0FAA1FBB145B0505849A89C6DB1EC06EA20A6A7EDE072A6268AF6FD9C809C7E422A5F33C6C3326EAD7402467DF3272A1B2726C1C20975950F0F50D8324578F13EC+ , ehS =+ 0x2CF3EA27EADD0612DD2F96F46E89AB894B01A10DF985C5FC099CFFE0EA083EB44BE682B08BFE405DAD5F37D0A2C59015BA41027E24B99F8F75A70B6B7385BF39BBEA02513EB880C+ }+ , EntryHash+ { ehAlgorithm = HashAlg SHA512+ , ehK =+ 0x21CE6EE4A2C72C9F93BDB3B552F4A633B8C20C200F894F008643240184BE57BB282A1645E47FBBE131E899B4C61244EFC2486D88CDBD1DD4A65EBDD837019D02628D0DCD6ED8FB5+ , ehR =+ 0x2AA1888EAB05F7B00B6A784C4F7081D2C833D50794D9FEAF6E22B8BE728A2A90BFCABDC803162020AA629718295A1489EE7ED0ECB8AAA197B9BDFC49D18DDD78FC85A48F9715544+ , ehS =+ 0x0AA5371FE5CA671D6ED9665849C37F394FED85D51FEF72DA2B5F28EDFB2C6479CA63320C19596F5E1101988E2C619E302DD05112F47E8823040CE540CD3E90DCF41DBC461744EE9+ }+ ]+ }+ ]+ }+ ]++testPublic :: PrivateKey -> PublicPoint -> TestTree+testPublic (PrivateKey curve key) pub =+ testCase "public" $+ pub @=? generateQ curve key++testNonce :: PrivateKey -> HashAlg -> ByteString -> Integer -> TestTree+testNonce key (HashAlg alg) msg nonc =+ testCase "nonce" $+ nonc @=? deterministicNonce alg key (hashWith alg msg) Just++testSignature+ :: PrivateKey -> HashAlg -> ByteString -> Integer -> Signature -> TestTree+testSignature key (HashAlg alg) msg nonc sig = testCase "signature" $+ case signWith nonc key alg msg of+ Nothing -> assertFailure "could not sign message"+ Just result -> sig @=? result++testVerify :: PublicKey -> HashAlg -> ByteString -> Signature -> TestTree+testVerify pub (HashAlg alg) msg sig =+ testCase "verify" $+ assertBool "signature verification failed" $+ verify alg pub sig msg++testEntry :: Entry -> TestTree+testEntry entry = testGroup (show entry) tests+ where+ tests =+ [ testPublic key $ publicPoint entry+ , testSignature+ key+ (hashAlgorithm entry)+ (message entry)+ (nonce entry)+ (signature entry)+ , testVerify pub (hashAlgorithm entry) (message entry) (signature entry)+ ]+ pub = PublicKey curve $ publicPoint entry+ key = PrivateKey curve $ privateNumber entry+ curve = getCurveByName $ curveName entry++testEntryNonce :: Entry -> TestTree+testEntryNonce entry = testGroup (show entry) tests+ where+ tests =+ [ testPublic key $ publicPoint entry+ , testNonce key (hashAlgorithm entry) (message entry) (nonce entry)+ , testSignature+ key+ (hashAlgorithm entry)+ (message entry)+ (nonce entry)+ (signature entry)+ , testVerify pub (hashAlgorithm entry) (message entry) (signature entry)+ ]+ pub = PublicKey curve $ publicPoint entry+ key = PrivateKey curve $ privateNumber entry+ curve = getCurveByName $ curveName entry++ecdsaTests :: TestTree+ecdsaTests =+ testGroup+ "ECDSA"+ [ testGroup "GEC 2" $ testEntry . normalize <$> gec2Entries+ , testGroup "RFC 6979" $ testEntryNonce . normalize <$> flatten rfc6979Entries+ ]
tests/KAT_PubKey/OAEP.hs view
@@ -1,97 +1,142 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_PubKey.OAEP (oaepTests) where +import Crypto.Hash import Crypto.PubKey.RSA import qualified Crypto.PubKey.RSA.OAEP as OAEP-import Crypto.Hash import Imports -rsaKeyInt = PrivateKey- { private_pub = PublicKey- { public_n = 0xbbf82f090682ce9c2338ac2b9da871f7368d07eed41043a440d6b6f07454f51fb8dfbaaf035c02ab61ea48ceeb6fcd4876ed520d60e1ec4619719d8a5b8b807fafb8e0a3dfc737723ee6b4b7d93a2584ee6a649d060953748834b2454598394ee0aab12d7b61a51f527a9a41f6c1687fe2537298ca2a8f5946f8e5fd091dbdcb- , public_e = 0x11 - , public_size = 128+rsaKeyInt =+ PrivateKey+ { private_pub =+ PublicKey+ { public_n =+ 0xbbf82f090682ce9c2338ac2b9da871f7368d07eed41043a440d6b6f07454f51fb8dfbaaf035c02ab61ea48ceeb6fcd4876ed520d60e1ec4619719d8a5b8b807fafb8e0a3dfc737723ee6b4b7d93a2584ee6a649d060953748834b2454598394ee0aab12d7b61a51f527a9a41f6c1687fe2537298ca2a8f5946f8e5fd091dbdcb+ , public_e = 0x11+ , public_size = 128+ }+ , private_d =+ 0xa5dafc5341faf289c4b988db30c1cdf83f31251e0668b42784813801579641b29410b3c7998d6bc465745e5c392669d6870da2c082a939e37fdcb82ec93edac97ff3ad5950accfbc111c76f1a9529444e56aaf68c56c092cd38dc3bef5d20a939926ed4f74a13eddfbe1a1cecc4894af9428c2b7b8883fe4463a4bc85b1cb3c1+ , private_p =+ 0xeecfae81b1b9b3c908810b10a1b5600199eb9f44aef4fda493b81a9e3d84f632124ef0236e5d1e3b7e28fae7aa040a2d5b252176459d1f397541ba2a58fb6599+ , private_q =+ 0xc97fb1f027f453f6341233eaaad1d9353f6c42d08866b1d05a0f2035028b9d869840b41666b42e92ea0da3b43204b5cfce3352524d0416a5a441e700af461503+ , private_dP =+ 0x54494ca63eba0337e4e24023fcd69a5aeb07dddc0183a4d0ac9b54b051f2b13ed9490975eab77414ff59c1f7692e9a2e202b38fc910a474174adc93c1f67c981+ , private_dQ =+ 0x471e0290ff0af0750351b7f878864ca961adbd3a8a7e991c5c0556a94c3146a7f9803f8f6f8ae342e931fd8ae47a220d1b99a495849807fe39f9245a9836da3d+ , private_qinv =+ 0xb06c4fdabb6301198d265bdbae9423b380f271f73453885093077fcd39e2119fc98632154f5883b167a967bf402b4e9e2e0f9656e698ea3666edfb25798039f7 }- , private_d = 0xa5dafc5341faf289c4b988db30c1cdf83f31251e0668b42784813801579641b29410b3c7998d6bc465745e5c392669d6870da2c082a939e37fdcb82ec93edac97ff3ad5950accfbc111c76f1a9529444e56aaf68c56c092cd38dc3bef5d20a939926ed4f74a13eddfbe1a1cecc4894af9428c2b7b8883fe4463a4bc85b1cb3c1- , private_p = 0xeecfae81b1b9b3c908810b10a1b5600199eb9f44aef4fda493b81a9e3d84f632124ef0236e5d1e3b7e28fae7aa040a2d5b252176459d1f397541ba2a58fb6599- , private_q = 0xc97fb1f027f453f6341233eaaad1d9353f6c42d08866b1d05a0f2035028b9d869840b41666b42e92ea0da3b43204b5cfce3352524d0416a5a441e700af461503- , private_dP = 0x54494ca63eba0337e4e24023fcd69a5aeb07dddc0183a4d0ac9b54b051f2b13ed9490975eab77414ff59c1f7692e9a2e202b38fc910a474174adc93c1f67c981- , private_dQ = 0x471e0290ff0af0750351b7f878864ca961adbd3a8a7e991c5c0556a94c3146a7f9803f8f6f8ae342e931fd8ae47a220d1b99a495849807fe39f9245a9836da3d- , private_qinv = 0xb06c4fdabb6301198d265bdbae9423b380f271f73453885093077fcd39e2119fc98632154f5883b167a967bf402b4e9e2e0f9656e698ea3666edfb25798039f7- } -rsaKey1 = PrivateKey- { private_pub = PublicKey- { public_n = 0xa8b3b284af8eb50b387034a860f146c4919f318763cd6c5598c8ae4811a1e0abc4c7e0b082d693a5e7fced675cf4668512772c0cbc64a742c6c630f533c8cc72f62ae833c40bf25842e984bb78bdbf97c0107d55bdb662f5c4e0fab9845cb5148ef7392dd3aaff93ae1e6b667bb3d4247616d4f5ba10d4cfd226de88d39f16fb- , public_e = 0x010001- , public_size = 128+rsaKey1 =+ PrivateKey+ { private_pub =+ PublicKey+ { public_n =+ 0xa8b3b284af8eb50b387034a860f146c4919f318763cd6c5598c8ae4811a1e0abc4c7e0b082d693a5e7fced675cf4668512772c0cbc64a742c6c630f533c8cc72f62ae833c40bf25842e984bb78bdbf97c0107d55bdb662f5c4e0fab9845cb5148ef7392dd3aaff93ae1e6b667bb3d4247616d4f5ba10d4cfd226de88d39f16fb+ , public_e = 0x010001+ , public_size = 128+ }+ , private_d =+ 0x53339cfdb79fc8466a655c7316aca85c55fd8f6dd898fdaf119517ef4f52e8fd8e258df93fee180fa0e4ab29693cd83b152a553d4ac4d1812b8b9fa5af0e7f55fe7304df41570926f3311f15c4d65a732c483116ee3d3d2d0af3549ad9bf7cbfb78ad884f84d5beb04724dc7369b31def37d0cf539e9cfcdd3de653729ead5d1+ , private_p =+ 0xd32737e7267ffe1341b2d5c0d150a81b586fb3132bed2f8d5262864a9cb9f30af38be448598d413a172efb802c21acf1c11c520c2f26a471dcad212eac7ca39d+ , private_q =+ 0xcc8853d1d54da630fac004f471f281c7b8982d8224a490edbeb33d3e3d5cc93c4765703d1dd791642f1f116a0dd852be2419b2af72bfe9a030e860b0288b5d77+ , private_dP =+ 0x0e12bf1718e9cef5599ba1c3882fe8046a90874eefce8f2ccc20e4f2741fb0a33a3848aec9c9305fbecbd2d76819967d4671acc6431e4037968db37878e695c1+ , private_dQ =+ 0x95297b0f95a2fa67d00707d609dfd4fc05c89dafc2ef6d6ea55bec771ea333734d9251e79082ecda866efef13c459e1a631386b7e354c899f5f112ca85d71583+ , private_qinv =+ 0x4f456c502493bdc0ed2ab756a3a6ed4d67352a697d4216e93212b127a63d5411ce6fa98d5dbefd73263e3728142743818166ed7dd63687dd2a8ca1d2f4fbd8e1 }- , private_d = 0x53339cfdb79fc8466a655c7316aca85c55fd8f6dd898fdaf119517ef4f52e8fd8e258df93fee180fa0e4ab29693cd83b152a553d4ac4d1812b8b9fa5af0e7f55fe7304df41570926f3311f15c4d65a732c483116ee3d3d2d0af3549ad9bf7cbfb78ad884f84d5beb04724dc7369b31def37d0cf539e9cfcdd3de653729ead5d1- , private_p = 0xd32737e7267ffe1341b2d5c0d150a81b586fb3132bed2f8d5262864a9cb9f30af38be448598d413a172efb802c21acf1c11c520c2f26a471dcad212eac7ca39d- , private_q = 0xcc8853d1d54da630fac004f471f281c7b8982d8224a490edbeb33d3e3d5cc93c4765703d1dd791642f1f116a0dd852be2419b2af72bfe9a030e860b0288b5d77- , private_dP = 0x0e12bf1718e9cef5599ba1c3882fe8046a90874eefce8f2ccc20e4f2741fb0a33a3848aec9c9305fbecbd2d76819967d4671acc6431e4037968db37878e695c1- , private_dQ = 0x95297b0f95a2fa67d00707d609dfd4fc05c89dafc2ef6d6ea55bec771ea333734d9251e79082ecda866efef13c459e1a631386b7e354c899f5f112ca85d71583- , private_qinv = 0x4f456c502493bdc0ed2ab756a3a6ed4d67352a697d4216e93212b127a63d5411ce6fa98d5dbefd73263e3728142743818166ed7dd63687dd2a8ca1d2f4fbd8e1- } --data VectorOAEP = VectorOAEP { seed :: ByteString- , message :: ByteString- , cipherText :: ByteString- }-vectorInt = VectorOAEP- { message = "\xd4\x36\xe9\x95\x69\xfd\x32\xa7\xc8\xa0\x5b\xbc\x90\xd3\x2c\x49"- , seed = "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f"- , cipherText = "\x12\x53\xe0\x4d\xc0\xa5\x39\x7b\xb4\x4a\x7a\xb8\x7e\x9b\xf2\xa0\x39\xa3\x3d\x1e\x99\x6f\xc8\x2a\x94\xcc\xd3\x00\x74\xc9\x5d\xf7\x63\x72\x20\x17\x06\x9e\x52\x68\xda\x5d\x1c\x0b\x4f\x87\x2c\xf6\x53\xc1\x1d\xf8\x23\x14\xa6\x79\x68\xdf\xea\xe2\x8d\xef\x04\xbb\x6d\x84\xb1\xc3\x1d\x65\x4a\x19\x70\xe5\x78\x3b\xd6\xeb\x96\xa0\x24\xc2\xca\x2f\x4a\x90\xfe\x9f\x2e\xf5\xc9\xc1\x40\xe5\xbb\x48\xda\x95\x36\xad\x87\x00\xc8\x4f\xc9\x13\x0a\xde\xa7\x4e\x55\x8d\x51\xa7\x4d\xdf\x85\xd8\xb5\x0d\xe9\x68\x38\xd6\x06\x3e\x09\x55"+data VectorOAEP = VectorOAEP+ { seed :: ByteString+ , message :: ByteString+ , cipherText :: ByteString }+vectorInt =+ VectorOAEP+ { message = "\xd4\x36\xe9\x95\x69\xfd\x32\xa7\xc8\xa0\x5b\xbc\x90\xd3\x2c\x49"+ , seed =+ "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f"+ , cipherText =+ "\x12\x53\xe0\x4d\xc0\xa5\x39\x7b\xb4\x4a\x7a\xb8\x7e\x9b\xf2\xa0\x39\xa3\x3d\x1e\x99\x6f\xc8\x2a\x94\xcc\xd3\x00\x74\xc9\x5d\xf7\x63\x72\x20\x17\x06\x9e\x52\x68\xda\x5d\x1c\x0b\x4f\x87\x2c\xf6\x53\xc1\x1d\xf8\x23\x14\xa6\x79\x68\xdf\xea\xe2\x8d\xef\x04\xbb\x6d\x84\xb1\xc3\x1d\x65\x4a\x19\x70\xe5\x78\x3b\xd6\xeb\x96\xa0\x24\xc2\xca\x2f\x4a\x90\xfe\x9f\x2e\xf5\xc9\xc1\x40\xe5\xbb\x48\xda\x95\x36\xad\x87\x00\xc8\x4f\xc9\x13\x0a\xde\xa7\x4e\x55\x8d\x51\xa7\x4d\xdf\x85\xd8\xb5\x0d\xe9\x68\x38\xd6\x06\x3e\x09\x55"+ } vectorsKey1 = [ VectorOAEP -- 1.1- { message = "\x66\x28\x19\x4e\x12\x07\x3d\xb0\x3b\xa9\x4c\xda\x9e\xf9\x53\x23\x97\xd5\x0d\xba\x79\xb9\x87\x00\x4a\xfe\xfe\x34"- , seed = "\x18\xb7\x76\xea\x21\x06\x9d\x69\x77\x6a\x33\xe9\x6b\xad\x48\xe1\xdd\xa0\xa5\xef"- , cipherText = "\x35\x4f\xe6\x7b\x4a\x12\x6d\x5d\x35\xfe\x36\xc7\x77\x79\x1a\x3f\x7b\xa1\x3d\xef\x48\x4e\x2d\x39\x08\xaf\xf7\x22\xfa\xd4\x68\xfb\x21\x69\x6d\xe9\x5d\x0b\xe9\x11\xc2\xd3\x17\x4f\x8a\xfc\xc2\x01\x03\x5f\x7b\x6d\x8e\x69\x40\x2d\xe5\x45\x16\x18\xc2\x1a\x53\x5f\xa9\xd7\xbf\xc5\xb8\xdd\x9f\xc2\x43\xf8\xcf\x92\x7d\xb3\x13\x22\xd6\xe8\x81\xea\xa9\x1a\x99\x61\x70\xe6\x57\xa0\x5a\x26\x64\x26\xd9\x8c\x88\x00\x3f\x84\x77\xc1\x22\x70\x94\xa0\xd9\xfa\x1e\x8c\x40\x24\x30\x9c\xe1\xec\xcc\xb5\x21\x00\x35\xd4\x7a\xc7\x2e\x8a"+ { message =+ "\x66\x28\x19\x4e\x12\x07\x3d\xb0\x3b\xa9\x4c\xda\x9e\xf9\x53\x23\x97\xd5\x0d\xba\x79\xb9\x87\x00\x4a\xfe\xfe\x34"+ , seed =+ "\x18\xb7\x76\xea\x21\x06\x9d\x69\x77\x6a\x33\xe9\x6b\xad\x48\xe1\xdd\xa0\xa5\xef"+ , cipherText =+ "\x35\x4f\xe6\x7b\x4a\x12\x6d\x5d\x35\xfe\x36\xc7\x77\x79\x1a\x3f\x7b\xa1\x3d\xef\x48\x4e\x2d\x39\x08\xaf\xf7\x22\xfa\xd4\x68\xfb\x21\x69\x6d\xe9\x5d\x0b\xe9\x11\xc2\xd3\x17\x4f\x8a\xfc\xc2\x01\x03\x5f\x7b\x6d\x8e\x69\x40\x2d\xe5\x45\x16\x18\xc2\x1a\x53\x5f\xa9\xd7\xbf\xc5\xb8\xdd\x9f\xc2\x43\xf8\xcf\x92\x7d\xb3\x13\x22\xd6\xe8\x81\xea\xa9\x1a\x99\x61\x70\xe6\x57\xa0\x5a\x26\x64\x26\xd9\x8c\x88\x00\x3f\x84\x77\xc1\x22\x70\x94\xa0\xd9\xfa\x1e\x8c\x40\x24\x30\x9c\xe1\xec\xcc\xb5\x21\x00\x35\xd4\x7a\xc7\x2e\x8a" }- , VectorOAEP -- 1.2- { message = "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5"- , seed = "\x0c\xc7\x42\xce\x4a\x9b\x7f\x32\xf9\x51\xbc\xb2\x51\xef\xd9\x25\xfe\x4f\xe3\x5f"- , cipherText = "\x64\x0d\xb1\xac\xc5\x8e\x05\x68\xfe\x54\x07\xe5\xf9\xb7\x01\xdf\xf8\xc3\xc9\x1e\x71\x6c\x53\x6f\xc7\xfc\xec\x6c\xb5\xb7\x1c\x11\x65\x98\x8d\x4a\x27\x9e\x15\x77\xd7\x30\xfc\x7a\x29\x93\x2e\x3f\x00\xc8\x15\x15\x23\x6d\x8d\x8e\x31\x01\x7a\x7a\x09\xdf\x43\x52\xd9\x04\xcd\xeb\x79\xaa\x58\x3a\xdc\xc3\x1e\xa6\x98\xa4\xc0\x52\x83\xda\xba\x90\x89\xbe\x54\x91\xf6\x7c\x1a\x4e\xe4\x8d\xc7\x4b\xbb\xe6\x64\x3a\xef\x84\x66\x79\xb4\xcb\x39\x5a\x35\x2d\x5e\xd1\x15\x91\x2d\xf6\x96\xff\xe0\x70\x29\x32\x94\x6d\x71\x49\x2b\x44"+ { message =+ "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5"+ , seed =+ "\x0c\xc7\x42\xce\x4a\x9b\x7f\x32\xf9\x51\xbc\xb2\x51\xef\xd9\x25\xfe\x4f\xe3\x5f"+ , cipherText =+ "\x64\x0d\xb1\xac\xc5\x8e\x05\x68\xfe\x54\x07\xe5\xf9\xb7\x01\xdf\xf8\xc3\xc9\x1e\x71\x6c\x53\x6f\xc7\xfc\xec\x6c\xb5\xb7\x1c\x11\x65\x98\x8d\x4a\x27\x9e\x15\x77\xd7\x30\xfc\x7a\x29\x93\x2e\x3f\x00\xc8\x15\x15\x23\x6d\x8d\x8e\x31\x01\x7a\x7a\x09\xdf\x43\x52\xd9\x04\xcd\xeb\x79\xaa\x58\x3a\xdc\xc3\x1e\xa6\x98\xa4\xc0\x52\x83\xda\xba\x90\x89\xbe\x54\x91\xf6\x7c\x1a\x4e\xe4\x8d\xc7\x4b\xbb\xe6\x64\x3a\xef\x84\x66\x79\xb4\xcb\x39\x5a\x35\x2d\x5e\xd1\x15\x91\x2d\xf6\x96\xff\xe0\x70\x29\x32\x94\x6d\x71\x49\x2b\x44" } , VectorOAEP -- 1.3- { message = "\xd9\x4a\xe0\x83\x2e\x64\x45\xce\x42\x33\x1c\xb0\x6d\x53\x1a\x82\xb1\xdb\x4b\xaa\xd3\x0f\x74\x6d\xc9\x16\xdf\x24\xd4\xe3\xc2\x45\x1f\xff\x59\xa6\x42\x3e\xb0\xe1\xd0\x2d\x4f\xe6\x46\xcf\x69\x9d\xfd\x81\x8c\x6e\x97\xb0\x51"- , seed = "\x25\x14\xdf\x46\x95\x75\x5a\x67\xb2\x88\xea\xf4\x90\x5c\x36\xee\xc6\x6f\xd2\xfd"- , cipherText = "\x42\x37\x36\xed\x03\x5f\x60\x26\xaf\x27\x6c\x35\xc0\xb3\x74\x1b\x36\x5e\x5f\x76\xca\x09\x1b\x4e\x8c\x29\xe2\xf0\xbe\xfe\xe6\x03\x59\x5a\xa8\x32\x2d\x60\x2d\x2e\x62\x5e\x95\xeb\x81\xb2\xf1\xc9\x72\x4e\x82\x2e\xca\x76\xdb\x86\x18\xcf\x09\xc5\x34\x35\x03\xa4\x36\x08\x35\xb5\x90\x3b\xc6\x37\xe3\x87\x9f\xb0\x5e\x0e\xf3\x26\x85\xd5\xae\xc5\x06\x7c\xd7\xcc\x96\xfe\x4b\x26\x70\xb6\xea\xc3\x06\x6b\x1f\xcf\x56\x86\xb6\x85\x89\xaa\xfb\x7d\x62\x9b\x02\xd8\xf8\x62\x5c\xa3\x83\x36\x24\xd4\x80\x0f\xb0\x81\xb1\xcf\x94\xeb"+ { message =+ "\xd9\x4a\xe0\x83\x2e\x64\x45\xce\x42\x33\x1c\xb0\x6d\x53\x1a\x82\xb1\xdb\x4b\xaa\xd3\x0f\x74\x6d\xc9\x16\xdf\x24\xd4\xe3\xc2\x45\x1f\xff\x59\xa6\x42\x3e\xb0\xe1\xd0\x2d\x4f\xe6\x46\xcf\x69\x9d\xfd\x81\x8c\x6e\x97\xb0\x51"+ , seed =+ "\x25\x14\xdf\x46\x95\x75\x5a\x67\xb2\x88\xea\xf4\x90\x5c\x36\xee\xc6\x6f\xd2\xfd"+ , cipherText =+ "\x42\x37\x36\xed\x03\x5f\x60\x26\xaf\x27\x6c\x35\xc0\xb3\x74\x1b\x36\x5e\x5f\x76\xca\x09\x1b\x4e\x8c\x29\xe2\xf0\xbe\xfe\xe6\x03\x59\x5a\xa8\x32\x2d\x60\x2d\x2e\x62\x5e\x95\xeb\x81\xb2\xf1\xc9\x72\x4e\x82\x2e\xca\x76\xdb\x86\x18\xcf\x09\xc5\x34\x35\x03\xa4\x36\x08\x35\xb5\x90\x3b\xc6\x37\xe3\x87\x9f\xb0\x5e\x0e\xf3\x26\x85\xd5\xae\xc5\x06\x7c\xd7\xcc\x96\xfe\x4b\x26\x70\xb6\xea\xc3\x06\x6b\x1f\xcf\x56\x86\xb6\x85\x89\xaa\xfb\x7d\x62\x9b\x02\xd8\xf8\x62\x5c\xa3\x83\x36\x24\xd4\x80\x0f\xb0\x81\xb1\xcf\x94\xeb" } , VectorOAEP- { message = "\x52\xe6\x50\xd9\x8e\x7f\x2a\x04\x8b\x4f\x86\x85\x21\x53\xb9\x7e\x01\xdd\x31\x6f\x34\x6a\x19\xf6\x7a\x85"- , seed = "\xc4\x43\x5a\x3e\x1a\x18\xa6\x8b\x68\x20\x43\x62\x90\xa3\x7c\xef\xb8\x5d\xb3\xfb"- , cipherText = "\x45\xea\xd4\xca\x55\x1e\x66\x2c\x98\x00\xf1\xac\xa8\x28\x3b\x05\x25\xe6\xab\xae\x30\xbe\x4b\x4a\xba\x76\x2f\xa4\x0f\xd3\xd3\x8e\x22\xab\xef\xc6\x97\x94\xf6\xeb\xbb\xc0\x5d\xdb\xb1\x12\x16\x24\x7d\x2f\x41\x2f\xd0\xfb\xa8\x7c\x6e\x3a\xcd\x88\x88\x13\x64\x6f\xd0\xe4\x8e\x78\x52\x04\xf9\xc3\xf7\x3d\x6d\x82\x39\x56\x27\x22\xdd\xdd\x87\x71\xfe\xc4\x8b\x83\xa3\x1e\xe6\xf5\x92\xc4\xcf\xd4\xbc\x88\x17\x4f\x3b\x13\xa1\x12\xaa\xe3\xb9\xf7\xb8\x0e\x0f\xc6\xf7\x25\x5b\xa8\x80\xdc\x7d\x80\x21\xe2\x2a\xd6\xa8\x5f\x07\x55"+ { message =+ "\x52\xe6\x50\xd9\x8e\x7f\x2a\x04\x8b\x4f\x86\x85\x21\x53\xb9\x7e\x01\xdd\x31\x6f\x34\x6a\x19\xf6\x7a\x85"+ , seed =+ "\xc4\x43\x5a\x3e\x1a\x18\xa6\x8b\x68\x20\x43\x62\x90\xa3\x7c\xef\xb8\x5d\xb3\xfb"+ , cipherText =+ "\x45\xea\xd4\xca\x55\x1e\x66\x2c\x98\x00\xf1\xac\xa8\x28\x3b\x05\x25\xe6\xab\xae\x30\xbe\x4b\x4a\xba\x76\x2f\xa4\x0f\xd3\xd3\x8e\x22\xab\xef\xc6\x97\x94\xf6\xeb\xbb\xc0\x5d\xdb\xb1\x12\x16\x24\x7d\x2f\x41\x2f\xd0\xfb\xa8\x7c\x6e\x3a\xcd\x88\x88\x13\x64\x6f\xd0\xe4\x8e\x78\x52\x04\xf9\xc3\xf7\x3d\x6d\x82\x39\x56\x27\x22\xdd\xdd\x87\x71\xfe\xc4\x8b\x83\xa3\x1e\xe6\xf5\x92\xc4\xcf\xd4\xbc\x88\x17\x4f\x3b\x13\xa1\x12\xaa\xe3\xb9\xf7\xb8\x0e\x0f\xc6\xf7\x25\x5b\xa8\x80\xdc\x7d\x80\x21\xe2\x2a\xd6\xa8\x5f\x07\x55" }- , VectorOAEP- { message = "\x8d\xa8\x9f\xd9\xe5\xf9\x74\xa2\x9f\xef\xfb\x46\x2b\x49\x18\x0f\x6c\xf9\xe8\x02"- , seed = "\xb3\x18\xc4\x2d\xf3\xbe\x0f\x83\xfe\xa8\x23\xf5\xa7\xb4\x7e\xd5\xe4\x25\xa3\xb5"- , cipherText = "\x36\xf6\xe3\x4d\x94\xa8\xd3\x4d\xaa\xcb\xa3\x3a\x21\x39\xd0\x0a\xd8\x5a\x93\x45\xa8\x60\x51\xe7\x30\x71\x62\x00\x56\xb9\x20\xe2\x19\x00\x58\x55\xa2\x13\xa0\xf2\x38\x97\xcd\xcd\x73\x1b\x45\x25\x7c\x77\x7f\xe9\x08\x20\x2b\xef\xdd\x0b\x58\x38\x6b\x12\x44\xea\x0c\xf5\x39\xa0\x5d\x5d\x10\x32\x9d\xa4\x4e\x13\x03\x0f\xd7\x60\xdc\xd6\x44\xcf\xef\x20\x94\xd1\x91\x0d\x3f\x43\x3e\x1c\x7c\x6d\xd1\x8b\xc1\xf2\xdf\x7f\x64\x3d\x66\x2f\xb9\xdd\x37\xea\xd9\x05\x91\x90\xf4\xfa\x66\xca\x39\xe8\x69\xc4\xeb\x44\x9c\xbd\xc4\x39"+ { message =+ "\x8d\xa8\x9f\xd9\xe5\xf9\x74\xa2\x9f\xef\xfb\x46\x2b\x49\x18\x0f\x6c\xf9\xe8\x02"+ , seed =+ "\xb3\x18\xc4\x2d\xf3\xbe\x0f\x83\xfe\xa8\x23\xf5\xa7\xb4\x7e\xd5\xe4\x25\xa3\xb5"+ , cipherText =+ "\x36\xf6\xe3\x4d\x94\xa8\xd3\x4d\xaa\xcb\xa3\x3a\x21\x39\xd0\x0a\xd8\x5a\x93\x45\xa8\x60\x51\xe7\x30\x71\x62\x00\x56\xb9\x20\xe2\x19\x00\x58\x55\xa2\x13\xa0\xf2\x38\x97\xcd\xcd\x73\x1b\x45\x25\x7c\x77\x7f\xe9\x08\x20\x2b\xef\xdd\x0b\x58\x38\x6b\x12\x44\xea\x0c\xf5\x39\xa0\x5d\x5d\x10\x32\x9d\xa4\x4e\x13\x03\x0f\xd7\x60\xdc\xd6\x44\xcf\xef\x20\x94\xd1\x91\x0d\x3f\x43\x3e\x1c\x7c\x6d\xd1\x8b\xc1\xf2\xdf\x7f\x64\x3d\x66\x2f\xb9\xdd\x37\xea\xd9\x05\x91\x90\xf4\xfa\x66\xca\x39\xe8\x69\xc4\xeb\x44\x9c\xbd\xc4\x39" } , VectorOAEP -- 1.6 { message = "\x26\x52\x10\x50\x84\x42\x71"- , seed = "\xe4\xec\x09\x82\xc2\x33\x6f\x3a\x67\x7f\x6a\x35\x61\x74\xeb\x0c\xe8\x87\xab\xc2"- , cipherText = "\x42\xce\xe2\x61\x7b\x1e\xce\xa4\xdb\x3f\x48\x29\x38\x6f\xbd\x61\xda\xfb\xf0\x38\xe1\x80\xd8\x37\xc9\x63\x66\xdf\x24\xc0\x97\xb4\xab\x0f\xac\x6b\xdf\x59\x0d\x82\x1c\x9f\x10\x64\x2e\x68\x1a\xd0\x5b\x8d\x78\xb3\x78\xc0\xf4\x6c\xe2\xfa\xd6\x3f\x74\xe0\xad\x3d\xf0\x6b\x07\x5d\x7e\xb5\xf5\x63\x6f\x8d\x40\x3b\x90\x59\xca\x76\x1b\x5c\x62\xbb\x52\xaa\x45\x00\x2e\xa7\x0b\xaa\xce\x08\xde\xd2\x43\xb9\xd8\xcb\xd6\x2a\x68\xad\xe2\x65\x83\x2b\x56\x56\x4e\x43\xa6\xfa\x42\xed\x19\x9a\x09\x97\x69\x74\x2d\xf1\x53\x9e\x82\x55"+ , seed =+ "\xe4\xec\x09\x82\xc2\x33\x6f\x3a\x67\x7f\x6a\x35\x61\x74\xeb\x0c\xe8\x87\xab\xc2"+ , cipherText =+ "\x42\xce\xe2\x61\x7b\x1e\xce\xa4\xdb\x3f\x48\x29\x38\x6f\xbd\x61\xda\xfb\xf0\x38\xe1\x80\xd8\x37\xc9\x63\x66\xdf\x24\xc0\x97\xb4\xab\x0f\xac\x6b\xdf\x59\x0d\x82\x1c\x9f\x10\x64\x2e\x68\x1a\xd0\x5b\x8d\x78\xb3\x78\xc0\xf4\x6c\xe2\xfa\xd6\x3f\x74\xe0\xad\x3d\xf0\x6b\x07\x5d\x7e\xb5\xf5\x63\x6f\x8d\x40\x3b\x90\x59\xca\x76\x1b\x5c\x62\xbb\x52\xaa\x45\x00\x2e\xa7\x0b\xaa\xce\x08\xde\xd2\x43\xb9\xd8\xcb\xd6\x2a\x68\xad\xe2\x65\x83\x2b\x56\x56\x4e\x43\xa6\xfa\x42\xed\x19\x9a\x09\x97\x69\x74\x2d\xf1\x53\x9e\x82\x55" } ] doEncryptionTest key i vec = testCase (show i) (Right (cipherText vec) @=? actual)- where actual = OAEP.encryptWithSeed (seed vec) (OAEP.defaultOAEPParams SHA1) key (message vec)+ where+ actual =+ OAEP.encryptWithSeed (seed vec) (OAEP.defaultOAEPParams SHA1) key (message vec) doDecryptionTest key i vec = testCase (show i) (Right (message vec) @=? actual)- where actual = OAEP.decrypt Nothing (OAEP.defaultOAEPParams SHA1) key (cipherText vec)+ 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+oaepTests =+ testGroup+ "RSA-OAEP"+ [ testGroup+ "internal"+ [ doEncryptionTest (private_pub rsaKeyInt) (0 :: Int) vectorInt+ , doDecryptionTest rsaKeyInt (0 :: Int) vectorInt+ ]+ , testGroup "encryption key 1024 bits" $+ zipWith (doEncryptionTest $ private_pub rsaKey1) [katZero ..] vectorsKey1+ , testGroup "decryption key 1024 bits" $+ zipWith (doDecryptionTest rsaKey1) [katZero ..] vectorsKey1 ]- , testGroup "encryption key 1024 bits" $ zipWith (doEncryptionTest $ private_pub rsaKey1) [katZero..] vectorsKey1- , testGroup "decryption key 1024 bits" $ zipWith (doDecryptionTest rsaKey1) [katZero..] vectorsKey1- ]
tests/KAT_PubKey/P256.hs view
@@ -1,37 +1,41 @@-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-}+ module KAT_PubKey.P256 (tests) where -import qualified Crypto.PubKey.ECC.Types as ECC-import qualified Crypto.PubKey.ECC.Prim as ECC import qualified Crypto.PubKey.ECC.P256 as P256+import qualified Crypto.PubKey.ECC.Prim as ECC+import qualified Crypto.PubKey.ECC.Types as ECC -import Data.ByteArray (Bytes)-import Crypto.Number.Serialize (i2ospOf, os2ip)-import Crypto.Number.ModArithmetic (inverseCoprimes)-import Crypto.Error+import Crypto.Error+import Crypto.Number.ModArithmetic (inverseCoprimes)+import Crypto.Number.Serialize (i2ospOf, os2ip)+import Data.ByteArray (Bytes) -import Imports+import Imports newtype P256Scalar = P256Scalar Integer- deriving (Show,Eq,Ord)+ deriving (Show, Eq, Ord) instance Arbitrary P256Scalar where -- Cover the full range up to 2^256-1 except 0 and curveN. To test edge -- cases with arithmetic functions, some values close to 0, curveN and -- 2^256 are given higher frequency.- arbitrary = P256Scalar <$> oneof- [ choose (1, w)- , choose (w + 1, curveN - w - 1)- , choose (curveN - w, curveN - 1)- , choose (curveN + 1, curveN + w)- , choose (curveN + w + 1, high - w - 1)- , choose (high - w, high - 1)- ]- where high = 2^(256 :: Int)- w = 100+ arbitrary =+ P256Scalar+ <$> oneof+ [ choose (1, w)+ , choose (w + 1, curveN - w - 1)+ , choose (curveN - w, curveN - 1)+ , choose (curveN + 1, curveN + w)+ , choose (curveN + w + 1, high - w - 1)+ , choose (high - w, high - 1)+ ]+ where+ high = 2 ^ (256 :: Int)+ w = 100 -curve = ECC.getCurveByName ECC.SEC_p256r1+curve = ECC.getCurveByName ECC.SEC_p256r1 curveN = ECC.ecc_n . ECC.common_curve $ curve curveGen = ECC.ecc_g . ECC.common_curve $ curve @@ -42,14 +46,14 @@ i2ospScalar i = case i2ospOf 32 i of Nothing -> error "invalid size of P256 scalar"- Just b -> b+ Just b -> b unP256Scalar :: P256Scalar -> P256.Scalar unP256Scalar (P256Scalar r) = let rBytes = i2ospScalar r in case P256.scalarFromBinary rBytes of- CryptoFailed err -> error ("cannot convert scalar: " ++ show err)- CryptoPassed scalar -> scalar+ CryptoFailed err -> error ("cannot convert scalar: " ++ show err)+ CryptoPassed scalar -> scalar unP256 :: P256Scalar -> Integer unP256 (P256Scalar r) = r@@ -67,122 +71,131 @@ xR = 0x72b13dd4354b6b81745195e98cc5ba6970349191ac476bd4553cf35a545a067e yR = 0x8d585cbb2e1327d75241a8a122d7620dc33b13315aa5c9d46d013011744ac264 -tests = testGroup "P256"- [ testGroup "scalar"- [ testProperty "marshalling" $ \(QAInteger r) ->- let rBytes = i2ospScalar r- in case P256.scalarFromBinary rBytes of- CryptoFailed err -> error (show err)- CryptoPassed scalar -> rBytes `propertyEq` P256.scalarToBinary scalar- , testProperty "add" $ \r1 r2 ->- let r = (unP256 r1 + unP256 r2) `mod` curveN- r' = P256.scalarAdd (unP256Scalar r1) (unP256Scalar r2)- in r `propertyEq` p256ScalarToInteger r'- , testProperty "add0" $ \r ->- let v = unP256 r `mod` curveN- v' = P256.scalarAdd (unP256Scalar r) P256.scalarZero- in v `propertyEq` p256ScalarToInteger v'- , testProperty "sub" $ \r1 r2 ->- let r = (unP256 r1 - unP256 r2) `mod` curveN- r' = P256.scalarSub (unP256Scalar r1) (unP256Scalar r2)- v = (unP256 r2 - unP256 r1) `mod` curveN- v' = P256.scalarSub (unP256Scalar r2) (unP256Scalar r1)- in propertyHold- [ eqTest "r1-r2" r (p256ScalarToInteger r')- , eqTest "r2-r1" v (p256ScalarToInteger v')- ]- , testProperty "sub0" $ \r ->- let v = unP256 r `mod` curveN- v' = P256.scalarSub (unP256Scalar r) P256.scalarZero- in v `propertyEq` p256ScalarToInteger v'- , testProperty "mul" $ \r1 r2 ->- let r = (unP256 r1 * unP256 r2) `mod` curveN- r' = P256.scalarMul (unP256Scalar r1) (unP256Scalar r2)- in r `propertyEq` p256ScalarToInteger r'- , testProperty "inv" $ \r' ->- let inv = inverseCoprimes (unP256 r') curveN- inv' = P256.scalarInv (unP256Scalar r')- in unP256 r' /= 0 ==> inv `propertyEq` p256ScalarToInteger inv'- , testProperty "inv-safe" $ \r' ->- let inv = P256.scalarInv (unP256Scalar r')- inv' = P256.scalarInvSafe (unP256Scalar r')- in unP256 r' /= 0 ==> inv `propertyEq` inv'- , testProperty "inv-safe-mul" $ \r' ->- let inv = P256.scalarInvSafe (unP256Scalar r')- res = P256.scalarMul (unP256Scalar r') inv- in unP256 r' /= 0 ==> 1 `propertyEq` p256ScalarToInteger res- , testProperty "inv-safe-zero" $- let inv0 = P256.scalarInvSafe P256.scalarZero- invN = P256.scalarInvSafe P256.scalarN- in propertyHold [ eqTest "scalarZero" P256.scalarZero inv0- , eqTest "scalarN" P256.scalarZero invN- ]- ]- , testGroup "point"- [ testProperty "marshalling" $ \rx ry ->- let p = P256.pointFromIntegers (unP256 rx, unP256 ry)- b = P256.pointToBinary p :: Bytes- p' = P256.unsafePointFromBinary b- in propertyHold [ eqTest "point" (CryptoPassed p) p' ]- , testProperty "marshalling-integer" $ \rx ry ->- let p = P256.pointFromIntegers (unP256 rx, unP256 ry)- (x,y) = P256.pointToIntegers p- in propertyHold [ eqTest "x" (unP256 rx) x, eqTest "y" (unP256 ry) y ]- , testCase "valid-point-1" $ casePointIsValid (xS,yS)- , testCase "valid-point-2" $ casePointIsValid (xR,yR)- , testCase "valid-point-3" $ casePointIsValid (xT,yT)- , testCase "point-add-1" $- let s = P256.pointFromIntegers (xS, yS)- t = P256.pointFromIntegers (xT, yT)- r = P256.pointFromIntegers (xR, yR)- in r @=? P256.pointAdd s t- , testProperty "lift-to-curve" propertyLiftToCurve- , testProperty "point-add" propertyPointAdd- , testProperty "point-negate" propertyPointNegate- , testProperty "point-mul" propertyPointMul- , testProperty "infinity" $- let gN = P256.toPoint P256.scalarN- g1 = P256.pointBase- in propertyHold [ eqTest "zero" True (P256.pointIsAtInfinity gN)- , eqTest "base" False (P256.pointIsAtInfinity g1)- ]+tests =+ testGroup+ "P256"+ [ testGroup+ "scalar"+ [ testProperty "marshalling" $ \(QAInteger r) ->+ let rBytes = i2ospScalar r+ in case P256.scalarFromBinary rBytes of+ CryptoFailed err -> error (show err)+ CryptoPassed scalar -> rBytes `propertyEq` P256.scalarToBinary scalar+ , testProperty "add" $ \r1 r2 ->+ let r = (unP256 r1 + unP256 r2) `mod` curveN+ r' = P256.scalarAdd (unP256Scalar r1) (unP256Scalar r2)+ in r `propertyEq` p256ScalarToInteger r'+ , testProperty "add0" $ \r ->+ let v = unP256 r `mod` curveN+ v' = P256.scalarAdd (unP256Scalar r) P256.scalarZero+ in v `propertyEq` p256ScalarToInteger v'+ , testProperty "sub" $ \r1 r2 ->+ let r = (unP256 r1 - unP256 r2) `mod` curveN+ r' = P256.scalarSub (unP256Scalar r1) (unP256Scalar r2)+ v = (unP256 r2 - unP256 r1) `mod` curveN+ v' = P256.scalarSub (unP256Scalar r2) (unP256Scalar r1)+ in propertyHold+ [ eqTest "r1-r2" r (p256ScalarToInteger r')+ , eqTest "r2-r1" v (p256ScalarToInteger v')+ ]+ , testProperty "sub0" $ \r ->+ let v = unP256 r `mod` curveN+ v' = P256.scalarSub (unP256Scalar r) P256.scalarZero+ in v `propertyEq` p256ScalarToInteger v'+ , testProperty "mul" $ \r1 r2 ->+ let r = (unP256 r1 * unP256 r2) `mod` curveN+ r' = P256.scalarMul (unP256Scalar r1) (unP256Scalar r2)+ in r `propertyEq` p256ScalarToInteger r'+ , testProperty "inv" $ \r' ->+ let inv = inverseCoprimes (unP256 r') curveN+ inv' = P256.scalarInv (unP256Scalar r')+ in unP256 r' /= 0 ==> inv `propertyEq` p256ScalarToInteger inv'+ , testProperty "inv-safe" $ \r' ->+ let inv = P256.scalarInv (unP256Scalar r')+ inv' = P256.scalarInvSafe (unP256Scalar r')+ in unP256 r' /= 0 ==> inv `propertyEq` inv'+ , testProperty "inv-safe-mul" $ \r' ->+ let inv = P256.scalarInvSafe (unP256Scalar r')+ res = P256.scalarMul (unP256Scalar r') inv+ in unP256 r' /= 0 ==> 1 `propertyEq` p256ScalarToInteger res+ , testProperty "inv-safe-zero" $+ let inv0 = P256.scalarInvSafe P256.scalarZero+ invN = P256.scalarInvSafe P256.scalarN+ in propertyHold+ [ eqTest "scalarZero" P256.scalarZero inv0+ , eqTest "scalarN" P256.scalarZero invN+ ]+ ]+ , testGroup+ "point"+ [ testProperty "marshalling" $ \rx ry ->+ let p = P256.pointFromIntegers (unP256 rx, unP256 ry)+ b = P256.pointToBinary p :: Bytes+ p' = P256.unsafePointFromBinary b+ in propertyHold [eqTest "point" (CryptoPassed p) p']+ , testProperty "marshalling-integer" $ \rx ry ->+ let p = P256.pointFromIntegers (unP256 rx, unP256 ry)+ (x, y) = P256.pointToIntegers p+ in propertyHold [eqTest "x" (unP256 rx) x, eqTest "y" (unP256 ry) y]+ , testCase "valid-point-1" $ casePointIsValid (xS, yS)+ , testCase "valid-point-2" $ casePointIsValid (xR, yR)+ , testCase "valid-point-3" $ casePointIsValid (xT, yT)+ , testCase "point-add-1" $+ let s = P256.pointFromIntegers (xS, yS)+ t = P256.pointFromIntegers (xT, yT)+ r = P256.pointFromIntegers (xR, yR)+ in r @=? P256.pointAdd s t+ , testProperty "lift-to-curve" propertyLiftToCurve+ , testProperty "point-add" propertyPointAdd+ , testProperty "point-negate" propertyPointNegate+ , testProperty "point-mul" propertyPointMul+ , testProperty "infinity" $+ let gN = P256.toPoint P256.scalarN+ g1 = P256.pointBase+ in propertyHold+ [ eqTest "zero" True (P256.pointIsAtInfinity gN)+ , eqTest "base" False (P256.pointIsAtInfinity g1)+ ]+ ] ]- ] where casePointIsValid pointTuple = let s = P256.pointFromIntegers pointTuple in True @=? P256.pointIsValid s propertyLiftToCurve r =- let p = P256.toPoint (unP256Scalar r)- (x,y) = P256.pointToIntegers p- pEcc = ECC.pointMul curve (unP256 r) curveGen+ let p = P256.toPoint (unP256Scalar r)+ (x, y) = P256.pointToIntegers p+ pEcc = ECC.pointMul curve (unP256 r) curveGen in pEcc `propertyEq` ECC.Point x y propertyPointAdd r1 r2 =- let p1 = P256.toPoint (unP256Scalar r1)- p2 = P256.toPoint (unP256Scalar r2)- pe1 = ECC.pointMul curve (unP256 r1) curveGen- pe2 = ECC.pointMul curve (unP256 r2) curveGen- pR = P256.toPoint (P256.scalarAdd (unP256Scalar r1) (unP256Scalar r2))- peR = ECC.pointAdd curve pe1 pe2- in (unP256 r1 + unP256 r2) `mod` curveN /= 0 ==>- propertyHold [ eqTest "p256" pR (P256.pointAdd p1 p2)- , eqTest "ecc" peR (pointP256ToECC pR)- ]+ let p1 = P256.toPoint (unP256Scalar r1)+ p2 = P256.toPoint (unP256Scalar r2)+ pe1 = ECC.pointMul curve (unP256 r1) curveGen+ pe2 = ECC.pointMul curve (unP256 r2) curveGen+ pR = P256.toPoint (P256.scalarAdd (unP256Scalar r1) (unP256Scalar r2))+ peR = ECC.pointAdd curve pe1 pe2+ in (unP256 r1 + unP256 r2) `mod` curveN+ /= 0+ ==> propertyHold+ [ eqTest "p256" pR (P256.pointAdd p1 p2)+ , eqTest "ecc" peR (pointP256ToECC pR)+ ] propertyPointNegate r =- let p = P256.toPoint (unP256Scalar r)+ let p = P256.toPoint (unP256Scalar r) pe = ECC.pointMul curve (unP256 r) curveGen pR = P256.pointNegate p in ECC.pointNegate curve pe `propertyEq` pointP256ToECC pR propertyPointMul s' r' =- let s = modP256Scalar s'- r = modP256Scalar r'- p = P256.toPoint (unP256Scalar r)- pe = ECC.pointMul curve (unP256 r) curveGen- pR = P256.toPoint (P256.scalarMul (unP256Scalar s) (unP256Scalar r))- peR = ECC.pointMul curve (unP256 s) pe- in propertyHold [ eqTest "p256" pR (P256.pointMul (unP256Scalar s) p)- , eqTest "ecc" peR (pointP256ToECC pR)- ]+ let s = modP256Scalar s'+ r = modP256Scalar r'+ p = P256.toPoint (unP256Scalar r)+ pe = ECC.pointMul curve (unP256 r) curveGen+ pR = P256.toPoint (P256.scalarMul (unP256Scalar s) (unP256Scalar r))+ peR = ECC.pointMul curve (unP256 s) pe+ in propertyHold+ [ eqTest "p256" pR (P256.pointMul (unP256Scalar s) p)+ , eqTest "ecc" peR (pointP256ToECC pR)+ ]
tests/KAT_PubKey/PSS.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_PubKey.PSS (pssTests) where import Crypto.PubKey.RSA@@ -9,146 +10,185 @@ -- Module contains one vector generated by the implementation itself and other -- vectors from <ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1-vec.zip> -data VectorPSS = VectorPSS { message :: ByteString- , salt :: ByteString- , signature :: ByteString- }+data VectorPSS = VectorPSS+ { message :: ByteString+ , salt :: ByteString+ , signature :: ByteString+ } -rsaKeyInt = PrivateKey- { private_pub = PublicKey- { public_n = 0xa2ba40ee07e3b2bd2f02ce227f36a195024486e49c19cb41bbbdfbba98b22b0e577c2eeaffa20d883a76e65e394c69d4b3c05a1e8fadda27edb2a42bc000fe888b9b32c22d15add0cd76b3e7936e19955b220dd17d4ea904b1ec102b2e4de7751222aa99151024c7cb41cc5ea21d00eeb41f7c800834d2c6e06bce3bce7ea9a5- , public_e = 0x010001- , public_size = 128+rsaKeyInt =+ PrivateKey+ { private_pub =+ PublicKey+ { public_n =+ 0xa2ba40ee07e3b2bd2f02ce227f36a195024486e49c19cb41bbbdfbba98b22b0e577c2eeaffa20d883a76e65e394c69d4b3c05a1e8fadda27edb2a42bc000fe888b9b32c22d15add0cd76b3e7936e19955b220dd17d4ea904b1ec102b2e4de7751222aa99151024c7cb41cc5ea21d00eeb41f7c800834d2c6e06bce3bce7ea9a5+ , public_e = 0x010001+ , public_size = 128+ }+ , private_d =+ 0x50e2c3e38d886110288dfc68a9533e7e12e27d2aa56d2cdb3fb6efa990bcff29e1d2987fb711962860e7391b1ce01ebadb9e812d2fbdfaf25df4ae26110a6d7a26f0b810f54875e17dd5c9fb6d641761245b81e79f8c88f0e55a6dcd5f133abd35f8f4ec80adf1bf86277a582894cb6ebcd2162f1c7534f1f4947b129151b71+ , private_p =+ 0xd17f655bf27c8b16d35462c905cc04a26f37e2a67fa9c0ce0dced472394a0df743fe7f929e378efdb368eddff453cf007af6d948e0ade757371f8a711e278f6b+ , private_q =+ 0xc6d92b6fee7414d1358ce1546fb62987530b90bd15e0f14963a5e2635adb69347ec0c01b2ab1763fd8ac1a592fb22757463a982425bb97a3a437c5bf86d03f2f+ , private_dP =+ 0x9d0dbf83e5ce9e4b1754dcd5cd05bcb7b55f1508330ea49f14d4e889550f8256cb5f806dff34b17ada44208853577d08e4262890acf752461cea05547601bc4f+ , private_dQ =+ 0x1291a524c6b7c059e90e46dc83b2171eb3fa98818fd179b6c8bf6cecaa476303abf283fe05769cfc495788fe5b1ddfde9e884a3cd5e936b7e955ebf97eb563b1+ , private_qinv =+ 0xa63f1da38b950c9ad1c67ce0d677ec2914cd7d40062df42a67eb198a176f9742aac7c5fea14f2297662b84812c4defc49a8025ab4382286be4c03788dd01d69f }- , private_d = 0x50e2c3e38d886110288dfc68a9533e7e12e27d2aa56d2cdb3fb6efa990bcff29e1d2987fb711962860e7391b1ce01ebadb9e812d2fbdfaf25df4ae26110a6d7a26f0b810f54875e17dd5c9fb6d641761245b81e79f8c88f0e55a6dcd5f133abd35f8f4ec80adf1bf86277a582894cb6ebcd2162f1c7534f1f4947b129151b71- , private_p = 0xd17f655bf27c8b16d35462c905cc04a26f37e2a67fa9c0ce0dced472394a0df743fe7f929e378efdb368eddff453cf007af6d948e0ade757371f8a711e278f6b- , private_q = 0xc6d92b6fee7414d1358ce1546fb62987530b90bd15e0f14963a5e2635adb69347ec0c01b2ab1763fd8ac1a592fb22757463a982425bb97a3a437c5bf86d03f2f- , private_dP = 0x9d0dbf83e5ce9e4b1754dcd5cd05bcb7b55f1508330ea49f14d4e889550f8256cb5f806dff34b17ada44208853577d08e4262890acf752461cea05547601bc4f- , private_dQ = 0x1291a524c6b7c059e90e46dc83b2171eb3fa98818fd179b6c8bf6cecaa476303abf283fe05769cfc495788fe5b1ddfde9e884a3cd5e936b7e955ebf97eb563b1- , private_qinv = 0xa63f1da38b950c9ad1c67ce0d677ec2914cd7d40062df42a67eb198a176f9742aac7c5fea14f2297662b84812c4defc49a8025ab4382286be4c03788dd01d69f- } -rsaKey1 = PrivateKey- { private_pub = PublicKey- { public_n = 0xa56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137- , public_e = 0x010001- , public_size = 128+rsaKey1 =+ PrivateKey+ { private_pub =+ PublicKey+ { public_n =+ 0xa56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137+ , public_e = 0x010001+ , public_size = 128+ }+ , private_d =+ 0x33a5042a90b27d4f5451ca9bbbd0b44771a101af884340aef9885f2a4bbe92e894a724ac3c568c8f97853ad07c0266c8c6a3ca0929f1e8f11231884429fc4d9ae55fee896a10ce707c3ed7e734e44727a39574501a532683109c2abacaba283c31b4bd2f53c3ee37e352cee34f9e503bd80c0622ad79c6dcee883547c6a3b325+ , private_p =+ 0xe7e8942720a877517273a356053ea2a1bc0c94aa72d55c6e86296b2dfc967948c0a72cbccca7eacb35706e09a1df55a1535bd9b3cc34160b3b6dcd3eda8e6443+ , private_q =+ 0xb69dca1cf7d4d7ec81e75b90fcca874abcde123fd2700180aa90479b6e48de8d67ed24f9f19d85ba275874f542cd20dc723e6963364a1f9425452b269a6799fd+ , private_dP =+ 0x28fa13938655be1f8a159cbaca5a72ea190c30089e19cd274a556f36c4f6e19f554b34c077790427bbdd8dd3ede2448328f385d81b30e8e43b2fffa027861979+ , private_dQ =+ 0x1a8b38f398fa712049898d7fb79ee0a77668791299cdfa09efc0e507acb21ed74301ef5bfd48be455eaeb6e1678255827580a8e4e8e14151d1510a82a3f2e729+ , private_qinv =+ 0x27156aba4126d24a81f3a528cbfb27f56886f840a9f6e86e17a44b94fe9319584b8e22fdde1e5a2e3bd8aa5ba8d8584194eb2190acf832b847f13a3d24a79f4d }- , private_d = 0x33a5042a90b27d4f5451ca9bbbd0b44771a101af884340aef9885f2a4bbe92e894a724ac3c568c8f97853ad07c0266c8c6a3ca0929f1e8f11231884429fc4d9ae55fee896a10ce707c3ed7e734e44727a39574501a532683109c2abacaba283c31b4bd2f53c3ee37e352cee34f9e503bd80c0622ad79c6dcee883547c6a3b325- , private_p = 0xe7e8942720a877517273a356053ea2a1bc0c94aa72d55c6e86296b2dfc967948c0a72cbccca7eacb35706e09a1df55a1535bd9b3cc34160b3b6dcd3eda8e6443- , private_q = 0xb69dca1cf7d4d7ec81e75b90fcca874abcde123fd2700180aa90479b6e48de8d67ed24f9f19d85ba275874f542cd20dc723e6963364a1f9425452b269a6799fd- , private_dP = 0x28fa13938655be1f8a159cbaca5a72ea190c30089e19cd274a556f36c4f6e19f554b34c077790427bbdd8dd3ede2448328f385d81b30e8e43b2fffa027861979- , private_dQ = 0x1a8b38f398fa712049898d7fb79ee0a77668791299cdfa09efc0e507acb21ed74301ef5bfd48be455eaeb6e1678255827580a8e4e8e14151d1510a82a3f2e729- , private_qinv = 0x27156aba4126d24a81f3a528cbfb27f56886f840a9f6e86e17a44b94fe9319584b8e22fdde1e5a2e3bd8aa5ba8d8584194eb2190acf832b847f13a3d24a79f4d- } -vectorInt = VectorPSS- { message = "\x85\x9e\xef\x2f\xd7\x8a\xca\x00\x30\x8b\xdc\x47\x11\x93\xbf\x55\xbf\x9d\x78\xdb\x8f\x8a\x67\x2b\x48\x46\x34\xf3\xc9\xc2\x6e\x64\x78\xae\x10\x26\x0f\xe0\xdd\x8c\x08\x2e\x53\xa5\x29\x3a\xf2\x17\x3c\xd5\x0c\x6d\x5d\x35\x4f\xeb\xf7\x8b\x26\x02\x1c\x25\xc0\x27\x12\xe7\x8c\xd4\x69\x4c\x9f\x46\x97\x77\xe4\x51\xe7\xf8\xe9\xe0\x4c\xd3\x73\x9c\x6b\xbf\xed\xae\x48\x7f\xb5\x56\x44\xe9\xca\x74\xff\x77\xa5\x3c\xb7\x29\x80\x2f\x6e\xd4\xa5\xff\xa8\xba\x15\x98\x90\xfc"- , salt = "\xe3\xb5\xd5\xd0\x02\xc1\xbc\xe5\x0c\x2b\x65\xef\x88\xa1\x88\xd8\x3b\xce\x7e\x61"- , signature = "\x8d\xaa\x62\x7d\x3d\xe7\x59\x5d\x63\x05\x6c\x7e\xc6\x59\xe5\x44\x06\xf1\x06\x10\x12\x8b\xaa\xe8\x21\xc8\xb2\xa0\xf3\x93\x6d\x54\xdc\x3b\xdc\xe4\x66\x89\xf6\xb7\x95\x1b\xb1\x8e\x84\x05\x42\x76\x97\x18\xd5\x71\x5d\x21\x0d\x85\xef\xbb\x59\x61\x92\x03\x2c\x42\xbe\x4c\x29\x97\x2c\x85\x62\x75\xeb\x6d\x5a\x45\xf0\x5f\x51\x87\x6f\xc6\x74\x3d\xed\xdd\x28\xca\xec\x9b\xb3\x0e\xa9\x9e\x02\xc3\x48\x82\x69\x60\x4f\xe4\x97\xf7\x4c\xcd\x7c\x7f\xca\x16\x71\x89\x71\x23\xcb\xd3\x0d\xef\x5d\x54\xa2\xb5\x53\x6a\xd9\x0a\x74\x7e"- }+vectorInt =+ VectorPSS+ { message =+ "\x85\x9e\xef\x2f\xd7\x8a\xca\x00\x30\x8b\xdc\x47\x11\x93\xbf\x55\xbf\x9d\x78\xdb\x8f\x8a\x67\x2b\x48\x46\x34\xf3\xc9\xc2\x6e\x64\x78\xae\x10\x26\x0f\xe0\xdd\x8c\x08\x2e\x53\xa5\x29\x3a\xf2\x17\x3c\xd5\x0c\x6d\x5d\x35\x4f\xeb\xf7\x8b\x26\x02\x1c\x25\xc0\x27\x12\xe7\x8c\xd4\x69\x4c\x9f\x46\x97\x77\xe4\x51\xe7\xf8\xe9\xe0\x4c\xd3\x73\x9c\x6b\xbf\xed\xae\x48\x7f\xb5\x56\x44\xe9\xca\x74\xff\x77\xa5\x3c\xb7\x29\x80\x2f\x6e\xd4\xa5\xff\xa8\xba\x15\x98\x90\xfc"+ , salt =+ "\xe3\xb5\xd5\xd0\x02\xc1\xbc\xe5\x0c\x2b\x65\xef\x88\xa1\x88\xd8\x3b\xce\x7e\x61"+ , signature =+ "\x8d\xaa\x62\x7d\x3d\xe7\x59\x5d\x63\x05\x6c\x7e\xc6\x59\xe5\x44\x06\xf1\x06\x10\x12\x8b\xaa\xe8\x21\xc8\xb2\xa0\xf3\x93\x6d\x54\xdc\x3b\xdc\xe4\x66\x89\xf6\xb7\x95\x1b\xb1\x8e\x84\x05\x42\x76\x97\x18\xd5\x71\x5d\x21\x0d\x85\xef\xbb\x59\x61\x92\x03\x2c\x42\xbe\x4c\x29\x97\x2c\x85\x62\x75\xeb\x6d\x5a\x45\xf0\x5f\x51\x87\x6f\xc6\x74\x3d\xed\xdd\x28\xca\xec\x9b\xb3\x0e\xa9\x9e\x02\xc3\x48\x82\x69\x60\x4f\xe4\x97\xf7\x4c\xcd\x7c\x7f\xca\x16\x71\x89\x71\x23\xcb\xd3\x0d\xef\x5d\x54\xa2\xb5\x53\x6a\xd9\x0a\x74\x7e"+ } {- # mHash = Hash(M) # salt = random string of octets # M' = Padding || mHash || salt # H = Hash(M')-# DB = Padding || salt +# DB = Padding || salt # dbMask = MGF(H, length(DB)) # maskedDB = DB xor dbMask (leftmost bit set to # zero) # EM = maskedDB || H || 0xbc # mHash:-37 b6 6a e0 44 58 43 35 3d 47 ec b0 b4 fd 14 c1 -10 e6 2d 6a +37 b6 6a e0 44 58 43 35 3d 47 ec b0 b4 fd 14 c1+10 e6 2d 6a # salt: # M':-00 00 00 00 00 00 00 00 37 b6 6a e0 44 58 43 35 -3d 47 ec b0 b4 fd 14 c1 10 e6 2d 6a e3 b5 d5 d0 -02 c1 bc e5 0c 2b 65 ef 88 a1 88 d8 3b ce 7e 61 +00 00 00 00 00 00 00 00 37 b6 6a e0 44 58 43 35+3d 47 ec b0 b4 fd 14 c1 10 e6 2d 6a e3 b5 d5 d0+02 c1 bc e5 0c 2b 65 ef 88 a1 88 d8 3b ce 7e 61 # H:-df 1a 89 6f 9d 8b c8 16 d9 7c d7 a2 c4 3b ad 54 -6f be 8c fe +df 1a 89 6f 9d 8b c8 16 d9 7c d7 a2 c4 3b ad 54+6f be 8c fe # DB:-00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -00 00 00 00 00 00 01 e3 b5 d5 d0 02 c1 bc e5 0c -2b 65 ef 88 a1 88 d8 3b ce 7e 61 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00+00 00 00 00 00 00 01 e3 b5 d5 d0 02 c1 bc e5 0c+2b 65 ef 88 a1 88 d8 3b ce 7e 61 # dbMask:-66 e4 67 2e 83 6a d1 21 ba 24 4b ed 65 76 b8 67 -d9 a4 47 c2 8a 6e 66 a5 b8 7d ee 7f bc 7e 65 af -50 57 f8 6f ae 89 84 d9 ba 7f 96 9a d6 fe 02 a4 -d7 5f 74 45 fe fd d8 5b 6d 3a 47 7c 28 d2 4b a1 -e3 75 6f 79 2d d1 dc e8 ca 94 44 0e cb 52 79 ec -d3 18 3a 31 1f c8 97 39 a9 66 43 13 6e 8b 0f 46 -5e 87 a4 53 5c d4 c5 9b 10 02 8d +66 e4 67 2e 83 6a d1 21 ba 24 4b ed 65 76 b8 67+d9 a4 47 c2 8a 6e 66 a5 b8 7d ee 7f bc 7e 65 af+50 57 f8 6f ae 89 84 d9 ba 7f 96 9a d6 fe 02 a4+d7 5f 74 45 fe fd d8 5b 6d 3a 47 7c 28 d2 4b a1+e3 75 6f 79 2d d1 dc e8 ca 94 44 0e cb 52 79 ec+d3 18 3a 31 1f c8 97 39 a9 66 43 13 6e 8b 0f 46+5e 87 a4 53 5c d4 c5 9b 10 02 8d # maskedDB:-66 e4 67 2e 83 6a d1 21 ba 24 4b ed 65 76 b8 67 -d9 a4 47 c2 8a 6e 66 a5 b8 7d ee 7f bc 7e 65 af -50 57 f8 6f ae 89 84 d9 ba 7f 96 9a d6 fe 02 a4 -d7 5f 74 45 fe fd d8 5b 6d 3a 47 7c 28 d2 4b a1 -e3 75 6f 79 2d d1 dc e8 ca 94 44 0e cb 52 79 ec -d3 18 3a 31 1f c8 96 da 1c b3 93 11 af 37 ea 4a -75 e2 4b db fd 5c 1d a0 de 7c ec +66 e4 67 2e 83 6a d1 21 ba 24 4b ed 65 76 b8 67+d9 a4 47 c2 8a 6e 66 a5 b8 7d ee 7f bc 7e 65 af+50 57 f8 6f ae 89 84 d9 ba 7f 96 9a d6 fe 02 a4+d7 5f 74 45 fe fd d8 5b 6d 3a 47 7c 28 d2 4b a1+e3 75 6f 79 2d d1 dc e8 ca 94 44 0e cb 52 79 ec+d3 18 3a 31 1f c8 96 da 1c b3 93 11 af 37 ea 4a+75 e2 4b db fd 5c 1d a0 de 7c ec # Encoded message EM:-66 e4 67 2e 83 6a d1 21 ba 24 4b ed 65 76 b8 67 -d9 a4 47 c2 8a 6e 66 a5 b8 7d ee 7f bc 7e 65 af -50 57 f8 6f ae 89 84 d9 ba 7f 96 9a d6 fe 02 a4 -d7 5f 74 45 fe fd d8 5b 6d 3a 47 7c 28 d2 4b a1 -e3 75 6f 79 2d d1 dc e8 ca 94 44 0e cb 52 79 ec -d3 18 3a 31 1f c8 96 da 1c b3 93 11 af 37 ea 4a -75 e2 4b db fd 5c 1d a0 de 7c ec df 1a 89 6f 9d -8b c8 16 d9 7c d7 a2 c4 3b ad 54 6f be 8c fe bc +66 e4 67 2e 83 6a d1 21 ba 24 4b ed 65 76 b8 67+d9 a4 47 c2 8a 6e 66 a5 b8 7d ee 7f bc 7e 65 af+50 57 f8 6f ae 89 84 d9 ba 7f 96 9a d6 fe 02 a4+d7 5f 74 45 fe fd d8 5b 6d 3a 47 7c 28 d2 4b a1+e3 75 6f 79 2d d1 dc e8 ca 94 44 0e cb 52 79 ec+d3 18 3a 31 1f c8 96 da 1c b3 93 11 af 37 ea 4a+75 e2 4b db fd 5c 1d a0 de 7c ec df 1a 89 6f 9d+8b c8 16 d9 7c d7 a2 c4 3b ad 54 6f be 8c fe bc -} vectorsKey1 =- [- -- Example 1.1+ [ -- Example 1.1 VectorPSS- { message = "\xcd\xc8\x7d\xa2\x23\xd7\x86\xdf\x3b\x45\xe0\xbb\xbc\x72\x13\x26\xd1\xee\x2a\xf8\x06\xcc\x31\x54\x75\xcc\x6f\x0d\x9c\x66\xe1\xb6\x23\x71\xd4\x5c\xe2\x39\x2e\x1a\xc9\x28\x44\xc3\x10\x10\x2f\x15\x6a\x0d\x8d\x52\xc1\xf4\xc4\x0b\xa3\xaa\x65\x09\x57\x86\xcb\x76\x97\x57\xa6\x56\x3b\xa9\x58\xfe\xd0\xbc\xc9\x84\xe8\xb5\x17\xa3\xd5\xf5\x15\xb2\x3b\x8a\x41\xe7\x4a\xa8\x67\x69\x3f\x90\xdf\xb0\x61\xa6\xe8\x6d\xfa\xae\xe6\x44\x72\xc0\x0e\x5f\x20\x94\x57\x29\xcb\xeb\xe7\x7f\x06\xce\x78\xe0\x8f\x40\x98\xfb\xa4\x1f\x9d\x61\x93\xc0\x31\x7e\x8b\x60\xd4\xb6\x08\x4a\xcb\x42\xd2\x9e\x38\x08\xa3\xbc\x37\x2d\x85\xe3\x31\x17\x0f\xcb\xf7\xcc\x72\xd0\xb7\x1c\x29\x66\x48\xb3\xa4\xd1\x0f\x41\x62\x95\xd0\x80\x7a\xa6\x25\xca\xb2\x74\x4f\xd9\xea\x8f\xd2\x23\xc4\x25\x37\x02\x98\x28\xbd\x16\xbe\x02\x54\x6f\x13\x0f\xd2\xe3\x3b\x93\x6d\x26\x76\xe0\x8a\xed\x1b\x73\x31\x8b\x75\x0a\x01\x67\xd0"- , salt = "\xde\xe9\x59\xc7\xe0\x64\x11\x36\x14\x20\xff\x80\x18\x5e\xd5\x7f\x3e\x67\x76\xaf"- , signature = "\x90\x74\x30\x8f\xb5\x98\xe9\x70\x1b\x22\x94\x38\x8e\x52\xf9\x71\xfa\xac\x2b\x60\xa5\x14\x5a\xf1\x85\xdf\x52\x87\xb5\xed\x28\x87\xe5\x7c\xe7\xfd\x44\xdc\x86\x34\xe4\x07\xc8\xe0\xe4\x36\x0b\xc2\x26\xf3\xec\x22\x7f\x9d\x9e\x54\x63\x8e\x8d\x31\xf5\x05\x12\x15\xdf\x6e\xbb\x9c\x2f\x95\x79\xaa\x77\x59\x8a\x38\xf9\x14\xb5\xb9\xc1\xbd\x83\xc4\xe2\xf9\xf3\x82\xa0\xd0\xaa\x35\x42\xff\xee\x65\x98\x4a\x60\x1b\xc6\x9e\xb2\x8d\xeb\x27\xdc\xa1\x2c\x82\xc2\xd4\xc3\xf6\x6c\xd5\x00\xf1\xff\x2b\x99\x4d\x8a\x4e\x30\xcb\xb3\x3c"+ { message =+ "\xcd\xc8\x7d\xa2\x23\xd7\x86\xdf\x3b\x45\xe0\xbb\xbc\x72\x13\x26\xd1\xee\x2a\xf8\x06\xcc\x31\x54\x75\xcc\x6f\x0d\x9c\x66\xe1\xb6\x23\x71\xd4\x5c\xe2\x39\x2e\x1a\xc9\x28\x44\xc3\x10\x10\x2f\x15\x6a\x0d\x8d\x52\xc1\xf4\xc4\x0b\xa3\xaa\x65\x09\x57\x86\xcb\x76\x97\x57\xa6\x56\x3b\xa9\x58\xfe\xd0\xbc\xc9\x84\xe8\xb5\x17\xa3\xd5\xf5\x15\xb2\x3b\x8a\x41\xe7\x4a\xa8\x67\x69\x3f\x90\xdf\xb0\x61\xa6\xe8\x6d\xfa\xae\xe6\x44\x72\xc0\x0e\x5f\x20\x94\x57\x29\xcb\xeb\xe7\x7f\x06\xce\x78\xe0\x8f\x40\x98\xfb\xa4\x1f\x9d\x61\x93\xc0\x31\x7e\x8b\x60\xd4\xb6\x08\x4a\xcb\x42\xd2\x9e\x38\x08\xa3\xbc\x37\x2d\x85\xe3\x31\x17\x0f\xcb\xf7\xcc\x72\xd0\xb7\x1c\x29\x66\x48\xb3\xa4\xd1\x0f\x41\x62\x95\xd0\x80\x7a\xa6\x25\xca\xb2\x74\x4f\xd9\xea\x8f\xd2\x23\xc4\x25\x37\x02\x98\x28\xbd\x16\xbe\x02\x54\x6f\x13\x0f\xd2\xe3\x3b\x93\x6d\x26\x76\xe0\x8a\xed\x1b\x73\x31\x8b\x75\x0a\x01\x67\xd0"+ , salt =+ "\xde\xe9\x59\xc7\xe0\x64\x11\x36\x14\x20\xff\x80\x18\x5e\xd5\x7f\x3e\x67\x76\xaf"+ , signature =+ "\x90\x74\x30\x8f\xb5\x98\xe9\x70\x1b\x22\x94\x38\x8e\x52\xf9\x71\xfa\xac\x2b\x60\xa5\x14\x5a\xf1\x85\xdf\x52\x87\xb5\xed\x28\x87\xe5\x7c\xe7\xfd\x44\xdc\x86\x34\xe4\x07\xc8\xe0\xe4\x36\x0b\xc2\x26\xf3\xec\x22\x7f\x9d\x9e\x54\x63\x8e\x8d\x31\xf5\x05\x12\x15\xdf\x6e\xbb\x9c\x2f\x95\x79\xaa\x77\x59\x8a\x38\xf9\x14\xb5\xb9\xc1\xbd\x83\xc4\xe2\xf9\xf3\x82\xa0\xd0\xaa\x35\x42\xff\xee\x65\x98\x4a\x60\x1b\xc6\x9e\xb2\x8d\xeb\x27\xdc\xa1\x2c\x82\xc2\xd4\xc3\xf6\x6c\xd5\x00\xf1\xff\x2b\x99\x4d\x8a\x4e\x30\xcb\xb3\x3c" }- -- Example 1.2- , VectorPSS- { message = "\x85\x13\x84\xcd\xfe\x81\x9c\x22\xed\x6c\x4c\xcb\x30\xda\xeb\x5c\xf0\x59\xbc\x8e\x11\x66\xb7\xe3\x53\x0c\x4c\x23\x3e\x2b\x5f\x8f\x71\xa1\xcc\xa5\x82\xd4\x3e\xcc\x72\xb1\xbc\xa1\x6d\xfc\x70\x13\x22\x6b\x9e"- , salt = "\xef\x28\x69\xfa\x40\xc3\x46\xcb\x18\x3d\xab\x3d\x7b\xff\xc9\x8f\xd5\x6d\xf4\x2d"- , signature = "\x3e\xf7\xf4\x6e\x83\x1b\xf9\x2b\x32\x27\x41\x42\xa5\x85\xff\xce\xfb\xdc\xa7\xb3\x2a\xe9\x0d\x10\xfb\x0f\x0c\x72\x99\x84\xf0\x4e\xf2\x9a\x9d\xf0\x78\x07\x75\xce\x43\x73\x9b\x97\x83\x83\x90\xdb\x0a\x55\x05\xe6\x3d\xe9\x27\x02\x8d\x9d\x29\xb2\x19\xca\x2c\x45\x17\x83\x25\x58\xa5\x5d\x69\x4a\x6d\x25\xb9\xda\xb6\x60\x03\xc4\xcc\xcd\x90\x78\x02\x19\x3b\xe5\x17\x0d\x26\x14\x7d\x37\xb9\x35\x90\x24\x1b\xe5\x1c\x25\x05\x5f\x47\xef\x62\x75\x2c\xfb\xe2\x14\x18\xfa\xfe\x98\xc2\x2c\x4d\x4d\x47\x72\x4f\xdb\x56\x69\xe8\x43"+ , -- Example 1.2+ VectorPSS+ { message =+ "\x85\x13\x84\xcd\xfe\x81\x9c\x22\xed\x6c\x4c\xcb\x30\xda\xeb\x5c\xf0\x59\xbc\x8e\x11\x66\xb7\xe3\x53\x0c\x4c\x23\x3e\x2b\x5f\x8f\x71\xa1\xcc\xa5\x82\xd4\x3e\xcc\x72\xb1\xbc\xa1\x6d\xfc\x70\x13\x22\x6b\x9e"+ , salt =+ "\xef\x28\x69\xfa\x40\xc3\x46\xcb\x18\x3d\xab\x3d\x7b\xff\xc9\x8f\xd5\x6d\xf4\x2d"+ , signature =+ "\x3e\xf7\xf4\x6e\x83\x1b\xf9\x2b\x32\x27\x41\x42\xa5\x85\xff\xce\xfb\xdc\xa7\xb3\x2a\xe9\x0d\x10\xfb\x0f\x0c\x72\x99\x84\xf0\x4e\xf2\x9a\x9d\xf0\x78\x07\x75\xce\x43\x73\x9b\x97\x83\x83\x90\xdb\x0a\x55\x05\xe6\x3d\xe9\x27\x02\x8d\x9d\x29\xb2\x19\xca\x2c\x45\x17\x83\x25\x58\xa5\x5d\x69\x4a\x6d\x25\xb9\xda\xb6\x60\x03\xc4\xcc\xcd\x90\x78\x02\x19\x3b\xe5\x17\x0d\x26\x14\x7d\x37\xb9\x35\x90\x24\x1b\xe5\x1c\x25\x05\x5f\x47\xef\x62\x75\x2c\xfb\xe2\x14\x18\xfa\xfe\x98\xc2\x2c\x4d\x4d\x47\x72\x4f\xdb\x56\x69\xe8\x43" }- -- Example 1.3- , VectorPSS- { message = "\xa4\xb1\x59\x94\x17\x61\xc4\x0c\x6a\x82\xf2\xb8\x0d\x1b\x94\xf5\xaa\x26\x54\xfd\x17\xe1\x2d\x58\x88\x64\x67\x9b\x54\xcd\x04\xef\x8b\xd0\x30\x12\xbe\x8d\xc3\x7f\x4b\x83\xaf\x79\x63\xfa\xff\x0d\xfa\x22\x54\x77\x43\x7c\x48\x01\x7f\xf2\xbe\x81\x91\xcf\x39\x55\xfc\x07\x35\x6e\xab\x3f\x32\x2f\x7f\x62\x0e\x21\xd2\x54\xe5\xdb\x43\x24\x27\x9f\xe0\x67\xe0\x91\x0e\x2e\x81\xca\x2c\xab\x31\xc7\x45\xe6\x7a\x54\x05\x8e\xb5\x0d\x99\x3c\xdb\x9e\xd0\xb4\xd0\x29\xc0\x6d\x21\xa9\x4c\xa6\x61\xc3\xce\x27\xfa\xe1\xd6\xcb\x20\xf4\x56\x4d\x66\xce\x47\x67\x58\x3d\x0e\x5f\x06\x02\x15\xb5\x90\x17\xbe\x85\xea\x84\x89\x39\x12\x7b\xd8\xc9\xc4\xd4\x7b\x51\x05\x6c\x03\x1c\xf3\x36\xf1\x7c\x99\x80\xf3\xb8\xf5\xb9\xb6\x87\x8e\x8b\x79\x7a\xa4\x3b\x88\x26\x84\x33\x3e\x17\x89\x3f\xe9\xca\xa6\xaa\x29\x9f\x7e\xd1\xa1\x8e\xe2\xc5\x48\x64\xb7\xb2\xb9\x9b\x72\x61\x8f\xb0\x25\x74\xd1\x39\xef\x50\xf0\x19\xc9\xee\xf4\x16\x97\x13\x38\xe7\xd4\x70"- , salt = "\x71\x0b\x9c\x47\x47\xd8\x00\xd4\xde\x87\xf1\x2a\xfd\xce\x6d\xf1\x81\x07\xcc\x77"- , signature = "\x66\x60\x26\xfb\xa7\x1b\xd3\xe7\xcf\x13\x15\x7c\xc2\xc5\x1a\x8e\x4a\xa6\x84\xaf\x97\x78\xf9\x18\x49\xf3\x43\x35\xd1\x41\xc0\x01\x54\xc4\x19\x76\x21\xf9\x62\x4a\x67\x5b\x5a\xbc\x22\xee\x7d\x5b\xaa\xff\xaa\xe1\xc9\xba\xca\x2c\xc3\x73\xb3\xf3\x3e\x78\xe6\x14\x3c\x39\x5a\x91\xaa\x7f\xac\xa6\x64\xeb\x73\x3a\xfd\x14\xd8\x82\x72\x59\xd9\x9a\x75\x50\xfa\xca\x50\x1e\xf2\xb0\x4e\x33\xc2\x3a\xa5\x1f\x4b\x9e\x82\x82\xef\xdb\x72\x8c\xc0\xab\x09\x40\x5a\x91\x60\x7c\x63\x69\x96\x1b\xc8\x27\x0d\x2d\x4f\x39\xfc\xe6\x12\xb1"+ , -- Example 1.3+ VectorPSS+ { message =+ "\xa4\xb1\x59\x94\x17\x61\xc4\x0c\x6a\x82\xf2\xb8\x0d\x1b\x94\xf5\xaa\x26\x54\xfd\x17\xe1\x2d\x58\x88\x64\x67\x9b\x54\xcd\x04\xef\x8b\xd0\x30\x12\xbe\x8d\xc3\x7f\x4b\x83\xaf\x79\x63\xfa\xff\x0d\xfa\x22\x54\x77\x43\x7c\x48\x01\x7f\xf2\xbe\x81\x91\xcf\x39\x55\xfc\x07\x35\x6e\xab\x3f\x32\x2f\x7f\x62\x0e\x21\xd2\x54\xe5\xdb\x43\x24\x27\x9f\xe0\x67\xe0\x91\x0e\x2e\x81\xca\x2c\xab\x31\xc7\x45\xe6\x7a\x54\x05\x8e\xb5\x0d\x99\x3c\xdb\x9e\xd0\xb4\xd0\x29\xc0\x6d\x21\xa9\x4c\xa6\x61\xc3\xce\x27\xfa\xe1\xd6\xcb\x20\xf4\x56\x4d\x66\xce\x47\x67\x58\x3d\x0e\x5f\x06\x02\x15\xb5\x90\x17\xbe\x85\xea\x84\x89\x39\x12\x7b\xd8\xc9\xc4\xd4\x7b\x51\x05\x6c\x03\x1c\xf3\x36\xf1\x7c\x99\x80\xf3\xb8\xf5\xb9\xb6\x87\x8e\x8b\x79\x7a\xa4\x3b\x88\x26\x84\x33\x3e\x17\x89\x3f\xe9\xca\xa6\xaa\x29\x9f\x7e\xd1\xa1\x8e\xe2\xc5\x48\x64\xb7\xb2\xb9\x9b\x72\x61\x8f\xb0\x25\x74\xd1\x39\xef\x50\xf0\x19\xc9\xee\xf4\x16\x97\x13\x38\xe7\xd4\x70"+ , salt =+ "\x71\x0b\x9c\x47\x47\xd8\x00\xd4\xde\x87\xf1\x2a\xfd\xce\x6d\xf1\x81\x07\xcc\x77"+ , signature =+ "\x66\x60\x26\xfb\xa7\x1b\xd3\xe7\xcf\x13\x15\x7c\xc2\xc5\x1a\x8e\x4a\xa6\x84\xaf\x97\x78\xf9\x18\x49\xf3\x43\x35\xd1\x41\xc0\x01\x54\xc4\x19\x76\x21\xf9\x62\x4a\x67\x5b\x5a\xbc\x22\xee\x7d\x5b\xaa\xff\xaa\xe1\xc9\xba\xca\x2c\xc3\x73\xb3\xf3\x3e\x78\xe6\x14\x3c\x39\x5a\x91\xaa\x7f\xac\xa6\x64\xeb\x73\x3a\xfd\x14\xd8\x82\x72\x59\xd9\x9a\x75\x50\xfa\xca\x50\x1e\xf2\xb0\x4e\x33\xc2\x3a\xa5\x1f\x4b\x9e\x82\x82\xef\xdb\x72\x8c\xc0\xab\x09\x40\x5a\x91\x60\x7c\x63\x69\x96\x1b\xc8\x27\x0d\x2d\x4f\x39\xfc\xe6\x12\xb1" }- -- Example 1.4- , VectorPSS+ , -- Example 1.4+ VectorPSS { message = "\xbc\x65\x67\x47\xfa\x9e\xaf\xb3\xf0"- , salt = "\x05\x6f\x00\x98\x5d\xe1\x4d\x8e\xf5\xce\xa9\xe8\x2f\x8c\x27\xbe\xf7\x20\x33\x5e"- , signature = "\x46\x09\x79\x3b\x23\xe9\xd0\x93\x62\xdc\x21\xbb\x47\xda\x0b\x4f\x3a\x76\x22\x64\x9a\x47\xd4\x64\x01\x9b\x9a\xea\xfe\x53\x35\x9c\x17\x8c\x91\xcd\x58\xba\x6b\xcb\x78\xbe\x03\x46\xa7\xbc\x63\x7f\x4b\x87\x3d\x4b\xab\x38\xee\x66\x1f\x19\x96\x34\xc5\x47\xa1\xad\x84\x42\xe0\x3d\xa0\x15\xb1\x36\xe5\x43\xf7\xab\x07\xc0\xc1\x3e\x42\x25\xb8\xde\x8c\xce\x25\xd4\xf6\xeb\x84\x00\xf8\x1f\x7e\x18\x33\xb7\xee\x6e\x33\x4d\x37\x09\x64\xca\x79\xfd\xb8\x72\xb4\xd7\x52\x23\xb5\xee\xb0\x81\x01\x59\x1f\xb5\x32\xd1\x55\xa6\xde\x87"+ , salt =+ "\x05\x6f\x00\x98\x5d\xe1\x4d\x8e\xf5\xce\xa9\xe8\x2f\x8c\x27\xbe\xf7\x20\x33\x5e"+ , signature =+ "\x46\x09\x79\x3b\x23\xe9\xd0\x93\x62\xdc\x21\xbb\x47\xda\x0b\x4f\x3a\x76\x22\x64\x9a\x47\xd4\x64\x01\x9b\x9a\xea\xfe\x53\x35\x9c\x17\x8c\x91\xcd\x58\xba\x6b\xcb\x78\xbe\x03\x46\xa7\xbc\x63\x7f\x4b\x87\x3d\x4b\xab\x38\xee\x66\x1f\x19\x96\x34\xc5\x47\xa1\xad\x84\x42\xe0\x3d\xa0\x15\xb1\x36\xe5\x43\xf7\xab\x07\xc0\xc1\x3e\x42\x25\xb8\xde\x8c\xce\x25\xd4\xf6\xeb\x84\x00\xf8\x1f\x7e\x18\x33\xb7\xee\x6e\x33\x4d\x37\x09\x64\xca\x79\xfd\xb8\x72\xb4\xd7\x52\x23\xb5\xee\xb0\x81\x01\x59\x1f\xb5\x32\xd1\x55\xa6\xde\x87" }- -- Example 1.5- , VectorPSS- { message = "\xb4\x55\x81\x54\x7e\x54\x27\x77\x0c\x76\x8e\x8b\x82\xb7\x55\x64\xe0\xea\x4e\x9c\x32\x59\x4d\x6b\xff\x70\x65\x44\xde\x0a\x87\x76\xc7\xa8\x0b\x45\x76\x55\x0e\xee\x1b\x2a\xca\xbc\x7e\x8b\x7d\x3e\xf7\xbb\x5b\x03\xe4\x62\xc1\x10\x47\xea\xdd\x00\x62\x9a\xe5\x75\x48\x0a\xc1\x47\x0f\xe0\x46\xf1\x3a\x2b\xf5\xaf\x17\x92\x1d\xc4\xb0\xaa\x8b\x02\xbe\xe6\x33\x49\x11\x65\x1d\x7f\x85\x25\xd1\x0f\x32\xb5\x1d\x33\xbe\x52\x0d\x3d\xdf\x5a\x70\x99\x55\xa3\xdf\xe7\x82\x83\xb9\xe0\xab\x54\x04\x6d\x15\x0c\x17\x7f\x03\x7f\xdc\xcc\x5b\xe4\xea\x5f\x68\xb5\xe5\xa3\x8c\x9d\x7e\xdc\xcc\xc4\x97\x5f\x45\x5a\x69\x09\xb4"- , salt = "\x80\xe7\x0f\xf8\x6a\x08\xde\x3e\xc6\x09\x72\xb3\x9b\x4f\xbf\xdc\xea\x67\xae\x8e"- , signature = "\x1d\x2a\xad\x22\x1c\xa4\xd3\x1d\xdf\x13\x50\x92\x39\x01\x93\x98\xe3\xd1\x4b\x32\xdc\x34\xdc\x5a\xf4\xae\xae\xa3\xc0\x95\xaf\x73\x47\x9c\xf0\xa4\x5e\x56\x29\x63\x5a\x53\xa0\x18\x37\x76\x15\xb1\x6c\xb9\xb1\x3b\x3e\x09\xd6\x71\xeb\x71\xe3\x87\xb8\x54\x5c\x59\x60\xda\x5a\x64\x77\x6e\x76\x8e\x82\xb2\xc9\x35\x83\xbf\x10\x4c\x3f\xdb\x23\x51\x2b\x7b\x4e\x89\xf6\x33\xdd\x00\x63\xa5\x30\xdb\x45\x24\xb0\x1c\x3f\x38\x4c\x09\x31\x0e\x31\x5a\x79\xdc\xd3\xd6\x84\x02\x2a\x7f\x31\xc8\x65\xa6\x64\xe3\x16\x97\x8b\x75\x9f\xad"+ , -- Example 1.5+ VectorPSS+ { message =+ "\xb4\x55\x81\x54\x7e\x54\x27\x77\x0c\x76\x8e\x8b\x82\xb7\x55\x64\xe0\xea\x4e\x9c\x32\x59\x4d\x6b\xff\x70\x65\x44\xde\x0a\x87\x76\xc7\xa8\x0b\x45\x76\x55\x0e\xee\x1b\x2a\xca\xbc\x7e\x8b\x7d\x3e\xf7\xbb\x5b\x03\xe4\x62\xc1\x10\x47\xea\xdd\x00\x62\x9a\xe5\x75\x48\x0a\xc1\x47\x0f\xe0\x46\xf1\x3a\x2b\xf5\xaf\x17\x92\x1d\xc4\xb0\xaa\x8b\x02\xbe\xe6\x33\x49\x11\x65\x1d\x7f\x85\x25\xd1\x0f\x32\xb5\x1d\x33\xbe\x52\x0d\x3d\xdf\x5a\x70\x99\x55\xa3\xdf\xe7\x82\x83\xb9\xe0\xab\x54\x04\x6d\x15\x0c\x17\x7f\x03\x7f\xdc\xcc\x5b\xe4\xea\x5f\x68\xb5\xe5\xa3\x8c\x9d\x7e\xdc\xcc\xc4\x97\x5f\x45\x5a\x69\x09\xb4"+ , salt =+ "\x80\xe7\x0f\xf8\x6a\x08\xde\x3e\xc6\x09\x72\xb3\x9b\x4f\xbf\xdc\xea\x67\xae\x8e"+ , signature =+ "\x1d\x2a\xad\x22\x1c\xa4\xd3\x1d\xdf\x13\x50\x92\x39\x01\x93\x98\xe3\xd1\x4b\x32\xdc\x34\xdc\x5a\xf4\xae\xae\xa3\xc0\x95\xaf\x73\x47\x9c\xf0\xa4\x5e\x56\x29\x63\x5a\x53\xa0\x18\x37\x76\x15\xb1\x6c\xb9\xb1\x3b\x3e\x09\xd6\x71\xeb\x71\xe3\x87\xb8\x54\x5c\x59\x60\xda\x5a\x64\x77\x6e\x76\x8e\x82\xb2\xc9\x35\x83\xbf\x10\x4c\x3f\xdb\x23\x51\x2b\x7b\x4e\x89\xf6\x33\xdd\x00\x63\xa5\x30\xdb\x45\x24\xb0\x1c\x3f\x38\x4c\x09\x31\x0e\x31\x5a\x79\xdc\xd3\xd6\x84\x02\x2a\x7f\x31\xc8\x65\xa6\x64\xe3\x16\x97\x8b\x75\x9f\xad" }- -- Example 1.6- , VectorPSS- { message = "\x10\xaa\xe9\xa0\xab\x0b\x59\x5d\x08\x41\x20\x7b\x70\x0d\x48\xd7\x5f\xae\xdd\xe3\xb7\x75\xcd\x6b\x4c\xc8\x8a\xe0\x6e\x46\x94\xec\x74\xba\x18\xf8\x52\x0d\x4f\x5e\xa6\x9c\xbb\xe7\xcc\x2b\xeb\xa4\x3e\xfd\xc1\x02\x15\xac\x4e\xb3\x2d\xc3\x02\xa1\xf5\x3d\xc6\xc4\x35\x22\x67\xe7\x93\x6c\xfe\xbf\x7c\x8d\x67\x03\x57\x84\xa3\x90\x9f\xa8\x59\xc7\xb7\xb5\x9b\x8e\x39\xc5\xc2\x34\x9f\x18\x86\xb7\x05\xa3\x02\x67\xd4\x02\xf7\x48\x6a\xb4\xf5\x8c\xad\x5d\x69\xad\xb1\x7a\xb8\xcd\x0c\xe1\xca\xf5\x02\x5a\xf4\xae\x24\xb1\xfb\x87\x94\xc6\x07\x0c\xc0\x9a\x51\xe2\xf9\x91\x13\x11\xe3\x87\x7d\x00\x44\xc7\x1c\x57\xa9\x93\x39\x50\x08\x80\x6b\x72\x3a\xc3\x83\x73\xd3\x95\x48\x18\x18\x52\x8c\x1e\x70\x53\x73\x92\x82\x05\x35\x29\x51\x0e\x93\x5c\xd0\xfa\x77\xb8\xfa\x53\xcc\x2d\x47\x4b\xd4\xfb\x3c\xc5\xc6\x72\xd6\xff\xdc\x90\xa0\x0f\x98\x48\x71\x2c\x4b\xcf\xe4\x6c\x60\x57\x36\x59\xb1\x1e\x64\x57\xe8\x61\xf0\xf6\x04\xb6\x13\x8d\x14\x4f\x8c\xe4\xe2\xda\x73"- , salt = "\xa8\xab\x69\xdd\x80\x1f\x00\x74\xc2\xa1\xfc\x60\x64\x98\x36\xc6\x16\xd9\x96\x81"- , signature = "\x2a\x34\xf6\x12\x5e\x1f\x6b\x0b\xf9\x71\xe8\x4f\xbd\x41\xc6\x32\xbe\x8f\x2c\x2a\xce\x7d\xe8\xb6\x92\x6e\x31\xff\x93\xe9\xaf\x98\x7f\xbc\x06\xe5\x1e\x9b\xe1\x4f\x51\x98\xf9\x1f\x3f\x95\x3b\xd6\x7d\xa6\x0a\x9d\xf5\x97\x64\xc3\xdc\x0f\xe0\x8e\x1c\xbe\xf0\xb7\x5f\x86\x8d\x10\xad\x3f\xba\x74\x9f\xef\x59\xfb\x6d\xac\x46\xa0\xd6\xe5\x04\x36\x93\x31\x58\x6f\x58\xe4\x62\x8f\x39\xaa\x27\x89\x82\x54\x3b\xc0\xee\xb5\x37\xdc\x61\x95\x80\x19\xb3\x94\xfb\x27\x3f\x21\x58\x58\xa0\xa0\x1a\xc4\xd6\x50\xb9\x55\xc6\x7f\x4c\x58"+ , -- Example 1.6+ VectorPSS+ { message =+ "\x10\xaa\xe9\xa0\xab\x0b\x59\x5d\x08\x41\x20\x7b\x70\x0d\x48\xd7\x5f\xae\xdd\xe3\xb7\x75\xcd\x6b\x4c\xc8\x8a\xe0\x6e\x46\x94\xec\x74\xba\x18\xf8\x52\x0d\x4f\x5e\xa6\x9c\xbb\xe7\xcc\x2b\xeb\xa4\x3e\xfd\xc1\x02\x15\xac\x4e\xb3\x2d\xc3\x02\xa1\xf5\x3d\xc6\xc4\x35\x22\x67\xe7\x93\x6c\xfe\xbf\x7c\x8d\x67\x03\x57\x84\xa3\x90\x9f\xa8\x59\xc7\xb7\xb5\x9b\x8e\x39\xc5\xc2\x34\x9f\x18\x86\xb7\x05\xa3\x02\x67\xd4\x02\xf7\x48\x6a\xb4\xf5\x8c\xad\x5d\x69\xad\xb1\x7a\xb8\xcd\x0c\xe1\xca\xf5\x02\x5a\xf4\xae\x24\xb1\xfb\x87\x94\xc6\x07\x0c\xc0\x9a\x51\xe2\xf9\x91\x13\x11\xe3\x87\x7d\x00\x44\xc7\x1c\x57\xa9\x93\x39\x50\x08\x80\x6b\x72\x3a\xc3\x83\x73\xd3\x95\x48\x18\x18\x52\x8c\x1e\x70\x53\x73\x92\x82\x05\x35\x29\x51\x0e\x93\x5c\xd0\xfa\x77\xb8\xfa\x53\xcc\x2d\x47\x4b\xd4\xfb\x3c\xc5\xc6\x72\xd6\xff\xdc\x90\xa0\x0f\x98\x48\x71\x2c\x4b\xcf\xe4\x6c\x60\x57\x36\x59\xb1\x1e\x64\x57\xe8\x61\xf0\xf6\x04\xb6\x13\x8d\x14\x4f\x8c\xe4\xe2\xda\x73"+ , salt =+ "\xa8\xab\x69\xdd\x80\x1f\x00\x74\xc2\xa1\xfc\x60\x64\x98\x36\xc6\x16\xd9\x96\x81"+ , signature =+ "\x2a\x34\xf6\x12\x5e\x1f\x6b\x0b\xf9\x71\xe8\x4f\xbd\x41\xc6\x32\xbe\x8f\x2c\x2a\xce\x7d\xe8\xb6\x92\x6e\x31\xff\x93\xe9\xaf\x98\x7f\xbc\x06\xe5\x1e\x9b\xe1\x4f\x51\x98\xf9\x1f\x3f\x95\x3b\xd6\x7d\xa6\x0a\x9d\xf5\x97\x64\xc3\xdc\x0f\xe0\x8e\x1c\xbe\xf0\xb7\x5f\x86\x8d\x10\xad\x3f\xba\x74\x9f\xef\x59\xfb\x6d\xac\x46\xa0\xd6\xe5\x04\x36\x93\x31\x58\x6f\x58\xe4\x62\x8f\x39\xaa\x27\x89\x82\x54\x3b\xc0\xee\xb5\x37\xdc\x61\x95\x80\x19\xb3\x94\xfb\x27\x3f\x21\x58\x58\xa0\xa0\x1a\xc4\xd6\x50\xb9\x55\xc6\x7f\x4c\x58" } ] @@ -156,57 +196,83 @@ -- Example 2: A 1025-bit RSA Key Pair -- ================================== -rsaKey2 = PrivateKey- { private_pub = PublicKey- { public_n = 0x01d40c1bcf97a68ae7cdbd8a7bf3e34fa19dcca4ef75a47454375f94514d88fed006fb829f8419ff87d6315da68a1ff3a0938e9abb3464011c303ad99199cf0c7c7a8b477dce829e8844f625b115e5e9c4a59cf8f8113b6834336a2fd2689b472cbb5e5cabe674350c59b6c17e176874fb42f8fc3d176a017edc61fd326c4b33c9- , public_e = 0x010001- , public_size = 129+rsaKey2 =+ PrivateKey+ { private_pub =+ PublicKey+ { public_n =+ 0x01d40c1bcf97a68ae7cdbd8a7bf3e34fa19dcca4ef75a47454375f94514d88fed006fb829f8419ff87d6315da68a1ff3a0938e9abb3464011c303ad99199cf0c7c7a8b477dce829e8844f625b115e5e9c4a59cf8f8113b6834336a2fd2689b472cbb5e5cabe674350c59b6c17e176874fb42f8fc3d176a017edc61fd326c4b33c9+ , public_e = 0x010001+ , public_size = 129+ }+ , private_d =+ 0x027d147e4673057377fd1ea201565772176a7dc38358d376045685a2e787c23c15576bc16b9f444402d6bfc5d98a3e88ea13ef67c353eca0c0ddba9255bd7b8bb50a644afdfd1dd51695b252d22e7318d1b6687a1c10ff75545f3db0fe602d5f2b7f294e3601eab7b9d1cecd767f64692e3e536ca2846cb0c2dd486a39fa75b1+ , private_p =+ 0x016601e926a0f8c9e26ecab769ea65a5e7c52cc9e080ef519457c644da6891c5a104d3ea7955929a22e7c68a7af9fcad777c3ccc2b9e3d3650bce404399b7e59d1+ , private_q =+ 0x014eafa1d4d0184da7e31f877d1281ddda625664869e8379e67ad3b75eae74a580e9827abd6eb7a002cb5411f5266797768fb8e95ae40e3e8a01f35ff89e56c079+ , private_dP =+ 0xe247cce504939b8f0a36090de200938755e2444b29539a7da7a902f6056835c0db7b52559497cfe2c61a8086d0213c472c78851800b171f6401de2e9c2756f31+ , private_dQ =+ 0xb12fba757855e586e46f64c38a70c68b3f548d93d787b399999d4c8f0bbd2581c21e19ed0018a6d5d3df86424b3abcad40199d31495b61309f27c1bf55d487c1+ , private_qinv =+ 0x564b1e1fa003bda91e89090425aac05b91da9ee25061e7628d5f51304a84992fdc33762bd378a59f030a334d532bd0dae8f298ea9ed844636ad5fb8cbdc03cad }- , private_d = 0x027d147e4673057377fd1ea201565772176a7dc38358d376045685a2e787c23c15576bc16b9f444402d6bfc5d98a3e88ea13ef67c353eca0c0ddba9255bd7b8bb50a644afdfd1dd51695b252d22e7318d1b6687a1c10ff75545f3db0fe602d5f2b7f294e3601eab7b9d1cecd767f64692e3e536ca2846cb0c2dd486a39fa75b1- , private_p = 0x016601e926a0f8c9e26ecab769ea65a5e7c52cc9e080ef519457c644da6891c5a104d3ea7955929a22e7c68a7af9fcad777c3ccc2b9e3d3650bce404399b7e59d1- , private_q = 0x014eafa1d4d0184da7e31f877d1281ddda625664869e8379e67ad3b75eae74a580e9827abd6eb7a002cb5411f5266797768fb8e95ae40e3e8a01f35ff89e56c079- , private_dP = 0xe247cce504939b8f0a36090de200938755e2444b29539a7da7a902f6056835c0db7b52559497cfe2c61a8086d0213c472c78851800b171f6401de2e9c2756f31- , private_dQ = 0xb12fba757855e586e46f64c38a70c68b3f548d93d787b399999d4c8f0bbd2581c21e19ed0018a6d5d3df86424b3abcad40199d31495b61309f27c1bf55d487c1- , private_qinv = 0x564b1e1fa003bda91e89090425aac05b91da9ee25061e7628d5f51304a84992fdc33762bd378a59f030a334d532bd0dae8f298ea9ed844636ad5fb8cbdc03cad- } vectorsKey2 =- [- -- Example 2.1+ [ -- Example 2.1 VectorPSS- { message = "\xda\xba\x03\x20\x66\x26\x3f\xae\xdb\x65\x98\x48\x11\x52\x78\xa5\x2c\x44\xfa\xa3\xa7\x6f\x37\x51\x5e\xd3\x36\x32\x10\x72\xc4\x0a\x9d\x9b\x53\xbc\x05\x01\x40\x78\xad\xf5\x20\x87\x51\x46\xaa\xe7\x0f\xf0\x60\x22\x6d\xcb\x7b\x1f\x1f\xc2\x7e\x93\x60"- , salt = "\x57\xbf\x16\x0b\xcb\x02\xbb\x1d\xc7\x28\x0c\xf0\x45\x85\x30\xb7\xd2\x83\x2f\xf7"- , signature = "\x01\x4c\x5b\xa5\x33\x83\x28\xcc\xc6\xe7\xa9\x0b\xf1\xc0\xab\x3f\xd6\x06\xff\x47\x96\xd3\xc1\x2e\x4b\x63\x9e\xd9\x13\x6a\x5f\xec\x6c\x16\xd8\x88\x4b\xdd\x99\xcf\xdc\x52\x14\x56\xb0\x74\x2b\x73\x68\x68\xcf\x90\xde\x09\x9a\xdb\x8d\x5f\xfd\x1d\xef\xf3\x9b\xa4\x00\x7a\xb7\x46\xce\xfd\xb2\x2d\x7d\xf0\xe2\x25\xf5\x46\x27\xdc\x65\x46\x61\x31\x72\x1b\x90\xaf\x44\x53\x63\xa8\x35\x8b\x9f\x60\x76\x42\xf7\x8f\xab\x0a\xb0\xf4\x3b\x71\x68\xd6\x4b\xae\x70\xd8\x82\x78\x48\xd8\xef\x1e\x42\x1c\x57\x54\xdd\xf4\x2c\x25\x89\xb5\xb3"+ { message =+ "\xda\xba\x03\x20\x66\x26\x3f\xae\xdb\x65\x98\x48\x11\x52\x78\xa5\x2c\x44\xfa\xa3\xa7\x6f\x37\x51\x5e\xd3\x36\x32\x10\x72\xc4\x0a\x9d\x9b\x53\xbc\x05\x01\x40\x78\xad\xf5\x20\x87\x51\x46\xaa\xe7\x0f\xf0\x60\x22\x6d\xcb\x7b\x1f\x1f\xc2\x7e\x93\x60"+ , salt =+ "\x57\xbf\x16\x0b\xcb\x02\xbb\x1d\xc7\x28\x0c\xf0\x45\x85\x30\xb7\xd2\x83\x2f\xf7"+ , signature =+ "\x01\x4c\x5b\xa5\x33\x83\x28\xcc\xc6\xe7\xa9\x0b\xf1\xc0\xab\x3f\xd6\x06\xff\x47\x96\xd3\xc1\x2e\x4b\x63\x9e\xd9\x13\x6a\x5f\xec\x6c\x16\xd8\x88\x4b\xdd\x99\xcf\xdc\x52\x14\x56\xb0\x74\x2b\x73\x68\x68\xcf\x90\xde\x09\x9a\xdb\x8d\x5f\xfd\x1d\xef\xf3\x9b\xa4\x00\x7a\xb7\x46\xce\xfd\xb2\x2d\x7d\xf0\xe2\x25\xf5\x46\x27\xdc\x65\x46\x61\x31\x72\x1b\x90\xaf\x44\x53\x63\xa8\x35\x8b\x9f\x60\x76\x42\xf7\x8f\xab\x0a\xb0\xf4\x3b\x71\x68\xd6\x4b\xae\x70\xd8\x82\x78\x48\xd8\xef\x1e\x42\x1c\x57\x54\xdd\xf4\x2c\x25\x89\xb5\xb3" }- -- Example 2.2- , VectorPSS- { message = "\xe4\xf8\x60\x1a\x8a\x6d\xa1\xbe\x34\x44\x7c\x09\x59\xc0\x58\x57\x0c\x36\x68\xcf\xd5\x1d\xd5\xf9\xcc\xd6\xad\x44\x11\xfe\x82\x13\x48\x6d\x78\xa6\xc4\x9f\x93\xef\xc2\xca\x22\x88\xce\xbc\x2b\x9b\x60\xbd\x04\xb1\xe2\x20\xd8\x6e\x3d\x48\x48\xd7\x09\xd0\x32\xd1\xe8\xc6\xa0\x70\xc6\xaf\x9a\x49\x9f\xcf\x95\x35\x4b\x14\xba\x61\x27\xc7\x39\xde\x1b\xb0\xfd\x16\x43\x1e\x46\x93\x8a\xec\x0c\xf8\xad\x9e\xb7\x2e\x83\x2a\x70\x35\xde\x9b\x78\x07\xbd\xc0\xed\x8b\x68\xeb\x0f\x5a\xc2\x21\x6b\xe4\x0c\xe9\x20\xc0\xdb\x0e\xdd\xd3\x86\x0e\xd7\x88\xef\xac\xca\xca\x50\x2d\x8f\x2b\xd6\xd1\xa7\xc1\xf4\x1f\xf4\x6f\x16\x81\xc8\xf1\xf8\x18\xe9\xc4\xf6\xd9\x1a\x0c\x78\x03\xcc\xc6\x3d\x76\xa6\x54\x4d\x84\x3e\x08\x4e\x36\x3b\x8a\xcc\x55\xaa\x53\x17\x33\xed\xb5\xde\xe5\xb5\x19\x6e\x9f\x03\xe8\xb7\x31\xb3\x77\x64\x28\xd9\xe4\x57\xfe\x3f\xbc\xb3\xdb\x72\x74\x44\x2d\x78\x58\x90\xe9\xcb\x08\x54\xb6\x44\x4d\xac\xe7\x91\xd7\x27\x3d\xe1\x88\x97\x19\x33\x8a\x77\xfe"- , salt = "\x7f\x6d\xd3\x59\xe6\x04\xe6\x08\x70\xe8\x98\xe4\x7b\x19\xbf\x2e\x5a\x7b\x2a\x90"- , signature = "\x01\x09\x91\x65\x6c\xca\x18\x2b\x7f\x29\xd2\xdb\xc0\x07\xe7\xae\x0f\xec\x15\x8e\xb6\x75\x9c\xb9\xc4\x5c\x5f\xf8\x7c\x76\x35\xdd\x46\xd1\x50\x88\x2f\x4d\xe1\xe9\xae\x65\xe7\xf7\xd9\x01\x8f\x68\x36\x95\x4a\x47\xc0\xa8\x1a\x8a\x6b\x6f\x83\xf2\x94\x4d\x60\x81\xb1\xaa\x7c\x75\x9b\x25\x4b\x2c\x34\xb6\x91\xda\x67\xcc\x02\x26\xe2\x0b\x2f\x18\xb4\x22\x12\x76\x1d\xcd\x4b\x90\x8a\x62\xb3\x71\xb5\x91\x8c\x57\x42\xaf\x4b\x53\x7e\x29\x69\x17\x67\x4f\xb9\x14\x19\x47\x61\x62\x1c\xc1\x9a\x41\xf6\xfb\x95\x3f\xbc\xbb\x64\x9d\xea"+ , -- Example 2.2+ VectorPSS+ { message =+ "\xe4\xf8\x60\x1a\x8a\x6d\xa1\xbe\x34\x44\x7c\x09\x59\xc0\x58\x57\x0c\x36\x68\xcf\xd5\x1d\xd5\xf9\xcc\xd6\xad\x44\x11\xfe\x82\x13\x48\x6d\x78\xa6\xc4\x9f\x93\xef\xc2\xca\x22\x88\xce\xbc\x2b\x9b\x60\xbd\x04\xb1\xe2\x20\xd8\x6e\x3d\x48\x48\xd7\x09\xd0\x32\xd1\xe8\xc6\xa0\x70\xc6\xaf\x9a\x49\x9f\xcf\x95\x35\x4b\x14\xba\x61\x27\xc7\x39\xde\x1b\xb0\xfd\x16\x43\x1e\x46\x93\x8a\xec\x0c\xf8\xad\x9e\xb7\x2e\x83\x2a\x70\x35\xde\x9b\x78\x07\xbd\xc0\xed\x8b\x68\xeb\x0f\x5a\xc2\x21\x6b\xe4\x0c\xe9\x20\xc0\xdb\x0e\xdd\xd3\x86\x0e\xd7\x88\xef\xac\xca\xca\x50\x2d\x8f\x2b\xd6\xd1\xa7\xc1\xf4\x1f\xf4\x6f\x16\x81\xc8\xf1\xf8\x18\xe9\xc4\xf6\xd9\x1a\x0c\x78\x03\xcc\xc6\x3d\x76\xa6\x54\x4d\x84\x3e\x08\x4e\x36\x3b\x8a\xcc\x55\xaa\x53\x17\x33\xed\xb5\xde\xe5\xb5\x19\x6e\x9f\x03\xe8\xb7\x31\xb3\x77\x64\x28\xd9\xe4\x57\xfe\x3f\xbc\xb3\xdb\x72\x74\x44\x2d\x78\x58\x90\xe9\xcb\x08\x54\xb6\x44\x4d\xac\xe7\x91\xd7\x27\x3d\xe1\x88\x97\x19\x33\x8a\x77\xfe"+ , salt =+ "\x7f\x6d\xd3\x59\xe6\x04\xe6\x08\x70\xe8\x98\xe4\x7b\x19\xbf\x2e\x5a\x7b\x2a\x90"+ , signature =+ "\x01\x09\x91\x65\x6c\xca\x18\x2b\x7f\x29\xd2\xdb\xc0\x07\xe7\xae\x0f\xec\x15\x8e\xb6\x75\x9c\xb9\xc4\x5c\x5f\xf8\x7c\x76\x35\xdd\x46\xd1\x50\x88\x2f\x4d\xe1\xe9\xae\x65\xe7\xf7\xd9\x01\x8f\x68\x36\x95\x4a\x47\xc0\xa8\x1a\x8a\x6b\x6f\x83\xf2\x94\x4d\x60\x81\xb1\xaa\x7c\x75\x9b\x25\x4b\x2c\x34\xb6\x91\xda\x67\xcc\x02\x26\xe2\x0b\x2f\x18\xb4\x22\x12\x76\x1d\xcd\x4b\x90\x8a\x62\xb3\x71\xb5\x91\x8c\x57\x42\xaf\x4b\x53\x7e\x29\x69\x17\x67\x4f\xb9\x14\x19\x47\x61\x62\x1c\xc1\x9a\x41\xf6\xfb\x95\x3f\xbc\xbb\x64\x9d\xea" }- -- Example 2.3- , VectorPSS- { message = "\x52\xa1\xd9\x6c\x8a\xc3\x9e\x41\xe4\x55\x80\x98\x01\xb9\x27\xa5\xb4\x45\xc1\x0d\x90\x2a\x0d\xcd\x38\x50\xd2\x2a\x66\xd2\xbb\x07\x03\xe6\x7d\x58\x67\x11\x45\x95\xaa\xbf\x5a\x7a\xeb\x5a\x8f\x87\x03\x4b\xbb\x30\xe1\x3c\xfd\x48\x17\xa9\xbe\x76\x23\x00\x23\x60\x6d\x02\x86\xa3\xfa\xf8\xa4\xd2\x2b\x72\x8e\xc5\x18\x07\x9f\x9e\x64\x52\x6e\x3a\x0c\xc7\x94\x1a\xa3\x38\xc4\x37\x99\x7c\x68\x0c\xca\xc6\x7c\x66\xbf\xa1"- , salt = "\xfc\xa8\x62\x06\x8b\xce\x22\x46\x72\x4b\x70\x8a\x05\x19\xda\x17\xe6\x48\x68\x8c"- , signature = "\x00\x7f\x00\x30\x01\x8f\x53\xcd\xc7\x1f\x23\xd0\x36\x59\xfd\xe5\x4d\x42\x41\xf7\x58\xa7\x50\xb4\x2f\x18\x5f\x87\x57\x85\x20\xc3\x07\x42\xaf\xd8\x43\x59\xb6\xe6\xe8\xd3\xed\x95\x9d\xc6\xfe\x48\x6b\xed\xc8\xe2\xcf\x00\x1f\x63\xa7\xab\xe1\x62\x56\xa1\xb8\x4d\xf0\xd2\x49\xfc\x05\xd3\x19\x4c\xe5\xf0\x91\x27\x42\xdb\xbf\x80\xdd\x17\x4f\x6c\x51\xf6\xba\xd7\xf1\x6c\xf3\x36\x4e\xba\x09\x5a\x06\x26\x7d\xc3\x79\x38\x03\xac\x75\x26\xae\xbe\x0a\x47\x5d\x38\xb8\xc2\x24\x7a\xb5\x1c\x48\x98\xdf\x70\x47\xdc\x6a\xdf\x52\xc6\xc4"+ , -- Example 2.3+ VectorPSS+ { message =+ "\x52\xa1\xd9\x6c\x8a\xc3\x9e\x41\xe4\x55\x80\x98\x01\xb9\x27\xa5\xb4\x45\xc1\x0d\x90\x2a\x0d\xcd\x38\x50\xd2\x2a\x66\xd2\xbb\x07\x03\xe6\x7d\x58\x67\x11\x45\x95\xaa\xbf\x5a\x7a\xeb\x5a\x8f\x87\x03\x4b\xbb\x30\xe1\x3c\xfd\x48\x17\xa9\xbe\x76\x23\x00\x23\x60\x6d\x02\x86\xa3\xfa\xf8\xa4\xd2\x2b\x72\x8e\xc5\x18\x07\x9f\x9e\x64\x52\x6e\x3a\x0c\xc7\x94\x1a\xa3\x38\xc4\x37\x99\x7c\x68\x0c\xca\xc6\x7c\x66\xbf\xa1"+ , salt =+ "\xfc\xa8\x62\x06\x8b\xce\x22\x46\x72\x4b\x70\x8a\x05\x19\xda\x17\xe6\x48\x68\x8c"+ , signature =+ "\x00\x7f\x00\x30\x01\x8f\x53\xcd\xc7\x1f\x23\xd0\x36\x59\xfd\xe5\x4d\x42\x41\xf7\x58\xa7\x50\xb4\x2f\x18\x5f\x87\x57\x85\x20\xc3\x07\x42\xaf\xd8\x43\x59\xb6\xe6\xe8\xd3\xed\x95\x9d\xc6\xfe\x48\x6b\xed\xc8\xe2\xcf\x00\x1f\x63\xa7\xab\xe1\x62\x56\xa1\xb8\x4d\xf0\xd2\x49\xfc\x05\xd3\x19\x4c\xe5\xf0\x91\x27\x42\xdb\xbf\x80\xdd\x17\x4f\x6c\x51\xf6\xba\xd7\xf1\x6c\xf3\x36\x4e\xba\x09\x5a\x06\x26\x7d\xc3\x79\x38\x03\xac\x75\x26\xae\xbe\x0a\x47\x5d\x38\xb8\xc2\x24\x7a\xb5\x1c\x48\x98\xdf\x70\x47\xdc\x6a\xdf\x52\xc6\xc4" }- -- Example 2.4- , VectorPSS- { message = "\xa7\x18\x2c\x83\xac\x18\xbe\x65\x70\xa1\x06\xaa\x9d\x5c\x4e\x3d\xbb\xd4\xaf\xae\xb0\xc6\x0c\x4a\x23\xe1\x96\x9d\x79\xff"- , salt = "\x80\x70\xef\x2d\xe9\x45\xc0\x23\x87\x68\x4b\xa0\xd3\x30\x96\x73\x22\x35\xd4\x40"- , signature = "\x00\x9c\xd2\xf4\xed\xbe\x23\xe1\x23\x46\xae\x8c\x76\xdd\x9a\xd3\x23\x0a\x62\x07\x61\x41\xf1\x6c\x15\x2b\xa1\x85\x13\xa4\x8e\xf6\xf0\x10\xe0\xe3\x7f\xd3\xdf\x10\xa1\xec\x62\x9a\x0c\xb5\xa3\xb5\xd2\x89\x30\x07\x29\x8c\x30\x93\x6a\x95\x90\x3b\x6b\xa8\x55\x55\xd9\xec\x36\x73\xa0\x61\x08\xfd\x62\xa2\xfd\xa5\x6d\x1c\xe2\xe8\x5c\x4d\xb6\xb2\x4a\x81\xca\x3b\x49\x6c\x36\xd4\xfd\x06\xeb\x7c\x91\x66\xd8\xe9\x48\x77\xc4\x2b\xea\x62\x2b\x3b\xfe\x92\x51\xfd\xc2\x1d\x8d\x53\x71\xba\xda\xd7\x8a\x48\x82\x14\x79\x63\x35\xb4\x0b"+ , -- Example 2.4+ VectorPSS+ { message =+ "\xa7\x18\x2c\x83\xac\x18\xbe\x65\x70\xa1\x06\xaa\x9d\x5c\x4e\x3d\xbb\xd4\xaf\xae\xb0\xc6\x0c\x4a\x23\xe1\x96\x9d\x79\xff"+ , salt =+ "\x80\x70\xef\x2d\xe9\x45\xc0\x23\x87\x68\x4b\xa0\xd3\x30\x96\x73\x22\x35\xd4\x40"+ , signature =+ "\x00\x9c\xd2\xf4\xed\xbe\x23\xe1\x23\x46\xae\x8c\x76\xdd\x9a\xd3\x23\x0a\x62\x07\x61\x41\xf1\x6c\x15\x2b\xa1\x85\x13\xa4\x8e\xf6\xf0\x10\xe0\xe3\x7f\xd3\xdf\x10\xa1\xec\x62\x9a\x0c\xb5\xa3\xb5\xd2\x89\x30\x07\x29\x8c\x30\x93\x6a\x95\x90\x3b\x6b\xa8\x55\x55\xd9\xec\x36\x73\xa0\x61\x08\xfd\x62\xa2\xfd\xa5\x6d\x1c\xe2\xe8\x5c\x4d\xb6\xb2\x4a\x81\xca\x3b\x49\x6c\x36\xd4\xfd\x06\xeb\x7c\x91\x66\xd8\xe9\x48\x77\xc4\x2b\xea\x62\x2b\x3b\xfe\x92\x51\xfd\xc2\x1d\x8d\x53\x71\xba\xda\xd7\x8a\x48\x82\x14\x79\x63\x35\xb4\x0b" }- -- Example 2.5- , VectorPSS- { message = "\x86\xa8\x3d\x4a\x72\xee\x93\x2a\x4f\x56\x30\xaf\x65\x79\xa3\x86\xb7\x8f\xe8\x89\x99\xe0\xab\xd2\xd4\x90\x34\xa4\xbf\xc8\x54\xdd\x94\xf1\x09\x4e\x2e\x8c\xd7\xa1\x79\xd1\x95\x88\xe4\xae\xfc\x1b\x1b\xd2\x5e\x95\xe3\xdd\x46\x1f"- , salt = "\x17\x63\x9a\x4e\x88\xd7\x22\xc4\xfc\xa2\x4d\x07\x9a\x8b\x29\xc3\x24\x33\xb0\xc9"- , signature = "\x00\xec\x43\x08\x24\x93\x1e\xbd\x3b\xaa\x43\x03\x4d\xae\x98\xba\x64\x6b\x8c\x36\x01\x3d\x16\x71\xc3\xcf\x1c\xf8\x26\x0c\x37\x4b\x19\xf8\xe1\xcc\x8d\x96\x50\x12\x40\x5e\x7e\x9b\xf7\x37\x86\x12\xdf\xcc\x85\xfc\xe1\x2c\xda\x11\xf9\x50\xbd\x0b\xa8\x87\x67\x40\x43\x6c\x1d\x25\x95\xa6\x4a\x1b\x32\xef\xcf\xb7\x4a\x21\xc8\x73\xb3\xcc\x33\xaa\xf4\xe3\xdc\x39\x53\xde\x67\xf0\x67\x4c\x04\x53\xb4\xfd\x9f\x60\x44\x06\xd4\x41\xb8\x16\x09\x8c\xb1\x06\xfe\x34\x72\xbc\x25\x1f\x81\x5f\x59\xdb\x2e\x43\x78\xa3\xad\xdc\x18\x1e\xcf"+ , -- Example 2.5+ VectorPSS+ { message =+ "\x86\xa8\x3d\x4a\x72\xee\x93\x2a\x4f\x56\x30\xaf\x65\x79\xa3\x86\xb7\x8f\xe8\x89\x99\xe0\xab\xd2\xd4\x90\x34\xa4\xbf\xc8\x54\xdd\x94\xf1\x09\x4e\x2e\x8c\xd7\xa1\x79\xd1\x95\x88\xe4\xae\xfc\x1b\x1b\xd2\x5e\x95\xe3\xdd\x46\x1f"+ , salt =+ "\x17\x63\x9a\x4e\x88\xd7\x22\xc4\xfc\xa2\x4d\x07\x9a\x8b\x29\xc3\x24\x33\xb0\xc9"+ , signature =+ "\x00\xec\x43\x08\x24\x93\x1e\xbd\x3b\xaa\x43\x03\x4d\xae\x98\xba\x64\x6b\x8c\x36\x01\x3d\x16\x71\xc3\xcf\x1c\xf8\x26\x0c\x37\x4b\x19\xf8\xe1\xcc\x8d\x96\x50\x12\x40\x5e\x7e\x9b\xf7\x37\x86\x12\xdf\xcc\x85\xfc\xe1\x2c\xda\x11\xf9\x50\xbd\x0b\xa8\x87\x67\x40\x43\x6c\x1d\x25\x95\xa6\x4a\x1b\x32\xef\xcf\xb7\x4a\x21\xc8\x73\xb3\xcc\x33\xaa\xf4\xe3\xdc\x39\x53\xde\x67\xf0\x67\x4c\x04\x53\xb4\xfd\x9f\x60\x44\x06\xd4\x41\xb8\x16\x09\x8c\xb1\x06\xfe\x34\x72\xbc\x25\x1f\x81\x5f\x59\xdb\x2e\x43\x78\xa3\xad\xdc\x18\x1e\xcf" }- -- Example 2.6- , VectorPSS- { message = "\x04\x9f\x91\x54\xd8\x71\xac\x4a\x7c\x7a\xb4\x53\x25\xba\x75\x45\xa1\xed\x08\xf7\x05\x25\xb2\x66\x7c\xf1"- , salt = "\x37\x81\x0d\xef\x10\x55\xed\x92\x2b\x06\x3d\xf7\x98\xde\x5d\x0a\xab\xf8\x86\xee"- , signature = "\x00\x47\x5b\x16\x48\xf8\x14\xa8\xdc\x0a\xbd\xc3\x7b\x55\x27\xf5\x43\xb6\x66\xbb\x6e\x39\xd3\x0e\x5b\x49\xd3\xb8\x76\xdc\xcc\x58\xea\xc1\x4e\x32\xa2\xd5\x5c\x26\x16\x01\x44\x56\xad\x2f\x24\x6f\xc8\xe3\xd5\x60\xda\x3d\xdf\x37\x9a\x1c\x0b\xd2\x00\xf1\x02\x21\xdf\x07\x8c\x21\x9a\x15\x1b\xc8\xd4\xec\x9d\x2f\xc2\x56\x44\x67\x81\x10\x14\xef\x15\xd8\xea\x01\xc2\xeb\xbf\xf8\xc2\xc8\xef\xab\x38\x09\x6e\x55\xfc\xbe\x32\x85\xc7\xaa\x55\x88\x51\x25\x4f\xaf\xfa\x92\xc1\xc7\x2b\x78\x75\x86\x63\xef\x45\x82\x84\x31\x39\xd7\xa6"+ , -- Example 2.6+ VectorPSS+ { message =+ "\x04\x9f\x91\x54\xd8\x71\xac\x4a\x7c\x7a\xb4\x53\x25\xba\x75\x45\xa1\xed\x08\xf7\x05\x25\xb2\x66\x7c\xf1"+ , salt =+ "\x37\x81\x0d\xef\x10\x55\xed\x92\x2b\x06\x3d\xf7\x98\xde\x5d\x0a\xab\xf8\x86\xee"+ , signature =+ "\x00\x47\x5b\x16\x48\xf8\x14\xa8\xdc\x0a\xbd\xc3\x7b\x55\x27\xf5\x43\xb6\x66\xbb\x6e\x39\xd3\x0e\x5b\x49\xd3\xb8\x76\xdc\xcc\x58\xea\xc1\x4e\x32\xa2\xd5\x5c\x26\x16\x01\x44\x56\xad\x2f\x24\x6f\xc8\xe3\xd5\x60\xda\x3d\xdf\x37\x9a\x1c\x0b\xd2\x00\xf1\x02\x21\xdf\x07\x8c\x21\x9a\x15\x1b\xc8\xd4\xec\x9d\x2f\xc2\x56\x44\x67\x81\x10\x14\xef\x15\xd8\xea\x01\xc2\xeb\xbf\xf8\xc2\xc8\xef\xab\x38\x09\x6e\x55\xfc\xbe\x32\x85\xc7\xaa\x55\x88\x51\x25\x4f\xaf\xfa\x92\xc1\xc7\x2b\x78\x75\x86\x63\xef\x45\x82\x84\x31\x39\xd7\xa6" } ] @@ -214,57 +280,83 @@ -- Example 3: A 1026-bit RSA Key Pair -- ================================== -rsaKey3 = PrivateKey- { private_pub = PublicKey- { public_n = 0x02f246ef451ed3eebb9a310200cc25859c048e4be798302991112eb68ce6db674e280da21feded1ae74880ca522b18db249385012827c515f0e466a1ffa691d98170574e9d0eadb087586ca48933da3cc953d95bd0ed50de10ddcb6736107d6c831c7f663e833ca4c097e700ce0fb945f88fb85fe8e5a773172565b914a471a443- , public_e = 0x010001- , public_size = 129+rsaKey3 =+ PrivateKey+ { private_pub =+ PublicKey+ { public_n =+ 0x02f246ef451ed3eebb9a310200cc25859c048e4be798302991112eb68ce6db674e280da21feded1ae74880ca522b18db249385012827c515f0e466a1ffa691d98170574e9d0eadb087586ca48933da3cc953d95bd0ed50de10ddcb6736107d6c831c7f663e833ca4c097e700ce0fb945f88fb85fe8e5a773172565b914a471a443+ , public_e = 0x010001+ , public_size = 129+ }+ , private_d =+ 0x651451733b56de5ac0a689a4aeb6e6894a69014e076c88dd7a667eab3232bbccd2fc44ba2fa9c31db46f21edd1fdb23c5c128a5da5bab91e7f952b67759c7cff705415ac9fa0907c7ca6178f668fb948d869da4cc3b7356f4008dfd5449d32ee02d9a477eb69fc29266e5d9070512375a50fbbcc27e238ad98425f6ebbf88991+ , private_p =+ 0x01bd36e18ece4b0fdb2e9c9d548bd1a7d6e2c21c6fdc35074a1d05b1c6c8b3d558ea2639c9a9a421680169317252558bd148ad215aac550e2dcf12a82d0ebfe853+ , private_q =+ 0x01b1b656ad86d8e19d5dc86292b3a192fdf6e0dd37877bad14822fa00190cab265f90d3f02057b6f54d6ecb14491e5adeacebc48bf0ebd2a2ad26d402e54f61651+ , private_dP =+ 0x1f2779fd2e3e5e6bae05539518fba0cd0ead1aa4513a7cba18f1cf10e3f68195693d278a0f0ee72f89f9bc760d80e2f9d0261d516501c6ae39f14a476ce2ccf5+ , private_dQ =+ 0x011a0d36794b04a854aab4b2462d439a5046c91d940b2bc6f75b62956fef35a2a6e63c5309817f307bbff9d59e7e331bd363f6d66849b18346adea169f0ae9aec1+ , private_qinv =+ 0x0b30f0ecf558752fb3a6ce4ba2b8c675f659eba6c376585a1b39712d038ae3d2b46fcb418ae15d0905da6440e1513a30b9b7d6668fbc5e88e5ab7a175e73ba35 }- , private_d = 0x651451733b56de5ac0a689a4aeb6e6894a69014e076c88dd7a667eab3232bbccd2fc44ba2fa9c31db46f21edd1fdb23c5c128a5da5bab91e7f952b67759c7cff705415ac9fa0907c7ca6178f668fb948d869da4cc3b7356f4008dfd5449d32ee02d9a477eb69fc29266e5d9070512375a50fbbcc27e238ad98425f6ebbf88991- , private_p = 0x01bd36e18ece4b0fdb2e9c9d548bd1a7d6e2c21c6fdc35074a1d05b1c6c8b3d558ea2639c9a9a421680169317252558bd148ad215aac550e2dcf12a82d0ebfe853- , private_q = 0x01b1b656ad86d8e19d5dc86292b3a192fdf6e0dd37877bad14822fa00190cab265f90d3f02057b6f54d6ecb14491e5adeacebc48bf0ebd2a2ad26d402e54f61651- , private_dP = 0x1f2779fd2e3e5e6bae05539518fba0cd0ead1aa4513a7cba18f1cf10e3f68195693d278a0f0ee72f89f9bc760d80e2f9d0261d516501c6ae39f14a476ce2ccf5- , private_dQ = 0x011a0d36794b04a854aab4b2462d439a5046c91d940b2bc6f75b62956fef35a2a6e63c5309817f307bbff9d59e7e331bd363f6d66849b18346adea169f0ae9aec1- , private_qinv = 0x0b30f0ecf558752fb3a6ce4ba2b8c675f659eba6c376585a1b39712d038ae3d2b46fcb418ae15d0905da6440e1513a30b9b7d6668fbc5e88e5ab7a175e73ba35- } vectorsKey3 =- [- -- Example 3.1+ [ -- Example 3.1 VectorPSS- { message = "\x59\x4b\x37\x33\x3b\xbb\x2c\x84\x52\x4a\x87\xc1\xa0\x1f\x75\xfc\xec\x0e\x32\x56\xf1\x08\xe3\x8d\xca\x36\xd7\x0d\x00\x57"- , salt = "\xf3\x1a\xd6\xc8\xcf\x89\xdf\x78\xed\x77\xfe\xac\xbc\xc2\xf8\xb0\xa8\xe4\xcf\xaa"- , signature = "\x00\x88\xb1\x35\xfb\x17\x94\xb6\xb9\x6c\x4a\x3e\x67\x81\x97\xf8\xca\xc5\x2b\x64\xb2\xfe\x90\x7d\x6f\x27\xde\x76\x11\x24\x96\x4a\x99\xa0\x1a\x88\x27\x40\xec\xfa\xed\x6c\x01\xa4\x74\x64\xbb\x05\x18\x23\x13\xc0\x13\x38\xa8\xcd\x09\x72\x14\xcd\x68\xca\x10\x3b\xd5\x7d\x3b\xc9\xe8\x16\x21\x3e\x61\xd7\x84\xf1\x82\x46\x7a\xbf\x8a\x01\xcf\x25\x3e\x99\xa1\x56\xea\xa8\xe3\xe1\xf9\x0e\x3c\x6e\x4e\x3a\xa2\xd8\x3e\xd0\x34\x5b\x89\xfa\xfc\x9c\x26\x07\x7c\x14\xb6\xac\x51\x45\x4f\xa2\x6e\x44\x6e\x3a\x2f\x15\x3b\x2b\x16\x79\x7f"+ { message =+ "\x59\x4b\x37\x33\x3b\xbb\x2c\x84\x52\x4a\x87\xc1\xa0\x1f\x75\xfc\xec\x0e\x32\x56\xf1\x08\xe3\x8d\xca\x36\xd7\x0d\x00\x57"+ , salt =+ "\xf3\x1a\xd6\xc8\xcf\x89\xdf\x78\xed\x77\xfe\xac\xbc\xc2\xf8\xb0\xa8\xe4\xcf\xaa"+ , signature =+ "\x00\x88\xb1\x35\xfb\x17\x94\xb6\xb9\x6c\x4a\x3e\x67\x81\x97\xf8\xca\xc5\x2b\x64\xb2\xfe\x90\x7d\x6f\x27\xde\x76\x11\x24\x96\x4a\x99\xa0\x1a\x88\x27\x40\xec\xfa\xed\x6c\x01\xa4\x74\x64\xbb\x05\x18\x23\x13\xc0\x13\x38\xa8\xcd\x09\x72\x14\xcd\x68\xca\x10\x3b\xd5\x7d\x3b\xc9\xe8\x16\x21\x3e\x61\xd7\x84\xf1\x82\x46\x7a\xbf\x8a\x01\xcf\x25\x3e\x99\xa1\x56\xea\xa8\xe3\xe1\xf9\x0e\x3c\x6e\x4e\x3a\xa2\xd8\x3e\xd0\x34\x5b\x89\xfa\xfc\x9c\x26\x07\x7c\x14\xb6\xac\x51\x45\x4f\xa2\x6e\x44\x6e\x3a\x2f\x15\x3b\x2b\x16\x79\x7f" }- -- Example 3.2- , VectorPSS- { message = "\x8b\x76\x95\x28\x88\x4a\x0d\x1f\xfd\x09\x0c\xf1\x02\x99\x3e\x79\x6d\xad\xcf\xbd\xdd\x38\xe4\x4f\xf6\x32\x4c\xa4\x51"- , salt = "\xfc\xf9\xf0\xe1\xf1\x99\xa3\xd1\xd0\xda\x68\x1c\x5b\x86\x06\xfc\x64\x29\x39\xf7"- , signature = "\x02\xa5\xf0\xa8\x58\xa0\x86\x4a\x4f\x65\x01\x7a\x7d\x69\x45\x4f\x3f\x97\x3a\x29\x99\x83\x9b\x7b\xbc\x48\xbf\x78\x64\x11\x69\x17\x95\x56\xf5\x95\xfa\x41\xf6\xff\x18\xe2\x86\xc2\x78\x30\x79\xbc\x09\x10\xee\x9c\xc3\x4f\x49\xba\x68\x11\x24\xf9\x23\xdf\xa8\x8f\x42\x61\x41\xa3\x68\xa5\xf5\xa9\x30\xc6\x28\xc2\xc3\xc2\x00\xe1\x8a\x76\x44\x72\x1a\x0c\xbe\xc6\xdd\x3f\x62\x79\xbd\xe3\xe8\xf2\xbe\x5e\x2d\x4e\xe5\x6f\x97\xe7\xce\xaf\x33\x05\x4b\xe7\x04\x2b\xd9\x1a\x63\xbb\x09\xf8\x97\xbd\x41\xe8\x11\x97\xde\xe9\x9b\x11\xaf"+ , -- Example 3.2+ VectorPSS+ { message =+ "\x8b\x76\x95\x28\x88\x4a\x0d\x1f\xfd\x09\x0c\xf1\x02\x99\x3e\x79\x6d\xad\xcf\xbd\xdd\x38\xe4\x4f\xf6\x32\x4c\xa4\x51"+ , salt =+ "\xfc\xf9\xf0\xe1\xf1\x99\xa3\xd1\xd0\xda\x68\x1c\x5b\x86\x06\xfc\x64\x29\x39\xf7"+ , signature =+ "\x02\xa5\xf0\xa8\x58\xa0\x86\x4a\x4f\x65\x01\x7a\x7d\x69\x45\x4f\x3f\x97\x3a\x29\x99\x83\x9b\x7b\xbc\x48\xbf\x78\x64\x11\x69\x17\x95\x56\xf5\x95\xfa\x41\xf6\xff\x18\xe2\x86\xc2\x78\x30\x79\xbc\x09\x10\xee\x9c\xc3\x4f\x49\xba\x68\x11\x24\xf9\x23\xdf\xa8\x8f\x42\x61\x41\xa3\x68\xa5\xf5\xa9\x30\xc6\x28\xc2\xc3\xc2\x00\xe1\x8a\x76\x44\x72\x1a\x0c\xbe\xc6\xdd\x3f\x62\x79\xbd\xe3\xe8\xf2\xbe\x5e\x2d\x4e\xe5\x6f\x97\xe7\xce\xaf\x33\x05\x4b\xe7\x04\x2b\xd9\x1a\x63\xbb\x09\xf8\x97\xbd\x41\xe8\x11\x97\xde\xe9\x9b\x11\xaf" }- -- Example 3.3- , VectorPSS- { message = "\x1a\xbd\xba\x48\x9c\x5a\xda\x2f\x99\x5e\xd1\x6f\x19\xd5\xa9\x4d\x9e\x6e\xc3\x4a\x8d\x84\xf8\x45\x57\xd2\x6e\x5e\xf9\xb0\x2b\x22\x88\x7e\x3f\x9a\x4b\x69\x0a\xd1\x14\x92\x09\xc2\x0c\x61\x43\x1f\x0c\x01\x7c\x36\xc2\x65\x7b\x35\xd7\xb0\x7d\x3f\x5a\xd8\x70\x85\x07\xa9\xc1\xb8\x31\xdf\x83\x5a\x56\xf8\x31\x07\x18\x14\xea\x5d\x3d\x8d\x8f\x6a\xde\x40\xcb\xa3\x8b\x42\xdb\x7a\x2d\x3d\x7a\x29\xc8\xf0\xa7\x9a\x78\x38\xcf\x58\xa9\x75\x7f\xa2\xfe\x4c\x40\xdf\x9b\xaa\x19\x3b\xfc\x6f\x92\xb1\x23\xad\x57\xb0\x7a\xce\x3e\x6a\xc0\x68\xc9\xf1\x06\xaf\xd9\xee\xb0\x3b\x4f\x37\xc2\x5d\xbf\xbc\xfb\x30\x71\xf6\xf9\x77\x17\x66\xd0\x72\xf3\xbb\x07\x0a\xf6\x60\x55\x32\x97\x3a\xe2\x50\x51"- , salt = "\x98\x6e\x7c\x43\xdb\xb6\x71\xbd\x41\xb9\xa7\xf4\xb6\xaf\xc8\x0e\x80\x5f\x24\x23"- , signature = "\x02\x44\xbc\xd1\xc8\xc1\x69\x55\x73\x6c\x80\x3b\xe4\x01\x27\x2e\x18\xcb\x99\x08\x11\xb1\x4f\x72\xdb\x96\x41\x24\xd5\xfa\x76\x06\x49\xcb\xb5\x7a\xfb\x87\x55\xdb\xb6\x2b\xf5\x1f\x46\x6c\xf2\x3a\x0a\x16\x07\x57\x6e\x98\x3d\x77\x8f\xce\xff\xa9\x2d\xf7\x54\x8a\xea\x8e\xa4\xec\xad\x2c\x29\xdd\x9f\x95\xbc\x07\xfe\x91\xec\xf8\xbe\xe2\x55\xbf\xe8\x76\x2f\xd7\x69\x0a\xa9\xbf\xa4\xfa\x08\x49\xef\x72\x8c\x2c\x42\xc4\x53\x23\x64\x52\x2d\xf2\xab\x7f\x9f\x8a\x03\xb6\x3f\x7a\x49\x91\x75\x82\x86\x68\xf5\xef\x5a\x29\xe3\x80\x2c"+ , -- Example 3.3+ VectorPSS+ { message =+ "\x1a\xbd\xba\x48\x9c\x5a\xda\x2f\x99\x5e\xd1\x6f\x19\xd5\xa9\x4d\x9e\x6e\xc3\x4a\x8d\x84\xf8\x45\x57\xd2\x6e\x5e\xf9\xb0\x2b\x22\x88\x7e\x3f\x9a\x4b\x69\x0a\xd1\x14\x92\x09\xc2\x0c\x61\x43\x1f\x0c\x01\x7c\x36\xc2\x65\x7b\x35\xd7\xb0\x7d\x3f\x5a\xd8\x70\x85\x07\xa9\xc1\xb8\x31\xdf\x83\x5a\x56\xf8\x31\x07\x18\x14\xea\x5d\x3d\x8d\x8f\x6a\xde\x40\xcb\xa3\x8b\x42\xdb\x7a\x2d\x3d\x7a\x29\xc8\xf0\xa7\x9a\x78\x38\xcf\x58\xa9\x75\x7f\xa2\xfe\x4c\x40\xdf\x9b\xaa\x19\x3b\xfc\x6f\x92\xb1\x23\xad\x57\xb0\x7a\xce\x3e\x6a\xc0\x68\xc9\xf1\x06\xaf\xd9\xee\xb0\x3b\x4f\x37\xc2\x5d\xbf\xbc\xfb\x30\x71\xf6\xf9\x77\x17\x66\xd0\x72\xf3\xbb\x07\x0a\xf6\x60\x55\x32\x97\x3a\xe2\x50\x51"+ , salt =+ "\x98\x6e\x7c\x43\xdb\xb6\x71\xbd\x41\xb9\xa7\xf4\xb6\xaf\xc8\x0e\x80\x5f\x24\x23"+ , signature =+ "\x02\x44\xbc\xd1\xc8\xc1\x69\x55\x73\x6c\x80\x3b\xe4\x01\x27\x2e\x18\xcb\x99\x08\x11\xb1\x4f\x72\xdb\x96\x41\x24\xd5\xfa\x76\x06\x49\xcb\xb5\x7a\xfb\x87\x55\xdb\xb6\x2b\xf5\x1f\x46\x6c\xf2\x3a\x0a\x16\x07\x57\x6e\x98\x3d\x77\x8f\xce\xff\xa9\x2d\xf7\x54\x8a\xea\x8e\xa4\xec\xad\x2c\x29\xdd\x9f\x95\xbc\x07\xfe\x91\xec\xf8\xbe\xe2\x55\xbf\xe8\x76\x2f\xd7\x69\x0a\xa9\xbf\xa4\xfa\x08\x49\xef\x72\x8c\x2c\x42\xc4\x53\x23\x64\x52\x2d\xf2\xab\x7f\x9f\x8a\x03\xb6\x3f\x7a\x49\x91\x75\x82\x86\x68\xf5\xef\x5a\x29\xe3\x80\x2c" }- -- Example 3.4- , VectorPSS- { message = "\x8f\xb4\x31\xf5\xee\x79\x2b\x6c\x2a\xc7\xdb\x53\xcc\x42\x86\x55\xae\xb3\x2d\x03\xf4\xe8\x89\xc5\xc2\x5d\xe6\x83\xc4\x61\xb5\x3a\xcf\x89\xf9\xf8\xd3\xaa\xbd\xf6\xb9\xf0\xc2\xa1\xde\x12\xe1\x5b\x49\xed\xb3\x91\x9a\x65\x2f\xe9\x49\x1c\x25\xa7\xfc\xe1\xf7\x22\xc2\x54\x36\x08\xb6\x9d\xc3\x75\xec"- , salt = "\xf8\x31\x2d\x9c\x8e\xea\x13\xec\x0a\x4c\x7b\x98\x12\x0c\x87\x50\x90\x87\xc4\x78"- , signature = "\x01\x96\xf1\x2a\x00\x5b\x98\x12\x9c\x8d\xf1\x3c\x4c\xb1\x6f\x8a\xa8\x87\xd3\xc4\x0d\x96\xdf\x3a\x88\xe7\x53\x2e\xf3\x9c\xd9\x92\xf2\x73\xab\xc3\x70\xbc\x1b\xe6\xf0\x97\xcf\xeb\xbf\x01\x18\xfd\x9e\xf4\xb9\x27\x15\x5f\x3d\xf2\x2b\x90\x4d\x90\x70\x2d\x1f\x7b\xa7\xa5\x2b\xed\x8b\x89\x42\xf4\x12\xcd\x7b\xd6\x76\xc9\xd1\x8e\x17\x03\x91\xdc\xd3\x45\xc0\x6a\x73\x09\x64\xb3\xf3\x0b\xcc\xe0\xbb\x20\xba\x10\x6f\x9a\xb0\xee\xb3\x9c\xf8\xa6\x60\x7f\x75\xc0\x34\x7f\x0a\xf7\x9f\x16\xaf\xa0\x81\xd2\xc9\x2d\x1e\xe6\xf8\x36\xb8"+ , -- Example 3.4+ VectorPSS+ { message =+ "\x8f\xb4\x31\xf5\xee\x79\x2b\x6c\x2a\xc7\xdb\x53\xcc\x42\x86\x55\xae\xb3\x2d\x03\xf4\xe8\x89\xc5\xc2\x5d\xe6\x83\xc4\x61\xb5\x3a\xcf\x89\xf9\xf8\xd3\xaa\xbd\xf6\xb9\xf0\xc2\xa1\xde\x12\xe1\x5b\x49\xed\xb3\x91\x9a\x65\x2f\xe9\x49\x1c\x25\xa7\xfc\xe1\xf7\x22\xc2\x54\x36\x08\xb6\x9d\xc3\x75\xec"+ , salt =+ "\xf8\x31\x2d\x9c\x8e\xea\x13\xec\x0a\x4c\x7b\x98\x12\x0c\x87\x50\x90\x87\xc4\x78"+ , signature =+ "\x01\x96\xf1\x2a\x00\x5b\x98\x12\x9c\x8d\xf1\x3c\x4c\xb1\x6f\x8a\xa8\x87\xd3\xc4\x0d\x96\xdf\x3a\x88\xe7\x53\x2e\xf3\x9c\xd9\x92\xf2\x73\xab\xc3\x70\xbc\x1b\xe6\xf0\x97\xcf\xeb\xbf\x01\x18\xfd\x9e\xf4\xb9\x27\x15\x5f\x3d\xf2\x2b\x90\x4d\x90\x70\x2d\x1f\x7b\xa7\xa5\x2b\xed\x8b\x89\x42\xf4\x12\xcd\x7b\xd6\x76\xc9\xd1\x8e\x17\x03\x91\xdc\xd3\x45\xc0\x6a\x73\x09\x64\xb3\xf3\x0b\xcc\xe0\xbb\x20\xba\x10\x6f\x9a\xb0\xee\xb3\x9c\xf8\xa6\x60\x7f\x75\xc0\x34\x7f\x0a\xf7\x9f\x16\xaf\xa0\x81\xd2\xc9\x2d\x1e\xe6\xf8\x36\xb8" }- -- Example 3.5- , VectorPSS- { message = "\xfe\xf4\x16\x1d\xfa\xaf\x9c\x52\x95\x05\x1d\xfc\x1f\xf3\x81\x0c\x8c\x9e\xc2\xe8\x66\xf7\x07\x54\x22\xc8\xec\x42\x16\xa9\xc4\xff\x49\x42\x7d\x48\x3c\xae\x10\xc8\x53\x4a\x41\xb2\xfd\x15\xfe\xe0\x69\x60\xec\x6f\xb3\xf7\xa7\xe9\x4a\x2f\x8a\x2e\x3e\x43\xdc\x4a\x40\x57\x6c\x30\x97\xac\x95\x3b\x1d\xe8\x6f\x0b\x4e\xd3\x6d\x64\x4f\x23\xae\x14\x42\x55\x29\x62\x24\x64\xca\x0c\xbf\x0b\x17\x41\x34\x72\x38\x15\x7f\xab\x59\xe4\xde\x55\x24\x09\x6d\x62\xba\xec\x63\xac\x64"- , salt = "\x50\x32\x7e\xfe\xc6\x29\x2f\x98\x01\x9f\xc6\x7a\x2a\x66\x38\x56\x3e\x9b\x6e\x2d"- , signature = "\x02\x1e\xca\x3a\xb4\x89\x22\x64\xec\x22\x41\x1a\x75\x2d\x92\x22\x10\x76\xd4\xe0\x1c\x0e\x6f\x0d\xde\x9a\xfd\x26\xba\x5a\xcf\x6d\x73\x9e\xf9\x87\x54\x5d\x16\x68\x3e\x56\x74\xc9\xe7\x0f\x1d\xe6\x49\xd7\xe6\x1d\x48\xd0\xca\xeb\x4f\xb4\xd8\xb2\x4f\xba\x84\xa6\xe3\x10\x8f\xee\x7d\x07\x05\x97\x32\x66\xac\x52\x4b\x4a\xd2\x80\xf7\xae\x17\xdc\x59\xd9\x6d\x33\x51\x58\x6b\x5a\x3b\xdb\x89\x5d\x1e\x1f\x78\x20\xac\x61\x35\xd8\x75\x34\x80\x99\x83\x82\xba\x32\xb7\x34\x95\x59\x60\x8c\x38\x74\x52\x90\xa8\x5e\xf4\xe9\xf9\xbd\x83"+ , -- Example 3.5+ VectorPSS+ { message =+ "\xfe\xf4\x16\x1d\xfa\xaf\x9c\x52\x95\x05\x1d\xfc\x1f\xf3\x81\x0c\x8c\x9e\xc2\xe8\x66\xf7\x07\x54\x22\xc8\xec\x42\x16\xa9\xc4\xff\x49\x42\x7d\x48\x3c\xae\x10\xc8\x53\x4a\x41\xb2\xfd\x15\xfe\xe0\x69\x60\xec\x6f\xb3\xf7\xa7\xe9\x4a\x2f\x8a\x2e\x3e\x43\xdc\x4a\x40\x57\x6c\x30\x97\xac\x95\x3b\x1d\xe8\x6f\x0b\x4e\xd3\x6d\x64\x4f\x23\xae\x14\x42\x55\x29\x62\x24\x64\xca\x0c\xbf\x0b\x17\x41\x34\x72\x38\x15\x7f\xab\x59\xe4\xde\x55\x24\x09\x6d\x62\xba\xec\x63\xac\x64"+ , salt =+ "\x50\x32\x7e\xfe\xc6\x29\x2f\x98\x01\x9f\xc6\x7a\x2a\x66\x38\x56\x3e\x9b\x6e\x2d"+ , signature =+ "\x02\x1e\xca\x3a\xb4\x89\x22\x64\xec\x22\x41\x1a\x75\x2d\x92\x22\x10\x76\xd4\xe0\x1c\x0e\x6f\x0d\xde\x9a\xfd\x26\xba\x5a\xcf\x6d\x73\x9e\xf9\x87\x54\x5d\x16\x68\x3e\x56\x74\xc9\xe7\x0f\x1d\xe6\x49\xd7\xe6\x1d\x48\xd0\xca\xeb\x4f\xb4\xd8\xb2\x4f\xba\x84\xa6\xe3\x10\x8f\xee\x7d\x07\x05\x97\x32\x66\xac\x52\x4b\x4a\xd2\x80\xf7\xae\x17\xdc\x59\xd9\x6d\x33\x51\x58\x6b\x5a\x3b\xdb\x89\x5d\x1e\x1f\x78\x20\xac\x61\x35\xd8\x75\x34\x80\x99\x83\x82\xba\x32\xb7\x34\x95\x59\x60\x8c\x38\x74\x52\x90\xa8\x5e\xf4\xe9\xf9\xbd\x83" }- -- Example 3.6- , VectorPSS- { message = "\xef\xd2\x37\xbb\x09\x8a\x44\x3a\xee\xb2\xbf\x6c\x3f\x8c\x81\xb8\xc0\x1b\x7f\xcb\x3f\xeb"- , salt = "\xb0\xde\x3f\xc2\x5b\x65\xf5\xaf\x96\xb1\xd5\xcc\x3b\x27\xd0\xc6\x05\x30\x87\xb3"- , signature = "\x01\x2f\xaf\xec\x86\x2f\x56\xe9\xe9\x2f\x60\xab\x0c\x77\x82\x4f\x42\x99\xa0\xca\x73\x4e\xd2\x6e\x06\x44\xd5\xd2\x22\xc7\xf0\xbd\xe0\x39\x64\xf8\xe7\x0a\x5c\xb6\x5e\xd4\x4e\x44\xd5\x6a\xe0\xed\xf1\xff\x86\xca\x03\x2c\xc5\xdd\x44\x04\xdb\xb7\x6a\xb8\x54\x58\x6c\x44\xee\xd8\x33\x6d\x08\xd4\x57\xce\x6c\x03\x69\x3b\x45\xc0\xf1\xef\xef\x93\x62\x4b\x95\xb8\xec\x16\x9c\x61\x6d\x20\xe5\x53\x8e\xbc\x0b\x67\x37\xa6\xf8\x2b\x4b\xc0\x57\x09\x24\xfc\x6b\x35\x75\x9a\x33\x48\x42\x62\x79\xf8\xb3\xd7\x74\x4e\x2d\x22\x24\x26\xce"+ , -- Example 3.6+ VectorPSS+ { message =+ "\xef\xd2\x37\xbb\x09\x8a\x44\x3a\xee\xb2\xbf\x6c\x3f\x8c\x81\xb8\xc0\x1b\x7f\xcb\x3f\xeb"+ , salt =+ "\xb0\xde\x3f\xc2\x5b\x65\xf5\xaf\x96\xb1\xd5\xcc\x3b\x27\xd0\xc6\x05\x30\x87\xb3"+ , signature =+ "\x01\x2f\xaf\xec\x86\x2f\x56\xe9\xe9\x2f\x60\xab\x0c\x77\x82\x4f\x42\x99\xa0\xca\x73\x4e\xd2\x6e\x06\x44\xd5\xd2\x22\xc7\xf0\xbd\xe0\x39\x64\xf8\xe7\x0a\x5c\xb6\x5e\xd4\x4e\x44\xd5\x6a\xe0\xed\xf1\xff\x86\xca\x03\x2c\xc5\xdd\x44\x04\xdb\xb7\x6a\xb8\x54\x58\x6c\x44\xee\xd8\x33\x6d\x08\xd4\x57\xce\x6c\x03\x69\x3b\x45\xc0\xf1\xef\xef\x93\x62\x4b\x95\xb8\xec\x16\x9c\x61\x6d\x20\xe5\x53\x8e\xbc\x0b\x67\x37\xa6\xf8\x2b\x4b\xc0\x57\x09\x24\xfc\x6b\x35\x75\x9a\x33\x48\x42\x62\x79\xf8\xb3\xd7\x74\x4e\x2d\x22\x24\x26\xce" } ] @@ -272,77 +364,128 @@ -- Example 8: A 1031-bit RSA Key Pair -- ================================== -rsaKey8 = PrivateKey- { private_pub = PublicKey- { public_n = 0x495370a1fb18543c16d3631e3163255df62be6eee890d5f25509e4f778a8ea6fbbbcdf85dff64e0d972003ab3681fbba6dd41fd541829b2e582de9f2a4a4e0a2d0900bef4753db3cee0ee06c7dfae8b1d53b5953218f9cceea695b08668edeaadced9463b1d790d5ebf27e9115b46cad4d9a2b8efab0561b0810344739ada0733f- , public_e = 0x010001- , public_size = 129+rsaKey8 =+ PrivateKey+ { private_pub =+ PublicKey+ { public_n =+ 0x495370a1fb18543c16d3631e3163255df62be6eee890d5f25509e4f778a8ea6fbbbcdf85dff64e0d972003ab3681fbba6dd41fd541829b2e582de9f2a4a4e0a2d0900bef4753db3cee0ee06c7dfae8b1d53b5953218f9cceea695b08668edeaadced9463b1d790d5ebf27e9115b46cad4d9a2b8efab0561b0810344739ada0733f+ , public_e = 0x010001+ , public_size = 129+ }+ , private_d =+ 0x6c66ffe98980c38fcdeab5159898836165f4b4b817c4f6a8d486ee4ea9130fe9b9092bd136d184f95f504a607eac565846d2fdd6597a8967c7396ef95a6eeebb4578a643966dca4d8ee3de842de63279c618159c1ab54a89437b6a6120e4930afb52a4ba6ced8a4947ac64b30a3497cbe701c2d6266d517219ad0ec6d347dbe9+ , private_p =+ 0x08dad7f11363faa623d5d6d5e8a319328d82190d7127d2846c439b0ab72619b0a43a95320e4ec34fc3a9cea876422305bd76c5ba7be9e2f410c8060645a1d29edb+ , private_q =+ 0x0847e732376fc7900f898ea82eb2b0fc418565fdae62f7d9ec4ce2217b97990dd272db157f99f63c0dcbb9fbacdbd4c4dadb6df67756358ca4174825b48f49706d+ , private_dP =+ 0x05c2a83c124b3621a2aa57ea2c3efe035eff4560f33ddebb7adab81fce69a0c8c2edc16520dda83d59a23be867963ac65f2cc710bbcfb96ee103deb771d105fd85+ , private_dQ =+ 0x04cae8aa0d9faa165c87b682ec140b8ed3b50b24594b7a3b2c220b3669bb819f984f55310a1ae7823651d4a02e99447972595139363434e5e30a7e7d241551e1b9+ , private_qinv =+ 0x07d3e47bf686600b11ac283ce88dbb3f6051e8efd04680e44c171ef531b80b2b7c39fc766320e2cf15d8d99820e96ff30dc69691839c4b40d7b06e45307dc91f3f }- , private_d = 0x6c66ffe98980c38fcdeab5159898836165f4b4b817c4f6a8d486ee4ea9130fe9b9092bd136d184f95f504a607eac565846d2fdd6597a8967c7396ef95a6eeebb4578a643966dca4d8ee3de842de63279c618159c1ab54a89437b6a6120e4930afb52a4ba6ced8a4947ac64b30a3497cbe701c2d6266d517219ad0ec6d347dbe9- , private_p = 0x08dad7f11363faa623d5d6d5e8a319328d82190d7127d2846c439b0ab72619b0a43a95320e4ec34fc3a9cea876422305bd76c5ba7be9e2f410c8060645a1d29edb- , private_q = 0x0847e732376fc7900f898ea82eb2b0fc418565fdae62f7d9ec4ce2217b97990dd272db157f99f63c0dcbb9fbacdbd4c4dadb6df67756358ca4174825b48f49706d- , private_dP = 0x05c2a83c124b3621a2aa57ea2c3efe035eff4560f33ddebb7adab81fce69a0c8c2edc16520dda83d59a23be867963ac65f2cc710bbcfb96ee103deb771d105fd85- , private_dQ = 0x04cae8aa0d9faa165c87b682ec140b8ed3b50b24594b7a3b2c220b3669bb819f984f55310a1ae7823651d4a02e99447972595139363434e5e30a7e7d241551e1b9- , private_qinv = 0x07d3e47bf686600b11ac283ce88dbb3f6051e8efd04680e44c171ef531b80b2b7c39fc766320e2cf15d8d99820e96ff30dc69691839c4b40d7b06e45307dc91f3f- } vectorsKey8 =- [- -- Example 8.1+ [ -- Example 8.1 VectorPSS- { message = "\x81\x33\x2f\x4b\xe6\x29\x48\x41\x5e\xa1\xd8\x99\x79\x2e\xea\xcf\x6c\x6e\x1d\xb1\xda\x8b\xe1\x3b\x5c\xea\x41\xdb\x2f\xed\x46\x70\x92\xe1\xff\x39\x89\x14\xc7\x14\x25\x97\x75\xf5\x95\xf8\x54\x7f\x73\x56\x92\xa5\x75\xe6\x92\x3a\xf7\x8f\x22\xc6\x99\x7d\xdb\x90\xfb\x6f\x72\xd7\xbb\x0d\xd5\x74\x4a\x31\xde\xcd\x3d\xc3\x68\x58\x49\x83\x6e\xd3\x4a\xec\x59\x63\x04\xad\x11\x84\x3c\x4f\x88\x48\x9f\x20\x97\x35\xf5\xfb\x7f\xda\xf7\xce\xc8\xad\xdc\x58\x18\x16\x8f\x88\x0a\xcb\xf4\x90\xd5\x10\x05\xb7\xa8\xe8\x4e\x43\xe5\x42\x87\x97\x75\x71\xdd\x99\xee\xa4\xb1\x61\xeb\x2d\xf1\xf5\x10\x8f\x12\xa4\x14\x2a\x83\x32\x2e\xdb\x05\xa7\x54\x87\xa3\x43\x5c\x9a\x78\xce\x53\xed\x93\xbc\x55\x08\x57\xd7\xa9\xfb"- , salt = "\x1d\x65\x49\x1d\x79\xc8\x64\xb3\x73\x00\x9b\xe6\xf6\xf2\x46\x7b\xac\x4c\x78\xfa"- , signature = "\x02\x62\xac\x25\x4b\xfa\x77\xf3\xc1\xac\xa2\x2c\x51\x79\xf8\xf0\x40\x42\x2b\x3c\x5b\xaf\xd4\x0a\x8f\x21\xcf\x0f\xa5\xa6\x67\xcc\xd5\x99\x3d\x42\xdb\xaf\xb4\x09\xc5\x20\xe2\x5f\xce\x2b\x1e\xe1\xe7\x16\x57\x7f\x1e\xfa\x17\xf3\xda\x28\x05\x2f\x40\xf0\x41\x9b\x23\x10\x6d\x78\x45\xaa\xf0\x11\x25\xb6\x98\xe7\xa4\xdf\xe9\x2d\x39\x67\xbb\x00\xc4\xd0\xd3\x5b\xa3\x55\x2a\xb9\xa8\xb3\xee\xf0\x7c\x7f\xec\xdb\xc5\x42\x4a\xc4\xdb\x1e\x20\xcb\x37\xd0\xb2\x74\x47\x69\x94\x0e\xa9\x07\xe1\x7f\xbb\xca\x67\x3b\x20\x52\x23\x80\xc5"+ { message =+ "\x81\x33\x2f\x4b\xe6\x29\x48\x41\x5e\xa1\xd8\x99\x79\x2e\xea\xcf\x6c\x6e\x1d\xb1\xda\x8b\xe1\x3b\x5c\xea\x41\xdb\x2f\xed\x46\x70\x92\xe1\xff\x39\x89\x14\xc7\x14\x25\x97\x75\xf5\x95\xf8\x54\x7f\x73\x56\x92\xa5\x75\xe6\x92\x3a\xf7\x8f\x22\xc6\x99\x7d\xdb\x90\xfb\x6f\x72\xd7\xbb\x0d\xd5\x74\x4a\x31\xde\xcd\x3d\xc3\x68\x58\x49\x83\x6e\xd3\x4a\xec\x59\x63\x04\xad\x11\x84\x3c\x4f\x88\x48\x9f\x20\x97\x35\xf5\xfb\x7f\xda\xf7\xce\xc8\xad\xdc\x58\x18\x16\x8f\x88\x0a\xcb\xf4\x90\xd5\x10\x05\xb7\xa8\xe8\x4e\x43\xe5\x42\x87\x97\x75\x71\xdd\x99\xee\xa4\xb1\x61\xeb\x2d\xf1\xf5\x10\x8f\x12\xa4\x14\x2a\x83\x32\x2e\xdb\x05\xa7\x54\x87\xa3\x43\x5c\x9a\x78\xce\x53\xed\x93\xbc\x55\x08\x57\xd7\xa9\xfb"+ , salt =+ "\x1d\x65\x49\x1d\x79\xc8\x64\xb3\x73\x00\x9b\xe6\xf6\xf2\x46\x7b\xac\x4c\x78\xfa"+ , signature =+ "\x02\x62\xac\x25\x4b\xfa\x77\xf3\xc1\xac\xa2\x2c\x51\x79\xf8\xf0\x40\x42\x2b\x3c\x5b\xaf\xd4\x0a\x8f\x21\xcf\x0f\xa5\xa6\x67\xcc\xd5\x99\x3d\x42\xdb\xaf\xb4\x09\xc5\x20\xe2\x5f\xce\x2b\x1e\xe1\xe7\x16\x57\x7f\x1e\xfa\x17\xf3\xda\x28\x05\x2f\x40\xf0\x41\x9b\x23\x10\x6d\x78\x45\xaa\xf0\x11\x25\xb6\x98\xe7\xa4\xdf\xe9\x2d\x39\x67\xbb\x00\xc4\xd0\xd3\x5b\xa3\x55\x2a\xb9\xa8\xb3\xee\xf0\x7c\x7f\xec\xdb\xc5\x42\x4a\xc4\xdb\x1e\x20\xcb\x37\xd0\xb2\x74\x47\x69\x94\x0e\xa9\x07\xe1\x7f\xbb\xca\x67\x3b\x20\x52\x23\x80\xc5" }- -- Example 8.2- , VectorPSS- { message = "\xe2\xf9\x6e\xaf\x0e\x05\xe7\xba\x32\x6e\xcc\xa0\xba\x7f\xd2\xf7\xc0\x23\x56\xf3\xce\xde\x9d\x0f\xaa\xbf\x4f\xcc\x8e\x60\xa9\x73\xe5\x59\x5f\xd9\xea\x08"- , salt = "\x43\x5c\x09\x8a\xa9\x90\x9e\xb2\x37\x7f\x12\x48\xb0\x91\xb6\x89\x87\xff\x18\x38"- , signature = "\x27\x07\xb9\xad\x51\x15\xc5\x8c\x94\xe9\x32\xe8\xec\x0a\x28\x0f\x56\x33\x9e\x44\xa1\xb5\x8d\x4d\xdc\xff\x2f\x31\x2e\x5f\x34\xdc\xfe\x39\xe8\x9c\x6a\x94\xdc\xee\x86\xdb\xbd\xae\x5b\x79\xba\x4e\x08\x19\xa9\xe7\xbf\xd9\xd9\x82\xe7\xee\x6c\x86\xee\x68\x39\x6e\x8b\x3a\x14\xc9\xc8\xf3\x4b\x17\x8e\xb7\x41\xf9\xd3\xf1\x21\x10\x9b\xf5\xc8\x17\x2f\xad\xa2\xe7\x68\xf9\xea\x14\x33\x03\x2c\x00\x4a\x8a\xa0\x7e\xb9\x90\x00\x0a\x48\xdc\x94\xc8\xba\xc8\xaa\xbe\x2b\x09\xb1\xaa\x46\xc0\xa2\xaa\x0e\x12\xf6\x3f\xbb\xa7\x75\xba\x7e"+ , -- Example 8.2+ VectorPSS+ { message =+ "\xe2\xf9\x6e\xaf\x0e\x05\xe7\xba\x32\x6e\xcc\xa0\xba\x7f\xd2\xf7\xc0\x23\x56\xf3\xce\xde\x9d\x0f\xaa\xbf\x4f\xcc\x8e\x60\xa9\x73\xe5\x59\x5f\xd9\xea\x08"+ , salt =+ "\x43\x5c\x09\x8a\xa9\x90\x9e\xb2\x37\x7f\x12\x48\xb0\x91\xb6\x89\x87\xff\x18\x38"+ , signature =+ "\x27\x07\xb9\xad\x51\x15\xc5\x8c\x94\xe9\x32\xe8\xec\x0a\x28\x0f\x56\x33\x9e\x44\xa1\xb5\x8d\x4d\xdc\xff\x2f\x31\x2e\x5f\x34\xdc\xfe\x39\xe8\x9c\x6a\x94\xdc\xee\x86\xdb\xbd\xae\x5b\x79\xba\x4e\x08\x19\xa9\xe7\xbf\xd9\xd9\x82\xe7\xee\x6c\x86\xee\x68\x39\x6e\x8b\x3a\x14\xc9\xc8\xf3\x4b\x17\x8e\xb7\x41\xf9\xd3\xf1\x21\x10\x9b\xf5\xc8\x17\x2f\xad\xa2\xe7\x68\xf9\xea\x14\x33\x03\x2c\x00\x4a\x8a\xa0\x7e\xb9\x90\x00\x0a\x48\xdc\x94\xc8\xba\xc8\xaa\xbe\x2b\x09\xb1\xaa\x46\xc0\xa2\xaa\x0e\x12\xf6\x3f\xbb\xa7\x75\xba\x7e" }- -- Example 8.3- , VectorPSS- { message = "\xe3\x5c\x6e\xd9\x8f\x64\xa6\xd5\xa6\x48\xfc\xab\x8a\xdb\x16\x33\x1d\xb3\x2e\x5d\x15\xc7\x4a\x40\xed\xf9\x4c\x3d\xc4\xa4\xde\x79\x2d\x19\x08\x89\xf2\x0f\x1e\x24\xed\x12\x05\x4a\x6b\x28\x79\x8f\xcb\x42\xd1\xc5\x48\x76\x9b\x73\x4c\x96\x37\x31\x42\x09\x2a\xed\x27\x76\x03\xf4\x73\x8d\xf4\xdc\x14\x46\x58\x6d\x0e\xc6\x4d\xa4\xfb\x60\x53\x6d\xb2\xae\x17\xfc\x7e\x3c\x04\xbb\xfb\xbb\xd9\x07\xbf\x11\x7c\x08\x63\x6f\xa1\x6f\x95\xf5\x1a\x62\x16\x93\x4d\x3e\x34\xf8\x50\x30\xf1\x7b\xbb\xc5\xba\x69\x14\x40\x58\xaf\xf0\x81\xe0\xb1\x9c\xf0\x3c\x17\x19\x5c\x5e\x88\x8b\xa5\x8f\x6f\xe0\xa0\x2e\x5c\x3b\xda\x97\x19\xa7"- , salt = "\xc6\xeb\xbe\x76\xdf\x0c\x4a\xea\x32\xc4\x74\x17\x5b\x2f\x13\x68\x62\xd0\x45\x29"- , signature = "\x2a\xd2\x05\x09\xd7\x8c\xf2\x6d\x1b\x6c\x40\x61\x46\x08\x6e\x4b\x0c\x91\xa9\x1c\x2b\xd1\x64\xc8\x7b\x96\x6b\x8f\xaa\x42\xaa\x0c\xa4\x46\x02\x23\x23\xba\x4b\x1a\x1b\x89\x70\x6d\x7f\x4c\x3b\xe5\x7d\x7b\x69\x70\x2d\x16\x8a\xb5\x95\x5e\xe2\x90\x35\x6b\x8c\x4a\x29\xed\x46\x7d\x54\x7e\xc2\x3c\xba\xdf\x28\x6c\xcb\x58\x63\xc6\x67\x9d\xa4\x67\xfc\x93\x24\xa1\x51\xc7\xec\x55\xaa\xc6\xdb\x40\x84\xf8\x27\x26\x82\x5c\xfe\x1a\xa4\x21\xbc\x64\x04\x9f\xb4\x2f\x23\x14\x8f\x9c\x25\xb2\xdc\x30\x04\x37\xc3\x8d\x42\x8a\xa7\x5f\x96"+ , -- Example 8.3+ VectorPSS+ { message =+ "\xe3\x5c\x6e\xd9\x8f\x64\xa6\xd5\xa6\x48\xfc\xab\x8a\xdb\x16\x33\x1d\xb3\x2e\x5d\x15\xc7\x4a\x40\xed\xf9\x4c\x3d\xc4\xa4\xde\x79\x2d\x19\x08\x89\xf2\x0f\x1e\x24\xed\x12\x05\x4a\x6b\x28\x79\x8f\xcb\x42\xd1\xc5\x48\x76\x9b\x73\x4c\x96\x37\x31\x42\x09\x2a\xed\x27\x76\x03\xf4\x73\x8d\xf4\xdc\x14\x46\x58\x6d\x0e\xc6\x4d\xa4\xfb\x60\x53\x6d\xb2\xae\x17\xfc\x7e\x3c\x04\xbb\xfb\xbb\xd9\x07\xbf\x11\x7c\x08\x63\x6f\xa1\x6f\x95\xf5\x1a\x62\x16\x93\x4d\x3e\x34\xf8\x50\x30\xf1\x7b\xbb\xc5\xba\x69\x14\x40\x58\xaf\xf0\x81\xe0\xb1\x9c\xf0\x3c\x17\x19\x5c\x5e\x88\x8b\xa5\x8f\x6f\xe0\xa0\x2e\x5c\x3b\xda\x97\x19\xa7"+ , salt =+ "\xc6\xeb\xbe\x76\xdf\x0c\x4a\xea\x32\xc4\x74\x17\x5b\x2f\x13\x68\x62\xd0\x45\x29"+ , signature =+ "\x2a\xd2\x05\x09\xd7\x8c\xf2\x6d\x1b\x6c\x40\x61\x46\x08\x6e\x4b\x0c\x91\xa9\x1c\x2b\xd1\x64\xc8\x7b\x96\x6b\x8f\xaa\x42\xaa\x0c\xa4\x46\x02\x23\x23\xba\x4b\x1a\x1b\x89\x70\x6d\x7f\x4c\x3b\xe5\x7d\x7b\x69\x70\x2d\x16\x8a\xb5\x95\x5e\xe2\x90\x35\x6b\x8c\x4a\x29\xed\x46\x7d\x54\x7e\xc2\x3c\xba\xdf\x28\x6c\xcb\x58\x63\xc6\x67\x9d\xa4\x67\xfc\x93\x24\xa1\x51\xc7\xec\x55\xaa\xc6\xdb\x40\x84\xf8\x27\x26\x82\x5c\xfe\x1a\xa4\x21\xbc\x64\x04\x9f\xb4\x2f\x23\x14\x8f\x9c\x25\xb2\xdc\x30\x04\x37\xc3\x8d\x42\x8a\xa7\x5f\x96" }- -- Example 8.4- , VectorPSS- { message = "\xdb\xc5\xf7\x50\xa7\xa1\x4b\xe2\xb9\x3e\x83\x8d\x18\xd1\x4a\x86\x95\xe5\x2e\x8a\xdd\x9c\x0a\xc7\x33\xb8\xf5\x6d\x27\x47\xe5\x29\xa0\xcc\xa5\x32\xdd\x49\xb9\x02\xae\xfe\xd5\x14\x44\x7f\x9e\x81\xd1\x61\x95\xc2\x85\x38\x68\xcb\x9b\x30\xf7\xd0\xd4\x95\xc6\x9d\x01\xb5\xc5\xd5\x0b\x27\x04\x5d\xb3\x86\x6c\x23\x24\xa4\x4a\x11\x0b\x17\x17\x74\x6d\xe4\x57\xd1\xc8\xc4\x5c\x3c\xd2\xa9\x29\x70\xc3\xd5\x96\x32\x05\x5d\x4c\x98\xa4\x1d\x6e\x99\xe2\xa3\xdd\xd5\xf7\xf9\x97\x9a\xb3\xcd\x18\xf3\x75\x05\xd2\x51\x41\xde\x2a\x1b\xff\x17\xb3\xa7\xdc\xe9\x41\x9e\xcc\x38\x5c\xf1\x1d\x72\x84\x0f\x19\x95\x3f\xd0\x50\x92\x51\xf6\xca\xfd\xe2\x89\x3d\x0e\x75\xc7\x81\xba\x7a\x50\x12\xca\x40\x1a\x4f\xa9\x9e\x04\xb3\xc3\x24\x9f\x92\x6d\x5a\xfe\x82\xcc\x87\xda\xb2\x2c\x3c\x1b\x10\x5d\xe4\x8e\x34\xac\xe9\xc9\x12\x4e\x59\x59\x7a\xc7\xeb\xf8"- , salt = "\x02\x1f\xdc\xc6\xeb\xb5\xe1\x9b\x1c\xb1\x6e\x9c\x67\xf2\x76\x81\x65\x7f\xe2\x0a"- , signature = "\x1e\x24\xe6\xe5\x86\x28\xe5\x17\x50\x44\xa9\xeb\x6d\x83\x7d\x48\xaf\x12\x60\xb0\x52\x0e\x87\x32\x7d\xe7\x89\x7e\xe4\xd5\xb9\xf0\xdf\x0b\xe3\xe0\x9e\xd4\xde\xa8\xc1\x45\x4f\xf3\x42\x3b\xb0\x8e\x17\x93\x24\x5a\x9d\xf8\xbf\x6a\xb3\x96\x8c\x8e\xdd\xc3\xb5\x32\x85\x71\xc7\x7f\x09\x1c\xc5\x78\x57\x69\x12\xdf\xeb\xd1\x64\xb9\xde\x54\x54\xfe\x0b\xe1\xc1\xf6\x38\x5b\x32\x83\x60\xce\x67\xec\x7a\x05\xf6\xe3\x0e\xb4\x5c\x17\xc4\x8a\xc7\x00\x41\xd2\xca\xb6\x7f\x0a\x2a\xe7\xaa\xfd\xcc\x8d\x24\x5e\xa3\x44\x2a\x63\x00\xcc\xc7"+ , -- Example 8.4+ VectorPSS+ { message =+ "\xdb\xc5\xf7\x50\xa7\xa1\x4b\xe2\xb9\x3e\x83\x8d\x18\xd1\x4a\x86\x95\xe5\x2e\x8a\xdd\x9c\x0a\xc7\x33\xb8\xf5\x6d\x27\x47\xe5\x29\xa0\xcc\xa5\x32\xdd\x49\xb9\x02\xae\xfe\xd5\x14\x44\x7f\x9e\x81\xd1\x61\x95\xc2\x85\x38\x68\xcb\x9b\x30\xf7\xd0\xd4\x95\xc6\x9d\x01\xb5\xc5\xd5\x0b\x27\x04\x5d\xb3\x86\x6c\x23\x24\xa4\x4a\x11\x0b\x17\x17\x74\x6d\xe4\x57\xd1\xc8\xc4\x5c\x3c\xd2\xa9\x29\x70\xc3\xd5\x96\x32\x05\x5d\x4c\x98\xa4\x1d\x6e\x99\xe2\xa3\xdd\xd5\xf7\xf9\x97\x9a\xb3\xcd\x18\xf3\x75\x05\xd2\x51\x41\xde\x2a\x1b\xff\x17\xb3\xa7\xdc\xe9\x41\x9e\xcc\x38\x5c\xf1\x1d\x72\x84\x0f\x19\x95\x3f\xd0\x50\x92\x51\xf6\xca\xfd\xe2\x89\x3d\x0e\x75\xc7\x81\xba\x7a\x50\x12\xca\x40\x1a\x4f\xa9\x9e\x04\xb3\xc3\x24\x9f\x92\x6d\x5a\xfe\x82\xcc\x87\xda\xb2\x2c\x3c\x1b\x10\x5d\xe4\x8e\x34\xac\xe9\xc9\x12\x4e\x59\x59\x7a\xc7\xeb\xf8"+ , salt =+ "\x02\x1f\xdc\xc6\xeb\xb5\xe1\x9b\x1c\xb1\x6e\x9c\x67\xf2\x76\x81\x65\x7f\xe2\x0a"+ , signature =+ "\x1e\x24\xe6\xe5\x86\x28\xe5\x17\x50\x44\xa9\xeb\x6d\x83\x7d\x48\xaf\x12\x60\xb0\x52\x0e\x87\x32\x7d\xe7\x89\x7e\xe4\xd5\xb9\xf0\xdf\x0b\xe3\xe0\x9e\xd4\xde\xa8\xc1\x45\x4f\xf3\x42\x3b\xb0\x8e\x17\x93\x24\x5a\x9d\xf8\xbf\x6a\xb3\x96\x8c\x8e\xdd\xc3\xb5\x32\x85\x71\xc7\x7f\x09\x1c\xc5\x78\x57\x69\x12\xdf\xeb\xd1\x64\xb9\xde\x54\x54\xfe\x0b\xe1\xc1\xf6\x38\x5b\x32\x83\x60\xce\x67\xec\x7a\x05\xf6\xe3\x0e\xb4\x5c\x17\xc4\x8a\xc7\x00\x41\xd2\xca\xb6\x7f\x0a\x2a\xe7\xaa\xfd\xcc\x8d\x24\x5e\xa3\x44\x2a\x63\x00\xcc\xc7" }- -- Example 8.5- , VectorPSS- { message = "\x04\xdc\x25\x1b\xe7\x2e\x88\xe5\x72\x34\x85\xb6\x38\x3a\x63\x7e\x2f\xef\xe0\x76\x60\xc5\x19\xa5\x60\xb8\xbc\x18\xbd\xed\xb8\x6e\xae\x23\x64\xea\x53\xba\x9d\xca\x6e\xb3\xd2\xe7\xd6\xb8\x06\xaf\x42\xb3\xe8\x7f\x29\x1b\x4a\x88\x81\xd5\xbf\x57\x2c\xc9\xa8\x5e\x19\xc8\x6a\xcb\x28\xf0\x98\xf9\xda\x03\x83\xc5\x66\xd3\xc0\xf5\x8c\xfd\x8f\x39\x5d\xcf\x60\x2e\x5c\xd4\x0e\x8c\x71\x83\xf7\x14\x99\x6e\x22\x97\xef"- , salt = "\xc5\x58\xd7\x16\x7c\xbb\x45\x08\xad\xa0\x42\x97\x1e\x71\xb1\x37\x7e\xea\x42\x69"- , signature = "\x33\x34\x1b\xa3\x57\x6a\x13\x0a\x50\xe2\xa5\xcf\x86\x79\x22\x43\x88\xd5\x69\x3f\x5a\xcc\xc2\x35\xac\x95\xad\xd6\x8e\x5e\xb1\xee\xc3\x16\x66\xd0\xca\x7a\x1c\xda\x6f\x70\xa1\xaa\x76\x2c\x05\x75\x2a\x51\x95\x0c\xdb\x8a\xf3\xc5\x37\x9f\x18\xcf\xe6\xb5\xbc\x55\xa4\x64\x82\x26\xa1\x5e\x91\x2e\xf1\x9a\xd7\x7a\xde\xea\x91\x1d\x67\xcf\xef\xd6\x9b\xa4\x3f\xa4\x11\x91\x35\xff\x64\x21\x17\xba\x98\x5a\x7e\x01\x00\x32\x5e\x95\x19\xf1\xca\x6a\x92\x16\xbd\xa0\x55\xb5\x78\x50\x15\x29\x11\x25\xe9\x0d\xcd\x07\xa2\xca\x96\x73\xee"+ , -- Example 8.5+ VectorPSS+ { message =+ "\x04\xdc\x25\x1b\xe7\x2e\x88\xe5\x72\x34\x85\xb6\x38\x3a\x63\x7e\x2f\xef\xe0\x76\x60\xc5\x19\xa5\x60\xb8\xbc\x18\xbd\xed\xb8\x6e\xae\x23\x64\xea\x53\xba\x9d\xca\x6e\xb3\xd2\xe7\xd6\xb8\x06\xaf\x42\xb3\xe8\x7f\x29\x1b\x4a\x88\x81\xd5\xbf\x57\x2c\xc9\xa8\x5e\x19\xc8\x6a\xcb\x28\xf0\x98\xf9\xda\x03\x83\xc5\x66\xd3\xc0\xf5\x8c\xfd\x8f\x39\x5d\xcf\x60\x2e\x5c\xd4\x0e\x8c\x71\x83\xf7\x14\x99\x6e\x22\x97\xef"+ , salt =+ "\xc5\x58\xd7\x16\x7c\xbb\x45\x08\xad\xa0\x42\x97\x1e\x71\xb1\x37\x7e\xea\x42\x69"+ , signature =+ "\x33\x34\x1b\xa3\x57\x6a\x13\x0a\x50\xe2\xa5\xcf\x86\x79\x22\x43\x88\xd5\x69\x3f\x5a\xcc\xc2\x35\xac\x95\xad\xd6\x8e\x5e\xb1\xee\xc3\x16\x66\xd0\xca\x7a\x1c\xda\x6f\x70\xa1\xaa\x76\x2c\x05\x75\x2a\x51\x95\x0c\xdb\x8a\xf3\xc5\x37\x9f\x18\xcf\xe6\xb5\xbc\x55\xa4\x64\x82\x26\xa1\x5e\x91\x2e\xf1\x9a\xd7\x7a\xde\xea\x91\x1d\x67\xcf\xef\xd6\x9b\xa4\x3f\xa4\x11\x91\x35\xff\x64\x21\x17\xba\x98\x5a\x7e\x01\x00\x32\x5e\x95\x19\xf1\xca\x6a\x92\x16\xbd\xa0\x55\xb5\x78\x50\x15\x29\x11\x25\xe9\x0d\xcd\x07\xa2\xca\x96\x73\xee" }- -- Example 8.6- , VectorPSS- { message = "\x0e\xa3\x7d\xf9\xa6\xfe\xa4\xa8\xb6\x10\x37\x3c\x24\xcf\x39\x0c\x20\xfa\x6e\x21\x35\xc4\x00\xc8\xa3\x4f\x5c\x18\x3a\x7e\x8e\xa4\xc9\xae\x09\x0e\xd3\x17\x59\xf4\x2d\xc7\x77\x19\xcc\xa4\x00\xec\xdc\xc5\x17\xac\xfc\x7a\xc6\x90\x26\x75\xb2\xef\x30\xc5\x09\x66\x5f\x33\x21\x48\x2f\xc6\x9a\x9f\xb5\x70\xd1\x5e\x01\xc8\x45\xd0\xd8\xe5\x0d\x2a\x24\xcb\xf1\xcf\x0e\x71\x49\x75\xa5\xdb\x7b\x18\xd9\xe9\xe9\xcb\x91\xb5\xcb\x16\x86\x90\x60\xed\x18\xb7\xb5\x62\x45\x50\x3f\x0c\xaf\x90\x35\x2b\x8d\xe8\x1c\xb5\xa1\xd9\xc6\x33\x60\x92\xf0\xcd"- , salt = "\x76\xfd\x4e\x64\xfd\xc9\x8e\xb9\x27\xa0\x40\x3e\x35\xa0\x84\xe7\x6b\xa9\xf9\x2a"- , signature = "\x1e\xd1\xd8\x48\xfb\x1e\xdb\x44\x12\x9b\xd9\xb3\x54\x79\x5a\xf9\x7a\x06\x9a\x7a\x00\xd0\x15\x10\x48\x59\x3e\x0c\x72\xc3\x51\x7f\xf9\xff\x2a\x41\xd0\xcb\x5a\x0a\xc8\x60\xd7\x36\xa1\x99\x70\x4f\x7c\xb6\xa5\x39\x86\xa8\x8b\xbd\x8a\xbc\xc0\x07\x6a\x2c\xe8\x47\x88\x00\x31\x52\x5d\x44\x9d\xa2\xac\x78\x35\x63\x74\xc5\x36\xe3\x43\xfa\xa7\xcb\xa4\x2a\x5a\xaa\x65\x06\x08\x77\x91\xc0\x6a\x8e\x98\x93\x35\xae\xd1\x9b\xfa\xb2\xd5\xe6\x7e\x27\xfb\x0c\x28\x75\xaf\x89\x6c\x21\xb6\xe8\xe7\x30\x9d\x04\xe4\xf6\x72\x7e\x69\x46\x3e"+ , -- Example 8.6+ VectorPSS+ { message =+ "\x0e\xa3\x7d\xf9\xa6\xfe\xa4\xa8\xb6\x10\x37\x3c\x24\xcf\x39\x0c\x20\xfa\x6e\x21\x35\xc4\x00\xc8\xa3\x4f\x5c\x18\x3a\x7e\x8e\xa4\xc9\xae\x09\x0e\xd3\x17\x59\xf4\x2d\xc7\x77\x19\xcc\xa4\x00\xec\xdc\xc5\x17\xac\xfc\x7a\xc6\x90\x26\x75\xb2\xef\x30\xc5\x09\x66\x5f\x33\x21\x48\x2f\xc6\x9a\x9f\xb5\x70\xd1\x5e\x01\xc8\x45\xd0\xd8\xe5\x0d\x2a\x24\xcb\xf1\xcf\x0e\x71\x49\x75\xa5\xdb\x7b\x18\xd9\xe9\xe9\xcb\x91\xb5\xcb\x16\x86\x90\x60\xed\x18\xb7\xb5\x62\x45\x50\x3f\x0c\xaf\x90\x35\x2b\x8d\xe8\x1c\xb5\xa1\xd9\xc6\x33\x60\x92\xf0\xcd"+ , salt =+ "\x76\xfd\x4e\x64\xfd\xc9\x8e\xb9\x27\xa0\x40\x3e\x35\xa0\x84\xe7\x6b\xa9\xf9\x2a"+ , signature =+ "\x1e\xd1\xd8\x48\xfb\x1e\xdb\x44\x12\x9b\xd9\xb3\x54\x79\x5a\xf9\x7a\x06\x9a\x7a\x00\xd0\x15\x10\x48\x59\x3e\x0c\x72\xc3\x51\x7f\xf9\xff\x2a\x41\xd0\xcb\x5a\x0a\xc8\x60\xd7\x36\xa1\x99\x70\x4f\x7c\xb6\xa5\x39\x86\xa8\x8b\xbd\x8a\xbc\xc0\x07\x6a\x2c\xe8\x47\x88\x00\x31\x52\x5d\x44\x9d\xa2\xac\x78\x35\x63\x74\xc5\x36\xe3\x43\xfa\xa7\xcb\xa4\x2a\x5a\xaa\x65\x06\x08\x77\x91\xc0\x6a\x8e\x98\x93\x35\xae\xd1\x9b\xfa\xb2\xd5\xe6\x7e\x27\xfb\x0c\x28\x75\xaf\x89\x6c\x21\xb6\xe8\xe7\x30\x9d\x04\xe4\xf6\x72\x7e\x69\x46\x3e" } ] doSignTest key i vector = testCase (show i) (Right (signature vector) @=? actual)- where actual = PSS.signWithSalt (salt vector) Nothing PSS.defaultPSSParamsSHA1 key (message vector)+ where+ actual =+ PSS.signWithSalt+ (salt vector)+ Nothing+ PSS.defaultPSSParamsSHA1+ key+ (message vector) doVerifyTest key i vector = testCase (show i) (True @=? actual)- where actual = PSS.verify PSS.defaultPSSParamsSHA1 (private_pub key) (message vector) (signature vector)+ where+ actual =+ PSS.verify+ PSS.defaultPSSParamsSHA1+ (private_pub key)+ (message vector)+ (signature vector) -pssTests = testGroup "RSA-PSS"- [ testGroup "signature internal"- [ doSignTest rsaKeyInt katZero vectorInt ]- , testGroup "verify internal"- [ 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- ]+pssTests =+ testGroup+ "RSA-PSS"+ [ testGroup+ "signature internal"+ [doSignTest rsaKeyInt katZero vectorInt]+ , testGroup+ "verify internal"+ [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+ ]
tests/KAT_PubKey/RSA.hs view
@@ -1,102 +1,130 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_PubKey.RSA (rsaTests) where -import qualified Crypto.PubKey.RSA as RSA+import Crypto.Hash+import qualified Crypto.PubKey.RSA as RSA import qualified Crypto.PubKey.RSA.PKCS15 as RSA-import Crypto.Hash--import Imports+import Data.Either -import Data.Either (isRight)+import Imports data VectorRSA = VectorRSA { size :: Int- , msg :: ByteString- , n :: Integer- , e :: Integer- , d :: Integer- , p :: Integer- , q :: Integer- , dP :: Integer- , dQ :: Integer+ , msg :: ByteString+ , n :: Integer+ , e :: Integer+ , d :: Integer+ , p :: Integer+ , q :: Integer+ , dP :: Integer+ , dQ :: Integer , qinv :: Integer- , sig :: Either RSA.Error ByteString+ , sig :: Either RSA.Error ByteString } +vectorsSHA1 :: [VectorRSA] vectorsSHA1 = [ VectorRSA { size = 2048 `div` 8- , msg = "The quick brown fox jumps over the lazy dog"- , n = 0x00c896c245fcca81775346c5f4f958229cab1aee08196dab4ee5959018b856aab93e4486f37a32da1a6804403c88473ecf9f1b9266fc682400d45329b6ec195710c98d9ba728bc09d767e7e9d9b8b102c3b7e7529b87f649a2a5ebe165da21863ec7842de600a834a8be2227bc989145b52f84ba685d45484a3d530745598a5d8a9e7551b3278bf139a770929f776aed5d43559205fe937df93eeb8ff3fb3f2ce22d4b8a5c17aeafd19758ac5e6251df09ef6a2858e8558a7f476dde4efe859ff2fcb97767614563033fd1d2d300196b1abf256f7badb16c17def3804946d1bf9cd51760176b41bbd506b44ff2bfe5bcd5052180da3cfbbc6cd6f662c06a8baed9- , e = 0x10001- , d = 0x58aa533bae8f310536d95cdd796e5cf655a7f4b9bdcbbd62859743f7b95c0de10e462a44ebaa18c07d640ba4f6344fee648d427ca56bbf2662b45407187be70173a655bc6104257182eb7f720ef2a79f2de6619c804ffca299a7179df6fac4a57179daf4052c550295f0f111ab7ae38e406ff219f9c88b38cdbcaac51bdc4e961361b87e100d168fc08b298626a806b3bfeaa9579f400bbe6e3e6e4ae9b27446e1c5ce8c10c848b9ad7b6ed3a6b3871ad6a1a88af24e581da054845c197e8bae1582858410087c1180c4f0cc61689abfd0f61b8031910f3b3779e11a7fbe823d9a704c63c313f78c994975de834ee9ead5faf6c18b3e4248c51ba307776bf845- , p = 0x00f85bfcfe55af59445f21f67ab1d8617d1f84360556eeb660d5c466f29e4d2228f9cc3fde4c594ea97069a19c666b68b6d905b65738ae63de6c11f9181ee9262313e5165591651bb3abec192abbc8c3694550bcffa451a2e2d1976bf3ecbc4480354f8d8646133298156aaa626b8807c5295850f93686400835466b6a5ccec61b- , q = 0x00cec28b22b1d37c6c60d25e9747cb1bebd1270f0306db56ed8533f392d6a0cfe6b3dde13789758cf89febac214ba96667e46599f89ca210dced550ca6092a854ff95dff80ea48ff1a83455f4bb93f2ececa782da03b85a789239e8be5264130628724ceab57c8f76e4c7e822bf4fbf334c7d32610bec65047433e0e3b636afe1b- , dP = 0x52fe0a50c339514f33ab19be6e67ac4c2f97f2a55e236ef674f8a89e329ffbe64d731f749d76ca7e7c7e0fef3f9a6ce78d260784a600408736fdda8b60e8f0419088612a3ee7d695f7c171b78200d8abf8e9bdfe7f5e785beb45fa610c9eed151abb76c383ef2e5cfbeb24fcb68a426e741e7b108c53d859e5d39e5970a1f839- , dQ = 0x39ef91853b47038a6ae707d2642fa9b73e782f60adbf307085eeb4c5e496532b56234a4481a40ac870275da846c74506bf9d28b3dd501c618baf5548013185018fe2a301c0a48bb726297e367dc6129ba7685d8094ad32f0dea64295074f24fbb6dabd7e8daea686a5b09d512be89d91a09cae01eb332eb389480e3cddf2d119- , qinv = 0x09ce1fa29008ef4b9798e5b8ec213dbdfec4fab4403ebf4b8786ad401ef33bc880c40a990b0826f72415192a206a504b27d2ba45ca555706200ea8e7a9b42d4077e9e6e0d80d4144966c53a36d23d30d987322dcc0013efe8df3b6b5914a2ceefc22cc5de6d569731794e9894f18f11d36a79558dc4c3ae5db1ce9bd05e7bf2e- , sig = Right "\x56\x66\x99\x0f\xd4\xea\x2b\xe0\x6d\x46\x3b\x10\x99\x5b\x06\x32\x5e\xec\x29\xfe\xa4\x63\x4d\x54\xf6\x31\x74\x5d\x01\x5a\x67\x09\x2e\xa7\x02\x8a\x48\x00\x3c\x0d\xef\x04\xe7\x52\x46\xe0\xfa\xb1\x42\x26\x89\xe7\xec\x25\x44\x76\xa0\x86\x33\xb0\xbe\x22\x17\x88\x9b\x18\x4d\x3e\xc2\x9b\xd4\x61\x2b\x9e\xde\x08\x56\xf8\xd5\xee\xb8\x38\xf4\x3d\xda\x9a\xbb\x34\x58\x87\x71\x1d\x1a\x7e\xc7\x3d\x46\x39\x01\x79\x29\x8b\xa4\xcd\xce\xd7\xab\xcb\x2e\x94\x5c\xfd\x54\xcc\xef\x80\x31\xfc\x5e\x8f\xc2\x4d\x76\x1e\x4c\xbc\x50\x7a\x9b\x08\xae\x85\xeb\x6a\xe0\x80\xdc\xff\x60\x13\xb0\x31\x94\x14\x9d\x8f\x9f\x48\x38\xcf\x4c\x82\x9d\x3b\x68\xc6\xe4\xe9\x5d\x94\x74\xa2\xac\x1f\xb9\x84\x41\x86\x11\xeb\x2c\x50\x64\xd7\x00\xe0\x85\x21\x5a\xd7\xae\x9b\x4c\x8e\x6a\x92\x97\xac\xcc\xb8\x38\x4f\x41\xb9\x3d\xa9\xfe\x69\x8b\x04\x81\xad\xfb\x0f\x49\x74\xfe\x26\x9c\x86\x0c\xf3\xd1\x8e\xa1\xb5\xaf\xef\x85\x3d\xfe\xd0\x7c\xcf\x18\xe4\x0f\x14\x99\xea\x93\x61\x79\x16\xbf\x38\xac\xa2\xa2\xac\xac\x2d\xae\x21\x85\x71\x94\xda\x5d\xa1\x82\xa8\x76\x82\xe5\x2f"+ , msg = "The quick brown fox jumps over the lazy dog"+ , n =+ 0x00c896c245fcca81775346c5f4f958229cab1aee08196dab4ee5959018b856aab93e4486f37a32da1a6804403c88473ecf9f1b9266fc682400d45329b6ec195710c98d9ba728bc09d767e7e9d9b8b102c3b7e7529b87f649a2a5ebe165da21863ec7842de600a834a8be2227bc989145b52f84ba685d45484a3d530745598a5d8a9e7551b3278bf139a770929f776aed5d43559205fe937df93eeb8ff3fb3f2ce22d4b8a5c17aeafd19758ac5e6251df09ef6a2858e8558a7f476dde4efe859ff2fcb97767614563033fd1d2d300196b1abf256f7badb16c17def3804946d1bf9cd51760176b41bbd506b44ff2bfe5bcd5052180da3cfbbc6cd6f662c06a8baed9+ , e = 0x10001+ , d =+ 0x58aa533bae8f310536d95cdd796e5cf655a7f4b9bdcbbd62859743f7b95c0de10e462a44ebaa18c07d640ba4f6344fee648d427ca56bbf2662b45407187be70173a655bc6104257182eb7f720ef2a79f2de6619c804ffca299a7179df6fac4a57179daf4052c550295f0f111ab7ae38e406ff219f9c88b38cdbcaac51bdc4e961361b87e100d168fc08b298626a806b3bfeaa9579f400bbe6e3e6e4ae9b27446e1c5ce8c10c848b9ad7b6ed3a6b3871ad6a1a88af24e581da054845c197e8bae1582858410087c1180c4f0cc61689abfd0f61b8031910f3b3779e11a7fbe823d9a704c63c313f78c994975de834ee9ead5faf6c18b3e4248c51ba307776bf845+ , p =+ 0x00f85bfcfe55af59445f21f67ab1d8617d1f84360556eeb660d5c466f29e4d2228f9cc3fde4c594ea97069a19c666b68b6d905b65738ae63de6c11f9181ee9262313e5165591651bb3abec192abbc8c3694550bcffa451a2e2d1976bf3ecbc4480354f8d8646133298156aaa626b8807c5295850f93686400835466b6a5ccec61b+ , q =+ 0x00cec28b22b1d37c6c60d25e9747cb1bebd1270f0306db56ed8533f392d6a0cfe6b3dde13789758cf89febac214ba96667e46599f89ca210dced550ca6092a854ff95dff80ea48ff1a83455f4bb93f2ececa782da03b85a789239e8be5264130628724ceab57c8f76e4c7e822bf4fbf334c7d32610bec65047433e0e3b636afe1b+ , dP =+ 0x52fe0a50c339514f33ab19be6e67ac4c2f97f2a55e236ef674f8a89e329ffbe64d731f749d76ca7e7c7e0fef3f9a6ce78d260784a600408736fdda8b60e8f0419088612a3ee7d695f7c171b78200d8abf8e9bdfe7f5e785beb45fa610c9eed151abb76c383ef2e5cfbeb24fcb68a426e741e7b108c53d859e5d39e5970a1f839+ , dQ =+ 0x39ef91853b47038a6ae707d2642fa9b73e782f60adbf307085eeb4c5e496532b56234a4481a40ac870275da846c74506bf9d28b3dd501c618baf5548013185018fe2a301c0a48bb726297e367dc6129ba7685d8094ad32f0dea64295074f24fbb6dabd7e8daea686a5b09d512be89d91a09cae01eb332eb389480e3cddf2d119+ , qinv =+ 0x09ce1fa29008ef4b9798e5b8ec213dbdfec4fab4403ebf4b8786ad401ef33bc880c40a990b0826f72415192a206a504b27d2ba45ca555706200ea8e7a9b42d4077e9e6e0d80d4144966c53a36d23d30d987322dcc0013efe8df3b6b5914a2ceefc22cc5de6d569731794e9894f18f11d36a79558dc4c3ae5db1ce9bd05e7bf2e+ , sig =+ Right+ "\x56\x66\x99\x0f\xd4\xea\x2b\xe0\x6d\x46\x3b\x10\x99\x5b\x06\x32\x5e\xec\x29\xfe\xa4\x63\x4d\x54\xf6\x31\x74\x5d\x01\x5a\x67\x09\x2e\xa7\x02\x8a\x48\x00\x3c\x0d\xef\x04\xe7\x52\x46\xe0\xfa\xb1\x42\x26\x89\xe7\xec\x25\x44\x76\xa0\x86\x33\xb0\xbe\x22\x17\x88\x9b\x18\x4d\x3e\xc2\x9b\xd4\x61\x2b\x9e\xde\x08\x56\xf8\xd5\xee\xb8\x38\xf4\x3d\xda\x9a\xbb\x34\x58\x87\x71\x1d\x1a\x7e\xc7\x3d\x46\x39\x01\x79\x29\x8b\xa4\xcd\xce\xd7\xab\xcb\x2e\x94\x5c\xfd\x54\xcc\xef\x80\x31\xfc\x5e\x8f\xc2\x4d\x76\x1e\x4c\xbc\x50\x7a\x9b\x08\xae\x85\xeb\x6a\xe0\x80\xdc\xff\x60\x13\xb0\x31\x94\x14\x9d\x8f\x9f\x48\x38\xcf\x4c\x82\x9d\x3b\x68\xc6\xe4\xe9\x5d\x94\x74\xa2\xac\x1f\xb9\x84\x41\x86\x11\xeb\x2c\x50\x64\xd7\x00\xe0\x85\x21\x5a\xd7\xae\x9b\x4c\x8e\x6a\x92\x97\xac\xcc\xb8\x38\x4f\x41\xb9\x3d\xa9\xfe\x69\x8b\x04\x81\xad\xfb\x0f\x49\x74\xfe\x26\x9c\x86\x0c\xf3\xd1\x8e\xa1\xb5\xaf\xef\x85\x3d\xfe\xd0\x7c\xcf\x18\xe4\x0f\x14\x99\xea\x93\x61\x79\x16\xbf\x38\xac\xa2\xa2\xac\xac\x2d\xae\x21\x85\x71\x94\xda\x5d\xa1\x82\xa8\x76\x82\xe5\x2f" } , VectorRSA { size = 360 `div` 8- , msg = "The quick brown fox jumps over the lazy dog"- , n = 0x00bc2d7481c83c8be55da4caeaf1a30dbf9a1226ba7443c0a66213180d3eb8e29c3162401b7be067dff8f571a8eb- , e = 0x10001- , d = 0x726fb62d82c707507a2d5055a6934136270d28ce350c3a36d89066e26fb54f5b33da0bc9a05c2084f2b39be4e1- , p = 0x0e3ff89e1f95a461c9f5ee480fd7b13529a225f3ee07fb- , q = 0x0d349ebc89329b493c03451ad20155de9775df55c55fd1- , dP = 0x00943adef9fb93a561967bab33f198c2c7414e777df997- , dQ = 0x078de99ceb5392f7f327dfb97717a27ae2e4606dddaa71+ , msg = "The quick brown fox jumps over the lazy dog"+ , n =+ 0x00bc2d7481c83c8be55da4caeaf1a30dbf9a1226ba7443c0a66213180d3eb8e29c3162401b7be067dff8f571a8eb+ , e = 0x10001+ , d =+ 0x726fb62d82c707507a2d5055a6934136270d28ce350c3a36d89066e26fb54f5b33da0bc9a05c2084f2b39be4e1+ , p = 0x0e3ff89e1f95a461c9f5ee480fd7b13529a225f3ee07fb+ , q = 0x0d349ebc89329b493c03451ad20155de9775df55c55fd1+ , dP = 0x00943adef9fb93a561967bab33f198c2c7414e777df997+ , dQ = 0x078de99ceb5392f7f327dfb97717a27ae2e4606dddaa71 , qinv = 0x0c54d59eaa029844fb3fe33a180161590b1cb103cc668e- , sig = Left RSA.SignatureTooLong+ , sig = Left RSA.SignatureTooLong } , VectorRSA { size = 368 `div` 8- , msg = "The quick brown fox jumps over the lazy dog"- , n = 0x009cff2fd20246e390d6860b48a3926e83086d1386f7147e9f195623cf8f18546ceb20d428b77e0748864c8f611cb7- , e = 0x10001- , d = 0x0097706cbf6624dd448c3a36ce35c27d49762a4948ca33804178d2ff826f8d336aaed622801c8d76d442be371da841- , p = 0x00d12519f81441069ab1a86c38e0065e9578a46e655d5a17- , q = 0x00c02b485ac3ee241d57b6b282f830d7d5bf6f4de75c1661- , dP = 0x00a1af4611444f34f4d88d7504cf23fd711e70382c42ec07- , dQ = 0x04226a4219a90bf9dda33e9ff6bb0649c0fea20c723cc1+ , msg = "The quick brown fox jumps over the lazy dog"+ , n =+ 0x009cff2fd20246e390d6860b48a3926e83086d1386f7147e9f195623cf8f18546ceb20d428b77e0748864c8f611cb7+ , e = 0x10001+ , d =+ 0x0097706cbf6624dd448c3a36ce35c27d49762a4948ca33804178d2ff826f8d336aaed622801c8d76d442be371da841+ , p = 0x00d12519f81441069ab1a86c38e0065e9578a46e655d5a17+ , q = 0x00c02b485ac3ee241d57b6b282f830d7d5bf6f4de75c1661+ , dP = 0x00a1af4611444f34f4d88d7504cf23fd711e70382c42ec07+ , dQ = 0x04226a4219a90bf9dda33e9ff6bb0649c0fea20c723cc1 , qinv = 0x5dd87bf3c1e295dcc8602859a7cd74f05a2fe91a9d5877- , sig = Right "\x51\xe4\xdd\x98\xee\xd5\x06\xef\x7a\xa5\x3c\xaf\x29\x33\xa4\x91\xfa\x8b\xb8\x09\xcf\x3e\xa1\x64\x92\x71\xad\x7b\x3a\x83\xb2\xa0\x77\x94\x4e\x59\xdf\x69\x58\x2e\xc8\x8d\xa0\x70\xfe\x7d"+ , sig =+ Right+ "\x51\xe4\xdd\x98\xee\xd5\x06\xef\x7a\xa5\x3c\xaf\x29\x33\xa4\x91\xfa\x8b\xb8\x09\xcf\x3e\xa1\x64\x92\x71\xad\x7b\x3a\x83\xb2\xa0\x77\x94\x4e\x59\xdf\x69\x58\x2e\xc8\x8d\xa0\x70\xfe\x7d" } ] vectorToPrivate :: VectorRSA -> RSA.PrivateKey-vectorToPrivate vector = RSA.PrivateKey- { RSA.private_pub = vectorToPublic vector- , RSA.private_d = d vector- , RSA.private_p = p vector- , RSA.private_q = q vector- , RSA.private_dP = dP vector- , RSA.private_dQ = dQ vector- , RSA.private_qinv = qinv vector- }+vectorToPrivate vector =+ RSA.PrivateKey+ { RSA.private_pub = vectorToPublic vector+ , RSA.private_d = d vector+ , RSA.private_p = p vector+ , RSA.private_q = q vector+ , RSA.private_dP = dP vector+ , RSA.private_dQ = dQ vector+ , RSA.private_qinv = qinv vector+ } vectorToPublic :: VectorRSA -> RSA.PublicKey-vectorToPublic vector = RSA.PublicKey- { RSA.public_size = size vector- , RSA.public_n = n vector- , RSA.public_e = e vector- }+vectorToPublic vector =+ RSA.PublicKey+ { RSA.public_size = size vector+ , RSA.public_n = n vector+ , RSA.public_e = e vector+ } vectorHasSignature :: VectorRSA -> Bool vectorHasSignature = isRight . sig +doSignatureTest :: Show a => a -> VectorRSA -> TestTree doSignatureTest i vector = testCase (show i) (expected @=? actual)- where expected = sig vector- actual = RSA.sign Nothing (Just SHA1) (vectorToPrivate vector) (msg vector)+ where+ expected = sig vector+ actual = RSA.sign Nothing (Just SHA1) (vectorToPrivate vector) (msg vector) +doVerifyTest :: Show a => a -> VectorRSA -> TestTree doVerifyTest i vector = testCase (show i) (True @=? actual)- where actual = RSA.verify (Just SHA1) (vectorToPublic vector) (msg vector) bs- Right bs = sig vector+ where+ actual = RSA.verify (Just SHA1) (vectorToPublic vector) (msg vector) bs+ bs = fromRight (error "doVerifyTest") $ sig vector -rsaTests = testGroup "RSA"- [ testGroup "SHA1"- [ testGroup "signature" $ zipWith doSignatureTest [katZero..] vectorsSHA1- , testGroup "verify" $ zipWith doVerifyTest [katZero..] $ filter vectorHasSignature vectorsSHA1+rsaTests :: TestTree+rsaTests =+ testGroup+ "RSA"+ [ testGroup+ "SHA1"+ [ testGroup "signature" $ zipWith doSignatureTest [katZero ..] vectorsSHA1+ , testGroup "verify" $+ zipWith doVerifyTest [katZero ..] $+ filter vectorHasSignature vectorsSHA1+ ] ]- ]
tests/KAT_PubKey/Rabin.hs view
@@ -1,47 +1,67 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_PubKey.Rabin (rabinTests) where import qualified Data.ByteString as B -import Crypto.Hash-import Crypto.Number.Serialize (os2ip)+import Crypto.Hash+import Crypto.Number.Serialize (os2ip) import qualified Crypto.PubKey.Rabin.Basic as BRabin import qualified Crypto.PubKey.Rabin.Modified as MRabin import qualified Crypto.PubKey.Rabin.OAEP as OAEP import qualified Crypto.PubKey.Rabin.RW as RW -import Imports+import Imports -basicRabinKey = BRabin.PrivateKey- { BRabin.private_pub = BRabin.PublicKey- { BRabin.public_n = 0xc9c4b0df9db989d93df4137fc2de2a9cee2610523f7a450ecbbf252babe98fba2f8e389c3e420c081e18f584c5746ca43f77f6af1fc79161f8bf8fbcb9564779986ecbe656dd16740cb8e399c33ff1dcc679e73c9c98a58c65a8673b7de57290a2d3191cb27e29d627f7ec6e874b1406051ffe9181e4d90d1b487b100ad30685 - , BRabin.public_size = 128+basicRabinKey =+ BRabin.PrivateKey+ { BRabin.private_pub =+ BRabin.PublicKey+ { BRabin.public_n =+ 0xc9c4b0df9db989d93df4137fc2de2a9cee2610523f7a450ecbbf252babe98fba2f8e389c3e420c081e18f584c5746ca43f77f6af1fc79161f8bf8fbcb9564779986ecbe656dd16740cb8e399c33ff1dcc679e73c9c98a58c65a8673b7de57290a2d3191cb27e29d627f7ec6e874b1406051ffe9181e4d90d1b487b100ad30685+ , BRabin.public_size = 128+ }+ , BRabin.private_p =+ 0xe071f231ab5912285a1f8db199795f5efdea4c32f646a3436eaec091ba853a3092216f26b539bbac1fe2ab2e4fbb20aad272a434a1e909bf6d3028aecae2a7b7+ , BRabin.private_q =+ 0xe6229470dc7da58bfcd962f1b3ddcf52304efbfb91d31c8ed84dbae2380c1ad2e338a523b4250863a689b3f262f949bd7a9f1a603c36634bb932dd71bf5daba3+ , BRabin.private_a =+ 0x65956653f711a63b776ce45862d4cd78f1ad7b1f8ed118bb8b5ea5fffd59762da5dc7c5298e236a8e45d5c93477cbc51f214b1cd1a4980eda859c1cb05e55666+ , BRabin.private_b =+ -0x63126dd9c5d6b5215f62012885570e1306b6a47ec1c46553f3b13ceae869149d14544438dbb976800cd62fbb52266f9a6405bc91f192a462c974bc8a6f832e03 }- , BRabin.private_p = 0xe071f231ab5912285a1f8db199795f5efdea4c32f646a3436eaec091ba853a3092216f26b539bbac1fe2ab2e4fbb20aad272a434a1e909bf6d3028aecae2a7b7- , BRabin.private_q = 0xe6229470dc7da58bfcd962f1b3ddcf52304efbfb91d31c8ed84dbae2380c1ad2e338a523b4250863a689b3f262f949bd7a9f1a603c36634bb932dd71bf5daba3- , BRabin.private_a = 0x65956653f711a63b776ce45862d4cd78f1ad7b1f8ed118bb8b5ea5fffd59762da5dc7c5298e236a8e45d5c93477cbc51f214b1cd1a4980eda859c1cb05e55666- , BRabin.private_b = -0x63126dd9c5d6b5215f62012885570e1306b6a47ec1c46553f3b13ceae869149d14544438dbb976800cd62fbb52266f9a6405bc91f192a462c974bc8a6f832e03- } -modifiedRabinKey = MRabin.PrivateKey- { MRabin.private_pub = MRabin.PublicKey- { MRabin.public_n = 0x9461a6e7c55cb610f20fd9af5d642404a63332a8d7c4fe7aa559cbcaec691e7216eed5d9322cb6a8619c220a0241b44e0d0a7cefda01fb84e59722b4e842ab5e190d214424bbdfed6d523426fc57a28045dfbb6e8159123077c542c0278ee2daf2d8993e286bf709a10a948da6b13008441581a22233f0ad3d5ebc5858ff7be5 - , MRabin.public_size = 128+modifiedRabinKey =+ MRabin.PrivateKey+ { MRabin.private_pub =+ MRabin.PublicKey+ { MRabin.public_n =+ 0x9461a6e7c55cb610f20fd9af5d642404a63332a8d7c4fe7aa559cbcaec691e7216eed5d9322cb6a8619c220a0241b44e0d0a7cefda01fb84e59722b4e842ab5e190d214424bbdfed6d523426fc57a28045dfbb6e8159123077c542c0278ee2daf2d8993e286bf709a10a948da6b13008441581a22233f0ad3d5ebc5858ff7be5+ , MRabin.public_size = 128+ }+ , MRabin.private_p =+ 0xc401e0ddbe565a8797292389bebb561c35eb019116ba25cc6c865a8d3d7bc599626ddf0bc4f575c22f89144fe99fc3300dd497ec2b7acc0221e729a61756b3f3+ , MRabin.private_q =+ 0xc1cc0e35f23f5086691a18c755881e3fe6937581948b109f47605b45d055e7b352e19ff729dfb33fbecb1d28b115e590449e5e4e228ab1876d889d3d41d87ec7+ , MRabin.private_d =+ 0x128c34dcf8ab96c21e41fb35ebac848094c666551af89fcf54ab39795d8d23ce42dddabb264596d50c33844140483689c1a14f9dfb403f709cb2e4569d08556b9267e6460e84c69beda1defabd0285c4852c288b7ac27b78987bd19da337a6b1c7b123476732d9c0f656cc62a17f70e8fe34516cfa85ce6475bddeae9ffa0926 }- , MRabin.private_p = 0xc401e0ddbe565a8797292389bebb561c35eb019116ba25cc6c865a8d3d7bc599626ddf0bc4f575c22f89144fe99fc3300dd497ec2b7acc0221e729a61756b3f3- , MRabin.private_q = 0xc1cc0e35f23f5086691a18c755881e3fe6937581948b109f47605b45d055e7b352e19ff729dfb33fbecb1d28b115e590449e5e4e228ab1876d889d3d41d87ec7 - , MRabin.private_d = 0x128c34dcf8ab96c21e41fb35ebac848094c666551af89fcf54ab39795d8d23ce42dddabb264596d50c33844140483689c1a14f9dfb403f709cb2e4569d08556b9267e6460e84c69beda1defabd0285c4852c288b7ac27b78987bd19da337a6b1c7b123476732d9c0f656cc62a17f70e8fe34516cfa85ce6475bddeae9ffa0926- } -rwKey = RW.PrivateKey- { RW.private_pub = RW.PublicKey- { RW.public_n = 0x992db4c84564c68d4ee2fe0903d938b41e83bcac48dfe8f2219ccee2ccbdefda4cbeea9f1c98a515c5f39a458f5ea11bca97102aaa3d9ac69e000093024e7b968359287cdf57bdacff5df1893df3539c7e358f037d49b5c6ae7110ab8117220c73b6265987039c2c97078fccacdd3f5a560aff5076fdc3958c532db28ab9a855 - , RW.public_size = 128+rwKey =+ RW.PrivateKey+ { RW.private_pub =+ RW.PublicKey+ { RW.public_n =+ 0x992db4c84564c68d4ee2fe0903d938b41e83bcac48dfe8f2219ccee2ccbdefda4cbeea9f1c98a515c5f39a458f5ea11bca97102aaa3d9ac69e000093024e7b968359287cdf57bdacff5df1893df3539c7e358f037d49b5c6ae7110ab8117220c73b6265987039c2c97078fccacdd3f5a560aff5076fdc3958c532db28ab9a855+ , RW.public_size = 128+ }+ , RW.private_p =+ 0xc144dd739c45397d61868ca944a9729a7ad34cf90466c8f5c98a88f5ab5e3288bcfd31d4af1d441d23a756a60abd4cf05c3e0b0053eb150166a327ae31e9347b+ , RW.private_q =+ 0xcae5a381f25a27ae2c359068753118fc384471cd6027e88b8b910306fb940781261089259a3c569546677aebd268704c767a071dbd4f50cb9f15fe448788856f+ , RW.private_d =+ 0x1325b69908ac98d1a9dc5fc1207b271683d07795891bfd1e443399dc5997bdfb4997dd53e39314a2b8be7348b1ebd4237952e2055547b358d3c000126049cf729ee5d4f0ea170b902e343a8ef0831900b963ba07a3176088ab2ab095db449d0052150d6be7b5402f459f17c759f6f043b06a5da64cb86bb910d340f7fa28fdce }- , RW.private_p = 0xc144dd739c45397d61868ca944a9729a7ad34cf90466c8f5c98a88f5ab5e3288bcfd31d4af1d441d23a756a60abd4cf05c3e0b0053eb150166a327ae31e9347b- , RW.private_q = 0xcae5a381f25a27ae2c359068753118fc384471cd6027e88b8b910306fb940781261089259a3c569546677aebd268704c767a071dbd4f50cb9f15fe448788856f- , RW.private_d = 0x1325b69908ac98d1a9dc5fc1207b271683d07795891bfd1e443399dc5997bdfb4997dd53e39314a2b8be7348b1ebd4237952e2055547b358d3c000126049cf729ee5d4f0ea170b902e343a8ef0831900b963ba07a3176088ab2ab095db449d0052150d6be7b5402f459f17c759f6f043b06a5da64cb86bb910d340f7fa28fdce- } data EncryptionVector = EncryptionVector { seed :: ByteString@@ -49,7 +69,7 @@ , cipherText :: ByteString } -data SignatureVector = SignatureVector +data SignatureVector = SignatureVector { message :: ByteString , padding :: ByteString , signature :: Integer@@ -57,89 +77,166 @@ basicRabinEncryptionVectors = [ EncryptionVector- { plainText = "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5"- , seed = "\x0c\xc7\x42\xce\x4a\x9b\x7f\x32\xf9\x51\xbc\xb2\x51\xef\xd9\x25\xfe\x4f\xe3\x5f"- , cipherText = "\xaf\xc7\x03\xe3\x9d\x2f\x81\xc6\x3a\x80\x2a\xd1\x44\x26\x3f\x17\x0c\x0a\xe6\x48\x68\x98\x23\x14\x8f\x95\xd2\xce\xbb\xe7\x3f\x49\x34\x76\x1d\x99\x30\x7b\xeb\x84\xe5\x2a\x10\xd2\x1e\x11\x7e\x65\xe8\x88\x24\xc1\x12\xeb\x19\x0d\x97\xcd\x12\x25\x6b\x1f\x9b\x0c\x40\x40\xa3\x47\x00\xb7\x11\xf8\x50\x08\x51\x79\xe8\x1b\xd1\x77\xe0\x99\xa7\xe1\x5c\x63\xda\x29\xc7\xde\x28\x5d\x60\xed\x8e\xb2\x12\xd4\xfe\xb8\x1a\x5d\x17\x65\x80\x62\x6e\x65\x5c\x37\x07\x1c\xfa\xff\xe6\x21\xa5\x9f\xcd\x6a\x6a\xce\xa6\x96\xb2\xc5\x08\xe6"- } + { plainText =+ "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5"+ , seed =+ "\x0c\xc7\x42\xce\x4a\x9b\x7f\x32\xf9\x51\xbc\xb2\x51\xef\xd9\x25\xfe\x4f\xe3\x5f"+ , cipherText =+ "\xaf\xc7\x03\xe3\x9d\x2f\x81\xc6\x3a\x80\x2a\xd1\x44\x26\x3f\x17\x0c\x0a\xe6\x48\x68\x98\x23\x14\x8f\x95\xd2\xce\xbb\xe7\x3f\x49\x34\x76\x1d\x99\x30\x7b\xeb\x84\xe5\x2a\x10\xd2\x1e\x11\x7e\x65\xe8\x88\x24\xc1\x12\xeb\x19\x0d\x97\xcd\x12\x25\x6b\x1f\x9b\x0c\x40\x40\xa3\x47\x00\xb7\x11\xf8\x50\x08\x51\x79\xe8\x1b\xd1\x77\xe0\x99\xa7\xe1\x5c\x63\xda\x29\xc7\xde\x28\x5d\x60\xed\x8e\xb2\x12\xd4\xfe\xb8\x1a\x5d\x17\x65\x80\x62\x6e\x65\x5c\x37\x07\x1c\xfa\xff\xe6\x21\xa5\x9f\xcd\x6a\x6a\xce\xa6\x96\xb2\xc5\x08\xe6"+ } ] basicRabinSignatureVectors = [ SignatureVector- { message = "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5"+ { message =+ "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5" , padding = "\xe9\x87\x17\x15\xa2\xe4\x30\x15"- , signature = 0xac95807bdd03ca975690151d39d23d75e5db2731c4ba30b83c3f3ea74709e4d4e340d7dab952356a76c9b8705b214e28d59f5bdc7c7fdff4e104569e30359b5c65c2dcd5b94db58505cd8b188267121700beebd7edbee492e374514646471b5c3fa252a2580dc7343f455683815d6d7c590dd3bcaa7df41d8b08197ccb183408- } + , signature =+ 0xac95807bdd03ca975690151d39d23d75e5db2731c4ba30b83c3f3ea74709e4d4e340d7dab952356a76c9b8705b214e28d59f5bdc7c7fdff4e104569e30359b5c65c2dcd5b94db58505cd8b188267121700beebd7edbee492e374514646471b5c3fa252a2580dc7343f455683815d6d7c590dd3bcaa7df41d8b08197ccb183408+ } ] modifiedRabinSignatureVectors = [ SignatureVector- { message = "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5"+ { message =+ "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5" , padding = B.empty -- not used- , signature = 0x278c7c269119218ab7f501ea53a97ab15a3a5a263c6daed8980abec78291e9729e0e3457731cdea8ec31a7566e93d10fc9b2615fe3e54f4533a5506ac24a3bd286e270324e538066f0ddf503f9b5e0c18e18379659834906ebd99c0d31588c66e70fc653bc8865b9239999cbd35704917d8647d1199286c533233e3e03582dd- } + , signature =+ 0x278c7c269119218ab7f501ea53a97ab15a3a5a263c6daed8980abec78291e9729e0e3457731cdea8ec31a7566e93d10fc9b2615fe3e54f4533a5506ac24a3bd286e270324e538066f0ddf503f9b5e0c18e18379659834906ebd99c0d31588c66e70fc653bc8865b9239999cbd35704917d8647d1199286c533233e3e03582dd+ } ]- + rwEncryptionVectors = [ EncryptionVector- { plainText = "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5"- , seed = "\x0c\xc7\x42\xce\x4a\x9b\x7f\x32\xf9\x51\xbc\xb2\x51\xef\xd9\x25\xfe\x4f\xe3\x5f"- , cipherText = "\x40\xc2\xe3\x36\xac\x46\x72\x8a\xaf\x33\x75\xe1\x27\xd0\x38\x40\xe2\x24\x4e\x20\xa7\x5d\x85\xd3\x74\x81\x21\xfd\xc9\x40\x90\x80\x8c\xed\x2d\xd3\x5b\xc4\xb7\xc9\x7c\x80\xa5\x2f\x63\x86\x34\x4e\x8c\x92\x07\x86\x9e\xda\xfd\xf8\x11\x83\x8a\x5a\x23\xc1\xe6\x77\x37\x5d\xf9\x5c\x60\xd1\x6d\xfd\x0c\x54\xd1\x00\xe9\xab\x97\x6d\x8e\x83\x8b\x6e\x1a\x38\x73\x43\xe2\x24\xc2\xe2\x4e\x74\x3f\xe4\x4d\xdd\x27\xed\xc7\x72\x88\xd3\x0f\x93\xb3\xdb\xa2\xb7\xaf\x6d\xe9\xab\x76\x53\x63\xf9\x62\xd7\x52\x44\x61\x60\x5d\x2e\x9b\xf7"- } + { plainText =+ "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5"+ , seed =+ "\x0c\xc7\x42\xce\x4a\x9b\x7f\x32\xf9\x51\xbc\xb2\x51\xef\xd9\x25\xfe\x4f\xe3\x5f"+ , cipherText =+ "\x40\xc2\xe3\x36\xac\x46\x72\x8a\xaf\x33\x75\xe1\x27\xd0\x38\x40\xe2\x24\x4e\x20\xa7\x5d\x85\xd3\x74\x81\x21\xfd\xc9\x40\x90\x80\x8c\xed\x2d\xd3\x5b\xc4\xb7\xc9\x7c\x80\xa5\x2f\x63\x86\x34\x4e\x8c\x92\x07\x86\x9e\xda\xfd\xf8\x11\x83\x8a\x5a\x23\xc1\xe6\x77\x37\x5d\xf9\x5c\x60\xd1\x6d\xfd\x0c\x54\xd1\x00\xe9\xab\x97\x6d\x8e\x83\x8b\x6e\x1a\x38\x73\x43\xe2\x24\xc2\xe2\x4e\x74\x3f\xe4\x4d\xdd\x27\xed\xc7\x72\x88\xd3\x0f\x93\xb3\xdb\xa2\xb7\xaf\x6d\xe9\xab\x76\x53\x63\xf9\x62\xd7\x52\x44\x61\x60\x5d\x2e\x9b\xf7"+ } ] rwSignatureVectors = [ SignatureVector- { message = "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5"+ { message =+ "\x75\x0c\x40\x47\xf5\x47\xe8\xe4\x14\x11\x85\x65\x23\x29\x8a\xc9\xba\xe2\x45\xef\xaf\x13\x97\xfb\xe5\x6f\x9d\xd5" , padding = B.empty -- not used- , signature = 0x1e57b554a8e83aacd9d4067f9535991e7db47803250cded5cc8af5458a6bb11fea852139e0afe143f9339dd94a518e354e702134d1ae222460127829d92e8bf6441336f5ae7044ec7b6c3ad8b9aeeb1ea02a49798e020cb5b558120bbb51f060eb1608ba68f90cac7edb1051c177d3bdbb99d1ad92e8d75d6f72f1d06f1d25be- } + , signature =+ 0x1e57b554a8e83aacd9d4067f9535991e7db47803250cded5cc8af5458a6bb11fea852139e0afe143f9339dd94a518e354e702134d1ae222460127829d92e8bf6441336f5ae7044ec7b6c3ad8b9aeeb1ea02a49798e020cb5b558120bbb51f060eb1608ba68f90cac7edb1051c177d3bdbb99d1ad92e8d75d6f72f1d06f1d25be+ } ] doBasicRabinEncryptTest key i vector = testCase (show i) (Right (cipherText vector) @=? actual)- where actual = BRabin.encryptWithSeed (seed vector) (OAEP.defaultOAEPParams SHA1) key (plainText vector)+ where+ actual =+ BRabin.encryptWithSeed+ (seed vector)+ (OAEP.defaultOAEPParams SHA1)+ key+ (plainText vector) doBasicRabinDecryptTest key i vector = testCase (show i) (Just (plainText vector) @=? actual)- where actual = BRabin.decrypt (OAEP.defaultOAEPParams SHA1) key (cipherText vector)+ 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)- where actual = BRabin.signWith (padding vector) key SHA1 (message vector)+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)- where actual = BRabin.verify key SHA1 (message vector) (BRabin.Signature ((os2ip $ padding vector), (signature vector)))+ 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)- where actual = MRabin.sign key SHA1 (message vector)+ where+ actual = MRabin.sign key SHA1 (message vector) doModifiedRabinVerifyTest key i vector = testCase (show i) (True @=? actual)- where actual = MRabin.verify key SHA1 (message vector) (signature vector)+ 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)+ where+ actual =+ RW.encryptWithSeed+ (seed vector)+ (OAEP.defaultOAEPParams SHA1)+ key+ (plainText vector) doRwDecryptTest key i vector = testCase (show i) (Just (plainText vector) @=? actual)- where actual = RW.decrypt (OAEP.defaultOAEPParams SHA1) key (cipherText vector)+ where+ actual = RW.decrypt (OAEP.defaultOAEPParams SHA1) key (cipherText vector) doRwSignTest key i vector = testCase (show i) (Right (signature vector) @=? actual)- where actual = RW.sign key SHA1 (message vector)+ where+ actual = RW.sign key SHA1 (message vector) doRwVerifyTest key i vector = testCase (show i) (True @=? actual)- where actual = RW.verify key SHA1 (message vector) (signature vector)+ where+ actual = RW.verify key SHA1 (message vector) (signature vector) -rabinTests = testGroup "Rabin"- [ testGroup "Basic"- [ 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" $ zipWith (doModifiedRabinSignTest modifiedRabinKey) [katZero..] modifiedRabinSignatureVectors- , testGroup "verify" $ zipWith (doModifiedRabinVerifyTest $ MRabin.private_pub modifiedRabinKey) [katZero..] modifiedRabinSignatureVectors- ]- , testGroup "RW"- [ 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+rabinTests =+ testGroup+ "Rabin"+ [ testGroup+ "Basic"+ [ 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" $+ zipWith+ (doModifiedRabinSignTest modifiedRabinKey)+ [katZero ..]+ modifiedRabinSignatureVectors+ , testGroup "verify" $+ zipWith+ (doModifiedRabinVerifyTest $ MRabin.private_pub modifiedRabinKey)+ [katZero ..]+ modifiedRabinSignatureVectors+ ]+ , testGroup+ "RW"+ [ 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+ ] ]- ]
tests/KAT_RC4.hs view
@@ -1,34 +1,42 @@-{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ViewPatterns #-}+ module KAT_RC4 where import Test.Tasty import Test.Tasty.HUnit +import qualified Crypto.Cipher.RC4 as RC4 import Data.ByteString (ByteString) import Data.ByteString.Char8 ()-import qualified Crypto.Cipher.RC4 as RC4 -- taken from wikipedia pages vectors :: [(ByteString, ByteString, ByteString)] vectors =- [ ("Key"- ,"Plaintext"- ,"\xBB\xF3\x16\xE8\xD9\x40\xAF\x0A\xD3"+ [+ ( "Key"+ , "Plaintext"+ , "\xBB\xF3\x16\xE8\xD9\x40\xAF\x0A\xD3" )- , ("Wiki"- ,"pedia"- ,"\x10\x21\xBF\x04\x20"+ ,+ ( "Wiki"+ , "pedia"+ , "\x10\x21\xBF\x04\x20" )- , ("Secret"- ,"Attack at dawn"- ,"\x45\xA0\x1F\x64\x5F\xC3\x5B\x38\x35\x52\x54\x4B\x9B\xF5"+ ,+ ( "Secret"+ , "Attack at dawn"+ , "\x45\xA0\x1F\x64\x5F\xC3\x5B\x38\x35\x52\x54\x4B\x9B\xF5" ) ] -tests = testGroup "RC4"- $ 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..]+tests =+ testGroup "RC4" $+ 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 ..]
tests/KAT_Scrypt.hs view
@@ -1,33 +1,41 @@ {-# LANGUAGE OverloadedStrings #-}+ module KAT_Scrypt (tests) where import Data.ByteString (ByteString) import Data.ByteString.Char8 () +import Data.Word import Test.Tasty import Test.Tasty.HUnit-import Data.Word import qualified Crypto.KDF.Scrypt as Scrypt -vectors :: [ ((ByteString, ByteString, Word64, Int, Int, Int), ByteString) ]+vectors :: [((ByteString, ByteString, Word64, Int, Int, Int), ByteString)] vectors = [ ( ("", "", 16, 1, 1, 64) , "\x77\xd6\x57\x62\x38\x65\x7b\x20\x3b\x19\xca\x42\xc1\x8a\x04\x97\xf1\x6b\x48\x44\xe3\x07\x4a\xe8\xdf\xdf\xfa\x3f\xed\xe2\x14\x42\xfc\xd0\x06\x9d\xed\x09\x48\xf8\x32\x6a\x75\x3a\x0f\xc8\x1f\x17\xe8\xd3\xe0\xfb\x2e\x0d\x36\x28\xcf\x35\xe2\x0c\x38\xd1\x89\x06" )- , ( ("password", "NaCl", 1024, 8, 16, 64)+ ,+ ( ("password", "NaCl", 1024, 8, 16, 64) , "\xfd\xba\xbe\x1c\x9d\x34\x72\x00\x78\x56\xe7\x19\x0d\x01\xe9\xfe\x7c\x6a\xd7\xcb\xc8\x23\x78\x30\xe7\x73\x76\x63\x4b\x37\x31\x62\x2e\xaf\x30\xd9\x2e\x22\xa3\x88\x6f\xf1\x09\x27\x9d\x98\x30\xda\xc7\x27\xaf\xb9\x4a\x83\xee\x6d\x83\x60\xcb\xdf\xa2\xcc\x06\x40" )- , ( ("pleaseletmein", "SodiumChloride", 16384, 8, 1, 64)+ ,+ ( ("pleaseletmein", "SodiumChloride", 16384, 8, 1, 64) , "\x70\x23\xbd\xcb\x3a\xfd\x73\x48\x46\x1c\x06\xcd\x81\xfd\x38\xeb\xfd\xa8\xfb\xba\x90\x4f\x8e\x3e\xa9\xb5\x43\xf6\x54\x5d\xa1\xf2\xd5\x43\x29\x55\x61\x3f\x0f\xcf\x62\xd4\x97\x05\x24\x2a\x9a\xf9\xe6\x1e\x85\xdc\x0d\x65\x1e\x40\xdf\xcf\x01\x7b\x45\x57\x58\x87" )- , ( ("pleaseletmein", "SodiumChloride", 1048576, 8, 1, 64)+ ,+ ( ("pleaseletmein", "SodiumChloride", 1048576, 8, 1, 64) , "\x21\x01\xcb\x9b\x6a\x51\x1a\xae\xad\xdb\xbe\x09\xcf\x70\xf8\x81\xec\x56\x8d\x57\x4a\x2f\xfd\x4d\xab\xe5\xee\x98\x20\xad\xaa\x47\x8e\x56\xfd\x8f\x4b\xa5\xd0\x9f\xfa\x1c\x6d\x92\x7c\x40\xf4\xc3\x37\x30\x40\x49\xe8\xa9\x52\xfb\xcb\xf4\x5c\x6f\xa7\x7a\x41\xa4" ) ] -tests = testGroup "Scrypt"- $ 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)+tests =+ testGroup "Scrypt" $+ 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)
tests/KAT_TripleDES.hs view
@@ -1,12 +1,14 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ViewPatterns #-}+ module KAT_TripleDES (tests) where -import Imports import BlockCipher import qualified Crypto.Cipher.TripleDES as TripleDES+import Imports kats = defaultKATs -tests = localOption (QuickCheckTests 5)- $ testBlockCipher kats (undefined :: TripleDES.DES_EEE3)+tests =+ localOption (QuickCheckTests 5) $+ testBlockCipher kats (undefined :: TripleDES.DES_EEE3)
tests/KAT_Twofish.hs view
@@ -1,45 +1,388 @@ module KAT_Twofish (tests) where -import Imports import BlockCipher+import Imports -import qualified Data.ByteString as B import Crypto.Cipher.Twofish-+import qualified Data.ByteString as B vectors_twofish128 =- [ KAT_ECB (B.replicate 16 0x00) (B.replicate 16 0x00) (B.pack [0x9F,0x58,0x9F,0x5C,0xF6,0x12,0x2C,0x32,0xB6,0xBF,0xEC,0x2F,0x2A,0xE8,0xC3,0x5A])- , KAT_ECB (B.pack [0x9F,0x58,0x9F,0x5C,0xF6,0x12,0x2C,0x32,0xB6,0xBF,0xEC,0x2F,0x2A,0xE8,0xC3,0x5A])- (B.pack [0xD4, 0x91, 0xDB, 0x16, 0xE7, 0xB1, 0xC3, 0x9E, 0x86, 0xCB, 0x08, 0x6B, 0x78, 0x9F, 0x54, 0x19])- (B.pack [0x01, 0x9F, 0x98, 0x09, 0xDE, 0x17, 0x11, 0x85, 0x8F, 0xAA, 0xC3, 0xA3, 0xBA, 0x20, 0xFB, 0xC3])+ [ KAT_ECB+ (B.replicate 16 0x00)+ (B.replicate 16 0x00)+ ( B.pack+ [ 0x9F+ , 0x58+ , 0x9F+ , 0x5C+ , 0xF6+ , 0x12+ , 0x2C+ , 0x32+ , 0xB6+ , 0xBF+ , 0xEC+ , 0x2F+ , 0x2A+ , 0xE8+ , 0xC3+ , 0x5A+ ]+ )+ , KAT_ECB+ ( B.pack+ [ 0x9F+ , 0x58+ , 0x9F+ , 0x5C+ , 0xF6+ , 0x12+ , 0x2C+ , 0x32+ , 0xB6+ , 0xBF+ , 0xEC+ , 0x2F+ , 0x2A+ , 0xE8+ , 0xC3+ , 0x5A+ ]+ )+ ( B.pack+ [ 0xD4+ , 0x91+ , 0xDB+ , 0x16+ , 0xE7+ , 0xB1+ , 0xC3+ , 0x9E+ , 0x86+ , 0xCB+ , 0x08+ , 0x6B+ , 0x78+ , 0x9F+ , 0x54+ , 0x19+ ]+ )+ ( B.pack+ [ 0x01+ , 0x9F+ , 0x98+ , 0x09+ , 0xDE+ , 0x17+ , 0x11+ , 0x85+ , 0x8F+ , 0xAA+ , 0xC3+ , 0xA3+ , 0xBA+ , 0x20+ , 0xFB+ , 0xC3+ ]+ ) ] vectors_twofish192 =- [ KAT_ECB (B.pack [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,- 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77])- (B.pack [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])- (B.pack [0xCF, 0xD1, 0xD2, 0xE5, 0xA9, 0xBE, 0x9C, 0xDF, 0x50, 0x1F, 0x13, 0xB8, 0x92, 0xBD, 0x22, 0x48])- , KAT_ECB (B.pack [0x88, 0xB2, 0xB2, 0x70, 0x6B, 0x10, 0x5E, 0x36, 0xB4, 0x46, 0xBB, 0x6D, 0x73, 0x1A, 0x1E, 0x88,- 0xEF, 0xA7, 0x1F, 0x78, 0x89, 0x65, 0xBD, 0x44])- (B.pack [0x39, 0xDA, 0x69, 0xD6, 0xBA, 0x49, 0x97, 0xD5, 0x85, 0xB6, 0xDC, 0x07, 0x3C, 0xA3, 0x41, 0xB2])- (B.pack [0x18, 0x2B, 0x02, 0xD8, 0x14, 0x97, 0xEA, 0x45, 0xF9, 0xDA, 0xAC, 0xDC, 0x29, 0x19, 0x3A, 0x65])]+ [ KAT_ECB+ ( B.pack+ [ 0x01+ , 0x23+ , 0x45+ , 0x67+ , 0x89+ , 0xAB+ , 0xCD+ , 0xEF+ , 0xFE+ , 0xDC+ , 0xBA+ , 0x98+ , 0x76+ , 0x54+ , 0x32+ , 0x10+ , 0x00+ , 0x11+ , 0x22+ , 0x33+ , 0x44+ , 0x55+ , 0x66+ , 0x77+ ]+ )+ ( B.pack+ [ 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ ]+ )+ ( B.pack+ [ 0xCF+ , 0xD1+ , 0xD2+ , 0xE5+ , 0xA9+ , 0xBE+ , 0x9C+ , 0xDF+ , 0x50+ , 0x1F+ , 0x13+ , 0xB8+ , 0x92+ , 0xBD+ , 0x22+ , 0x48+ ]+ )+ , KAT_ECB+ ( B.pack+ [ 0x88+ , 0xB2+ , 0xB2+ , 0x70+ , 0x6B+ , 0x10+ , 0x5E+ , 0x36+ , 0xB4+ , 0x46+ , 0xBB+ , 0x6D+ , 0x73+ , 0x1A+ , 0x1E+ , 0x88+ , 0xEF+ , 0xA7+ , 0x1F+ , 0x78+ , 0x89+ , 0x65+ , 0xBD+ , 0x44+ ]+ )+ ( B.pack+ [ 0x39+ , 0xDA+ , 0x69+ , 0xD6+ , 0xBA+ , 0x49+ , 0x97+ , 0xD5+ , 0x85+ , 0xB6+ , 0xDC+ , 0x07+ , 0x3C+ , 0xA3+ , 0x41+ , 0xB2+ ]+ )+ ( B.pack+ [ 0x18+ , 0x2B+ , 0x02+ , 0xD8+ , 0x14+ , 0x97+ , 0xEA+ , 0x45+ , 0xF9+ , 0xDA+ , 0xAC+ , 0xDC+ , 0x29+ , 0x19+ , 0x3A+ , 0x65+ ]+ )+ ] vectors_twofish256 =- [ KAT_ECB (B.pack [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,- 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF])- (B.pack [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])- (B.pack [0x37, 0x52, 0x7B, 0xE0, 0x05, 0x23, 0x34, 0xB8, 0x9F, 0x0C, 0xFC, 0xCA, 0xE8, 0x7C, 0xFA, 0x20])- , KAT_ECB (B.pack [0xD4, 0x3B, 0xB7, 0x55, 0x6E, 0xA3, 0x2E, 0x46, 0xF2, 0xA2, 0x82, 0xB7, 0xD4, 0x5B, 0x4E, 0x0D,- 0x57, 0xFF, 0x73, 0x9D, 0x4D, 0xC9, 0x2C, 0x1B, 0xD7, 0xFC, 0x01, 0x70, 0x0C, 0xC8, 0x21, 0x6F])- (B.pack [0x90, 0xAF, 0xE9, 0x1B, 0xB2, 0x88, 0x54, 0x4F, 0x2C, 0x32, 0xDC, 0x23, 0x9B, 0x26, 0x35, 0xE6])- (B.pack [0x6C, 0xB4, 0x56, 0x1C, 0x40, 0xBF, 0x0A, 0x97, 0x05, 0x93, 0x1C, 0xB6, 0xD4, 0x08, 0xE7, 0xFA])]--kats128 = defaultKATs { kat_ECB = vectors_twofish128 }-kats192 = defaultKATs { kat_ECB = vectors_twofish192 }-kats256 = defaultKATs { kat_ECB = vectors_twofish256 }+ [ KAT_ECB+ ( B.pack+ [ 0x01+ , 0x23+ , 0x45+ , 0x67+ , 0x89+ , 0xAB+ , 0xCD+ , 0xEF+ , 0xFE+ , 0xDC+ , 0xBA+ , 0x98+ , 0x76+ , 0x54+ , 0x32+ , 0x10+ , 0x00+ , 0x11+ , 0x22+ , 0x33+ , 0x44+ , 0x55+ , 0x66+ , 0x77+ , 0x88+ , 0x99+ , 0xAA+ , 0xBB+ , 0xCC+ , 0xDD+ , 0xEE+ , 0xFF+ ]+ )+ ( B.pack+ [ 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ , 0x00+ ]+ )+ ( B.pack+ [ 0x37+ , 0x52+ , 0x7B+ , 0xE0+ , 0x05+ , 0x23+ , 0x34+ , 0xB8+ , 0x9F+ , 0x0C+ , 0xFC+ , 0xCA+ , 0xE8+ , 0x7C+ , 0xFA+ , 0x20+ ]+ )+ , KAT_ECB+ ( B.pack+ [ 0xD4+ , 0x3B+ , 0xB7+ , 0x55+ , 0x6E+ , 0xA3+ , 0x2E+ , 0x46+ , 0xF2+ , 0xA2+ , 0x82+ , 0xB7+ , 0xD4+ , 0x5B+ , 0x4E+ , 0x0D+ , 0x57+ , 0xFF+ , 0x73+ , 0x9D+ , 0x4D+ , 0xC9+ , 0x2C+ , 0x1B+ , 0xD7+ , 0xFC+ , 0x01+ , 0x70+ , 0x0C+ , 0xC8+ , 0x21+ , 0x6F+ ]+ )+ ( B.pack+ [ 0x90+ , 0xAF+ , 0xE9+ , 0x1B+ , 0xB2+ , 0x88+ , 0x54+ , 0x4F+ , 0x2C+ , 0x32+ , 0xDC+ , 0x23+ , 0x9B+ , 0x26+ , 0x35+ , 0xE6+ ]+ )+ ( B.pack+ [ 0x6C+ , 0xB4+ , 0x56+ , 0x1C+ , 0x40+ , 0xBF+ , 0x0A+ , 0x97+ , 0x05+ , 0x93+ , 0x1C+ , 0xB6+ , 0xD4+ , 0x08+ , 0xE7+ , 0xFA+ ]+ )+ ] -tests = testGroup "Twofish"- [ testBlockCipher kats128 (undefined :: Twofish128)- , testBlockCipher kats192 (undefined :: Twofish192)- , testBlockCipher kats256 (undefined :: Twofish256) ]+kats128 = defaultKATs{kat_ECB = vectors_twofish128}+kats192 = defaultKATs{kat_ECB = vectors_twofish192}+kats256 = defaultKATs{kat_ECB = vectors_twofish256} +tests =+ testGroup+ "Twofish"+ [ testBlockCipher kats128 (undefined :: Twofish128)+ , testBlockCipher kats192 (undefined :: Twofish192)+ , testBlockCipher kats256 (undefined :: Twofish256)+ ]
tests/Number.hs view
@@ -1,87 +1,117 @@ {-# LANGUAGE OverloadedStrings #-}+ module Number (tests) where import Imports -import Data.ByteArray (Bytes)-import qualified Data.ByteArray as B import Crypto.Number.Basic import Crypto.Number.Generate-import qualified Crypto.Number.Serialize as BE-import qualified Crypto.Number.Serialize.LE as LE-import Crypto.Number.Prime import Crypto.Number.ModArithmetic+import Crypto.Number.Prime+import qualified Crypto.Number.Serialize as BE+import qualified Crypto.Number.Serialize.LE as LE import Data.Bits+import Data.ByteArray (Bytes)+import qualified Data.ByteArray as B serializationVectors :: [(Int, Integer, ByteString)] serializationVectors =- [ (128, 468189858948067662094510918729062682059955669513914188715630930503497261316361784677177564296207557978182700664806717692596876084916561811001371208806217360635705059859428069669992937334724312890015700331031248133952795914192719979937664050389500162437642525331653766885896869239678885404647468665996400635, "\x00\xaa\xae\x74\xc8\xec\x3c\x36\x06\x5e\x46\xca\x8e\x57\xab\x09\x87\xfd\xcd\x1f\xa4\xe7\xf9\xd2\x60\xd5\x4a\x1b\x74\xdc\xa8\x75\xd8\xdd\xff\x2b\x74\x28\x14\x59\x67\x6c\x82\xae\xa3\xa5\x1d\x3f\xb4\xb7\xfe\x5c\xd2\xf0\x7f\xd8\xd9\xa9\xb0\xce\x26\xc1\x26\x74\x96\xf5\xf6\x4c\x8f\x66\x7f\x5d\xf1\x68\x38\xd4\x03\x62\xe9\x30\xc8\xa1\xc1\x84\x97\x62\x20\xfd\xd7\x03\x35\xc1\x25\x45\x1b\x86\x81\x3d\xa4\x92\xc0\xd3\xdd\xfa\x86\x1d\xdf\x0a\xbb\xf4\xc0\x56\xf7\xa2\xb0\x3b\x52\xf7\xa5\x89\x4c\x69\x34\x91\x46\xd9\x57\xfb")- , (128, 40031303476923779996794876613623495515025748694978019540894726181695410095832601107261950025830235596060960914255795497479135806963313279476038687192202016132891881954743054164975707083302554941058329647014950354509055121290280892911153779672733723699997592027662953953692834215577119173225643193201177329, "\x00\x0e\x97\xf9\xd5\x79\xb9\x90\x7c\x85\x48\x49\x01\x19\x64\xfb\x76\x31\xcd\x51\xfb\x8a\x9d\x55\xe5\xd3\x7b\x87\x2d\xad\x63\x2d\x6b\x1c\x84\x3f\x65\x95\xb6\xf3\x1a\xa9\x43\x3f\x06\x46\x7b\xf8\xf3\x35\x45\x84\x11\x56\x91\x53\x43\xd7\xe1\x6d\x80\x64\x14\x45\x35\x4e\x93\x7d\x5e\x48\xec\xe0\x79\x7b\x44\x8e\xab\x0f\xc4\x5f\xc6\xa1\x71\xee\x37\xb1\x55\x51\x98\x44\x57\xe3\xc3\x56\x3a\x50\x27\xaf\xa5\x1d\x1a\x0a\x90\x19\x0d\x14\xed\x3d\x93\x40\x62\x76\xa3\xaa\x00\x23\x86\xca\x98\xb2\x6e\x02\x43\xa7\xbc\xb1\xb2\xf1")- , (128, 75152325976543603337003024341071663845101857195436434620947904288957274825323005869230041326941600298094896018190395352332646796347130114769768242670539699217743549573961461985255265474392937773768121046339453584830072421569334022498680626938734088755136253492360177084153487115846920446085149631919580041, "\x00\x1b\x65\xb1\x73\x74\xed\xd2\xcb\xb8\xf3\x6b\x3f\xc2\x05\xaa\x91\xab\x48\x5b\x03\x30\xae\x24\xa3\xec\x7a\x6a\xf0\x34\x73\x18\x04\xea\xe4\xd6\x19\x97\xc4\xc1\x13\x7d\x12\x0d\xd5\xcb\xbd\x18\x05\xc2\xce\x87\x66\x84\x12\xe8\x24\xa3\x31\x69\xfa\xf4\x2c\x21\x53\xa6\x04\x74\x78\xc4\x93\x0d\x38\x7f\x28\xfe\x80\x8e\xd2\x7b\x20\xc8\xf5\x1f\x0f\x73\x68\xb2\xe5\x08\xf1\x94\xa1\xe6\xcf\x3a\x2c\x12\x63\xda\x08\x3a\x78\x12\xb8\x11\x23\x3c\x38\x38\x10\x94\x2b\xac\x64\x5d\x67\x0c\xb6\x0d\xc3\x9a\x45\x39\x50\x8a\x63\x89")- , (128, 132094272981815297755209818914225029878347650582749561568514551350741192910991391836297682842650690115955454061006435646226436379226218676796260483719213285072886626400953065229934239690821114513313427305727000011361769875430428291375851099221794646192854831002408178061474948738788927399080262963320752452, "\x00\x30\x27\xe0\xbf\x46\xec\x77\x2d\xc6\x06\x77\xbc\x68\x87\x3c\x1b\x2e\xc7\xb7\x6c\x88\x25\xec\x8c\x95\xbf\x74\xe5\x37\x01\x25\x96\xe1\x70\x33\x5c\x7d\xab\x1f\xc2\x9c\xad\xf7\xca\x26\x85\x2d\xfc\x8f\xc7\xab\x49\x28\xa4\x47\xe6\xd5\x6e\xfa\x0a\xbb\x57\xe4\xa2\x51\xc7\xc6\x12\x0f\xa9\x98\x69\xb8\x05\x84\xc5\xe3\x28\x86\x0f\x54\x1d\xf9\x92\x42\x9f\xb1\x77\x2b\x58\x89\xe2\xfc\x22\xb0\x1e\x71\x78\xea\x39\xc1\x87\x4f\xd4\x83\x2c\x96\x1d\xea\xd5\xf9\xf9\xb9\x7b\x86\xfa\xf6\xad\x5b\xb1\x3c\xe7\x11\xd7\x96\x89\x44")- , (128, 577245873336454863811643140721674509319073059708446946821011267146688442860798353087462545395033001525475835015592425207995480357299993009193426638306801669333644226765032464458284920004140299209138389393494751627076239104390434285377314678827349631962212281858308570255468721491493027423799738158196939966, "\x00\xd2\x70\x41\xdb\x3d\xb5\xfe\x8c\xef\x79\xcf\x5b\x7b\x37\xb0\x05\xb8\x5a\x9b\x7d\x01\x28\xc7\xf5\x5a\x02\xba\xce\xbc\xf5\x8e\x91\x59\xd0\x42\x6f\x04\x82\x4b\x78\xb0\xdd\x91\x2e\x15\x9d\xea\x4f\x0c\x21\xc0\x67\x54\xa2\x39\xa8\xe1\x13\x8f\xa9\xff\x46\x2d\x11\x56\x04\xa0\xde\x64\xc8\x0f\xf4\x2c\xd2\x31\xdf\x2a\xfd\xac\xc7\x25\x58\xc8\xea\xfd\x47\x6e\xdd\x2a\x53\x02\x77\x49\xa7\x0d\x18\xfb\x05\x18\x4b\x28\xd3\xa2\x39\x8c\x83\x80\x90\xd1\xa8\x81\x56\x6f\xd1\x94\x9d\x65\x34\x95\x79\xc1\x27\xbc\x76\xc3\x5c\xbe")+ [+ ( 128+ , 468189858948067662094510918729062682059955669513914188715630930503497261316361784677177564296207557978182700664806717692596876084916561811001371208806217360635705059859428069669992937334724312890015700331031248133952795914192719979937664050389500162437642525331653766885896869239678885404647468665996400635+ , "\x00\xaa\xae\x74\xc8\xec\x3c\x36\x06\x5e\x46\xca\x8e\x57\xab\x09\x87\xfd\xcd\x1f\xa4\xe7\xf9\xd2\x60\xd5\x4a\x1b\x74\xdc\xa8\x75\xd8\xdd\xff\x2b\x74\x28\x14\x59\x67\x6c\x82\xae\xa3\xa5\x1d\x3f\xb4\xb7\xfe\x5c\xd2\xf0\x7f\xd8\xd9\xa9\xb0\xce\x26\xc1\x26\x74\x96\xf5\xf6\x4c\x8f\x66\x7f\x5d\xf1\x68\x38\xd4\x03\x62\xe9\x30\xc8\xa1\xc1\x84\x97\x62\x20\xfd\xd7\x03\x35\xc1\x25\x45\x1b\x86\x81\x3d\xa4\x92\xc0\xd3\xdd\xfa\x86\x1d\xdf\x0a\xbb\xf4\xc0\x56\xf7\xa2\xb0\x3b\x52\xf7\xa5\x89\x4c\x69\x34\x91\x46\xd9\x57\xfb"+ )+ ,+ ( 128+ , 40031303476923779996794876613623495515025748694978019540894726181695410095832601107261950025830235596060960914255795497479135806963313279476038687192202016132891881954743054164975707083302554941058329647014950354509055121290280892911153779672733723699997592027662953953692834215577119173225643193201177329+ , "\x00\x0e\x97\xf9\xd5\x79\xb9\x90\x7c\x85\x48\x49\x01\x19\x64\xfb\x76\x31\xcd\x51\xfb\x8a\x9d\x55\xe5\xd3\x7b\x87\x2d\xad\x63\x2d\x6b\x1c\x84\x3f\x65\x95\xb6\xf3\x1a\xa9\x43\x3f\x06\x46\x7b\xf8\xf3\x35\x45\x84\x11\x56\x91\x53\x43\xd7\xe1\x6d\x80\x64\x14\x45\x35\x4e\x93\x7d\x5e\x48\xec\xe0\x79\x7b\x44\x8e\xab\x0f\xc4\x5f\xc6\xa1\x71\xee\x37\xb1\x55\x51\x98\x44\x57\xe3\xc3\x56\x3a\x50\x27\xaf\xa5\x1d\x1a\x0a\x90\x19\x0d\x14\xed\x3d\x93\x40\x62\x76\xa3\xaa\x00\x23\x86\xca\x98\xb2\x6e\x02\x43\xa7\xbc\xb1\xb2\xf1"+ )+ ,+ ( 128+ , 75152325976543603337003024341071663845101857195436434620947904288957274825323005869230041326941600298094896018190395352332646796347130114769768242670539699217743549573961461985255265474392937773768121046339453584830072421569334022498680626938734088755136253492360177084153487115846920446085149631919580041+ , "\x00\x1b\x65\xb1\x73\x74\xed\xd2\xcb\xb8\xf3\x6b\x3f\xc2\x05\xaa\x91\xab\x48\x5b\x03\x30\xae\x24\xa3\xec\x7a\x6a\xf0\x34\x73\x18\x04\xea\xe4\xd6\x19\x97\xc4\xc1\x13\x7d\x12\x0d\xd5\xcb\xbd\x18\x05\xc2\xce\x87\x66\x84\x12\xe8\x24\xa3\x31\x69\xfa\xf4\x2c\x21\x53\xa6\x04\x74\x78\xc4\x93\x0d\x38\x7f\x28\xfe\x80\x8e\xd2\x7b\x20\xc8\xf5\x1f\x0f\x73\x68\xb2\xe5\x08\xf1\x94\xa1\xe6\xcf\x3a\x2c\x12\x63\xda\x08\x3a\x78\x12\xb8\x11\x23\x3c\x38\x38\x10\x94\x2b\xac\x64\x5d\x67\x0c\xb6\x0d\xc3\x9a\x45\x39\x50\x8a\x63\x89"+ )+ ,+ ( 128+ , 132094272981815297755209818914225029878347650582749561568514551350741192910991391836297682842650690115955454061006435646226436379226218676796260483719213285072886626400953065229934239690821114513313427305727000011361769875430428291375851099221794646192854831002408178061474948738788927399080262963320752452+ , "\x00\x30\x27\xe0\xbf\x46\xec\x77\x2d\xc6\x06\x77\xbc\x68\x87\x3c\x1b\x2e\xc7\xb7\x6c\x88\x25\xec\x8c\x95\xbf\x74\xe5\x37\x01\x25\x96\xe1\x70\x33\x5c\x7d\xab\x1f\xc2\x9c\xad\xf7\xca\x26\x85\x2d\xfc\x8f\xc7\xab\x49\x28\xa4\x47\xe6\xd5\x6e\xfa\x0a\xbb\x57\xe4\xa2\x51\xc7\xc6\x12\x0f\xa9\x98\x69\xb8\x05\x84\xc5\xe3\x28\x86\x0f\x54\x1d\xf9\x92\x42\x9f\xb1\x77\x2b\x58\x89\xe2\xfc\x22\xb0\x1e\x71\x78\xea\x39\xc1\x87\x4f\xd4\x83\x2c\x96\x1d\xea\xd5\xf9\xf9\xb9\x7b\x86\xfa\xf6\xad\x5b\xb1\x3c\xe7\x11\xd7\x96\x89\x44"+ )+ ,+ ( 128+ , 577245873336454863811643140721674509319073059708446946821011267146688442860798353087462545395033001525475835015592425207995480357299993009193426638306801669333644226765032464458284920004140299209138389393494751627076239104390434285377314678827349631962212281858308570255468721491493027423799738158196939966+ , "\x00\xd2\x70\x41\xdb\x3d\xb5\xfe\x8c\xef\x79\xcf\x5b\x7b\x37\xb0\x05\xb8\x5a\x9b\x7d\x01\x28\xc7\xf5\x5a\x02\xba\xce\xbc\xf5\x8e\x91\x59\xd0\x42\x6f\x04\x82\x4b\x78\xb0\xdd\x91\x2e\x15\x9d\xea\x4f\x0c\x21\xc0\x67\x54\xa2\x39\xa8\xe1\x13\x8f\xa9\xff\x46\x2d\x11\x56\x04\xa0\xde\x64\xc8\x0f\xf4\x2c\xd2\x31\xdf\x2a\xfd\xac\xc7\x25\x58\xc8\xea\xfd\x47\x6e\xdd\x2a\x53\x02\x77\x49\xa7\x0d\x18\xfb\x05\x18\x4b\x28\xd3\xa2\x39\x8c\x83\x80\x90\xd1\xa8\x81\x56\x6f\xd1\x94\x9d\x65\x34\x95\x79\xc1\x27\xbc\x76\xc3\x5c\xbe"+ ) ] -tests = testGroup "number"- [ testProperty "num-bits" $ \(Int1_2901 i) ->- and [ (numBits (2^i-1) == i)- , (numBits (2^i) == i+1)- , (numBits (2^i + (2^i-1)) == i+1)- ]- , testProperty "num-bits2" $ \(Positive i) ->- not (i `testBit` numBits i) && (i `testBit` (numBits i - 1))- , testProperty "generate-param" $ \testDRG (Int1_2901 bits) ->- let r = withTestDRG testDRG $ generateParams bits (Just SetHighest) False- in r >= 0 && numBits r == bits && testBit r (bits-1)- , testProperty "generate-param2" $ \testDRG (Int1_2901 m1bits) ->- let bits = m1bits + 1 -- make sure minimum is 2- r = withTestDRG testDRG $ generateParams bits (Just SetTwoHighest) False- in r >= 0 && numBits r == bits && testBit r (bits-1) && testBit r (bits-2)- , testProperty "generate-param-odd" $ \testDRG (Int1_2901 bits) ->- let r = withTestDRG testDRG $ generateParams bits Nothing True- in r >= 0 && odd r- , testProperty "generate-range" $ \testDRG (Positive range) ->- let r = withTestDRG testDRG $ generateMax range- in 0 <= r && r < range- , testProperty "generate-prime" $ \testDRG (Int0_2901 baseBits') ->- let baseBits = baseBits' `mod` 800- bits = 5 + baseBits -- generating lower than 5 bits causes an error ..- prime = withTestDRG testDRG $ generatePrime bits- in bits == numBits prime- , testProperty "generate-safe-prime" $ \testDRG (Int0_2901 baseBits') ->- let baseBits = baseBits' `mod` 200- bits = 6 + baseBits- prime = withTestDRG testDRG $ generateSafePrime bits- in bits == numBits prime- , testProperty "as-power-of-2-and-odd" $ \n ->- let (e, a1) = asPowerOf2AndOdd n- in n == (2^e)*a1- , testProperty "squareRoot" $ \testDRG (Int0_2901 baseBits') -> do- let baseBits = baseBits' `mod` 500- bits = 5 + baseBits -- generating lower than 5 bits causes an error ..- p = withTestDRG testDRG $ generatePrime bits- g <- choose (1, p - 1)- let square x = (x * x) `mod` p- r = square <$> squareRoot p g- case jacobi g p of- Just 1 -> return $ Just g `assertEq` r- Just (-1) -> return $ Nothing `assertEq` r- _ -> error "invalid jacobi result"- , testProperty "marshalling-be" $ \qaInt ->- getQAInteger qaInt == BE.os2ip (BE.i2osp (getQAInteger qaInt) :: Bytes)- , testProperty "marshalling-le" $ \qaInt ->- getQAInteger qaInt == LE.os2ip (LE.i2osp (getQAInteger qaInt) :: Bytes)- , testProperty "be-rev-le" $ \qaInt ->- getQAInteger qaInt == LE.os2ip (B.reverse (BE.i2osp (getQAInteger qaInt) :: Bytes))- , testProperty "be-rev-le-40" $ \qaInt ->- getQAInteger qaInt == LE.os2ip (B.reverse (BE.i2ospOf_ 40 (getQAInteger qaInt) :: Bytes))- , testProperty "le-rev-be" $ \qaInt ->- 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" $ zipWith toSerializationKat [katZero..] serializationVectors- , testGroup "marshalling-kat-to-integer" $ zipWith toSerializationKatInteger [katZero..] serializationVectors- ]+tests =+ testGroup+ "number"+ [ testProperty "num-bits" $ \(Int1_2901 i) ->+ and+ [ (numBits (2 ^ i - 1) == i)+ , (numBits (2 ^ i) == i + 1)+ , (numBits (2 ^ i + (2 ^ i - 1)) == i + 1)+ ]+ , testProperty "num-bits2" $ \(Positive i) ->+ not (i `testBit` numBits i) && (i `testBit` (numBits i - 1))+ , testProperty "generate-param" $ \testDRG (Int1_2901 bits) ->+ let r = withTestDRG testDRG $ generateParams bits (Just SetHighest) False+ in r >= 0 && numBits r == bits && testBit r (bits - 1)+ , testProperty "generate-param2" $ \testDRG (Int1_2901 m1bits) ->+ let bits = m1bits + 1 -- make sure minimum is 2+ r = withTestDRG testDRG $ generateParams bits (Just SetTwoHighest) False+ in r >= 0 && numBits r == bits && testBit r (bits - 1) && testBit r (bits - 2)+ , testProperty "generate-param-odd" $ \testDRG (Int1_2901 bits) ->+ let r = withTestDRG testDRG $ generateParams bits Nothing True+ in r >= 0 && odd r+ , testProperty "generate-range" $ \testDRG (Positive range) ->+ let r = withTestDRG testDRG $ generateMax range+ in 0 <= r && r < range+ , testProperty "generate-prime" $ \testDRG (Int0_2901 baseBits') ->+ let baseBits = baseBits' `mod` 800+ bits = 5 + baseBits -- generating lower than 5 bits causes an error ..+ prime = withTestDRG testDRG $ generatePrime bits+ in bits == numBits prime+ , testProperty "generate-safe-prime" $ \testDRG (Int0_2901 baseBits') ->+ let baseBits = baseBits' `mod` 200+ bits = 6 + baseBits+ prime = withTestDRG testDRG $ generateSafePrime bits+ in bits == numBits prime+ , testProperty "as-power-of-2-and-odd" $ \n ->+ let (e, a1) = asPowerOf2AndOdd n+ in n == (2 ^ e) * a1+ , testProperty "squareRoot" $ \testDRG (Int0_2901 baseBits') -> do+ let baseBits = baseBits' `mod` 500+ bits = 5 + baseBits -- generating lower than 5 bits causes an error ..+ p = withTestDRG testDRG $ generatePrime bits+ g <- choose (1, p - 1)+ let square x = (x * x) `mod` p+ r = square <$> squareRoot p g+ case jacobi g p of+ Just 1 -> return $ Just g `assertEq` r+ Just (-1) -> return $ Nothing `assertEq` r+ _ -> error "invalid jacobi result"+ , testProperty "marshalling-be" $ \qaInt ->+ getQAInteger qaInt == BE.os2ip (BE.i2osp (getQAInteger qaInt) :: Bytes)+ , testProperty "marshalling-le" $ \qaInt ->+ getQAInteger qaInt == LE.os2ip (LE.i2osp (getQAInteger qaInt) :: Bytes)+ , testProperty "be-rev-le" $ \qaInt ->+ getQAInteger qaInt+ == LE.os2ip (B.reverse (BE.i2osp (getQAInteger qaInt) :: Bytes))+ , testProperty "be-rev-le-40" $ \qaInt ->+ getQAInteger qaInt+ == LE.os2ip (B.reverse (BE.i2ospOf_ 40 (getQAInteger qaInt) :: Bytes))+ , testProperty "le-rev-be" $ \qaInt ->+ 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" $+ 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)
tests/Number/F2m.hs view
@@ -1,111 +1,127 @@ module Number.F2m (tests) where -import Imports hiding ((.&.))-import Data.Bits-import Data.Maybe import Crypto.Number.Basic (log2) import Crypto.Number.F2m+import Data.Bits+import Data.Maybe+import Imports hiding ((.&.)) -addTests = testGroup "addF2m"- [ testProperty "commutative"- $ \a b -> a `addF2m` b == b `addF2m` a- , testProperty "associative"- $ \a b c -> (a `addF2m` b) `addF2m` c == a `addF2m` (b `addF2m` c)- , testProperty "0 is neutral"- $ \a -> a `addF2m` 0 == a- , testProperty "nullable"- $ \a -> a `addF2m` a == 0- , testProperty "works per bit"- $ \a b -> (a `addF2m` b) .&. b == (a .&. b) `addF2m` b- ]+addTests =+ testGroup+ "addF2m"+ [ testProperty "commutative" $+ \a b -> a `addF2m` b == b `addF2m` a+ , testProperty "associative" $+ \a b c -> (a `addF2m` b) `addF2m` c == a `addF2m` (b `addF2m` c)+ , testProperty "0 is neutral" $+ \a -> a `addF2m` 0 == a+ , testProperty "nullable" $+ \a -> a `addF2m` a == 0+ , testProperty "works per bit" $+ \a b -> (a `addF2m` b) .&. b == (a .&. b) `addF2m` b+ ] -modTests = testGroup "modF2m"- [ testProperty "idempotent"- $ \(Positive m) (NonNegative a) -> modF2m m a == modF2m m (modF2m m a)- , testProperty "upper bound"- $ \(Positive m) (NonNegative a) -> modF2m m a < 2 ^ log2 m- , testProperty "reach upper"- $ \(Positive m) -> let a = 2 ^ log2 m - 1 in modF2m m (m `addF2m` a) == a- , testProperty "lower bound"- $ \(Positive m) (NonNegative a) -> modF2m m a >= 0- , testProperty "reach lower"- $ \(Positive m) -> modF2m m m == 0- , testProperty "additive"- $ \(Positive m) (NonNegative a) (NonNegative b)- -> modF2m m a `addF2m` modF2m m b == modF2m m (a `addF2m` b)- ]+modTests =+ testGroup+ "modF2m"+ [ testProperty "idempotent" $+ \(Positive m) (NonNegative a) -> modF2m m a == modF2m m (modF2m m a)+ , testProperty "upper bound" $+ \(Positive m) (NonNegative a) -> modF2m m a < 2 ^ log2 m+ , testProperty "reach upper" $+ \(Positive m) -> let a = 2 ^ log2 m - 1 in modF2m m (m `addF2m` a) == a+ , testProperty "lower bound" $+ \(Positive m) (NonNegative a) -> modF2m m a >= 0+ , testProperty "reach lower" $+ \(Positive m) -> modF2m m m == 0+ , testProperty "additive" $+ \(Positive m) (NonNegative a) (NonNegative b) ->+ modF2m m a `addF2m` modF2m m b == modF2m m (a `addF2m` b)+ ] -mulTests = testGroup "mulF2m"- [ testProperty "commutative"- $ \(Positive m) (NonNegative a) (NonNegative b) -> mulF2m m a b == mulF2m m b a- , testProperty "associative"- $ \(Positive m) (NonNegative a) (NonNegative b) (NonNegative c)- -> mulF2m m (mulF2m m a b) c == mulF2m m a (mulF2m m b c)- , testProperty "1 is neutral"- $ \(Positive m) (NonNegative a) -> mulF2m m a 1 == modF2m m a- , testProperty "0 is annihilator"- $ \(Positive m) (NonNegative a) -> mulF2m m a 0 == 0- , testProperty "distributive"- $ \(Positive m) (NonNegative a) (NonNegative b) (NonNegative c)- -> mulF2m m a (b `addF2m` c) == mulF2m m a b `addF2m` mulF2m m a c- ]+mulTests =+ testGroup+ "mulF2m"+ [ testProperty "commutative" $+ \(Positive m) (NonNegative a) (NonNegative b) -> mulF2m m a b == mulF2m m b a+ , testProperty "associative" $+ \(Positive m) (NonNegative a) (NonNegative b) (NonNegative c) ->+ mulF2m m (mulF2m m a b) c == mulF2m m a (mulF2m m b c)+ , testProperty "1 is neutral" $+ \(Positive m) (NonNegative a) -> mulF2m m a 1 == modF2m m a+ , testProperty "0 is annihilator" $+ \(Positive m) (NonNegative a) -> mulF2m m a 0 == 0+ , testProperty "distributive" $+ \(Positive m) (NonNegative a) (NonNegative b) (NonNegative c) ->+ mulF2m m a (b `addF2m` c) == mulF2m m a b `addF2m` mulF2m m a c+ ] -squareTests = testGroup "squareF2m"- [ testProperty "sqr(a) == a * a"- $ \(Positive m) (NonNegative a) -> mulF2m m a a == squareF2m m a- -- disabled because we require @m@ to be a suitable modulus and there is no- -- way to guarantee this- -- , testProperty "sqrt(a) * sqrt(a) = a"- -- $ \(Positive m) (NonNegative aa) -> let a = sqrtF2m m aa in mulF2m m a a == modF2m m aa- , testProperty "sqrt(a) * sqrt(a) = a in GF(2^16)"- $ let m = 65581 :: Integer -- x^16 + x^5 + x^3 + x^2 + 1- nums = [0 .. 65535 :: Integer]- in nums == [let y = sqrtF2m m x in squareF2m m y | x <- nums]- ]+squareTests =+ testGroup+ "squareF2m"+ [ testProperty "sqr(a) == a * a" $+ \(Positive m) (NonNegative a) -> mulF2m m a a == squareF2m m a+ , -- disabled because we require @m@ to be a suitable modulus and there is no+ -- way to guarantee this+ -- , testProperty "sqrt(a) * sqrt(a) = a"+ -- $ \(Positive m) (NonNegative aa) -> let a = sqrtF2m m aa in mulF2m m a a == modF2m m aa+ testProperty "sqrt(a) * sqrt(a) = a in GF(2^16)" $+ let m = 65581 :: Integer -- x^16 + x^5 + x^3 + x^2 + 1+ nums = [0 .. 65535 :: Integer]+ in nums == [let y = sqrtF2m m x in squareF2m m y | x <- nums]+ ] -powTests = testGroup "powF2m"- [ testProperty "2 is square"- $ \(Positive m) (NonNegative a) -> powF2m m a 2 == squareF2m m a- , testProperty "1 is identity"- $ \(Positive m) (NonNegative a) -> powF2m m a 1 == modF2m m a- , testProperty "0 is annihilator"- $ \(Positive m) (NonNegative a) -> powF2m m a 0 == modF2m m 1- , testProperty "(a * b) ^ c == (a ^ c) * (b ^ c)"- $ \(Positive m) (NonNegative a) (NonNegative b) (NonNegative c)- -> powF2m m (mulF2m m a b) c == mulF2m m (powF2m m a c) (powF2m m b c)- , testProperty "a ^ (b + c) == (a ^ b) * (a ^ c)"- $ \(Positive m) (NonNegative a) (NonNegative b) (NonNegative c)- -> powF2m m a (b + c) == mulF2m m (powF2m m a b) (powF2m m a c)- , testProperty "a ^ (b * c) == (a ^ b) ^ c"- $ \(Positive m) (NonNegative a) (NonNegative b) (NonNegative c)- -> powF2m m a (b * c) == powF2m m (powF2m m a b) c- ]+powTests =+ testGroup+ "powF2m"+ [ testProperty "2 is square" $+ \(Positive m) (NonNegative a) -> powF2m m a 2 == squareF2m m a+ , testProperty "1 is identity" $+ \(Positive m) (NonNegative a) -> powF2m m a 1 == modF2m m a+ , testProperty "0 is annihilator" $+ \(Positive m) (NonNegative a) -> powF2m m a 0 == modF2m m 1+ , testProperty "(a * b) ^ c == (a ^ c) * (b ^ c)" $+ \(Positive m) (NonNegative a) (NonNegative b) (NonNegative c) ->+ powF2m m (mulF2m m a b) c == mulF2m m (powF2m m a c) (powF2m m b c)+ , testProperty "a ^ (b + c) == (a ^ b) * (a ^ c)" $+ \(Positive m) (NonNegative a) (NonNegative b) (NonNegative c) ->+ powF2m m a (b + c) == mulF2m m (powF2m m a b) (powF2m m a c)+ , testProperty "a ^ (b * c) == (a ^ b) ^ c" $+ \(Positive m) (NonNegative a) (NonNegative b) (NonNegative c) ->+ powF2m m a (b * c) == powF2m m (powF2m m a b) c+ ] -invTests = testGroup "invF2m"- [ testProperty "1 / a * a == 1"- $ \(Positive m) (NonNegative a)- -> maybe True (\c -> mulF2m m c a == modF2m m 1) (invF2m m a)- , testProperty "1 / a == a (mod a^2-1)"- $ \(NonNegative a) -> a < 2 || invF2m (squareF2m' a `addF2m` 1) a == Just a- ]+invTests =+ testGroup+ "invF2m"+ [ testProperty "1 / a * a == 1" $+ \(Positive m) (NonNegative a) ->+ maybe True (\c -> mulF2m m c a == modF2m m 1) (invF2m m a)+ , testProperty "1 / a == a (mod a^2-1)" $+ \(NonNegative a) -> a < 2 || invF2m (squareF2m' a `addF2m` 1) a == Just a+ ] -divTests = testGroup "divF2m"- [ testProperty "1 / a == inv a"- $ \(Positive m) (NonNegative a) -> divF2m m 1 a == invF2m m a- , testProperty "a / b == a * inv b"- $ \(Positive m) (NonNegative a) (NonNegative b)- -> divF2m m a b == (mulF2m m a <$> invF2m m b)- , testProperty "a * b / b == a"- $ \(Positive m) (NonNegative a) (NonNegative b)- -> isNothing (invF2m m b) || divF2m m (mulF2m m a b) b == Just (modF2m m a)- ]+divTests =+ testGroup+ "divF2m"+ [ testProperty "1 / a == inv a" $+ \(Positive m) (NonNegative a) -> divF2m m 1 a == invF2m m a+ , testProperty "a / b == a * inv b" $+ \(Positive m) (NonNegative a) (NonNegative b) ->+ divF2m m a b == (mulF2m m a <$> invF2m m b)+ , testProperty "a * b / b == a" $+ \(Positive m) (NonNegative a) (NonNegative b) ->+ isNothing (invF2m m b) || divF2m m (mulF2m m a b) b == Just (modF2m m a)+ ] -tests = testGroup "number.F2m"- [ addTests- , modTests- , mulTests- , squareTests- , powTests- , invTests- , divTests- ]+tests =+ testGroup+ "number.F2m"+ [ addTests+ , modTests+ , mulTests+ , squareTests+ , powTests+ , invTests+ , divTests+ ]
tests/Padding.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+ module Padding (tests) where import qualified Data.ByteString as B@@ -18,21 +19,28 @@ , ("0123456789abcdef", 16, "0123456789abcdef", Just "0123456789abcdef") ] ---instance Arbitrary where+-- instance Arbitrary where testPad :: Int -> (B.ByteString, Int, B.ByteString) -> TestTree testPad n (inp, sz, padded) =- testCase (show n) $ propertyHoldCase [ eqTest "padded" padded (pad (PKCS7 sz) inp)- , eqTest "unpadded" (Just inp) (unpad (PKCS7 sz) padded)- ]+ testCase (show n) $+ propertyHoldCase+ [ eqTest "padded" padded (pad (PKCS7 sz) inp)+ , eqTest "unpadded" (Just inp) (unpad (PKCS7 sz) padded)+ ] -testZeroPad :: Int -> (B.ByteString, Int, B.ByteString, Maybe B.ByteString) -> TestTree+testZeroPad+ :: Int -> (B.ByteString, Int, B.ByteString, Maybe B.ByteString) -> TestTree testZeroPad n (inp, sz, padded, unpadded) =- testCase (show n) $ propertyHoldCase [ eqTest "padded" padded (pad (ZERO sz) inp)- , eqTest "unpadded" unpadded (unpad (ZERO sz) padded)- ]+ testCase (show n) $+ propertyHoldCase+ [ eqTest "padded" padded (pad (ZERO sz) inp)+ , eqTest "unpadded" unpadded (unpad (ZERO sz) padded)+ ] -tests = testGroup "Padding"- [ testGroup "Cases" $ zipWith testPad [1..] cases- , testGroup "ZeroCases" $ zipWith testZeroPad [1..] zeroCases- ]+tests =+ testGroup+ "Padding"+ [ testGroup "Cases" $ zipWith testPad [1 ..] cases+ , testGroup "ZeroCases" $ zipWith testZeroPad [1 ..] zeroCases+ ]
tests/Poly1305.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE OverloadedStrings #-}+ module Poly1305 (tests) where import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as B () -import Imports import Crypto.Error+import Imports import qualified Crypto.MAC.Poly1305 as Poly1305 import qualified Data.ByteArray as B (convert)@@ -14,23 +15,34 @@ show _ = "Auth" data Chunking = Chunking Int Int- deriving (Show,Eq)+ deriving (Show, Eq) instance Arbitrary Chunking where- arbitrary = Chunking <$> choose (1,34) <*> choose (1,2048)+ arbitrary = Chunking <$> choose (1, 34) <*> choose (1, 2048) -tests = testGroup "Poly1305"- [ testCase "V0" $- let key = "\x85\xd6\xbe\x78\x57\x55\x6d\x33\x7f\x44\x52\xfe\x42\xd5\x06\xa8\x01\x03\x80\x8a\xfb\x0d\xb2\xfd\x4a\xbf\xf6\xaf\x41\x49\xf5\x1b" :: ByteString- msg = "Cryptographic Forum Research Group" :: ByteString- tag = "\xa8\x06\x1d\xc1\x30\x51\x36\xc6\xc2\x2b\x8b\xaf\x0c\x01\x27\xa9" :: ByteString- in tag @=? B.convert (Poly1305.auth key msg)- , testProperty "Chunking" $ \(Chunking chunkLen totalLen) ->- let key = B.replicate 32 0- msg = B.pack $ take totalLen $ concat (replicate 10 [1..255])- in Poly1305.auth key msg == Poly1305.finalize (foldr (flip Poly1305.update) (throwCryptoError $ Poly1305.initialize key) (chunks chunkLen msg))- ]+tests =+ testGroup+ "Poly1305"+ [ testCase "V0" $+ let key =+ "\x85\xd6\xbe\x78\x57\x55\x6d\x33\x7f\x44\x52\xfe\x42\xd5\x06\xa8\x01\x03\x80\x8a\xfb\x0d\xb2\xfd\x4a\xbf\xf6\xaf\x41\x49\xf5\x1b"+ :: ByteString+ msg = "Cryptographic Forum Research Group" :: ByteString+ tag =+ "\xa8\x06\x1d\xc1\x30\x51\x36\xc6\xc2\x2b\x8b\xaf\x0c\x01\x27\xa9" :: ByteString+ in tag @=? B.convert (Poly1305.auth key msg)+ , testProperty "Chunking" $ \(Chunking chunkLen totalLen) ->+ let key = B.replicate 32 0+ msg = B.pack $ take totalLen $ concat (replicate 10 [1 .. 255])+ in Poly1305.auth key msg+ == Poly1305.finalize+ ( foldr+ (flip Poly1305.update)+ (throwCryptoError $ Poly1305.initialize key)+ (chunks chunkLen msg)+ )+ ] where- chunks i bs- | B.length bs < i = [bs]- | otherwise = let (b1,b2) = B.splitAt i bs in b1 : chunks i b2+ chunks i bs+ | B.length bs < i = [bs]+ | otherwise = let (b1, b2) = B.splitAt i bs in b1 : chunks i b2
tests/Salsa.hs view
@@ -1,100 +1,134 @@ {-# LANGUAGE OverloadedStrings #-}+ module Salsa (tests) where -import qualified Data.ByteString as B import qualified Crypto.Cipher.Salsa as Salsa+import qualified Data.ByteString as B -import Imports+import Imports type Vector = (Int, B.ByteString, B.ByteString, [(Int, B.ByteString)]) vectors :: [Vector] vectors =- [ (20, key, iv- , [ (0, "\x99\xA8\xCC\xEC\x6C\x5B\x2A\x0B\x6E\x33\x6C\xB2\x06\x52\x24\x1C\x32\xB2\x4D\x34\xAC\xC0\x45\x7E\xF6\x79\x17\x8E\xDE\x7C\xF8\x05\x80\x5A\x93\x05\xC7\xC4\x99\x09\x68\x3B\xD1\xA8\x03\x32\x78\x17\x62\x7C\xA4\x6F\xE8\xB9\x29\xB6\xDF\x00\x12\xBD\x86\x41\x83\xBE")- , (192, "\x2D\x22\x6C\x11\xF4\x7B\x3C\x0C\xCD\x09\x59\xB6\x1F\x59\xD5\xCC\x30\xFC\xEF\x6D\xBB\x8C\xBB\x3D\xCC\x1C\xC2\x52\x04\xFC\xD4\x49\x8C\x37\x42\x6A\x63\xBE\xA3\x28\x2B\x1A\x8A\x0D\x60\xE1\x3E\xB2\xFE\x59\x24\x1A\x9F\x6A\xF4\x26\x68\x98\x66\xED\xC7\x69\xE1\xE6\x48\x2F\xE1\xC1\x28\xA1\x5C\x11\x23\xB5\x65\x5E\xD5\x46\xDF\x01\x4C\xE0\xC4\x55\xDB\xF5\xD3\xA1\x3D\x9C\xD4\xF0\xE2\xD1\xDA\xB9\xF1\x2F\xB6\x8C\x54\x42\x61\xD7\xF8\x8E\xAC\x1C\x6C\xBF\x99\x3F\xBB\xB8\xE0\xAA\x85\x10\xBF\xF8\xE7\x38\x35\xA1\xE8\x6E\xAD\xBB")- , (448, "\x05\x97\x18\x8A\x1C\x19\x25\x57\x69\xBE\x1C\x21\x03\x99\xAD\x17\x2E\xB4\x6C\x52\xF9\x2F\xD5\x41\xDF\x2E\xAD\x71\xB1\xFF\x8E\xA7\xAD\xD3\x80\xEC\x71\xA5\xFD\x7A\xDB\x51\x81\xEA\xDD\x18\x25\xEC\x02\x77\x9A\x45\x09\xBE\x58\x32\x70\x8C\xA2\x83\x6C\x16\x93\xA5")- ])- , (20- , "\x00\x53\xA6\xF9\x4C\x9F\xF2\x45\x98\xEB\x3E\x91\xE4\x37\x8A\xDD\x30\x83\xD6\x29\x7C\xCF\x22\x75\xC8\x1B\x6E\xC1\x14\x67\xBA\x0D"- , "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"- , [ (0, "\xF5\xFA\xD5\x3F\x79\xF9\xDF\x58\xC4\xAE\xA0\xD0\xED\x9A\x96\x01\xF2\x78\x11\x2C\xA7\x18\x0D\x56\x5B\x42\x0A\x48\x01\x96\x70\xEA\xF2\x4C\xE4\x93\xA8\x62\x63\xF6\x77\xB4\x6A\xCE\x19\x24\x77\x3D\x2B\xB2\x55\x71\xE1\xAA\x85\x93\x75\x8F\xC3\x82\xB1\x28\x0B\x71")- , (65472, "\xB7\x0C\x50\x13\x9C\x63\x33\x2E\xF6\xE7\x7A\xC5\x43\x38\xA4\x07\x9B\x82\xBE\xC9\xF9\xA4\x03\xDF\xEA\x82\x1B\x83\xF7\x86\x07\x91\x65\x0E\xF1\xB2\x48\x9D\x05\x90\xB1\xDE\x77\x2E\xED\xA4\xE3\xBC\xD6\x0F\xA7\xCE\x9C\xD6\x23\xD9\xD2\xFD\x57\x58\xB8\x65\x3E\x70\x81\x58\x2C\x65\xD7\x56\x2B\x80\xAE\xC2\xF1\xA6\x73\xA9\xD0\x1C\x9F\x89\x2A\x23\xD4\x91\x9F\x6A\xB4\x7B\x91\x54\xE0\x8E\x69\x9B\x41\x17\xD7\xC6\x66\x47\x7B\x60\xF8\x39\x14\x81\x68\x2F\x5D\x95\xD9\x66\x23\xDB\xC4\x89\xD8\x8D\xAA\x69\x56\xB9\xF0\x64\x6B\x6E")- , (131008, "\xA1\x3F\xFA\x12\x08\xF8\xBF\x50\x90\x08\x86\xFA\xAB\x40\xFD\x10\xE8\xCA\xA3\x06\xE6\x3D\xF3\x95\x36\xA1\x56\x4F\xB7\x60\xB2\x42\xA9\xD6\xA4\x62\x8C\xDC\x87\x87\x62\x83\x4E\x27\xA5\x41\xDA\x2A\x5E\x3B\x34\x45\x98\x9C\x76\xF6\x11\xE0\xFE\xC6\xD9\x1A\xCA\xCC")- ])+ [+ ( 20+ , key+ , iv+ ,+ [+ ( 0+ , "\x99\xA8\xCC\xEC\x6C\x5B\x2A\x0B\x6E\x33\x6C\xB2\x06\x52\x24\x1C\x32\xB2\x4D\x34\xAC\xC0\x45\x7E\xF6\x79\x17\x8E\xDE\x7C\xF8\x05\x80\x5A\x93\x05\xC7\xC4\x99\x09\x68\x3B\xD1\xA8\x03\x32\x78\x17\x62\x7C\xA4\x6F\xE8\xB9\x29\xB6\xDF\x00\x12\xBD\x86\x41\x83\xBE"+ )+ ,+ ( 192+ , "\x2D\x22\x6C\x11\xF4\x7B\x3C\x0C\xCD\x09\x59\xB6\x1F\x59\xD5\xCC\x30\xFC\xEF\x6D\xBB\x8C\xBB\x3D\xCC\x1C\xC2\x52\x04\xFC\xD4\x49\x8C\x37\x42\x6A\x63\xBE\xA3\x28\x2B\x1A\x8A\x0D\x60\xE1\x3E\xB2\xFE\x59\x24\x1A\x9F\x6A\xF4\x26\x68\x98\x66\xED\xC7\x69\xE1\xE6\x48\x2F\xE1\xC1\x28\xA1\x5C\x11\x23\xB5\x65\x5E\xD5\x46\xDF\x01\x4C\xE0\xC4\x55\xDB\xF5\xD3\xA1\x3D\x9C\xD4\xF0\xE2\xD1\xDA\xB9\xF1\x2F\xB6\x8C\x54\x42\x61\xD7\xF8\x8E\xAC\x1C\x6C\xBF\x99\x3F\xBB\xB8\xE0\xAA\x85\x10\xBF\xF8\xE7\x38\x35\xA1\xE8\x6E\xAD\xBB"+ )+ ,+ ( 448+ , "\x05\x97\x18\x8A\x1C\x19\x25\x57\x69\xBE\x1C\x21\x03\x99\xAD\x17\x2E\xB4\x6C\x52\xF9\x2F\xD5\x41\xDF\x2E\xAD\x71\xB1\xFF\x8E\xA7\xAD\xD3\x80\xEC\x71\xA5\xFD\x7A\xDB\x51\x81\xEA\xDD\x18\x25\xEC\x02\x77\x9A\x45\x09\xBE\x58\x32\x70\x8C\xA2\x83\x6C\x16\x93\xA5"+ )+ ]+ )+ ,+ ( 20+ , "\x00\x53\xA6\xF9\x4C\x9F\xF2\x45\x98\xEB\x3E\x91\xE4\x37\x8A\xDD\x30\x83\xD6\x29\x7C\xCF\x22\x75\xC8\x1B\x6E\xC1\x14\x67\xBA\x0D"+ , "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"+ ,+ [+ ( 0+ , "\xF5\xFA\xD5\x3F\x79\xF9\xDF\x58\xC4\xAE\xA0\xD0\xED\x9A\x96\x01\xF2\x78\x11\x2C\xA7\x18\x0D\x56\x5B\x42\x0A\x48\x01\x96\x70\xEA\xF2\x4C\xE4\x93\xA8\x62\x63\xF6\x77\xB4\x6A\xCE\x19\x24\x77\x3D\x2B\xB2\x55\x71\xE1\xAA\x85\x93\x75\x8F\xC3\x82\xB1\x28\x0B\x71"+ )+ ,+ ( 65472+ , "\xB7\x0C\x50\x13\x9C\x63\x33\x2E\xF6\xE7\x7A\xC5\x43\x38\xA4\x07\x9B\x82\xBE\xC9\xF9\xA4\x03\xDF\xEA\x82\x1B\x83\xF7\x86\x07\x91\x65\x0E\xF1\xB2\x48\x9D\x05\x90\xB1\xDE\x77\x2E\xED\xA4\xE3\xBC\xD6\x0F\xA7\xCE\x9C\xD6\x23\xD9\xD2\xFD\x57\x58\xB8\x65\x3E\x70\x81\x58\x2C\x65\xD7\x56\x2B\x80\xAE\xC2\xF1\xA6\x73\xA9\xD0\x1C\x9F\x89\x2A\x23\xD4\x91\x9F\x6A\xB4\x7B\x91\x54\xE0\x8E\x69\x9B\x41\x17\xD7\xC6\x66\x47\x7B\x60\xF8\x39\x14\x81\x68\x2F\x5D\x95\xD9\x66\x23\xDB\xC4\x89\xD8\x8D\xAA\x69\x56\xB9\xF0\x64\x6B\x6E"+ )+ ,+ ( 131008+ , "\xA1\x3F\xFA\x12\x08\xF8\xBF\x50\x90\x08\x86\xFA\xAB\x40\xFD\x10\xE8\xCA\xA3\x06\xE6\x3D\xF3\x95\x36\xA1\x56\x4F\xB7\x60\xB2\x42\xA9\xD6\xA4\x62\x8C\xDC\x87\x87\x62\x83\x4E\x27\xA5\x41\xDA\x2A\x5E\x3B\x34\x45\x98\x9C\x76\xF6\x11\xE0\xFE\xC6\xD9\x1A\xCA\xCC"+ )+ ]+ ) ] where- key :: B.ByteString- key = "\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09"+ key :: B.ByteString+ key =+ "\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09" - iv = B.replicate 8 0+ iv = B.replicate 8 0 newtype RandomVector = RandomVector Vector- deriving (Show,Eq)+ deriving (Show, Eq) instance Arbitrary RandomVector where arbitrary = RandomVector <$> elements vectors -tests = testGroup "Salsa"- [ testGroup "KAT" $- 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- ]+tests =+ testGroup+ "Salsa"+ [ testGroup "KAT" $+ 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+ ] where- salsaRunSimple expected rounds key nonce =- let salsa = Salsa.initialize rounds key nonce- in map snd expected @=? salsaLoop 0 salsa expected-- salsaLoop _ _ [] = []- salsaLoop current salsa (r@(ofs,expectBs):rs)- | current < ofs =- let (_, salsaNext) = Salsa.generate salsa (ofs - current) :: (ByteString, Salsa.State)- in salsaLoop ofs salsaNext (r:rs)- | current == ofs =- let (e, salsaNext) = Salsa.generate salsa (B.length expectBs)- in e : salsaLoop (current + B.length expectBs) salsaNext rs- | otherwise = error "internal error in salsaLoop"-- salsaGenerateCombine :: ChunkingLen0_127 -> RandomVector -> Int0_2901 -> Bool- salsaGenerateCombine (ChunkingLen0_127 ckLen) (RandomVector (rounds, key, iv, _)) (Int0_2901 nbBytes) =- let initSalsa = Salsa.initialize rounds key iv- in loop nbBytes ckLen initSalsa- where loop n [] salsa = loop n ckLen salsa- loop 0 _ _ = True- loop n (x:xs) salsa =- let len = min x n- (c1, next) = Salsa.generate salsa len- (c2, _) = Salsa.combine salsa (B.replicate len 0)- in if c1 == c2 then loop (n - len) xs next else False+ salsaRunSimple expected rounds key nonce =+ let salsa = Salsa.initialize rounds key nonce+ in map snd expected @=? salsaLoop 0 salsa expected - salsaGenerateChunks :: ChunkingLen -> RandomVector -> Bool- salsaGenerateChunks (ChunkingLen ckLen) (RandomVector (rounds, key, iv, _)) =- let initSalsa = Salsa.initialize rounds key iv- nbBytes = 1048- (expected,_) = Salsa.generate initSalsa nbBytes- chunks = loop nbBytes ckLen (Salsa.initialize rounds key iv)- in expected == B.concat chunks+ salsaLoop _ _ [] = []+ salsaLoop current salsa (r@(ofs, expectBs) : rs)+ | current < ofs =+ let (_, salsaNext) = Salsa.generate salsa (ofs - current) :: (ByteString, Salsa.State)+ in salsaLoop ofs salsaNext (r : rs)+ | current == ofs =+ let (e, salsaNext) = Salsa.generate salsa (B.length expectBs)+ in e : salsaLoop (current + B.length expectBs) salsaNext rs+ | otherwise = error "internal error in salsaLoop" - where loop n [] salsa = loop n ckLen salsa- loop 0 _ _ = []- loop n (x:xs) salsa =- let len = min x n- (c, next) = Salsa.generate salsa len- in c : loop (n - len) xs next+ salsaGenerateCombine :: ChunkingLen0_127 -> RandomVector -> Int0_2901 -> Bool+ salsaGenerateCombine (ChunkingLen0_127 ckLen) (RandomVector (rounds, key, iv, _)) (Int0_2901 nbBytes) =+ let initSalsa = Salsa.initialize rounds key iv+ in loop nbBytes ckLen initSalsa+ where+ loop n [] salsa = loop n ckLen salsa+ loop 0 _ _ = True+ loop n (x : xs) salsa =+ let len = min x n+ (c1, next) = Salsa.generate salsa len+ (c2, _) = Salsa.combine salsa (B.replicate len 0)+ in if c1 == c2 then loop (n - len) xs next else False - salsaCombineChunks :: ChunkingLen -> RandomVector -> ArbitraryBS0_2901 -> Bool- salsaCombineChunks (ChunkingLen ckLen) (RandomVector (rounds, key, iv, _)) (ArbitraryBS0_2901 wholebs) =- let initSalsa = Salsa.initialize rounds key iv- (expected,_) = Salsa.combine initSalsa wholebs- chunks = loop wholebs ckLen initSalsa- in expected `propertyEq` B.concat chunks+ salsaGenerateChunks :: ChunkingLen -> RandomVector -> Bool+ salsaGenerateChunks (ChunkingLen ckLen) (RandomVector (rounds, key, iv, _)) =+ let initSalsa = Salsa.initialize rounds key iv+ nbBytes = 1048+ (expected, _) = Salsa.generate initSalsa nbBytes+ chunks = loop nbBytes ckLen (Salsa.initialize rounds key iv)+ in expected == B.concat chunks+ where+ loop n [] salsa = loop n ckLen salsa+ loop 0 _ _ = []+ loop n (x : xs) salsa =+ let len = min x n+ (c, next) = Salsa.generate salsa len+ in c : loop (n - len) xs next - where loop bs [] salsa = loop bs ckLen salsa- loop bs (x:xs) salsa- | B.null bs = []- | otherwise =- let (bs1, bs2) = B.splitAt (min x (B.length bs)) bs- (c, next) = Salsa.combine salsa bs1- in c : loop bs2 xs next+ salsaCombineChunks :: ChunkingLen -> RandomVector -> ArbitraryBS0_2901 -> Bool+ salsaCombineChunks (ChunkingLen ckLen) (RandomVector (rounds, key, iv, _)) (ArbitraryBS0_2901 wholebs) =+ let initSalsa = Salsa.initialize rounds key iv+ (expected, _) = Salsa.combine initSalsa wholebs+ chunks = loop wholebs ckLen initSalsa+ in expected `propertyEq` B.concat chunks+ where+ loop bs [] salsa = loop bs ckLen salsa+ loop bs (x : xs) salsa+ | B.null bs = []+ | otherwise =+ let (bs1, bs2) = B.splitAt (min x (B.length bs)) bs+ (c, next) = Salsa.combine salsa bs1+ in c : loop bs2 xs next
tests/Tests.hs view
@@ -1,39 +1,41 @@ {-# LANGUAGE OverloadedStrings #-}+ module Main where import Imports import Crypto.System.CPU -import qualified Number-import qualified Number.F2m import qualified BCrypt import qualified BCryptPBKDF+import qualified ChaCha+import qualified ChaChaPoly1305 import qualified ECC import qualified ECC.Edwards25519 import qualified ECDSA import qualified Hash-import qualified Poly1305-import qualified Salsa-import qualified XSalsa-import qualified ChaCha-import qualified ChaChaPoly1305-import qualified KAT_MiyaguchiPreneel+import qualified KAT_Argon2 import qualified KAT_Blake2 import qualified KAT_CMAC-import qualified KAT_HMAC-import qualified KAT_KMAC-import qualified KAT_HKDF-import qualified KAT_Argon2-import qualified KAT_PBKDF2 import qualified KAT_Curve25519 import qualified KAT_Curve448 import qualified KAT_Ed25519 import qualified KAT_Ed448 import qualified KAT_EdDSA+import qualified KAT_HKDF+import qualified KAT_HMAC+import qualified KAT_KMAC+import qualified KAT_MiyaguchiPreneel import qualified KAT_OTP+import qualified KAT_PBKDF2 import qualified KAT_PubKey import qualified KAT_Scrypt+import qualified Number+import qualified Number.F2m+import qualified Poly1305+import qualified Salsa+import qualified XSalsa+ -- symmetric cipher -------------------- import qualified KAT_AES import qualified KAT_AESGCMSIV@@ -44,64 +46,73 @@ import qualified KAT_RC4 import qualified KAT_TripleDES import qualified KAT_Twofish+ -- misc -------------------------------- import qualified KAT_AFIS import qualified Padding -tests = testGroup "crypton"- [ testGroup "runtime"- [ testCaseInfo "CPU" (return $ show processorOptions)- ]- , Number.tests- , Number.F2m.tests- , Hash.tests- , Padding.tests- , testGroup "ConstructHash"- [ KAT_MiyaguchiPreneel.tests- ]- , testGroup "MAC"- [ Poly1305.tests- , KAT_Blake2.tests- , KAT_CMAC.tests- , KAT_HMAC.tests- , KAT_KMAC.tests- ]- , KAT_Curve25519.tests- , KAT_Curve448.tests- , KAT_Ed25519.tests- , KAT_Ed448.tests- , KAT_EdDSA.tests- , KAT_PubKey.tests- , KAT_OTP.tests- , testGroup "KDF"- [ KAT_PBKDF2.tests- , KAT_Scrypt.tests- , BCrypt.tests- , BCryptPBKDF.tests- , KAT_HKDF.tests- , KAT_Argon2.tests- ]- , testGroup "block-cipher"- [ KAT_AES.tests- , KAT_AESGCMSIV.tests- , KAT_Blowfish.tests- , KAT_CAST5.tests- , KAT_Camellia.tests- , KAT_DES.tests- , KAT_TripleDES.tests- , KAT_Twofish.tests- ]- , testGroup "stream-cipher"- [ KAT_RC4.tests- , ChaCha.tests- , ChaChaPoly1305.tests- , Salsa.tests- , XSalsa.tests+tests =+ testGroup+ "crypton"+ [ testGroup+ "runtime"+ [ testCaseInfo "CPU" (return $ show processorOptions)+ ]+ , Number.tests+ , Number.F2m.tests+ , Hash.tests+ , Padding.tests+ , testGroup+ "ConstructHash"+ [ KAT_MiyaguchiPreneel.tests+ ]+ , testGroup+ "MAC"+ [ Poly1305.tests+ , KAT_Blake2.tests+ , KAT_CMAC.tests+ , KAT_HMAC.tests+ , KAT_KMAC.tests+ ]+ , KAT_Curve25519.tests+ , KAT_Curve448.tests+ , KAT_Ed25519.tests+ , KAT_Ed448.tests+ , KAT_EdDSA.tests+ , KAT_PubKey.tests+ , KAT_OTP.tests+ , testGroup+ "KDF"+ [ KAT_PBKDF2.tests+ , KAT_Scrypt.tests+ , BCrypt.tests+ , BCryptPBKDF.tests+ , KAT_HKDF.tests+ , KAT_Argon2.tests+ ]+ , testGroup+ "block-cipher"+ [ KAT_AES.tests+ , KAT_AESGCMSIV.tests+ , KAT_Blowfish.tests+ , KAT_CAST5.tests+ , KAT_Camellia.tests+ , KAT_DES.tests+ , KAT_TripleDES.tests+ , KAT_Twofish.tests+ ]+ , testGroup+ "stream-cipher"+ [ KAT_RC4.tests+ , ChaCha.tests+ , ChaChaPoly1305.tests+ , Salsa.tests+ , XSalsa.tests+ ]+ , KAT_AFIS.tests+ , ECC.tests+ , ECC.Edwards25519.tests+ , ECDSA.tests ]- , KAT_AFIS.tests- , ECC.tests- , ECC.Edwards25519.tests- , ECDSA.tests- ] main = defaultMain tests
tests/Utils.hs view
@@ -1,69 +1,70 @@ {-# LANGUAGE ExistentialQuantification #-}+ module Utils where import Control.Applicative-import Data.Char-import Data.Word-import Data.List+import Crypto.Number.Serialize (os2ip)+import Crypto.Random import Data.ByteString (ByteString) import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as L-import Crypto.Random-import Crypto.Number.Serialize (os2ip)+import Data.Char+import Data.List+import Data.Word import Prelude -import Test.Tasty.QuickCheck import Test.Tasty.HUnit ((@=?))+import Test.Tasty.QuickCheck newtype TestDRG = TestDRG (Word64, Word64, Word64, Word64, Word64)- deriving (Show,Eq)+ deriving (Show, Eq) instance Arbitrary TestDRG where- arbitrary = TestDRG `fmap` arbitrary -- distribution not uniform+ arbitrary = TestDRG `fmap` arbitrary -- distribution not uniform withTestDRG (TestDRG l) f = fst $ withDRG (drgNewTest l) f newtype ChunkingLen = ChunkingLen [Int]- deriving (Show,Eq)+ deriving (Show, Eq) instance Arbitrary ChunkingLen where- arbitrary = ChunkingLen `fmap` vectorOf 16 (choose (0,14))+ arbitrary = ChunkingLen `fmap` vectorOf 16 (choose (0, 14)) newtype ChunkingLen0_127 = ChunkingLen0_127 [Int]- deriving (Show,Eq)+ deriving (Show, Eq) instance Arbitrary ChunkingLen0_127 where- arbitrary = ChunkingLen0_127 `fmap` vectorOf 16 (choose (0,127))-+ arbitrary = ChunkingLen0_127 `fmap` vectorOf 16 (choose (0, 127)) newtype ArbitraryBS0_2901 = ArbitraryBS0_2901 ByteString- deriving (Show,Eq,Ord)+ deriving (Show, Eq, Ord) instance Arbitrary ArbitraryBS0_2901 where arbitrary = ArbitraryBS0_2901 `fmap` arbitraryBSof 0 2901 newtype Int0_2901 = Int0_2901 Int- deriving (Show,Eq,Ord)+ deriving (Show, Eq, Ord) newtype Int1_2901 = Int1_2901 Int- deriving (Show,Eq,Ord)+ deriving (Show, Eq, Ord) instance Arbitrary Int0_2901 where- arbitrary = Int0_2901 `fmap` choose (0,2901)+ arbitrary = Int0_2901 `fmap` choose (0, 2901) instance Arbitrary Int1_2901 where- arbitrary = Int1_2901 `fmap` choose (1,2901)+ arbitrary = Int1_2901 `fmap` choose (1, 2901) -- | a integer wrapper with a better range property-newtype QAInteger = QAInteger { getQAInteger :: Integer }- deriving (Show,Eq)+newtype QAInteger = QAInteger {getQAInteger :: Integer}+ deriving (Show, Eq) instance Arbitrary QAInteger where- arbitrary = oneof- [ QAInteger . fromIntegral <$> (choose (0, 65536) :: Gen Int) -- small integer- , larger <$> choose (0,4096) <*> choose (0, 65536) -- medium integer- , QAInteger . os2ip <$> arbitraryBSof 0 32 -- [ 0 .. 2^32 ] sized integer- ]+ arbitrary =+ oneof+ [ QAInteger . fromIntegral <$> (choose (0, 65536) :: Gen Int) -- small integer+ , larger <$> choose (0, 4096) <*> choose (0, 65536) -- medium integer+ , QAInteger . os2ip <$> arbitraryBSof 0 32 -- [ 0 .. 2^32 ] sized integer+ ] where larger :: Int -> Int -> QAInteger larger p b = QAInteger (fromIntegral p * somePrime + fromIntegral b)@@ -79,73 +80,81 @@ chunkS :: ChunkingLen -> ByteString -> [ByteString] chunkS (ChunkingLen originalChunks) = loop originalChunks- where loop l bs- | B.null bs = []- | otherwise =- case l of- (x:xs) -> let (b1, b2) = B.splitAt x bs in b1 : loop xs b2- [] -> loop originalChunks bs+ where+ loop l bs+ | B.null bs = []+ | otherwise =+ case l of+ (x : xs) -> let (b1, b2) = B.splitAt x bs in b1 : loop xs b2+ [] -> loop originalChunks bs chunksL :: ChunkingLen -> L.ByteString -> L.ByteString chunksL (ChunkingLen originalChunks) = L.fromChunks . loop originalChunks . L.toChunks- where loop _ [] = []- loop l (b:bs)- | B.null b = loop l bs- | otherwise =- case l of- (x:xs) -> let (b1, b2) = B.splitAt x b in b1 : loop xs (b2:bs)- [] -> loop originalChunks (b:bs)+ where+ loop _ [] = []+ loop l (b : bs)+ | B.null b = loop l bs+ | otherwise =+ case l of+ (x : xs) -> let (b1, b2) = B.splitAt x b in b1 : loop xs (b2 : bs)+ [] -> loop originalChunks (b : bs) katZero :: Int katZero = 0 ---hexalise :: String -> [Word8]-hexalise s = concatMap (\c -> [ hex $ c `div` 16, hex $ c `mod` 16 ]) s- where hex i- | i >= 0 && i <= 9 = fromIntegral (ord '0') + i- | i >= 10 && i <= 15 = fromIntegral (ord 'a') + i - 10- | otherwise = 0+-- hexalise :: String -> [Word8]+hexalise s = concatMap (\c -> [hex $ c `div` 16, hex $ c `mod` 16]) s+ where+ hex i+ | i >= 0 && i <= 9 = fromIntegral (ord '0') + i+ | i >= 10 && i <= 15 = fromIntegral (ord 'a') + i - 10+ | otherwise = 0 splitB :: Int -> ByteString -> [ByteString] splitB l b = if B.length b > l then- let (b1, b2) = B.splitAt l b in- b1 : splitB l b2+ let (b1, b2) = B.splitAt l b+ in b1 : splitB l b2 else- [ b ]+ [b] assertBytesEq :: ByteString -> ByteString -> Bool-assertBytesEq b1 b2 | b1 /= b2 = error ("expected: " ++ show b1 ++ " got: " ++ show b2)- | otherwise = True+assertBytesEq b1 b2+ | b1 /= b2 = error ("expected: " ++ show b1 ++ " got: " ++ show b2)+ | otherwise = True assertEq :: (Show a, Eq a) => a -> a -> Bool-assertEq b1 b2 | b1 /= b2 = error ("expected: " ++ show b1 ++ " got: " ++ show b2)- | otherwise = True+assertEq b1 b2+ | b1 /= b2 = error ("expected: " ++ show b1 ++ " got: " ++ show b2)+ | otherwise = True propertyEq :: (Show a, Eq a) => a -> a -> Bool propertyEq = assertEq -data PropertyTest =- forall a . (Show a, Eq a) => EqTest String a a+data PropertyTest+ = forall a. (Show a, Eq a) => EqTest String a a type PropertyName = String -eqTest :: (Show a, Eq a)- => PropertyName- -> a -- ^ expected value- -> a -- ^ got- -> PropertyTest+eqTest+ :: (Show a, Eq a)+ => PropertyName+ -> a+ -- ^ expected value+ -> a+ -- ^ got+ -> PropertyTest eqTest name a b = EqTest name a b propertyHold :: [PropertyTest] -> Bool propertyHold l = case foldl runProperty [] l of- [] -> True+ [] -> True failed -> error (intercalate "\n" failed) where runProperty acc (EqTest name a b)- | a == b = acc+ | a == b = acc | otherwise = (name ++ ": expected " ++ show a ++ " but got: " ++ show b) : acc
tests/XSalsa.hs view
@@ -1,128 +1,173 @@ {-# LANGUAGE OverloadedStrings #-}+ module XSalsa (tests) where -import qualified Data.ByteString as B import qualified Crypto.Cipher.XSalsa as XSalsa+import qualified Data.ByteString as B -import Imports+import Imports type Vector = (Int, B.ByteString, B.ByteString, B.ByteString, B.ByteString) -- Test vectors generated by naclcrypto library (https://nacl.cr.yp.to) vectors :: [Vector] vectors =- [ ( 20- , "\xA6\xA7\x25\x1C\x1E\x72\x91\x6D\x11\xC2\xCB\x21\x4D\x3C\x25\x25\x39\x12\x1D\x8E\x23\x4E\x65\x2D\x65\x1F\xA4\xC8\xCF\xF8\x80\x30"- , "\x9E\x64\x5A\x74\xE9\xE0\xA6\x0D\x82\x43\xAC\xD9\x17\x7A\xB5\x1A\x1B\xEB\x8D\x5A\x2F\x5D\x70\x0C"- , "\x09\x3C\x5E\x55\x85\x57\x96\x25\x33\x7B\xD3\xAB\x61\x9D\x61\x57\x60\xD8\xC5\xB2\x24\xA8\x5B\x1D\x0E\xFE\x0E\xB8\xA7\xEE\x16\x3A\xBB\x03\x76\x52\x9F\xCC\x09\xBA\xB5\x06\xC6\x18\xE1\x3C\xE7\x77\xD8\x2C\x3A\xE9\xD1\xA6\xF9\x72\xD4\x16\x02\x87\xCB\xFE\x60\xBF\x21\x30\xFC\x0A\x6F\xF6\x04\x9D\x0A\x5C\x8A\x82\xF4\x29\x23\x1F\x00\x80\x82\xE8\x45\xD7\xE1\x89\xD3\x7F\x9E\xD2\xB4\x64\xE6\xB9\x19\xE6\x52\x3A\x8C\x12\x10\xBD\x52\xA0\x2A\x4C\x3F\xE4\x06\xD3\x08\x5F\x50\x68\xD1\x90\x9E\xEE\xCA\x63\x69\xAB\xC9\x81\xA4\x2E\x87\xFE\x66\x55\x83\xF0\xAB\x85\xAE\x71\xF6\xF8\x4F\x52\x8E\x6B\x39\x7A\xF8\x6F\x69\x17\xD9\x75\x4B\x73\x20\xDB\xDC\x2F\xEA\x81\x49\x6F\x27\x32\xF5\x32\xAC\x78\xC4\xE9\xC6\xCF\xB1\x8F\x8E\x9B\xDF\x74\x62\x2E\xB1\x26\x14\x14\x16\x77\x69\x71\xA8\x4F\x94\xD1\x56\xBE\xAF\x67\xAE\xCB\xF2\xAD\x41\x2E\x76\xE6\x6E\x8F\xAD\x76\x33\xF5\xB6\xD7\xF3\xD6\x4B\x5C\x6C\x69\xCE\x29\x00\x3C\x60\x24\x46\x5A\xE3\xB8\x9B\xE7\x8E\x91\x5D\x88\xB4\xB5\x62\x1D"- , "\xB2\xAF\x68\x8E\x7D\x8F\xC4\xB5\x08\xC0\x5C\xC3\x9D\xD5\x83\xD6\x71\x43\x22\xC6\x4D\x7F\x3E\x63\x14\x7A\xED\xE2\xD9\x53\x49\x34\xB0\x4F\xF6\xF3\x37\xB0\x31\x81\x5C\xD0\x94\xBD\xBC\x6D\x7A\x92\x07\x7D\xCE\x70\x94\x12\x28\x68\x22\xEF\x07\x37\xEE\x47\xF6\xB7\xFF\xA2\x2F\x9D\x53\xF1\x1D\xD2\xB0\xA3\xBB\x9F\xC0\x1D\x9A\x88\xF9\xD5\x3C\x26\xE9\x36\x5C\x2C\x3C\x06\x3B\xC4\x84\x0B\xFC\x81\x2E\x4B\x80\x46\x3E\x69\xD1\x79\x53\x0B\x25\xC1\x58\xF5\x43\x19\x1C\xFF\x99\x31\x06\x51\x1A\xA0\x36\x04\x3B\xBC\x75\x86\x6A\xB7\xE3\x4A\xFC\x57\xE2\xCC\xE4\x93\x4A\x5F\xAA\xE6\xEA\xBE\x4F\x22\x17\x70\x18\x3D\xD0\x60\x46\x78\x27\xC2\x7A\x35\x41\x59\xA0\x81\x27\x5A\x29\x1F\x69\xD9\x46\xD6\xFE\x28\xED\x0B\x9C\xE0\x82\x06\xCF\x48\x49\x25\xA5\x1B\x94\x98\xDB\xDE\x17\x8D\xDD\x3A\xE9\x1A\x85\x81\xB9\x16\x82\xD8\x60\xF8\x40\x78\x2F\x6E\xEA\x49\xDB\xB9\xBD\x72\x15\x01\xD2\xC6\x71\x22\xDE\xA3\xB7\x28\x38\x48\xC5\xF1\x3E\x0C\x0D\xE8\x76\xBD\x22\x7A\x85\x6E\x4D\xE5\x93\xA3")- , ( 20- , "\x9E\x1D\xA2\x39\xD1\x55\xF5\x2A\xD3\x7F\x75\xC7\x36\x8A\x53\x66\x68\xB0\x51\x95\x29\x23\xAD\x44\xF5\x7E\x75\xAB\x58\x8E\x47\x5A"- , "\xAF\x06\xF1\x78\x59\xDF\xFA\x79\x98\x91\xC4\x28\x8F\x66\x35\xB5\xC5\xA4\x5E\xEE\x90\x17\xFD\x72"- , "\xFE\xAC\x9D\x54\xFC\x8C\x11\x5A\xE2\x47\xD9\xA7\xE9\x19\xDD\x76\xCF\xCB\xC7\x2D\x32\xCA\xE4\x94\x48\x60\x81\x7C\xBD\xFB\x8C\x04\xE6\xB1\xDF\x76\xA1\x65\x17\xCD\x33\xCC\xF1\xAC\xDA\x92\x06\x38\x9E\x9E\x31\x8F\x59\x66\xC0\x93\xCF\xB3\xEC\x2D\x9E\xE2\xDE\x85\x64\x37\xED\x58\x1F\x55\x2F\x26\xAC\x29\x07\x60\x9D\xF8\xC6\x13\xB9\xE3\x3D\x44\xBF\xC2\x1F\xF7\x91\x53\xE9\xEF\x81\xA9\xD6\x6C\xC3\x17\x85\x7F\x75\x2C\xC1\x75\xFD\x88\x91\xFE\xFE\xBB\x7D\x04\x1E\x65\x17\xC3\x16\x2D\x19\x7E\x21\x12\x83\x7D\x3B\xC4\x10\x43\x12\xAD\x35\xB7\x5E\xA6\x86\xE7\xC7\x0D\x4E\xC0\x47\x46\xB5\x2F\xF0\x9C\x42\x14\x51\x45\x9F\xB5\x9F"- , "\x2C\x26\x1A\x2F\x4E\x61\xA6\x2E\x1B\x27\x68\x99\x16\xBF\x03\x45\x3F\xCB\xC9\x7B\xB2\xAF\x6F\x32\x93\x91\xEF\x06\x3B\x5A\x21\x9B\xF9\x84\xD0\x7D\x70\xF6\x02\xD8\x5F\x6D\xB6\x14\x74\xE9\xD9\xF5\xA2\xDE\xEC\xB4\xFC\xD9\x01\x84\xD1\x6F\x3B\x5B\x5E\x16\x8E\xE0\x3E\xA8\xC9\x3F\x39\x33\xA2\x2B\xC3\xD1\xA5\xAE\x8C\x2D\x8B\x02\x75\x7C\x87\xC0\x73\x40\x90\x52\xA2\xA8\xA4\x1E\x7F\x48\x7E\x04\x1F\x9A\x49\xA0\x99\x7B\x54\x0E\x18\x62\x1C\xAD\x3A\x24\xF0\xA5\x6D\x9B\x19\x22\x79\x29\x05\x7A\xB3\xBA\x95\x0F\x62\x74\xB1\x21\xF1\x93\xE3\x2E\x06\xE5\x38\x87\x81\xA1\xCB\x57\x31\x7C\x0B\xA6\x30\x5E\x91\x09\x61\xD0\x10\x02\xF0")- , ( 20- , "\xD5\xC7\xF6\x79\x7B\x7E\x7E\x9C\x1D\x7F\xD2\x61\x0B\x2A\xBF\x2B\xC5\xA7\x88\x5F\xB3\xFF\x78\x09\x2F\xB3\xAB\xE8\x98\x6D\x35\xE2"- , "\x74\x4E\x17\x31\x2B\x27\x96\x9D\x82\x64\x44\x64\x0E\x9C\x4A\x37\x8A\xE3\x34\xF1\x85\x36\x9C\x95"- , "\x77\x58\x29\x8C\x62\x8E\xB3\xA4\xB6\x96\x3C\x54\x45\xEF\x66\x97\x12\x22\xBE\x5D\x1A\x4A\xD8\x39\x71\x5D\x11\x88\x07\x17\x39\xB7\x7C\xC6\xE0\x5D\x54\x10\xF9\x63\xA6\x41\x67\x62\x97\x57"- , "\x27\xB8\xCF\xE8\x14\x16\xA7\x63\x01\xFD\x1E\xEC\x6A\x4D\x99\x67\x50\x69\xB2\xDA\x27\x76\xC3\x60\xDB\x1B\xDF\xEA\x7C\x0A\xA6\x13\x91\x3E\x10\xF7\xA6\x0F\xEC\x04\xD1\x1E\x65\xF2\xD6\x4E")- , ( 20- , "\x73\x7D\x78\x11\xCE\x96\x47\x2E\xFE\xD1\x22\x58\xB7\x81\x22\xF1\x1D\xEA\xEC\x87\x59\xCC\xBD\x71\xEA\xC6\xBB\xEF\xA6\x27\x78\x5C"- , "\x6F\xB2\xEE\x3D\xDA\x6D\xBD\x12\xF1\x27\x4F\x12\x67\x01\xEC\x75\xC3\x5C\x86\x60\x7A\xDB\x3E\xDD"- , "\x50\x13\x25\xFB\x26\x45\x26\x48\x64\xDF\x11\xFA\xA1\x7B\xBD\x58\x31\x2B\x77\xCA\xD3\xD9\x4A\xC8\xFB\x85\x42\xF0\xEB\x65\x3A\xD7\x3D\x7F\xCE\x93\x2B\xB8\x74\xCB\x89\xAC\x39\xFC\x47\xF8\x26\x7C\xF0\xF0\xC2\x09\xF2\x04\xB2\xD8\x57\x8A\x3B\xDF\x46\x1C\xB6\xA2\x71\xA4\x68\xBE\xBA\xCC\xD9\x68\x50\x14\xCC\xBC\x9A\x73\x61\x8C\x6A\x5E\x77\x8A\x21\xCC\x84\x16\xC6\x0A\xD2\x4D\xDC\x41\x7A\x13\x0D\x53\xED\xA6\xDF\xBF\xE4\x7D\x09\x17\x0A\x7B\xE1\xA7\x08\xB7\xB5\xF3\xAD\x46\x43\x10\xBE\x36\xD9\xA2\xA9\x5D\xC3\x9E\x83\xD3\x86\x67\xE8\x42\xEB\x64\x11\xE8\xA2\x37\x12\x29\x7B\x16\x5F\x69\x0C\x2D\x7C\xA1\xB1\x34\x6E\x3C\x1F\xCC\xF5\xCA\xFD\x4F\x8B\xE0"- , "\x67\x24\xC3\x72\xD2\xE9\x07\x4D\xA5\xE2\x7A\x6C\x54\xB2\xD7\x03\xDC\x1D\x4C\x9B\x1F\x8D\x90\xF0\x0C\x12\x2E\x69\x2A\xCE\x77\x00\xEA\xDC\xA9\x42\x54\x45\x07\xF1\x37\x5B\x65\x81\xD5\xA8\xFB\x39\x98\x1C\x1C\x0E\x6E\x1F\xF2\x14\x0B\x08\x2E\x9E\xC0\x16\xFC\xE1\x41\xD5\x19\x96\x47\xD4\x3B\x0B\x68\xBF\xD0\xFE\xA5\xE0\x0F\x46\x89\x62\xC7\x38\x4D\xD6\x12\x9A\xEA\x6A\x3F\xDF\xE7\x5A\xBB\x21\x0E\xD5\x60\x7C\xEF\x8F\xA0\xE1\x52\x83\x3D\x5A\xC3\x7D\x52\xE5\x57\xB9\x10\x98\xA3\x22\xE7\x6A\x45\xBB\xBC\xF4\x89\x9E\x79\x06\x18\xAA\x3F\x4C\x2E\x5E\x0F\xC3\xDE\x93\x26\x9A\x57\x7D\x77\xA5\x50\x2E\x8E\xA0\x2F\x71\x7B\x1D\xD2\xDF\x1E\xC6\x9D\x8B\x61\xCA")- , ( 20- , "\x76\x01\x58\xDA\x09\xF8\x9B\xBA\xB2\xC9\x9E\x69\x97\xF9\x52\x3A\x95\xFC\xEF\x10\x23\x9B\xCC\xA2\x57\x3B\x71\x05\xF6\x89\x8D\x34"- , "\x43\x63\x6B\x2C\xC3\x46\xFC\x8B\x7C\x85\xA1\x9B\xF5\x07\xBD\xC3\xDA\xFE\x95\x3B\x88\xC6\x9D\xBA"- , "\xD3\x0A\x6D\x42\xDF\xF4\x9F\x0E\xD0\x39\xA3\x06\xBA\xE9\xDE\xC8\xD9\xE8\x83\x66\xCC\x19\xE8\xC3\x64\x2F\xD5\x8F\xA0\x79\x4E\xBF\x80\x29\xD9\x49\x73\x03\x39\xB0\x82\x3A\x51\xF0\xF4\x9F\x0D\x2C\x71\xF1\x05\x1C\x1E\x0E\x2C\x86\x94\x1F\x17\x27\x89\xCD\xB1\xB0\x10\x74\x13\xE7\x0F\x98\x2F\xF9\x76\x18\x77\xBB\x52\x6E\xF1\xC3\xEB\x11\x06\xA9\x48\xD6\x0E\xF2\x1B\xD3\x5D\x32\xCF\xD6\x4F\x89\xB7\x9E\xD6\x3E\xCC\x5C\xCA\x56\x24\x6A\xF7\x36\x76\x6F\x28\x5D\x8E\x6B\x0D\xA9\xCB\x1C\xD2\x10\x20\x22\x3F\xFA\xCC\x5A\x32"- , "\xC8\x15\xB6\xB7\x9B\x64\xF9\x36\x9A\xEC\x8D\xCE\x8C\x75\x3D\xF8\xA5\x0F\x2B\xC9\x7C\x70\xCE\x2F\x01\x4D\xB3\x3A\x65\xAC\x58\x16\xBA\xC9\xE3\x0A\xC0\x8B\xDD\xED\x30\x8C\x65\xCB\x87\xE2\x8E\x2E\x71\xB6\x77\xDC\x25\xC5\xA6\x49\x9C\x15\x53\x55\x5D\xAF\x1F\x55\x27\x0A\x56\x95\x9D\xFF\xA0\xC6\x6F\x24\xE0\xAF\x00\x95\x1E\xC4\xBB\x59\xCC\xC3\xA6\xC5\xF5\x2E\x09\x81\x64\x7E\x53\xE4\x39\x31\x3A\x52\xC4\x0F\xA7\x00\x4C\x85\x5B\x6E\x6E\xB2\x5B\x21\x2A\x13\x8E\x84\x3A\x9B\xA4\x6E\xDB\x2A\x03\x9E\xE8\x2A\x26\x3A\xBE")- , ( 20- , "\x27\xBA\x7E\x81\xE7\xED\xD4\xE7\x1B\xE5\x3C\x07\xCE\x8E\x63\x31\x38\xF2\x87\xE1\x55\xC7\xFA\x9E\x84\xC4\xAD\x80\x4B\x7F\xA1\xB9"- , "\xEA\x05\xF4\xEB\xCD\x2F\xB6\xB0\x00\xDA\x06\x12\x86\x1B\xA5\x4F\xF5\xC1\x76\xFB\x60\x13\x91\xAA"- , "\xE0\x9F\xF5\xD2\xCB\x05\x0D\x69\xB2\xD4\x24\x94\xBD\xE5\x82\x52\x38\xC7\x56\xD6\x99\x1D\x99\xD7\xA2\x0D\x1E\xF0\xB8\x3C\x37\x1C\x89\x87\x26\x90\xB2\xFC\x11\xD5\x36\x9F\x4F\xC4\x97\x1B\x6D\x3D\x6C\x07\x8A\xEF\x9B\x0F\x05\xC0\xE6\x1A\xB8\x9C\x02\x51\x68\x05\x4D\xEF\xEB\x03\xFE\xF6\x33\x85\x87\x00\xC5\x8B\x12\x62\xCE\x01\x13\x00\x01\x26\x73\xE8\x93\xE4\x49\x01\xDC\x18\xEE\xE3\x10\x56\x99\xC4\x4C\x80\x58\x97\xBD\xAF\x77\x6A\xF1\x83\x31\x62\xA2\x1A"- , "\xA2\x3E\x7E\xF9\x3C\x5D\x06\x67\xC9\x6D\x9E\x40\x4D\xCB\xE6\xBE\x62\x02\x6F\xA9\x8F\x7A\x3F\xF9\xBA\x5D\x45\x86\x43\xA1\x6A\x1C\xEF\x72\x72\xDC\x60\x97\xA9\xB5\x2F\x35\x98\x35\x57\xC7\x7A\x11\xB3\x14\xB4\xF7\xD5\xDC\x2C\xCA\x15\xEE\x47\x61\x6F\x86\x18\x73\xCB\xFE\xD1\xD3\x23\x72\x17\x1A\x61\xE3\x8E\x44\x7F\x3C\xF3\x62\xB3\xAB\xBB\x2E\xD4\x17\x0D\x89\xDC\xB2\x81\x87\xB7\xBF\xD2\x06\xA3\xE0\x26\xF0\x84\xA7\xE0\xED\x63\xD3\x19\xDE\x6B\xC9\xAF\xC0")- , ( 20- , "\x67\x99\xD7\x6E\x5F\xFB\x5B\x49\x20\xBC\x27\x68\xBA\xFD\x3F\x8C\x16\x55\x4E\x65\xEF\xCF\x9A\x16\xF4\x68\x3A\x7A\x06\x92\x7C\x11"- , "\x61\xAB\x95\x19\x21\xE5\x4F\xF0\x6D\x9B\x77\xF3\x13\xA4\xE4\x9D\xF7\xA0\x57\xD5\xFD\x62\x79\x89"- , "\x47\x27\x66"- , "\x8F\xD7\xDF")- , ( 20+ [+ ( 20+ , "\xA6\xA7\x25\x1C\x1E\x72\x91\x6D\x11\xC2\xCB\x21\x4D\x3C\x25\x25\x39\x12\x1D\x8E\x23\x4E\x65\x2D\x65\x1F\xA4\xC8\xCF\xF8\x80\x30"+ , "\x9E\x64\x5A\x74\xE9\xE0\xA6\x0D\x82\x43\xAC\xD9\x17\x7A\xB5\x1A\x1B\xEB\x8D\x5A\x2F\x5D\x70\x0C"+ , "\x09\x3C\x5E\x55\x85\x57\x96\x25\x33\x7B\xD3\xAB\x61\x9D\x61\x57\x60\xD8\xC5\xB2\x24\xA8\x5B\x1D\x0E\xFE\x0E\xB8\xA7\xEE\x16\x3A\xBB\x03\x76\x52\x9F\xCC\x09\xBA\xB5\x06\xC6\x18\xE1\x3C\xE7\x77\xD8\x2C\x3A\xE9\xD1\xA6\xF9\x72\xD4\x16\x02\x87\xCB\xFE\x60\xBF\x21\x30\xFC\x0A\x6F\xF6\x04\x9D\x0A\x5C\x8A\x82\xF4\x29\x23\x1F\x00\x80\x82\xE8\x45\xD7\xE1\x89\xD3\x7F\x9E\xD2\xB4\x64\xE6\xB9\x19\xE6\x52\x3A\x8C\x12\x10\xBD\x52\xA0\x2A\x4C\x3F\xE4\x06\xD3\x08\x5F\x50\x68\xD1\x90\x9E\xEE\xCA\x63\x69\xAB\xC9\x81\xA4\x2E\x87\xFE\x66\x55\x83\xF0\xAB\x85\xAE\x71\xF6\xF8\x4F\x52\x8E\x6B\x39\x7A\xF8\x6F\x69\x17\xD9\x75\x4B\x73\x20\xDB\xDC\x2F\xEA\x81\x49\x6F\x27\x32\xF5\x32\xAC\x78\xC4\xE9\xC6\xCF\xB1\x8F\x8E\x9B\xDF\x74\x62\x2E\xB1\x26\x14\x14\x16\x77\x69\x71\xA8\x4F\x94\xD1\x56\xBE\xAF\x67\xAE\xCB\xF2\xAD\x41\x2E\x76\xE6\x6E\x8F\xAD\x76\x33\xF5\xB6\xD7\xF3\xD6\x4B\x5C\x6C\x69\xCE\x29\x00\x3C\x60\x24\x46\x5A\xE3\xB8\x9B\xE7\x8E\x91\x5D\x88\xB4\xB5\x62\x1D"+ , "\xB2\xAF\x68\x8E\x7D\x8F\xC4\xB5\x08\xC0\x5C\xC3\x9D\xD5\x83\xD6\x71\x43\x22\xC6\x4D\x7F\x3E\x63\x14\x7A\xED\xE2\xD9\x53\x49\x34\xB0\x4F\xF6\xF3\x37\xB0\x31\x81\x5C\xD0\x94\xBD\xBC\x6D\x7A\x92\x07\x7D\xCE\x70\x94\x12\x28\x68\x22\xEF\x07\x37\xEE\x47\xF6\xB7\xFF\xA2\x2F\x9D\x53\xF1\x1D\xD2\xB0\xA3\xBB\x9F\xC0\x1D\x9A\x88\xF9\xD5\x3C\x26\xE9\x36\x5C\x2C\x3C\x06\x3B\xC4\x84\x0B\xFC\x81\x2E\x4B\x80\x46\x3E\x69\xD1\x79\x53\x0B\x25\xC1\x58\xF5\x43\x19\x1C\xFF\x99\x31\x06\x51\x1A\xA0\x36\x04\x3B\xBC\x75\x86\x6A\xB7\xE3\x4A\xFC\x57\xE2\xCC\xE4\x93\x4A\x5F\xAA\xE6\xEA\xBE\x4F\x22\x17\x70\x18\x3D\xD0\x60\x46\x78\x27\xC2\x7A\x35\x41\x59\xA0\x81\x27\x5A\x29\x1F\x69\xD9\x46\xD6\xFE\x28\xED\x0B\x9C\xE0\x82\x06\xCF\x48\x49\x25\xA5\x1B\x94\x98\xDB\xDE\x17\x8D\xDD\x3A\xE9\x1A\x85\x81\xB9\x16\x82\xD8\x60\xF8\x40\x78\x2F\x6E\xEA\x49\xDB\xB9\xBD\x72\x15\x01\xD2\xC6\x71\x22\xDE\xA3\xB7\x28\x38\x48\xC5\xF1\x3E\x0C\x0D\xE8\x76\xBD\x22\x7A\x85\x6E\x4D\xE5\x93\xA3"+ )+ ,+ ( 20+ , "\x9E\x1D\xA2\x39\xD1\x55\xF5\x2A\xD3\x7F\x75\xC7\x36\x8A\x53\x66\x68\xB0\x51\x95\x29\x23\xAD\x44\xF5\x7E\x75\xAB\x58\x8E\x47\x5A"+ , "\xAF\x06\xF1\x78\x59\xDF\xFA\x79\x98\x91\xC4\x28\x8F\x66\x35\xB5\xC5\xA4\x5E\xEE\x90\x17\xFD\x72"+ , "\xFE\xAC\x9D\x54\xFC\x8C\x11\x5A\xE2\x47\xD9\xA7\xE9\x19\xDD\x76\xCF\xCB\xC7\x2D\x32\xCA\xE4\x94\x48\x60\x81\x7C\xBD\xFB\x8C\x04\xE6\xB1\xDF\x76\xA1\x65\x17\xCD\x33\xCC\xF1\xAC\xDA\x92\x06\x38\x9E\x9E\x31\x8F\x59\x66\xC0\x93\xCF\xB3\xEC\x2D\x9E\xE2\xDE\x85\x64\x37\xED\x58\x1F\x55\x2F\x26\xAC\x29\x07\x60\x9D\xF8\xC6\x13\xB9\xE3\x3D\x44\xBF\xC2\x1F\xF7\x91\x53\xE9\xEF\x81\xA9\xD6\x6C\xC3\x17\x85\x7F\x75\x2C\xC1\x75\xFD\x88\x91\xFE\xFE\xBB\x7D\x04\x1E\x65\x17\xC3\x16\x2D\x19\x7E\x21\x12\x83\x7D\x3B\xC4\x10\x43\x12\xAD\x35\xB7\x5E\xA6\x86\xE7\xC7\x0D\x4E\xC0\x47\x46\xB5\x2F\xF0\x9C\x42\x14\x51\x45\x9F\xB5\x9F"+ , "\x2C\x26\x1A\x2F\x4E\x61\xA6\x2E\x1B\x27\x68\x99\x16\xBF\x03\x45\x3F\xCB\xC9\x7B\xB2\xAF\x6F\x32\x93\x91\xEF\x06\x3B\x5A\x21\x9B\xF9\x84\xD0\x7D\x70\xF6\x02\xD8\x5F\x6D\xB6\x14\x74\xE9\xD9\xF5\xA2\xDE\xEC\xB4\xFC\xD9\x01\x84\xD1\x6F\x3B\x5B\x5E\x16\x8E\xE0\x3E\xA8\xC9\x3F\x39\x33\xA2\x2B\xC3\xD1\xA5\xAE\x8C\x2D\x8B\x02\x75\x7C\x87\xC0\x73\x40\x90\x52\xA2\xA8\xA4\x1E\x7F\x48\x7E\x04\x1F\x9A\x49\xA0\x99\x7B\x54\x0E\x18\x62\x1C\xAD\x3A\x24\xF0\xA5\x6D\x9B\x19\x22\x79\x29\x05\x7A\xB3\xBA\x95\x0F\x62\x74\xB1\x21\xF1\x93\xE3\x2E\x06\xE5\x38\x87\x81\xA1\xCB\x57\x31\x7C\x0B\xA6\x30\x5E\x91\x09\x61\xD0\x10\x02\xF0"+ )+ ,+ ( 20+ , "\xD5\xC7\xF6\x79\x7B\x7E\x7E\x9C\x1D\x7F\xD2\x61\x0B\x2A\xBF\x2B\xC5\xA7\x88\x5F\xB3\xFF\x78\x09\x2F\xB3\xAB\xE8\x98\x6D\x35\xE2"+ , "\x74\x4E\x17\x31\x2B\x27\x96\x9D\x82\x64\x44\x64\x0E\x9C\x4A\x37\x8A\xE3\x34\xF1\x85\x36\x9C\x95"+ , "\x77\x58\x29\x8C\x62\x8E\xB3\xA4\xB6\x96\x3C\x54\x45\xEF\x66\x97\x12\x22\xBE\x5D\x1A\x4A\xD8\x39\x71\x5D\x11\x88\x07\x17\x39\xB7\x7C\xC6\xE0\x5D\x54\x10\xF9\x63\xA6\x41\x67\x62\x97\x57"+ , "\x27\xB8\xCF\xE8\x14\x16\xA7\x63\x01\xFD\x1E\xEC\x6A\x4D\x99\x67\x50\x69\xB2\xDA\x27\x76\xC3\x60\xDB\x1B\xDF\xEA\x7C\x0A\xA6\x13\x91\x3E\x10\xF7\xA6\x0F\xEC\x04\xD1\x1E\x65\xF2\xD6\x4E"+ )+ ,+ ( 20+ , "\x73\x7D\x78\x11\xCE\x96\x47\x2E\xFE\xD1\x22\x58\xB7\x81\x22\xF1\x1D\xEA\xEC\x87\x59\xCC\xBD\x71\xEA\xC6\xBB\xEF\xA6\x27\x78\x5C"+ , "\x6F\xB2\xEE\x3D\xDA\x6D\xBD\x12\xF1\x27\x4F\x12\x67\x01\xEC\x75\xC3\x5C\x86\x60\x7A\xDB\x3E\xDD"+ , "\x50\x13\x25\xFB\x26\x45\x26\x48\x64\xDF\x11\xFA\xA1\x7B\xBD\x58\x31\x2B\x77\xCA\xD3\xD9\x4A\xC8\xFB\x85\x42\xF0\xEB\x65\x3A\xD7\x3D\x7F\xCE\x93\x2B\xB8\x74\xCB\x89\xAC\x39\xFC\x47\xF8\x26\x7C\xF0\xF0\xC2\x09\xF2\x04\xB2\xD8\x57\x8A\x3B\xDF\x46\x1C\xB6\xA2\x71\xA4\x68\xBE\xBA\xCC\xD9\x68\x50\x14\xCC\xBC\x9A\x73\x61\x8C\x6A\x5E\x77\x8A\x21\xCC\x84\x16\xC6\x0A\xD2\x4D\xDC\x41\x7A\x13\x0D\x53\xED\xA6\xDF\xBF\xE4\x7D\x09\x17\x0A\x7B\xE1\xA7\x08\xB7\xB5\xF3\xAD\x46\x43\x10\xBE\x36\xD9\xA2\xA9\x5D\xC3\x9E\x83\xD3\x86\x67\xE8\x42\xEB\x64\x11\xE8\xA2\x37\x12\x29\x7B\x16\x5F\x69\x0C\x2D\x7C\xA1\xB1\x34\x6E\x3C\x1F\xCC\xF5\xCA\xFD\x4F\x8B\xE0"+ , "\x67\x24\xC3\x72\xD2\xE9\x07\x4D\xA5\xE2\x7A\x6C\x54\xB2\xD7\x03\xDC\x1D\x4C\x9B\x1F\x8D\x90\xF0\x0C\x12\x2E\x69\x2A\xCE\x77\x00\xEA\xDC\xA9\x42\x54\x45\x07\xF1\x37\x5B\x65\x81\xD5\xA8\xFB\x39\x98\x1C\x1C\x0E\x6E\x1F\xF2\x14\x0B\x08\x2E\x9E\xC0\x16\xFC\xE1\x41\xD5\x19\x96\x47\xD4\x3B\x0B\x68\xBF\xD0\xFE\xA5\xE0\x0F\x46\x89\x62\xC7\x38\x4D\xD6\x12\x9A\xEA\x6A\x3F\xDF\xE7\x5A\xBB\x21\x0E\xD5\x60\x7C\xEF\x8F\xA0\xE1\x52\x83\x3D\x5A\xC3\x7D\x52\xE5\x57\xB9\x10\x98\xA3\x22\xE7\x6A\x45\xBB\xBC\xF4\x89\x9E\x79\x06\x18\xAA\x3F\x4C\x2E\x5E\x0F\xC3\xDE\x93\x26\x9A\x57\x7D\x77\xA5\x50\x2E\x8E\xA0\x2F\x71\x7B\x1D\xD2\xDF\x1E\xC6\x9D\x8B\x61\xCA"+ )+ ,+ ( 20+ , "\x76\x01\x58\xDA\x09\xF8\x9B\xBA\xB2\xC9\x9E\x69\x97\xF9\x52\x3A\x95\xFC\xEF\x10\x23\x9B\xCC\xA2\x57\x3B\x71\x05\xF6\x89\x8D\x34"+ , "\x43\x63\x6B\x2C\xC3\x46\xFC\x8B\x7C\x85\xA1\x9B\xF5\x07\xBD\xC3\xDA\xFE\x95\x3B\x88\xC6\x9D\xBA"+ , "\xD3\x0A\x6D\x42\xDF\xF4\x9F\x0E\xD0\x39\xA3\x06\xBA\xE9\xDE\xC8\xD9\xE8\x83\x66\xCC\x19\xE8\xC3\x64\x2F\xD5\x8F\xA0\x79\x4E\xBF\x80\x29\xD9\x49\x73\x03\x39\xB0\x82\x3A\x51\xF0\xF4\x9F\x0D\x2C\x71\xF1\x05\x1C\x1E\x0E\x2C\x86\x94\x1F\x17\x27\x89\xCD\xB1\xB0\x10\x74\x13\xE7\x0F\x98\x2F\xF9\x76\x18\x77\xBB\x52\x6E\xF1\xC3\xEB\x11\x06\xA9\x48\xD6\x0E\xF2\x1B\xD3\x5D\x32\xCF\xD6\x4F\x89\xB7\x9E\xD6\x3E\xCC\x5C\xCA\x56\x24\x6A\xF7\x36\x76\x6F\x28\x5D\x8E\x6B\x0D\xA9\xCB\x1C\xD2\x10\x20\x22\x3F\xFA\xCC\x5A\x32"+ , "\xC8\x15\xB6\xB7\x9B\x64\xF9\x36\x9A\xEC\x8D\xCE\x8C\x75\x3D\xF8\xA5\x0F\x2B\xC9\x7C\x70\xCE\x2F\x01\x4D\xB3\x3A\x65\xAC\x58\x16\xBA\xC9\xE3\x0A\xC0\x8B\xDD\xED\x30\x8C\x65\xCB\x87\xE2\x8E\x2E\x71\xB6\x77\xDC\x25\xC5\xA6\x49\x9C\x15\x53\x55\x5D\xAF\x1F\x55\x27\x0A\x56\x95\x9D\xFF\xA0\xC6\x6F\x24\xE0\xAF\x00\x95\x1E\xC4\xBB\x59\xCC\xC3\xA6\xC5\xF5\x2E\x09\x81\x64\x7E\x53\xE4\x39\x31\x3A\x52\xC4\x0F\xA7\x00\x4C\x85\x5B\x6E\x6E\xB2\x5B\x21\x2A\x13\x8E\x84\x3A\x9B\xA4\x6E\xDB\x2A\x03\x9E\xE8\x2A\x26\x3A\xBE"+ )+ ,+ ( 20+ , "\x27\xBA\x7E\x81\xE7\xED\xD4\xE7\x1B\xE5\x3C\x07\xCE\x8E\x63\x31\x38\xF2\x87\xE1\x55\xC7\xFA\x9E\x84\xC4\xAD\x80\x4B\x7F\xA1\xB9"+ , "\xEA\x05\xF4\xEB\xCD\x2F\xB6\xB0\x00\xDA\x06\x12\x86\x1B\xA5\x4F\xF5\xC1\x76\xFB\x60\x13\x91\xAA"+ , "\xE0\x9F\xF5\xD2\xCB\x05\x0D\x69\xB2\xD4\x24\x94\xBD\xE5\x82\x52\x38\xC7\x56\xD6\x99\x1D\x99\xD7\xA2\x0D\x1E\xF0\xB8\x3C\x37\x1C\x89\x87\x26\x90\xB2\xFC\x11\xD5\x36\x9F\x4F\xC4\x97\x1B\x6D\x3D\x6C\x07\x8A\xEF\x9B\x0F\x05\xC0\xE6\x1A\xB8\x9C\x02\x51\x68\x05\x4D\xEF\xEB\x03\xFE\xF6\x33\x85\x87\x00\xC5\x8B\x12\x62\xCE\x01\x13\x00\x01\x26\x73\xE8\x93\xE4\x49\x01\xDC\x18\xEE\xE3\x10\x56\x99\xC4\x4C\x80\x58\x97\xBD\xAF\x77\x6A\xF1\x83\x31\x62\xA2\x1A"+ , "\xA2\x3E\x7E\xF9\x3C\x5D\x06\x67\xC9\x6D\x9E\x40\x4D\xCB\xE6\xBE\x62\x02\x6F\xA9\x8F\x7A\x3F\xF9\xBA\x5D\x45\x86\x43\xA1\x6A\x1C\xEF\x72\x72\xDC\x60\x97\xA9\xB5\x2F\x35\x98\x35\x57\xC7\x7A\x11\xB3\x14\xB4\xF7\xD5\xDC\x2C\xCA\x15\xEE\x47\x61\x6F\x86\x18\x73\xCB\xFE\xD1\xD3\x23\x72\x17\x1A\x61\xE3\x8E\x44\x7F\x3C\xF3\x62\xB3\xAB\xBB\x2E\xD4\x17\x0D\x89\xDC\xB2\x81\x87\xB7\xBF\xD2\x06\xA3\xE0\x26\xF0\x84\xA7\xE0\xED\x63\xD3\x19\xDE\x6B\xC9\xAF\xC0"+ )+ ,+ ( 20+ , "\x67\x99\xD7\x6E\x5F\xFB\x5B\x49\x20\xBC\x27\x68\xBA\xFD\x3F\x8C\x16\x55\x4E\x65\xEF\xCF\x9A\x16\xF4\x68\x3A\x7A\x06\x92\x7C\x11"+ , "\x61\xAB\x95\x19\x21\xE5\x4F\xF0\x6D\x9B\x77\xF3\x13\xA4\xE4\x9D\xF7\xA0\x57\xD5\xFD\x62\x79\x89"+ , "\x47\x27\x66"+ , "\x8F\xD7\xDF"+ )+ ,+ ( 20 , "\xF6\x82\x38\xC0\x83\x65\xBB\x29\x3D\x26\x98\x0A\x60\x64\x88\xD0\x9C\x2F\x10\x9E\xDA\xFA\x0B\xBA\xE9\x93\x7B\x5C\xC2\x19\xA4\x9C" , "\x51\x90\xB5\x1E\x9B\x70\x86\x24\x82\x0B\x5A\xBD\xF4\xE4\x0F\xAD\x1F\xB9\x50\xAD\x1A\xDC\x2D\x26" , "\x47\xEC\x6B\x1F\x73\xC4\xB7\xFF\x52\x74\xA0\xBF\xD7\xF4\x5F\x86\x48\x12\xC8\x5A\x12\xFB\xCB\x3C\x2C\xF8\xA3\xE9\x0C\xF6\x6C\xCF\x2E\xAC\xB5\x21\xE7\x48\x36\x3C\x77\xF5\x2E\xB4\x26\xAE\x57\xA0\xC6\xC7\x8F\x75\xAF\x71\x28\x45\x69\xE7\x9D\x1A\x92\xF9\x49\xA9\xD6\x9C\x4E\xFC\x0B\x69\x90\x2F\x1E\x36\xD7\x56\x27\x65\x54\x3E\x2D\x39\x42\xD9\xF6\xFF\x59\x48\xD8\xA3\x12\xCF\xF7\x2C\x1A\xFD\x9E\xA3\x08\x8A\xFF\x76\x40\xBF\xD2\x65\xF7\xA9\x94\x6E\x60\x6A\xBC\x77\xBC\xED\xAE\x6B\xDD\xC7\x5A\x0D\xBA\x0B\xD9\x17\xD7\x3E\x3B\xD1\x26\x8F\x72\x7E\x00\x96\x34\x5D\xA1\xED\x25\xCF\x55\x3E\xA7\xA9\x8F\xEA\x6B\x6F\x28\x57\x32\xDE\x37\x43\x15\x61\xEE\x1B\x30\x64\x88\x7F\xBC\xBD\x71\x93\x5E\x02"- , "\x36\x16\x0E\x88\xD3\x50\x05\x29\xBA\x4E\xDB\xA1\x7B\xC2\x4D\x8C\xFA\xCA\x9A\x06\x80\xB3\xB1\xFC\x97\xCF\x03\xF3\x67\x5B\x7A\xC3\x01\xC8\x83\xA6\x8C\x07\x1B\xC5\x4A\xCD\xD3\xB6\x3A\xF4\xA2\xD7\x2F\x98\x5E\x51\xF9\xD6\x0A\x4C\x7F\xD4\x81\xAF\x10\xB2\xFC\x75\xE2\x52\xFD\xEE\x7E\xA6\xB6\x45\x31\x90\x61\x7D\xCC\x6E\x2F\xE1\xCD\x56\x58\x5F\xC2\xF0\xB0\xE9\x7C\x5C\x3F\x8A\xD7\xEB\x4F\x31\xBC\x48\x90\xC0\x38\x82\xAA\xC2\x4C\xC5\x3A\xCC\x19\x82\x29\x65\x26\x69\x0A\x22\x02\x71\xC2\xF6\xE3\x26\x75\x0D\x3F\xBD\xA5\xD5\xB6\x35\x12\xC8\x31\xF6\x78\x30\xF5\x9A\xC4\x9A\xAE\x33\x0B\x3E\x0E\x02\xC9\xEA\x00\x91\xD1\x98\x41\xF1\xB0\xE1\x3D\x69\xC9\xFB\xFE\x8A\x12\xD6\xF3\x0B\xB7\x34\xD9\xD2")- , ( 20- , "\x45\xB2\xBD\x0D\xE4\xED\x92\x93\xEC\x3E\x26\xC4\x84\x0F\xAA\xF6\x4B\x7D\x61\x9D\x51\xE9\xD7\xA2\xC7\xE3\x6C\x83\xD5\x84\xC3\xDF"- , "\x54\x6C\x8C\x5D\x6B\xE8\xF9\x09\x52\xCA\xB3\xF3\x6D\x7C\x19\x57\xBA\xAA\x7A\x59\xAB\xE3\xD7\xE5"- , "\x50\x07\xC8\xCD\x5B\x3C\x40\xE1\x7D\x7F\xE4\x23\xA8\x7A\xE0\xCE\xD8\x6B\xEC\x1C\x39\xDC\x07\xA2\x57\x72\xF3\xE9\x6D\xAB\xD5\x6C\xD3\xFD\x73\x19\xF6\xC9\x65\x49\x25\xF2\xD8\x70\x87\xA7\x00\xE1\xB1\x30\xDA\x79\x68\x95\xD1\xC9\xB9\xAC\xD6\x2B\x26\x61\x44\x06\x7D\x37\x3E\xD5\x1E\x78\x74\x98\xB0\x3C\x52\xFA\xAD\x16\xBB\x38\x26\xFA\x51\x1B\x0E\xD2\xA1\x9A\x86\x63\xF5\xBA\x2D\x6E\xA7\xC3\x8E\x72\x12\xE9\x69\x7D\x91\x48\x6C\x49\xD8\xA0\x00\xB9\xA1\x93\x5D\x6A\x7F\xF7\xEF\x23\xE7\x20\xA4\x58\x55\x48\x14\x40\x46\x3B\x4A\xC8\xC4\xF6\xE7\x06\x2A\xDC\x1F\x1E\x1E\x25\xD3\xD6\x5A\x31\x81\x2F\x58\xA7\x11\x60"- , "\x8E\xAC\xFB\xA5\x68\x89\x8B\x10\xC0\x95\x7A\x7D\x44\x10\x06\x85\xE8\x76\x3A\x71\xA6\x9A\x8D\x16\xBC\x7B\x3F\x88\x08\x5B\xB9\xA2\xF0\x96\x42\xE4\xD0\x9A\x9F\x0A\xD0\x9D\x0A\xAD\x66\xB2\x26\x10\xC8\xBD\x02\xFF\x66\x79\xBB\x92\xC2\xC0\x26\xA2\x16\xBF\x42\x5C\x6B\xE3\x5F\xB8\xDA\xE7\xFF\x0C\x72\xB0\xEF\xD6\xA1\x80\x37\xC7\x0E\xED\x0C\xA9\x00\x62\xA4\x9A\x3C\x97\xFD\xC9\x0A\x8F\x9C\x2E\xA5\x36\xBF\xDC\x41\x91\x8A\x75\x82\xC9\x92\x7F\xAE\x47\xEF\xAA\x3D\xC8\x79\x67\xB7\x88\x7D\xEE\x1B\xF0\x71\x73\x4C\x76\x65\x90\x1D\x91\x05\xDA\xE2\xFD\xF6\x6B\x49\x18\xE5\x1D\x8F\x4A\x48\xC6\x0D\x19\xFB\xFB\xBC\xBA")- , ( 20- , "\xFE\x55\x9C\x9A\x28\x2B\xEB\x40\x81\x4D\x01\x6D\x6B\xFC\xB2\xC0\xC0\xD8\xBF\x07\x7B\x11\x10\xB8\x70\x3A\x3C\xE3\x9D\x70\xE0\xE1"- , "\xB0\x76\x20\x0C\xC7\x01\x12\x59\x80\x5E\x18\xB3\x04\x09\x27\x54\x00\x27\x23\xEB\xEC\x5D\x62\x00"- , "\x6D\xB6\x5B\x9E\xC8\xB1\x14\xA9\x44\x13\x7C\x82\x1F\xD6\x06\xBE\x75\x47\x8D\x92\x83\x66\xD5\x28\x40\x96\xCD\xEF\x78\x2F\xCF\xF7\xE8\xF5\x9C\xB8\xFF\xCD\xA9\x79\x75\x79\x02\xC5\xFF\xA6\xBC\x47\x7C\xEA\xA4\xCB\x5D\x5E\xA7\x6F\x94\xD9\x1E\x83\x3F\x82\x3A\x6B\xC7\x8F\x10\x55\xDF\xA6\xA9\x7B\xEA\x89\x65\xC1\xCD\xE6\x7A\x66\x8E\x00\x12\x57\x33\x4A\x58\x57\x27\xD9\xE0\xF7\xC1\xA0\x6E\x88\xD3\xD2\x5A\x4E\x6D\x90\x96\xC9\x68\xBF\x13\x8E\x11\x6A\x3E\xBE\xFF\xD4\xBB\x48\x08\xAD\xB1\xFD\x69\x81\x64\xBA\x0A\x35\xC7\x09\xA4\x7F\x16\xF1\xF4\x43\x5A\x23\x45\xA9\x19\x4A\x00\xB9\x5A\xBD\x51\x85\x1D\x50\x58\x09\xA6\x07\x7D\xA9\xBA\xCA\x58\x31\xAF\xFF\x31\x57\x8C\x48\x7E\xE6\x8F\x27\x67\x97\x4A\x98\xA7\xE8\x03\xAA\xC7\x88\xDA\x98\x31\x9C\x4E\xA8\xEA\xA3\xD3\x94\x85\x56\x51\xF4\x84\xCE\xF5\x43\xF5\x37\xE3\x51\x58\xEE\x29"- , "\x4D\xCE\x9C\x8F\x97\xA0\x28\x05\x1B\x07\x27\xF3\x4E\x1B\x9E\xF2\x1F\x06\xF0\x76\x0F\x36\xE7\x17\x13\x20\x40\x27\x90\x20\x90\xBA\x2B\xB6\xB1\x34\x36\xEE\x77\x8D\x9F\x50\x53\x0E\xFB\xD7\xA3\x2B\x0D\x41\x44\x3F\x58\xCC\xAE\xE7\x81\xC7\xB7\x16\xD3\xA9\x6F\xDE\xC0\xE3\x76\x4E\xD7\x95\x9F\x34\xC3\x94\x12\x78\x59\x1E\xA0\x33\xB5\xCB\xAD\xC0\xF1\x91\x60\x32\xE9\xBE\xBB\xD1\xA8\x39\x5B\x83\xFB\x63\xB1\x45\x4B\xD7\x75\xBD\x20\xB3\xA2\xA9\x6F\x95\x12\x46\xAC\x14\xDA\xF6\x81\x66\xBA\x62\xF6\xCB\xFF\x8B\xD1\x21\xAC\x94\x98\xFF\x88\x52\xFD\x2B\xE9\x75\xDF\x52\xB5\xDA\xEF\x38\x29\xD1\x8E\xDA\x42\xE7\x15\x02\x2D\xCB\xF9\x30\xD0\xA7\x89\xEE\x6A\x14\x6C\x2C\x70\x88\xC3\x57\x73\xC6\x3C\x06\xB4\xAF\x45\x59\x85\x6A\xC1\x99\xCE\xD8\x68\x63\xE4\x29\x47\x07\x82\x53\x37\xC5\x85\x79\x70\xEB\x7F\xDD\xEB\x26\x37\x81\x30\x90\x11")- , ( 20- , "\x0A\xE1\x00\x12\xD7\xE5\x66\x14\xB0\x3D\xCC\x89\xB1\x4B\xAE\x92\x42\xFF\xE6\x30\xF3\xD7\xE3\x5C\xE8\xBB\xB9\x7B\xBC\x2C\x92\xC3"- , "\xF9\x6B\x02\x5D\x6C\xF4\x6A\x8A\x12\xAC\x2A\xF1\xE2\xAE\xF1\xFB\x83\x59\x0A\xDA\xDA\xA5\xC5\xEA"- , "\xEA\x0F\x35\x4E\x96\xF1\x2B\xC7\x2B\xBA\xA3\xD1\x2B\x4A\x8E\xD8\x79\xB0\x42\xF0\x68\x98\x78\xF4\x6B\x65\x1C\xC4\x11\x6D\x6F\x78\x40\x9B\x11\x43\x0B\x3A\xAA\x30\xB2\x07\x68\x91\xE8\xE1\xFA\x52\x8F\x2F\xD1\x69\xED\x93\xDC\x9F\x84\xE2\x44\x09\xEE\xC2\x10\x1D\xAF\x4D\x05\x7B\xE2\x49\x2D\x11\xDE\x64\x0C\xBD\x7B\x35\x5A\xD2\x9F\xB7\x04\x00\xFF\xFD\x7C\xD6\xD4\x25\xAB\xEE\xB7\x32\xA0\xEA\xA4\x33\x0A\xF4\xC6\x56\x25\x2C\x41\x73\xDE\xAB\x65\x3E\xB8\x5C\x58\x46\x2D\x7A\xB0\xF3\x5F\xD1\x2B\x61\x3D\x29\xD4\x73\xD3\x30\x31\x0D\xC3\x23\xD3\xC6\x63\x48\xBB\xDB\xB6\x8A\x32\x63\x24\x65\x7C\xAE\x7B\x77\xA9\xE3\x43\x58\xF2\xCE\xC5\x0C\x85\x60\x9E\x73\x05\x68\x56\x79\x6E\x3B\xE8\xD6\x2B\x6E\x2F\xE9\xF9\x53"- , "\xE8\xAB\xD4\x89\x24\xB5\x4E\x5B\x80\x86\x6B\xE7\xD4\xEB\xE5\xCF\x42\x74\xCA\xFF\xF0\x8B\x39\xCB\x2D\x40\xA8\xF0\xB4\x72\x39\x8A\xED\xC7\x76\xE0\x79\x38\x12\xFB\xF1\xF6\x00\x78\x63\x5D\x2E\xD8\x6B\x15\xEF\xCD\xBA\x60\x41\x1E\xE2\x3B\x07\x23\x35\x92\xA4\x4E\xC3\x1B\x10\x13\xCE\x89\x64\x23\x66\x75\xF8\xF1\x83\xAE\xF8\x85\xE8\x64\xF2\xA7\x2E\xDF\x42\x15\xB5\x33\x8F\xA2\xB5\x46\x53\xDF\xA1\xA8\xC5\x5C\xE5\xD9\x5C\xC6\x05\xB9\xB3\x11\x52\x7F\x2E\x34\x63\xFF\xBE\xC7\x8A\x9D\x1D\x65\xDA\xBA\xD2\xF3\x38\x76\x9C\x9F\x43\xF1\x33\xA7\x91\xA1\x1C\x7E\xCA\x9A\xF0\xB7\x71\xA4\xAC\x32\x96\x3D\xC8\xF6\x31\xA2\xC1\x12\x17\xAC\x6E\x1B\x94\x30\xC1\xAA\xE1\xCE\xEB\xE2\x27\x03\xF4\x29\x99\x8A\x8F\xB8\xC6\x41")- , ( 20- , "\x08\x2C\x53\x9B\xC5\xB2\x0F\x97\xD7\x67\xCD\x3F\x22\x9E\xDA\x80\xB2\xAD\xC4\xFE\x49\xC8\x63\x29\xB5\xCD\x62\x50\xA9\x87\x74\x50"- , "\x84\x55\x43\x50\x2E\x8B\x64\x91\x2D\x8F\x2C\x8D\x9F\xFF\xB3\xC6\x93\x65\x68\x65\x87\xC0\x8D\x0C"- , "\xA9\x6B\xB7\xE9\x10\x28\x1A\x6D\xFA\xD7\xC8\xA9\xC3\x70\x67\x4F\x0C\xEE\xC1\xAD\x8D\x4F\x0D\xE3\x2F\x9A\xE4\xA2\x3E\xD3\x29\xE3\xD6\xBC\x70\x8F\x87\x66\x40\xA2\x29\x15\x3A\xC0\xE7\x28\x1A\x81\x88\xDD\x77\x69\x51\x38\xF0\x1C\xDA\x5F\x41\xD5\x21\x5F\xD5\xC6\xBD\xD4\x6D\x98\x2C\xB7\x3B\x1E\xFE\x29\x97\x97\x0A\x9F\xDB\xDB\x1E\x76\x8D\x7E\x5D\xB7\x12\x06\x8D\x8B\xA1\xAF\x60\x67\xB5\x75\x34\x95\xE2\x3E\x6E\x19\x63\xAF\x01\x2F\x9C\x7C\xE4\x50\xBF\x2D\xE6\x19\xD3\xD5\x95\x42\xFB\x55\xF3"- , "\x83\x5D\xA7\x4F\xC6\xDE\x08\xCB\xDA\x27\x7A\x79\x66\xA0\x7C\x8D\xCD\x62\x7E\x7B\x17\xAD\xDE\x6D\x93\x0B\x65\x81\xE3\x12\x4B\x8B\xAA\xD0\x96\xF6\x93\x99\x1F\xED\xB1\x57\x29\x30\x60\x1F\xC7\x70\x95\x41\x83\x9B\x8E\x3F\xFD\x5F\x03\x3D\x20\x60\xD9\x99\xC6\xC6\xE3\x04\x82\x76\x61\x3E\x64\x80\x00\xAC\xB5\x21\x2C\xC6\x32\xA9\x16\xAF\xCE\x29\x0E\x20\xEB\xDF\x61\x2D\x08\xA6\xAA\x4C\x79\xA7\x4B\x07\x0D\x3F\x87\x2A\x86\x1F\x8D\xC6\xBB\x07\x61\x4D\xB5\x15\xD3\x63\x34\x9D\x3A\x8E\x33\x36\xA3")- , ( 20- , "\x3D\x02\xBF\xF3\x37\x5D\x40\x30\x27\x35\x6B\x94\xF5\x14\x20\x37\x37\xEE\x9A\x85\xD2\x05\x2D\xB3\xE4\xE5\xA2\x17\xC2\x59\xD1\x8A"- , "\x74\x21\x6C\x95\x03\x18\x95\xF4\x8C\x1D\xBA\x65\x15\x55\xEB\xFA\x3C\xA3\x26\xA7\x55\x23\x70\x25"- , "\x0D\x4B\x0F\x54\xFD\x09\xAE\x39\xBA\xA5\xFA\x4B\xAC\xCF\x2E\x66\x82\xE6\x1B\x25\x7E\x01\xF4\x2B\x8F"- , "\x16\xC4\x00\x6C\x28\x36\x51\x90\x41\x1E\xB1\x59\x38\x14\xCF\x15\xE7\x4C\x22\x23\x8F\x21\x0A\xFC\x3D")- , ( 20- , "\xAD\x1A\x5C\x47\x68\x88\x74\xE6\x66\x3A\x0F\x3F\xA1\x6F\xA7\xEF\xB7\xEC\xAD\xC1\x75\xC4\x68\xE5\x43\x29\x14\xBD\xB4\x80\xFF\xC6"- , "\xE4\x89\xEE\xD4\x40\xF1\xAA\xE1\xFA\xC8\xFB\x7A\x98\x25\x63\x54\x54\xF8\xF8\xF1\xF5\x2E\x2F\xCC"- , "\xAA\x6C\x1E\x53\x58\x0F\x03\xA9\xAB\xB7\x3B\xFD\xAD\xED\xFE\xCA\xDA\x4C\x6B\x0E\xBE\x02\x0E\xF1\x0D\xB7\x45\xE5\x4B\xA8\x61\xCA\xF6\x5F\x0E\x40\xDF\xC5\x20\x20\x3B\xB5\x4D\x29\xE0\xA8\xF7\x8F\x16\xB3\xF1\xAA\x52\x5D\x6B\xFA\x33\xC5\x47\x26\xE5\x99\x88\xCF\xBE\xC7\x80\x56"- , "\x02\xFE\x84\xCE\x81\xE1\x78\xE7\xAA\xBD\xD3\xBA\x92\x5A\x76\x6C\x3C\x24\x75\x6E\xEF\xAE\x33\x94\x2A\xF7\x5E\x8B\x46\x45\x56\xB5\x99\x7E\x61\x6F\x3F\x2D\xFC\x7F\xCE\x91\x84\x8A\xFD\x79\x91\x2D\x9F\xB5\x52\x01\xB5\x81\x3A\x5A\x07\x4D\x2C\x0D\x42\x92\xC1\xFD\x44\x18\x07\xC5")- , ( 20- , "\x05\x3A\x02\xBE\xDD\x63\x68\xC1\xFB\x8A\xFC\x7A\x1B\x19\x9F\x7F\x7E\xA2\x22\x0C\x9A\x4B\x64\x2A\x68\x50\x09\x1C\x9D\x20\xAB\x9C"- , "\xC7\x13\xEE\xA5\xC2\x6D\xAD\x75\xAD\x3F\x52\x45\x1E\x00\x3A\x9C\xB0\xD6\x49\xF9\x17\xC8\x9D\xDE"- , "\x8F\x0A\x8A\x16\x47\x60\x42\x65\x67\xE3\x88\x84\x02\x76\xDE\x3F\x95\xCB\x5E\x3F\xAD\xC6\xED\x3F\x3E\x4F\xE8\xBC\x16\x9D\x93\x88\x80\x4D\xCB\x94\xB6\x58\x7D\xBB\x66\xCB\x0B\xD5\xF8\x7B\x8E\x98\xB5\x2A\xF3\x7B\xA2\x90\x62\x9B\x85\x8E\x0E\x2A\xA7\x37\x80\x47\xA2\x66\x02"- , "\x51\x67\x10\xE5\x98\x43\xE6\xFB\xD4\xF2\x5D\x0D\x8C\xA0\xEC\x0D\x47\xD3\x9D\x12\x5E\x9D\xAD\x98\x7E\x05\x18\xD4\x91\x07\x01\x4C\xB0\xAE\x40\x5E\x30\xC2\xEB\x37\x94\x75\x0B\xCA\x14\x2C\xE9\x5E\x29\x0C\xF9\x5A\xBE\x15\xE8\x22\x82\x3E\x2E\x7D\x3A\xB2\x1B\xC8\xFB\xD4\x45")- , ( 20- ,"\x5B\x14\xAB\x0F\xBE\xD4\xC5\x89\x52\x54\x8A\x6C\xB1\xE0\x00\x0C\xF4\x48\x14\x21\xF4\x12\x88\xEA\x0A\xA8\x4A\xDD\x9F\x7D\xEB\x96"- , "\x54\xBF\x52\xB9\x11\x23\x1B\x95\x2B\xA1\xA6\xAF\x8E\x45\xB1\xC5\xA2\x9D\x97\xE2\xAB\xAD\x7C\x83"- , "\x37\xFB\x44\xA6\x75\x97\x8B\x56\x0F\xF9\xA4\xA8\x70\x11\xD6\xF3\xAD\x2D\x37\xA2\xC3\x81\x5B\x45\xA3\xC0\xE6\xD1\xB1\xD8\xB1\x78\x4C\xD4\x68\x92\x7C\x2E\xE3\x9E\x1D\xCC\xD4\x76\x5E\x1C\x3D\x67\x6A\x33\x5B\xE1\xCC\xD6\x90\x0A\x45\xF5\xD4\x1A\x31\x76\x48\x31\x5D\x8A\x8C\x24\xAD\xC6\x4E\xB2\x85\xF6\xAE\xBA\x05\xB9\x02\x95\x86\x35\x3D\x30\x3F\x17\xA8\x07\x65\x8B\x9F\xF7\x90\x47\x4E\x17\x37\xBD\x5F\xDC\x60\x4A\xEF\xF8\xDF\xCA\xF1\x42\x7D\xCC\x3A\xAC\xBB\x02\x56\xBA\xDC\xD1\x83\xED\x75\xA2\xDC\x52\x45\x2F\x87\xD3\xC1\xED\x2A\xA5\x83\x47\x2B\x0A\xB9\x1C\xDA\x20\x61\x4E\x9B\x6F\xDB\xDA\x3B\x49\xB0\x98\xC9\x58\x23\xCC\x72\xD8\xE5\xB7\x17\xF2\x31\x4B\x03\x24\xE9\xCE"- , "\xAE\x6D\xEB\x5D\x6C\xE4\x3D\x4B\x09\xD0\xE6\xB1\xC0\xE9\xF4\x61\x57\xBC\xD8\xAB\x50\xEA\xA3\x19\x7F\xF9\xFA\x2B\xF7\xAF\x64\x9E\xB5\x2C\x68\x54\x4F\xD3\xAD\xFE\x6B\x1E\xB3\x16\xF1\xF2\x35\x38\xD4\x70\xC3\x0D\xBF\xEC\x7E\x57\xB6\x0C\xBC\xD0\x96\xC7\x82\xE7\x73\x6B\x66\x91\x99\xC8\x25\x3E\x70\x21\x4C\xF2\xA0\x98\xFD\xA8\xEA\xC5\xDA\x79\xA9\x49\x6A\x3A\xAE\x75\x4D\x03\xB1\x7C\x6D\x70\xD1\x02\x7F\x42\xBF\x7F\x95\xCE\x3D\x1D\x9C\x33\x88\x54\xE1\x58\xFC\xC8\x03\xE4\xD6\x26\x2F\xB6\x39\x52\x1E\x47\x11\x6E\xF7\x8A\x7A\x43\x7C\xA9\x42\x7B\xA6\x45\xCD\x64\x68\x32\xFE\xAB\x82\x2A\x20\x82\x78\xE4\x5E\x93\xE1\x18\xD7\x80\xB9\x88\xD6\x53\x97\xED\xDF\xD7\xA8\x19\x52\x6E")- , ( 20- , "\xD7\x46\x36\xE3\x41\x3A\x88\xD8\x5F\x32\x2C\xA8\x0F\xB0\xBD\x65\x0B\xD0\xBF\x01\x34\xE2\x32\x91\x60\xB6\x96\x09\xCD\x58\xA4\xB0"- , "\xEF\xB6\x06\xAA\x1D\x9D\x9F\x0F\x46\x5E\xAA\x7F\x81\x65\xF1\xAC\x09\xF5\xCB\x46\xFE\xCF\x2A\x57"- , "\xF8\x54\x71\xB7\x5F\x6E\xC8\x1A\xBA\xC2\x79\x9E\xC0\x9E\x98\xE2\x80\xB2\xFF\xD6\x4C\xA2\x85\xE5\xA0\x10\x9C\xFB\x31\xFF\xAB\x2D\x61\x7B\x2C\x29\x52\xA2\xA8\xA7\x88\xFC\x0D\xA2\xAF\x7F\x53\x07\x58\xF7\x4F\x1A\xB5\x63\x91\xAB\x5F\xF2\xAD\xBC\xC5\xBE\x2D\x6C\x7F\x49\xFB\xE8\x11\x81\x04\xC6\xFF\x9A\x23\xC6\xDF\xE5\x2F\x57\x95\x4E\x6A\x69\xDC\xEE\x5D\xB0\x6F\x51\x4F\x4A\x0A\x57\x2A\x9A\x85\x25\xD9\x61\xDA\xE7\x22\x69\xB9\x87\x18\x9D\x46\x5D\xF6\x10\x71\x19\xC7\xFA\x79\x08\x53\xE0\x63\xCB\xA0\xFA\xB7\x80\x0C\xA9\x32\xE2\x58\x88\x0F\xD7\x4C\x33\xC7\x84\x67\x5B\xED\xAD\x0E\x7C\x09\xE9\xCC\x4D\x63\xDD\x5E\x97\x13\xD5\xD4\xA0\x19\x6E\x6B\x56\x22\x26\xAC\x31\xB4\xF5\x7C\x04\xF9\x0A\x18\x19\x73\x73\x7D\xDC\x7E\x80\xF3\x64\x11\x2A\x9F\xBB\x43\x5E\xBD\xBC\xAB\xF7\xD4\x90\xCE\x52"- , "\xB2\xB7\x95\xFE\x6C\x1D\x4C\x83\xC1\x32\x7E\x01\x5A\x67\xD4\x46\x5F\xD8\xE3\x28\x13\x57\x5C\xBA\xB2\x63\xE2\x0E\xF0\x58\x64\xD2\xDC\x17\xE0\xE4\xEB\x81\x43\x6A\xDF\xE9\xF6\x38\xDC\xC1\xC8\xD7\x8F\x6B\x03\x06\xBA\xF9\x38\xE5\xD2\xAB\x0B\x3E\x05\xE7\x35\xCC\x6F\xFF\x2D\x6E\x02\xE3\xD6\x04\x84\xBE\xA7\xC7\xA8\xE1\x3E\x23\x19\x7F\xEA\x7B\x04\xD4\x7D\x48\xF4\xA4\xE5\x94\x41\x74\x53\x94\x92\x80\x0D\x3E\xF5\x1E\x2E\xE5\xE4\xC8\xA0\xBD\xF0\x50\xC2\xDD\x3D\xD7\x4F\xCE\x5E\x7E\x5C\x37\x36\x4F\x75\x47\xA1\x14\x80\xA3\x06\x3B\x9A\x0A\x15\x7B\x15\xB1\x0A\x5A\x95\x4D\xE2\x73\x1C\xED\x05\x5A\xA2\xE2\x76\x7F\x08\x91\xD4\x32\x9C\x42\x6F\x38\x08\xEE\x86\x7B\xED\x0D\xC7\x5B\x59\x22\xB7\xCF\xB8\x95\x70\x0F\xDA\x01\x61\x05\xA4\xC7\xB7\xF0\xBB\x90\xF0\x29\xF6\xBB\xCB\x04\xAC\x36\xAC\x16") + , "\x36\x16\x0E\x88\xD3\x50\x05\x29\xBA\x4E\xDB\xA1\x7B\xC2\x4D\x8C\xFA\xCA\x9A\x06\x80\xB3\xB1\xFC\x97\xCF\x03\xF3\x67\x5B\x7A\xC3\x01\xC8\x83\xA6\x8C\x07\x1B\xC5\x4A\xCD\xD3\xB6\x3A\xF4\xA2\xD7\x2F\x98\x5E\x51\xF9\xD6\x0A\x4C\x7F\xD4\x81\xAF\x10\xB2\xFC\x75\xE2\x52\xFD\xEE\x7E\xA6\xB6\x45\x31\x90\x61\x7D\xCC\x6E\x2F\xE1\xCD\x56\x58\x5F\xC2\xF0\xB0\xE9\x7C\x5C\x3F\x8A\xD7\xEB\x4F\x31\xBC\x48\x90\xC0\x38\x82\xAA\xC2\x4C\xC5\x3A\xCC\x19\x82\x29\x65\x26\x69\x0A\x22\x02\x71\xC2\xF6\xE3\x26\x75\x0D\x3F\xBD\xA5\xD5\xB6\x35\x12\xC8\x31\xF6\x78\x30\xF5\x9A\xC4\x9A\xAE\x33\x0B\x3E\x0E\x02\xC9\xEA\x00\x91\xD1\x98\x41\xF1\xB0\xE1\x3D\x69\xC9\xFB\xFE\x8A\x12\xD6\xF3\x0B\xB7\x34\xD9\xD2"+ )+ ,+ ( 20+ , "\x45\xB2\xBD\x0D\xE4\xED\x92\x93\xEC\x3E\x26\xC4\x84\x0F\xAA\xF6\x4B\x7D\x61\x9D\x51\xE9\xD7\xA2\xC7\xE3\x6C\x83\xD5\x84\xC3\xDF"+ , "\x54\x6C\x8C\x5D\x6B\xE8\xF9\x09\x52\xCA\xB3\xF3\x6D\x7C\x19\x57\xBA\xAA\x7A\x59\xAB\xE3\xD7\xE5"+ , "\x50\x07\xC8\xCD\x5B\x3C\x40\xE1\x7D\x7F\xE4\x23\xA8\x7A\xE0\xCE\xD8\x6B\xEC\x1C\x39\xDC\x07\xA2\x57\x72\xF3\xE9\x6D\xAB\xD5\x6C\xD3\xFD\x73\x19\xF6\xC9\x65\x49\x25\xF2\xD8\x70\x87\xA7\x00\xE1\xB1\x30\xDA\x79\x68\x95\xD1\xC9\xB9\xAC\xD6\x2B\x26\x61\x44\x06\x7D\x37\x3E\xD5\x1E\x78\x74\x98\xB0\x3C\x52\xFA\xAD\x16\xBB\x38\x26\xFA\x51\x1B\x0E\xD2\xA1\x9A\x86\x63\xF5\xBA\x2D\x6E\xA7\xC3\x8E\x72\x12\xE9\x69\x7D\x91\x48\x6C\x49\xD8\xA0\x00\xB9\xA1\x93\x5D\x6A\x7F\xF7\xEF\x23\xE7\x20\xA4\x58\x55\x48\x14\x40\x46\x3B\x4A\xC8\xC4\xF6\xE7\x06\x2A\xDC\x1F\x1E\x1E\x25\xD3\xD6\x5A\x31\x81\x2F\x58\xA7\x11\x60"+ , "\x8E\xAC\xFB\xA5\x68\x89\x8B\x10\xC0\x95\x7A\x7D\x44\x10\x06\x85\xE8\x76\x3A\x71\xA6\x9A\x8D\x16\xBC\x7B\x3F\x88\x08\x5B\xB9\xA2\xF0\x96\x42\xE4\xD0\x9A\x9F\x0A\xD0\x9D\x0A\xAD\x66\xB2\x26\x10\xC8\xBD\x02\xFF\x66\x79\xBB\x92\xC2\xC0\x26\xA2\x16\xBF\x42\x5C\x6B\xE3\x5F\xB8\xDA\xE7\xFF\x0C\x72\xB0\xEF\xD6\xA1\x80\x37\xC7\x0E\xED\x0C\xA9\x00\x62\xA4\x9A\x3C\x97\xFD\xC9\x0A\x8F\x9C\x2E\xA5\x36\xBF\xDC\x41\x91\x8A\x75\x82\xC9\x92\x7F\xAE\x47\xEF\xAA\x3D\xC8\x79\x67\xB7\x88\x7D\xEE\x1B\xF0\x71\x73\x4C\x76\x65\x90\x1D\x91\x05\xDA\xE2\xFD\xF6\x6B\x49\x18\xE5\x1D\x8F\x4A\x48\xC6\x0D\x19\xFB\xFB\xBC\xBA"+ )+ ,+ ( 20+ , "\xFE\x55\x9C\x9A\x28\x2B\xEB\x40\x81\x4D\x01\x6D\x6B\xFC\xB2\xC0\xC0\xD8\xBF\x07\x7B\x11\x10\xB8\x70\x3A\x3C\xE3\x9D\x70\xE0\xE1"+ , "\xB0\x76\x20\x0C\xC7\x01\x12\x59\x80\x5E\x18\xB3\x04\x09\x27\x54\x00\x27\x23\xEB\xEC\x5D\x62\x00"+ , "\x6D\xB6\x5B\x9E\xC8\xB1\x14\xA9\x44\x13\x7C\x82\x1F\xD6\x06\xBE\x75\x47\x8D\x92\x83\x66\xD5\x28\x40\x96\xCD\xEF\x78\x2F\xCF\xF7\xE8\xF5\x9C\xB8\xFF\xCD\xA9\x79\x75\x79\x02\xC5\xFF\xA6\xBC\x47\x7C\xEA\xA4\xCB\x5D\x5E\xA7\x6F\x94\xD9\x1E\x83\x3F\x82\x3A\x6B\xC7\x8F\x10\x55\xDF\xA6\xA9\x7B\xEA\x89\x65\xC1\xCD\xE6\x7A\x66\x8E\x00\x12\x57\x33\x4A\x58\x57\x27\xD9\xE0\xF7\xC1\xA0\x6E\x88\xD3\xD2\x5A\x4E\x6D\x90\x96\xC9\x68\xBF\x13\x8E\x11\x6A\x3E\xBE\xFF\xD4\xBB\x48\x08\xAD\xB1\xFD\x69\x81\x64\xBA\x0A\x35\xC7\x09\xA4\x7F\x16\xF1\xF4\x43\x5A\x23\x45\xA9\x19\x4A\x00\xB9\x5A\xBD\x51\x85\x1D\x50\x58\x09\xA6\x07\x7D\xA9\xBA\xCA\x58\x31\xAF\xFF\x31\x57\x8C\x48\x7E\xE6\x8F\x27\x67\x97\x4A\x98\xA7\xE8\x03\xAA\xC7\x88\xDA\x98\x31\x9C\x4E\xA8\xEA\xA3\xD3\x94\x85\x56\x51\xF4\x84\xCE\xF5\x43\xF5\x37\xE3\x51\x58\xEE\x29"+ , "\x4D\xCE\x9C\x8F\x97\xA0\x28\x05\x1B\x07\x27\xF3\x4E\x1B\x9E\xF2\x1F\x06\xF0\x76\x0F\x36\xE7\x17\x13\x20\x40\x27\x90\x20\x90\xBA\x2B\xB6\xB1\x34\x36\xEE\x77\x8D\x9F\x50\x53\x0E\xFB\xD7\xA3\x2B\x0D\x41\x44\x3F\x58\xCC\xAE\xE7\x81\xC7\xB7\x16\xD3\xA9\x6F\xDE\xC0\xE3\x76\x4E\xD7\x95\x9F\x34\xC3\x94\x12\x78\x59\x1E\xA0\x33\xB5\xCB\xAD\xC0\xF1\x91\x60\x32\xE9\xBE\xBB\xD1\xA8\x39\x5B\x83\xFB\x63\xB1\x45\x4B\xD7\x75\xBD\x20\xB3\xA2\xA9\x6F\x95\x12\x46\xAC\x14\xDA\xF6\x81\x66\xBA\x62\xF6\xCB\xFF\x8B\xD1\x21\xAC\x94\x98\xFF\x88\x52\xFD\x2B\xE9\x75\xDF\x52\xB5\xDA\xEF\x38\x29\xD1\x8E\xDA\x42\xE7\x15\x02\x2D\xCB\xF9\x30\xD0\xA7\x89\xEE\x6A\x14\x6C\x2C\x70\x88\xC3\x57\x73\xC6\x3C\x06\xB4\xAF\x45\x59\x85\x6A\xC1\x99\xCE\xD8\x68\x63\xE4\x29\x47\x07\x82\x53\x37\xC5\x85\x79\x70\xEB\x7F\xDD\xEB\x26\x37\x81\x30\x90\x11"+ )+ ,+ ( 20+ , "\x0A\xE1\x00\x12\xD7\xE5\x66\x14\xB0\x3D\xCC\x89\xB1\x4B\xAE\x92\x42\xFF\xE6\x30\xF3\xD7\xE3\x5C\xE8\xBB\xB9\x7B\xBC\x2C\x92\xC3"+ , "\xF9\x6B\x02\x5D\x6C\xF4\x6A\x8A\x12\xAC\x2A\xF1\xE2\xAE\xF1\xFB\x83\x59\x0A\xDA\xDA\xA5\xC5\xEA"+ , "\xEA\x0F\x35\x4E\x96\xF1\x2B\xC7\x2B\xBA\xA3\xD1\x2B\x4A\x8E\xD8\x79\xB0\x42\xF0\x68\x98\x78\xF4\x6B\x65\x1C\xC4\x11\x6D\x6F\x78\x40\x9B\x11\x43\x0B\x3A\xAA\x30\xB2\x07\x68\x91\xE8\xE1\xFA\x52\x8F\x2F\xD1\x69\xED\x93\xDC\x9F\x84\xE2\x44\x09\xEE\xC2\x10\x1D\xAF\x4D\x05\x7B\xE2\x49\x2D\x11\xDE\x64\x0C\xBD\x7B\x35\x5A\xD2\x9F\xB7\x04\x00\xFF\xFD\x7C\xD6\xD4\x25\xAB\xEE\xB7\x32\xA0\xEA\xA4\x33\x0A\xF4\xC6\x56\x25\x2C\x41\x73\xDE\xAB\x65\x3E\xB8\x5C\x58\x46\x2D\x7A\xB0\xF3\x5F\xD1\x2B\x61\x3D\x29\xD4\x73\xD3\x30\x31\x0D\xC3\x23\xD3\xC6\x63\x48\xBB\xDB\xB6\x8A\x32\x63\x24\x65\x7C\xAE\x7B\x77\xA9\xE3\x43\x58\xF2\xCE\xC5\x0C\x85\x60\x9E\x73\x05\x68\x56\x79\x6E\x3B\xE8\xD6\x2B\x6E\x2F\xE9\xF9\x53"+ , "\xE8\xAB\xD4\x89\x24\xB5\x4E\x5B\x80\x86\x6B\xE7\xD4\xEB\xE5\xCF\x42\x74\xCA\xFF\xF0\x8B\x39\xCB\x2D\x40\xA8\xF0\xB4\x72\x39\x8A\xED\xC7\x76\xE0\x79\x38\x12\xFB\xF1\xF6\x00\x78\x63\x5D\x2E\xD8\x6B\x15\xEF\xCD\xBA\x60\x41\x1E\xE2\x3B\x07\x23\x35\x92\xA4\x4E\xC3\x1B\x10\x13\xCE\x89\x64\x23\x66\x75\xF8\xF1\x83\xAE\xF8\x85\xE8\x64\xF2\xA7\x2E\xDF\x42\x15\xB5\x33\x8F\xA2\xB5\x46\x53\xDF\xA1\xA8\xC5\x5C\xE5\xD9\x5C\xC6\x05\xB9\xB3\x11\x52\x7F\x2E\x34\x63\xFF\xBE\xC7\x8A\x9D\x1D\x65\xDA\xBA\xD2\xF3\x38\x76\x9C\x9F\x43\xF1\x33\xA7\x91\xA1\x1C\x7E\xCA\x9A\xF0\xB7\x71\xA4\xAC\x32\x96\x3D\xC8\xF6\x31\xA2\xC1\x12\x17\xAC\x6E\x1B\x94\x30\xC1\xAA\xE1\xCE\xEB\xE2\x27\x03\xF4\x29\x99\x8A\x8F\xB8\xC6\x41"+ )+ ,+ ( 20+ , "\x08\x2C\x53\x9B\xC5\xB2\x0F\x97\xD7\x67\xCD\x3F\x22\x9E\xDA\x80\xB2\xAD\xC4\xFE\x49\xC8\x63\x29\xB5\xCD\x62\x50\xA9\x87\x74\x50"+ , "\x84\x55\x43\x50\x2E\x8B\x64\x91\x2D\x8F\x2C\x8D\x9F\xFF\xB3\xC6\x93\x65\x68\x65\x87\xC0\x8D\x0C"+ , "\xA9\x6B\xB7\xE9\x10\x28\x1A\x6D\xFA\xD7\xC8\xA9\xC3\x70\x67\x4F\x0C\xEE\xC1\xAD\x8D\x4F\x0D\xE3\x2F\x9A\xE4\xA2\x3E\xD3\x29\xE3\xD6\xBC\x70\x8F\x87\x66\x40\xA2\x29\x15\x3A\xC0\xE7\x28\x1A\x81\x88\xDD\x77\x69\x51\x38\xF0\x1C\xDA\x5F\x41\xD5\x21\x5F\xD5\xC6\xBD\xD4\x6D\x98\x2C\xB7\x3B\x1E\xFE\x29\x97\x97\x0A\x9F\xDB\xDB\x1E\x76\x8D\x7E\x5D\xB7\x12\x06\x8D\x8B\xA1\xAF\x60\x67\xB5\x75\x34\x95\xE2\x3E\x6E\x19\x63\xAF\x01\x2F\x9C\x7C\xE4\x50\xBF\x2D\xE6\x19\xD3\xD5\x95\x42\xFB\x55\xF3"+ , "\x83\x5D\xA7\x4F\xC6\xDE\x08\xCB\xDA\x27\x7A\x79\x66\xA0\x7C\x8D\xCD\x62\x7E\x7B\x17\xAD\xDE\x6D\x93\x0B\x65\x81\xE3\x12\x4B\x8B\xAA\xD0\x96\xF6\x93\x99\x1F\xED\xB1\x57\x29\x30\x60\x1F\xC7\x70\x95\x41\x83\x9B\x8E\x3F\xFD\x5F\x03\x3D\x20\x60\xD9\x99\xC6\xC6\xE3\x04\x82\x76\x61\x3E\x64\x80\x00\xAC\xB5\x21\x2C\xC6\x32\xA9\x16\xAF\xCE\x29\x0E\x20\xEB\xDF\x61\x2D\x08\xA6\xAA\x4C\x79\xA7\x4B\x07\x0D\x3F\x87\x2A\x86\x1F\x8D\xC6\xBB\x07\x61\x4D\xB5\x15\xD3\x63\x34\x9D\x3A\x8E\x33\x36\xA3"+ )+ ,+ ( 20+ , "\x3D\x02\xBF\xF3\x37\x5D\x40\x30\x27\x35\x6B\x94\xF5\x14\x20\x37\x37\xEE\x9A\x85\xD2\x05\x2D\xB3\xE4\xE5\xA2\x17\xC2\x59\xD1\x8A"+ , "\x74\x21\x6C\x95\x03\x18\x95\xF4\x8C\x1D\xBA\x65\x15\x55\xEB\xFA\x3C\xA3\x26\xA7\x55\x23\x70\x25"+ , "\x0D\x4B\x0F\x54\xFD\x09\xAE\x39\xBA\xA5\xFA\x4B\xAC\xCF\x2E\x66\x82\xE6\x1B\x25\x7E\x01\xF4\x2B\x8F"+ , "\x16\xC4\x00\x6C\x28\x36\x51\x90\x41\x1E\xB1\x59\x38\x14\xCF\x15\xE7\x4C\x22\x23\x8F\x21\x0A\xFC\x3D"+ )+ ,+ ( 20+ , "\xAD\x1A\x5C\x47\x68\x88\x74\xE6\x66\x3A\x0F\x3F\xA1\x6F\xA7\xEF\xB7\xEC\xAD\xC1\x75\xC4\x68\xE5\x43\x29\x14\xBD\xB4\x80\xFF\xC6"+ , "\xE4\x89\xEE\xD4\x40\xF1\xAA\xE1\xFA\xC8\xFB\x7A\x98\x25\x63\x54\x54\xF8\xF8\xF1\xF5\x2E\x2F\xCC"+ , "\xAA\x6C\x1E\x53\x58\x0F\x03\xA9\xAB\xB7\x3B\xFD\xAD\xED\xFE\xCA\xDA\x4C\x6B\x0E\xBE\x02\x0E\xF1\x0D\xB7\x45\xE5\x4B\xA8\x61\xCA\xF6\x5F\x0E\x40\xDF\xC5\x20\x20\x3B\xB5\x4D\x29\xE0\xA8\xF7\x8F\x16\xB3\xF1\xAA\x52\x5D\x6B\xFA\x33\xC5\x47\x26\xE5\x99\x88\xCF\xBE\xC7\x80\x56"+ , "\x02\xFE\x84\xCE\x81\xE1\x78\xE7\xAA\xBD\xD3\xBA\x92\x5A\x76\x6C\x3C\x24\x75\x6E\xEF\xAE\x33\x94\x2A\xF7\x5E\x8B\x46\x45\x56\xB5\x99\x7E\x61\x6F\x3F\x2D\xFC\x7F\xCE\x91\x84\x8A\xFD\x79\x91\x2D\x9F\xB5\x52\x01\xB5\x81\x3A\x5A\x07\x4D\x2C\x0D\x42\x92\xC1\xFD\x44\x18\x07\xC5"+ )+ ,+ ( 20+ , "\x05\x3A\x02\xBE\xDD\x63\x68\xC1\xFB\x8A\xFC\x7A\x1B\x19\x9F\x7F\x7E\xA2\x22\x0C\x9A\x4B\x64\x2A\x68\x50\x09\x1C\x9D\x20\xAB\x9C"+ , "\xC7\x13\xEE\xA5\xC2\x6D\xAD\x75\xAD\x3F\x52\x45\x1E\x00\x3A\x9C\xB0\xD6\x49\xF9\x17\xC8\x9D\xDE"+ , "\x8F\x0A\x8A\x16\x47\x60\x42\x65\x67\xE3\x88\x84\x02\x76\xDE\x3F\x95\xCB\x5E\x3F\xAD\xC6\xED\x3F\x3E\x4F\xE8\xBC\x16\x9D\x93\x88\x80\x4D\xCB\x94\xB6\x58\x7D\xBB\x66\xCB\x0B\xD5\xF8\x7B\x8E\x98\xB5\x2A\xF3\x7B\xA2\x90\x62\x9B\x85\x8E\x0E\x2A\xA7\x37\x80\x47\xA2\x66\x02"+ , "\x51\x67\x10\xE5\x98\x43\xE6\xFB\xD4\xF2\x5D\x0D\x8C\xA0\xEC\x0D\x47\xD3\x9D\x12\x5E\x9D\xAD\x98\x7E\x05\x18\xD4\x91\x07\x01\x4C\xB0\xAE\x40\x5E\x30\xC2\xEB\x37\x94\x75\x0B\xCA\x14\x2C\xE9\x5E\x29\x0C\xF9\x5A\xBE\x15\xE8\x22\x82\x3E\x2E\x7D\x3A\xB2\x1B\xC8\xFB\xD4\x45"+ )+ ,+ ( 20+ , "\x5B\x14\xAB\x0F\xBE\xD4\xC5\x89\x52\x54\x8A\x6C\xB1\xE0\x00\x0C\xF4\x48\x14\x21\xF4\x12\x88\xEA\x0A\xA8\x4A\xDD\x9F\x7D\xEB\x96"+ , "\x54\xBF\x52\xB9\x11\x23\x1B\x95\x2B\xA1\xA6\xAF\x8E\x45\xB1\xC5\xA2\x9D\x97\xE2\xAB\xAD\x7C\x83"+ , "\x37\xFB\x44\xA6\x75\x97\x8B\x56\x0F\xF9\xA4\xA8\x70\x11\xD6\xF3\xAD\x2D\x37\xA2\xC3\x81\x5B\x45\xA3\xC0\xE6\xD1\xB1\xD8\xB1\x78\x4C\xD4\x68\x92\x7C\x2E\xE3\x9E\x1D\xCC\xD4\x76\x5E\x1C\x3D\x67\x6A\x33\x5B\xE1\xCC\xD6\x90\x0A\x45\xF5\xD4\x1A\x31\x76\x48\x31\x5D\x8A\x8C\x24\xAD\xC6\x4E\xB2\x85\xF6\xAE\xBA\x05\xB9\x02\x95\x86\x35\x3D\x30\x3F\x17\xA8\x07\x65\x8B\x9F\xF7\x90\x47\x4E\x17\x37\xBD\x5F\xDC\x60\x4A\xEF\xF8\xDF\xCA\xF1\x42\x7D\xCC\x3A\xAC\xBB\x02\x56\xBA\xDC\xD1\x83\xED\x75\xA2\xDC\x52\x45\x2F\x87\xD3\xC1\xED\x2A\xA5\x83\x47\x2B\x0A\xB9\x1C\xDA\x20\x61\x4E\x9B\x6F\xDB\xDA\x3B\x49\xB0\x98\xC9\x58\x23\xCC\x72\xD8\xE5\xB7\x17\xF2\x31\x4B\x03\x24\xE9\xCE"+ , "\xAE\x6D\xEB\x5D\x6C\xE4\x3D\x4B\x09\xD0\xE6\xB1\xC0\xE9\xF4\x61\x57\xBC\xD8\xAB\x50\xEA\xA3\x19\x7F\xF9\xFA\x2B\xF7\xAF\x64\x9E\xB5\x2C\x68\x54\x4F\xD3\xAD\xFE\x6B\x1E\xB3\x16\xF1\xF2\x35\x38\xD4\x70\xC3\x0D\xBF\xEC\x7E\x57\xB6\x0C\xBC\xD0\x96\xC7\x82\xE7\x73\x6B\x66\x91\x99\xC8\x25\x3E\x70\x21\x4C\xF2\xA0\x98\xFD\xA8\xEA\xC5\xDA\x79\xA9\x49\x6A\x3A\xAE\x75\x4D\x03\xB1\x7C\x6D\x70\xD1\x02\x7F\x42\xBF\x7F\x95\xCE\x3D\x1D\x9C\x33\x88\x54\xE1\x58\xFC\xC8\x03\xE4\xD6\x26\x2F\xB6\x39\x52\x1E\x47\x11\x6E\xF7\x8A\x7A\x43\x7C\xA9\x42\x7B\xA6\x45\xCD\x64\x68\x32\xFE\xAB\x82\x2A\x20\x82\x78\xE4\x5E\x93\xE1\x18\xD7\x80\xB9\x88\xD6\x53\x97\xED\xDF\xD7\xA8\x19\x52\x6E"+ )+ ,+ ( 20+ , "\xD7\x46\x36\xE3\x41\x3A\x88\xD8\x5F\x32\x2C\xA8\x0F\xB0\xBD\x65\x0B\xD0\xBF\x01\x34\xE2\x32\x91\x60\xB6\x96\x09\xCD\x58\xA4\xB0"+ , "\xEF\xB6\x06\xAA\x1D\x9D\x9F\x0F\x46\x5E\xAA\x7F\x81\x65\xF1\xAC\x09\xF5\xCB\x46\xFE\xCF\x2A\x57"+ , "\xF8\x54\x71\xB7\x5F\x6E\xC8\x1A\xBA\xC2\x79\x9E\xC0\x9E\x98\xE2\x80\xB2\xFF\xD6\x4C\xA2\x85\xE5\xA0\x10\x9C\xFB\x31\xFF\xAB\x2D\x61\x7B\x2C\x29\x52\xA2\xA8\xA7\x88\xFC\x0D\xA2\xAF\x7F\x53\x07\x58\xF7\x4F\x1A\xB5\x63\x91\xAB\x5F\xF2\xAD\xBC\xC5\xBE\x2D\x6C\x7F\x49\xFB\xE8\x11\x81\x04\xC6\xFF\x9A\x23\xC6\xDF\xE5\x2F\x57\x95\x4E\x6A\x69\xDC\xEE\x5D\xB0\x6F\x51\x4F\x4A\x0A\x57\x2A\x9A\x85\x25\xD9\x61\xDA\xE7\x22\x69\xB9\x87\x18\x9D\x46\x5D\xF6\x10\x71\x19\xC7\xFA\x79\x08\x53\xE0\x63\xCB\xA0\xFA\xB7\x80\x0C\xA9\x32\xE2\x58\x88\x0F\xD7\x4C\x33\xC7\x84\x67\x5B\xED\xAD\x0E\x7C\x09\xE9\xCC\x4D\x63\xDD\x5E\x97\x13\xD5\xD4\xA0\x19\x6E\x6B\x56\x22\x26\xAC\x31\xB4\xF5\x7C\x04\xF9\x0A\x18\x19\x73\x73\x7D\xDC\x7E\x80\xF3\x64\x11\x2A\x9F\xBB\x43\x5E\xBD\xBC\xAB\xF7\xD4\x90\xCE\x52"+ , "\xB2\xB7\x95\xFE\x6C\x1D\x4C\x83\xC1\x32\x7E\x01\x5A\x67\xD4\x46\x5F\xD8\xE3\x28\x13\x57\x5C\xBA\xB2\x63\xE2\x0E\xF0\x58\x64\xD2\xDC\x17\xE0\xE4\xEB\x81\x43\x6A\xDF\xE9\xF6\x38\xDC\xC1\xC8\xD7\x8F\x6B\x03\x06\xBA\xF9\x38\xE5\xD2\xAB\x0B\x3E\x05\xE7\x35\xCC\x6F\xFF\x2D\x6E\x02\xE3\xD6\x04\x84\xBE\xA7\xC7\xA8\xE1\x3E\x23\x19\x7F\xEA\x7B\x04\xD4\x7D\x48\xF4\xA4\xE5\x94\x41\x74\x53\x94\x92\x80\x0D\x3E\xF5\x1E\x2E\xE5\xE4\xC8\xA0\xBD\xF0\x50\xC2\xDD\x3D\xD7\x4F\xCE\x5E\x7E\x5C\x37\x36\x4F\x75\x47\xA1\x14\x80\xA3\x06\x3B\x9A\x0A\x15\x7B\x15\xB1\x0A\x5A\x95\x4D\xE2\x73\x1C\xED\x05\x5A\xA2\xE2\x76\x7F\x08\x91\xD4\x32\x9C\x42\x6F\x38\x08\xEE\x86\x7B\xED\x0D\xC7\x5B\x59\x22\xB7\xCF\xB8\x95\x70\x0F\xDA\x01\x61\x05\xA4\xC7\xB7\xF0\xBB\x90\xF0\x29\xF6\xBB\xCB\x04\xAC\x36\xAC\x16"+ ) ] -- Test vector from paper "Cryptography in NaCl" vectorsCB :: [Vector] vectorsCB =- [ ( 20- , "\x4A\x5D\x9D\x5B\xA4\xCE\x2D\xE1\x72\x8E\x3B\xF4\x80\x35\x0F\x25\xE0\x7E\x21\xC9\x47\xD1\x9E\x33\x76\xF0\x9B\x3C\x1E\x16\x17\x42"- , "\x69\x69\x6E\xE9\x55\xB6\x2B\x73\xCD\x62\xBD\xA8\x75\xFC\x73\xD6\x82\x19\xE0\x03\x6B\x7A\x0B\x37"- , "\xBE\x07\x5F\xC5\x3C\x81\xF2\xD5\xCF\x14\x13\x16\xEB\xEB\x0C\x7B\x52\x28\xC5\x2A\x4C\x62\xCB\xD4\x4B\x66\x84\x9B\x64\x24\x4F\xFC\xE5\xEC\xBA\xAF\x33\xBD\x75\x1A\x1A\xC7\x28\xD4\x5E\x6C\x61\x29\x6C\xDC\x3C\x01\x23\x35\x61\xF4\x1D\xB6\x6C\xCE\x31\x4A\xDB\x31\x0E\x3B\xE8\x25\x0C\x46\xF0\x6D\xCE\xEA\x3A\x7F\xA1\x34\x80\x57\xE2\xF6\x55\x6A\xD6\xB1\x31\x8A\x02\x4A\x83\x8F\x21\xAF\x1F\xDE\x04\x89\x77\xEB\x48\xF5\x9F\xFD\x49\x24\xCA\x1C\x60\x90\x2E\x52\xF0\xA0\x89\xBC\x76\x89\x70\x40\xE0\x82\xF9\x37\x76\x38\x48\x64\x5E\x07\x05"- , "\x8E\x99\x3B\x9F\x48\x68\x12\x73\xC2\x96\x50\xBA\x32\xFC\x76\xCE\x48\x33\x2E\xA7\x16\x4D\x96\xA4\x47\x6F\xB8\xC5\x31\xA1\x18\x6A\xC0\xDF\xC1\x7C\x98\xDC\xE8\x7B\x4D\xA7\xF0\x11\xEC\x48\xC9\x72\x71\xD2\xC2\x0F\x9B\x92\x8F\xE2\x27\x0D\x6F\xB8\x63\xD5\x17\x38\xB4\x8E\xEE\xE3\x14\xA7\xCC\x8A\xB9\x32\x16\x45\x48\xE5\x26\xAE\x90\x22\x43\x68\x51\x7A\xCF\xEA\xBD\x6B\xB3\x73\x2B\xC0\xE9\xDA\x99\x83\x2B\x61\xCA\x01\xB6\xDE\x56\x24\x4A\x9E\x88\xD5\xF9\xB3\x79\x73\xF6\x22\xA4\x3D\x14\xA6\x59\x9B\x1F\x65\x4C\xB4\x5A\x74\xE3\x55\xA5")+ [+ ( 20+ , "\x4A\x5D\x9D\x5B\xA4\xCE\x2D\xE1\x72\x8E\x3B\xF4\x80\x35\x0F\x25\xE0\x7E\x21\xC9\x47\xD1\x9E\x33\x76\xF0\x9B\x3C\x1E\x16\x17\x42"+ , "\x69\x69\x6E\xE9\x55\xB6\x2B\x73\xCD\x62\xBD\xA8\x75\xFC\x73\xD6\x82\x19\xE0\x03\x6B\x7A\x0B\x37"+ , "\xBE\x07\x5F\xC5\x3C\x81\xF2\xD5\xCF\x14\x13\x16\xEB\xEB\x0C\x7B\x52\x28\xC5\x2A\x4C\x62\xCB\xD4\x4B\x66\x84\x9B\x64\x24\x4F\xFC\xE5\xEC\xBA\xAF\x33\xBD\x75\x1A\x1A\xC7\x28\xD4\x5E\x6C\x61\x29\x6C\xDC\x3C\x01\x23\x35\x61\xF4\x1D\xB6\x6C\xCE\x31\x4A\xDB\x31\x0E\x3B\xE8\x25\x0C\x46\xF0\x6D\xCE\xEA\x3A\x7F\xA1\x34\x80\x57\xE2\xF6\x55\x6A\xD6\xB1\x31\x8A\x02\x4A\x83\x8F\x21\xAF\x1F\xDE\x04\x89\x77\xEB\x48\xF5\x9F\xFD\x49\x24\xCA\x1C\x60\x90\x2E\x52\xF0\xA0\x89\xBC\x76\x89\x70\x40\xE0\x82\xF9\x37\x76\x38\x48\x64\x5E\x07\x05"+ , "\x8E\x99\x3B\x9F\x48\x68\x12\x73\xC2\x96\x50\xBA\x32\xFC\x76\xCE\x48\x33\x2E\xA7\x16\x4D\x96\xA4\x47\x6F\xB8\xC5\x31\xA1\x18\x6A\xC0\xDF\xC1\x7C\x98\xDC\xE8\x7B\x4D\xA7\xF0\x11\xEC\x48\xC9\x72\x71\xD2\xC2\x0F\x9B\x92\x8F\xE2\x27\x0D\x6F\xB8\x63\xD5\x17\x38\xB4\x8E\xEE\xE3\x14\xA7\xCC\x8A\xB9\x32\x16\x45\x48\xE5\x26\xAE\x90\x22\x43\x68\x51\x7A\xCF\xEA\xBD\x6B\xB3\x73\x2B\xC0\xE9\xDA\x99\x83\x2B\x61\xCA\x01\xB6\xDE\x56\x24\x4A\x9E\x88\xD5\xF9\xB3\x79\x73\xF6\x22\xA4\x3D\x14\xA6\x59\x9B\x1F\x65\x4C\xB4\x5A\x74\xE3\x55\xA5"+ ) ] -tests = testGroup "XSalsa"- [ testGroup "KAT" $- zipWith (\i (r, k, n, p, e) -> testCase (show (i :: Int)) $ salsaRunSimple r k n p e) [1..] vectors- , testGroup "crypto_box encryption" $- zipWith (\i (r, k, n, p, e) -> testCase (show (i :: Int)) $ cryptoBoxEnc r k n p e) [1..] vectorsCB- ]+tests =+ testGroup+ "XSalsa"+ [ testGroup "KAT" $+ zipWith+ (\i (r, k, n, p, e) -> testCase (show (i :: Int)) $ salsaRunSimple r k n p e)+ [1 ..]+ vectors+ , testGroup "crypto_box encryption" $+ 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 =- let salsa = XSalsa.initialize rounds key nonce- in fst (XSalsa.combine salsa plain) @?= expected+ salsaRunSimple rounds key nonce plain expected =+ let salsa = XSalsa.initialize rounds key nonce+ in fst (XSalsa.combine salsa plain) @?= expected - cryptoBoxEnc rounds shared nonce plain expected =- let zero = B.replicate 16 0- (iv0, iv1) = B.splitAt 8 nonce- salsa0 = XSalsa.initialize rounds shared (zero `B.append` iv0)- salsa1 = XSalsa.derive salsa0 iv1- (_, salsa2) = XSalsa.generate salsa1 32 :: (B.ByteString, XSalsa.State)- in fst (XSalsa.combine salsa2 plain) @?= expected+ cryptoBoxEnc rounds shared nonce plain expected =+ let zero = B.replicate 16 0+ (iv0, iv1) = B.splitAt 8 nonce+ salsa0 = XSalsa.initialize rounds shared (zero `B.append` iv0)+ salsa1 = XSalsa.derive salsa0 iv1+ (_, salsa2) = XSalsa.generate salsa1 32 :: (B.ByteString, XSalsa.State)+ in fst (XSalsa.combine salsa2 plain) @?= expected