cryptonite/Crypto/Cipher/Blowfish.hs
Vincent Hanquez ca125f3e66 wip
2015-04-08 14:12:58 +01:00

61 lines
1.6 KiB
Haskell

{-# LANGUAGE CPP #-}
-- |
-- Module : Crypto.Cipher.Blowfish
-- License : BSD-style
-- Maintainer : Vincent Hanquez <vincent@snarc.org>
-- Stability : stable
-- Portability : good
--
module Crypto.Cipher.Blowfish
( Blowfish
, Blowfish64
, Blowfish128
, Blowfish256
, Blowfish448
) where
import Crypto.Cipher.Types
import Crypto.Cipher.Blowfish.Primitive
-- | variable keyed blowfish state
newtype Blowfish = Blowfish Context
-- | 64 bit keyed blowfish state
newtype Blowfish64 = Blowfish64 Context
-- | 128 bit keyed blowfish state
newtype Blowfish128 = Blowfish128 Context
-- | 256 bit keyed blowfish state
newtype Blowfish256 = Blowfish256 Context
-- | 448 bit keyed blowfish state
newtype Blowfish448 = Blowfish448 Context
instance Cipher Blowfish where
cipherName _ = "blowfish"
cipherKeySize _ = KeySizeRange 6 56
cipherInit k = Blowfish `fmap` initBlowfish k
instance BlockCipher Blowfish where
blockSize _ = 8
ecbEncrypt (Blowfish bf) = ecbEncryptLegacy encrypt bf
ecbDecrypt (Blowfish bf) = ecbDecryptLegacy decrypt bf
#define INSTANCE_CIPHER(CSTR, NAME, KEYSIZE) \
instance Cipher CSTR where \
{ cipherName _ = NAME \
; cipherKeySize _ = KeySizeFixed KEYSIZE \
; cipherInit k = CSTR `fmap` initBlowfish k \
}; \
instance BlockCipher CSTR where \
{ blockSize _ = 8 \
; ecbEncrypt (CSTR bf) = ecbEncryptLegacy encrypt bf \
; ecbDecrypt (CSTR bf) = ecbDecryptLegacy decrypt bf \
};
INSTANCE_CIPHER(Blowfish64, "blowfish64", 8)
INSTANCE_CIPHER(Blowfish128, "blowfish128", 16)
INSTANCE_CIPHER(Blowfish256, "blowfish256", 32)
INSTANCE_CIPHER(Blowfish448, "blowfish448", 56)