1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
-- Crypton.hs: shim for crypton
-- Copyright © 2016-2024 Clint Adams
-- This software is released under the terms of the Expat license.
-- (See the LICENSE file).
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE UndecidableInstances #-}
module Codec.Encryption.OpenPGP.Internal.Crypton
( HOWrappedCCT(..)
) where
import Control.Error.Util (note)
import qualified "crypton" Crypto.Cipher.Types as CCT
import qualified Crypto.Error as CE
import Data.Bifunctor (bimap)
import qualified Data.ByteString as B
import Codec.Encryption.OpenPGP.Internal.HOBlockCipher
newtype HOWrappedCCT a =
HWCCT a
instance CCT.BlockCipher cipher => HOBlockCipher (HOWrappedCCT cipher) where
cipherInit = bimap show HWCCT . CE.eitherCryptoError . CCT.cipherInit
cipherName (HWCCT c) = CCT.cipherName c
cipherKeySize (HWCCT c) = CCT.cipherKeySize c
blockSize (HWCCT c) = CCT.blockSize c
cfbEncrypt (HWCCT c) iv bs =
hammerIV iv >>= \i -> return (CCT.cfbEncrypt c i bs)
cfbDecrypt (HWCCT c) iv bs =
hammerIV iv >>= \i -> return (CCT.cfbDecrypt c i bs)
hammerIV ::
CCT.BlockCipher cipher => B.ByteString -> Either String (CCT.IV cipher)
hammerIV = note "crypton bad IV" . CCT.makeIV
|