Add benchmark with AES GCM and CCM
This commit is contained in:
parent
3161630390
commit
76ba39fc95
@ -22,6 +22,7 @@ module Crypto.Cipher.Types.Base
|
|||||||
import Data.Word
|
import Data.Word
|
||||||
import Crypto.Internal.ByteArray (Bytes, ByteArrayAccess, ByteArray)
|
import Crypto.Internal.ByteArray (Bytes, ByteArrayAccess, ByteArray)
|
||||||
import qualified Crypto.Internal.ByteArray as B
|
import qualified Crypto.Internal.ByteArray as B
|
||||||
|
import Crypto.Internal.DeepSeq
|
||||||
import Crypto.Error
|
import Crypto.Error
|
||||||
|
|
||||||
-- | Different specifier for key size in bytes
|
-- | Different specifier for key size in bytes
|
||||||
@ -36,7 +37,7 @@ type DataUnitOffset = Word32
|
|||||||
|
|
||||||
-- | Authentication Tag for AE cipher mode
|
-- | Authentication Tag for AE cipher mode
|
||||||
newtype AuthTag = AuthTag { unAuthTag :: Bytes }
|
newtype AuthTag = AuthTag { unAuthTag :: Bytes }
|
||||||
deriving (Show, ByteArrayAccess)
|
deriving (Show, ByteArrayAccess, NFData)
|
||||||
|
|
||||||
instance Eq AuthTag where
|
instance Eq AuthTag where
|
||||||
(AuthTag a) == (AuthTag b) = B.constEq a b
|
(AuthTag a) == (AuthTag b) = B.constEq a b
|
||||||
|
|||||||
@ -162,14 +162,27 @@ benchBlockCipher =
|
|||||||
iv16 = maybe (error "iv size 16") id $ makeIV key16
|
iv16 = maybe (error "iv size 16") id $ makeIV key16
|
||||||
|
|
||||||
benchAE =
|
benchAE =
|
||||||
[ bench "ChaChaPoly1305" $ nf (run key32) (input64, input1024)
|
[ bench "ChaChaPoly1305" $ nf (cp key32) (input64, input1024)
|
||||||
|
, bench "AES-GCM" $ nf (gcm key32) (input64, input1024)
|
||||||
|
, bench "AES-CCM" $ nf (ccm key32) (input64, input1024)
|
||||||
]
|
]
|
||||||
where run k (ini, plain) =
|
where cp k (ini, plain) =
|
||||||
let iniState = throwCryptoError $ CP.initialize k (throwCryptoError $ CP.nonce12 nonce12)
|
let iniState = throwCryptoError $ CP.initialize k (throwCryptoError $ CP.nonce12 nonce12)
|
||||||
afterAAD = CP.finalizeAAD (CP.appendAAD ini iniState)
|
afterAAD = CP.finalizeAAD (CP.appendAAD ini iniState)
|
||||||
(out, afterEncrypt) = CP.encrypt plain afterAAD
|
(out, afterEncrypt) = CP.encrypt plain afterAAD
|
||||||
outtag = CP.finalize afterEncrypt
|
outtag = CP.finalize afterEncrypt
|
||||||
in (out, outtag)
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
input64 = B.replicate 64 0
|
input64 = B.replicate 64 0
|
||||||
input1024 = B.replicate 1024 0
|
input1024 = B.replicate 1024 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user