[AES] add gcm / ocb support to base AES type
This commit is contained in:
parent
03fab98cd2
commit
b28b25abe7
@ -40,22 +40,6 @@ instance Cipher AES256 where
|
|||||||
cipherKeySize _ = KeySizeFixed 32
|
cipherKeySize _ = KeySizeFixed 32
|
||||||
cipherInit k = AES256 `fmap` initAES k
|
cipherInit k = AES256 `fmap` initAES k
|
||||||
|
|
||||||
gcmMode :: AES -> AEADModeImpl AESGCM
|
|
||||||
gcmMode aes = AEADModeImpl
|
|
||||||
{ aeadImplAppendHeader = gcmAppendAAD
|
|
||||||
, aeadImplEncrypt = gcmAppendEncrypt aes
|
|
||||||
, aeadImplDecrypt = gcmAppendDecrypt aes
|
|
||||||
, aeadImplFinalize = gcmFinish aes
|
|
||||||
}
|
|
||||||
|
|
||||||
ocbMode :: AES -> AEADModeImpl AESOCB
|
|
||||||
ocbMode aes = AEADModeImpl
|
|
||||||
{ aeadImplAppendHeader = ocbAppendAAD aes
|
|
||||||
, aeadImplEncrypt = ocbAppendEncrypt aes
|
|
||||||
, aeadImplDecrypt = ocbAppendDecrypt aes
|
|
||||||
, aeadImplFinalize = ocbFinish aes
|
|
||||||
}
|
|
||||||
|
|
||||||
#define INSTANCE_BLOCKCIPHER(CSTR) \
|
#define INSTANCE_BLOCKCIPHER(CSTR) \
|
||||||
instance BlockCipher CSTR where \
|
instance BlockCipher CSTR where \
|
||||||
{ blockSize _ = 16 \
|
{ blockSize _ = 16 \
|
||||||
|
|||||||
@ -44,6 +44,7 @@ module Crypto.Cipher.AES.Primitive
|
|||||||
, decryptOCB
|
, decryptOCB
|
||||||
|
|
||||||
-- * incremental GCM
|
-- * incremental GCM
|
||||||
|
, gcmMode
|
||||||
, gcmInit
|
, gcmInit
|
||||||
, gcmAppendAAD
|
, gcmAppendAAD
|
||||||
, gcmAppendEncrypt
|
, gcmAppendEncrypt
|
||||||
@ -51,6 +52,7 @@ module Crypto.Cipher.AES.Primitive
|
|||||||
, gcmFinish
|
, gcmFinish
|
||||||
|
|
||||||
-- * incremental OCB
|
-- * incremental OCB
|
||||||
|
, ocbMode
|
||||||
, ocbInit
|
, ocbInit
|
||||||
, ocbAppendAAD
|
, ocbAppendAAD
|
||||||
, ocbAppendEncrypt
|
, ocbAppendEncrypt
|
||||||
@ -86,15 +88,30 @@ instance BlockCipher AES where
|
|||||||
cbcEncrypt = encryptCBC
|
cbcEncrypt = encryptCBC
|
||||||
cbcDecrypt = decryptCBC
|
cbcDecrypt = decryptCBC
|
||||||
ctrCombine = encryptCTR
|
ctrCombine = encryptCTR
|
||||||
{-
|
aeadInit AEAD_GCM aes iv = CryptoPassed $ AEAD (gcmMode aes) (gcmInit aes iv)
|
||||||
aeadInit AEAD_GCM aes iv = Just $ AEAD aes $ AEADState $ gcmInit aes iv
|
aeadInit AEAD_OCB aes iv = CryptoPassed $ AEAD (ocbMode aes) (ocbInit aes iv)
|
||||||
aeadInit AEAD_OCB aes iv = Just $ AEAD aes $ AEADState $ ocbInit aes iv
|
aeadInit _ _ _ = CryptoFailed CryptoError_AEADModeNotSupported
|
||||||
aeadInit _ _ _ = Nothing
|
|
||||||
-}
|
|
||||||
instance BlockCipher128 AES where
|
instance BlockCipher128 AES where
|
||||||
xtsEncrypt = encryptXTS
|
xtsEncrypt = encryptXTS
|
||||||
xtsDecrypt = decryptXTS
|
xtsDecrypt = decryptXTS
|
||||||
|
|
||||||
|
gcmMode :: AES -> AEADModeImpl AESGCM
|
||||||
|
gcmMode aes = AEADModeImpl
|
||||||
|
{ aeadImplAppendHeader = gcmAppendAAD
|
||||||
|
, aeadImplEncrypt = gcmAppendEncrypt aes
|
||||||
|
, aeadImplDecrypt = gcmAppendDecrypt aes
|
||||||
|
, aeadImplFinalize = gcmFinish aes
|
||||||
|
}
|
||||||
|
|
||||||
|
ocbMode :: AES -> AEADModeImpl AESOCB
|
||||||
|
ocbMode aes = AEADModeImpl
|
||||||
|
{ aeadImplAppendHeader = ocbAppendAAD aes
|
||||||
|
, aeadImplEncrypt = ocbAppendEncrypt aes
|
||||||
|
, aeadImplDecrypt = ocbAppendDecrypt aes
|
||||||
|
, aeadImplFinalize = ocbFinish aes
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
-- | AES Context (pre-processed key)
|
-- | AES Context (pre-processed key)
|
||||||
newtype AES = AES SecureBytes
|
newtype AES = AES SecureBytes
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user