packages feed

crypton-2.3.1 / Crypto / Cipher / DES.hs

-- |-- Module      : Crypto.Cipher.DES-- License     : BSD-style-- Maintainer  : Vincent Hanquez <vincent@snarc.org>-- Stability   : stable-- Portability : good---- DES, which is here because callers still meet it rather than because it-- should be chosen: its 56-bit key is exhaustible.  Prefer "Crypto.Cipher.AES".module Crypto.Cipher.DES (    DES,) whereimport Crypto.Cipher.DES.Primitiveimport Crypto.Cipher.Typesimport Crypto.Errorimport Crypto.Internal.ByteArray (ByteArrayAccess)import qualified Crypto.Internal.ByteArray as B-- | DES Contextdata DES = DES Schedule Schedule    deriving (Eq)instance Cipher DES where    cipherName _ = "DES"    cipherKeySize _ = KeySizeFixed 8    cipherInit k = initDES kinstance BlockCipher DES where    blockSize _ = 8    ecbEncrypt (DES enc _) = ecb enc    ecbDecrypt (DES _ dec) = ecb decinitDES :: ByteArrayAccess key => key -> CryptoFailable DESinitDES k    | B.length k == 8 =        CryptoPassed $ DES (schedule [(Encrypt, k)]) (schedule [(Decrypt, k)])    | otherwise = CryptoFailed CryptoError_KeySizeInvalid