hOpenPGP-3.7: Codec/Encryption/OpenPGP/Internal/HOBlockCipher.hs
-- HOBlockCipher.hs: abstraction for the different BlockCipher classes, plus crazy CFB mode stuff
-- Copyright © 2016-2024 Clint Adams
-- This software is released under the terms of the Expat license.
-- (See the LICENSE file).
{-# LANGUAGE PackageImports #-}
module Codec.Encryption.OpenPGP.Internal.HOBlockCipher
( HOBlockCipher (..)
) where
import Data.ByteArray (ByteArray, ByteArrayAccess)
import qualified Data.ByteString as B
import qualified "crypton" Crypto.Cipher.Types as CCT
import Codec.Encryption.OpenPGP.Types.Internal.Errors
( CipherError (..)
)
class HOBlockCipher cipher where
cipherInit :: ByteArray key => key -> Either CipherError cipher
cipherName :: cipher -> String
cipherKeySize :: cipher -> CCT.KeySizeSpecifier
blockSize :: cipher -> Int
ecbEncrypt
:: cipher -> B.ByteString -> Either CipherError B.ByteString
ecbDecrypt
:: cipher -> B.ByteString -> Either CipherError B.ByteString
cfbEncrypt
:: cipher
-> B.ByteString
-> B.ByteString
-> Either CipherError B.ByteString
cfbDecrypt
:: cipher
-> B.ByteString
-> B.ByteString
-> Either CipherError B.ByteString
paddedCfbEncrypt
:: cipher
-> B.ByteString
-> B.ByteString
-> Either CipherError B.ByteString
paddedCfbEncrypt = cfbEncrypt
paddedCfbDecrypt
:: cipher
-> B.ByteString
-> B.ByteString
-> Either CipherError B.ByteString
paddedCfbDecrypt = cfbDecrypt
aeadInit
:: CCT.AEADMode
-> cipher
-> B.ByteString
-> Either CipherError (CCT.AEAD cipher)
aeadInit _ _ _ = Left CipherAEADInitUnsupported
aeadSimpleEncrypt
:: (ByteArray pt, ByteArrayAccess aad)
=> CCT.AEAD cipher
-> aad
-> pt
-> Int
-> (CCT.AuthTag, pt)
aeadSimpleEncrypt _ _ _ _ = error "aeadSimpleEncrypt not supported"
aeadSimpleDecrypt
:: (ByteArray ct, ByteArrayAccess aad)
=> CCT.AEAD cipher
-> aad
-> ct
-> CCT.AuthTag
-> Maybe ct
aeadSimpleDecrypt _ _ _ _ = Nothing