module Codec.Encryption.AES (
encrypt, decrypt, AESKey) where
import Codec.Encryption.AESAux
import Data.LargeWord
import Codec.Utils
import Data.Word
import Data.Bits
class (Bits a, Integral a) => AESKeyIndirection a
class AESKeyIndirection a => AESKey a
instance AESKeyIndirection Word128
instance AESKeyIndirection Word192
instance AESKeyIndirection Word256
instance AESKey Word128
instance AESKey Word192
instance AESKey Word256
encrypt :: AESKey a => a -> Word128 -> Word128
encrypt k p =
case bitSize k of
128 -> f aes128Encrypt k p
192 -> f aes192Encrypt k p
256 -> f aes256Encrypt k p
f g k p =
fromIntegral $ fromOctets 256 $
g (i2osp (bitSize k `div` bitSize (0::Octet)) $ fromIntegral k)
(i2osp (bitSize p `div` bitSize (0::Octet)) $ fromIntegral p)
decrypt :: AESKey a => a -> Word128 -> Word128
decrypt k p =
case bitSize k of
128 -> f aes128Decrypt k p
192 -> f aes192Decrypt k p
256 -> f aes256Decrypt k p