{-# LANGUAGE MagicHash #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Crypto.Cipher.CAST5.Primitive
-- License     :  BSD-style
--
-- Haskell implementation of the CAST-128 Encryption Algorithm
--
-----------------------------------------------------------------------------


module Crypto.Cipher.CAST5.Primitive
    ( encrypt
    , decrypt
    , Key()
    , buildKey
    ) where

import Control.Monad (void, (>=>))

import Data.Bits
import Data.Memory.Endian
import Data.Word

import           Crypto.Internal.ByteArray (ByteArrayAccess)
import qualified Crypto.Internal.ByteArray as B
import           Crypto.Internal.WordArray


-- Data Types

data P = P {-# UNPACK #-} !Word32 -- left word
           {-# UNPACK #-} !Word32 -- right word

data Q = Q {-# UNPACK #-} !Word32 {-# UNPACK #-} !Word32
           {-# UNPACK #-} !Word32 {-# UNPACK #-} !Word32

-- | All subkeys for 12 or 16 rounds
data Key = K12 {-# UNPACK #-} !Array32 -- [ km1, kr1, km2, kr2, ..., km12, kr12 ]
         | K16 {-# UNPACK #-} !Array32 -- [ km1, kr1, km2, kr2, ..., km16, kr16 ]


-- Big-endian Transformations

decomp64 :: Word64 -> P
decomp64 :: Word64 -> P
decomp64 Word64
x = Word32 -> Word32 -> P
P (Word64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
x Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
32)) (Word64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
x)

comp64 :: P -> Word64
comp64 :: P -> Word64
comp64 (P Word32
l Word32
r) = (Word32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
l Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
32) Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
r

decomp32 :: Word32 -> (Word8, Word8, Word8, Word8)
decomp32 :: Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x =
    let a :: Word8
a = Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
x Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` Int
24)
        b :: Word8
b = Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
x Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` Int
16)
        c :: Word8
c = Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
x Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR`  Int
8)
        d :: Word8
d = Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
x
    in (Word8
a, Word8
b, Word8
c, Word8
d)


-- Encryption

-- | Encrypts a block using the specified key
encrypt :: Key -> Word64 -> Word64
encrypt :: Key -> Word64 -> Word64
encrypt Key
k = P -> Word64
comp64 (P -> Word64) -> (Word64 -> P) -> Word64 -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> P -> P
cast_enc Key
k (P -> P) -> (Word64 -> P) -> Word64 -> P
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> P
decomp64

cast_enc :: Key -> P -> P
cast_enc :: Key -> P -> P
cast_enc (K12 Array32
a) (P Word32
l0 Word32
r0) = Word32 -> Word32 -> P
P Word32
r12 Word32
r11
  where
    r1 :: Word32
r1  = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
0  Word32
l0  Word32
r0
    r2 :: Word32
r2  = Array32 -> Int -> Word32 -> Word32 -> Word32
type2 Array32
a Int
2  Word32
r0  Word32
r1
    r3 :: Word32
r3  = Array32 -> Int -> Word32 -> Word32 -> Word32
type3 Array32
a Int
4  Word32
r1  Word32
r2
    r4 :: Word32
r4  = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
6  Word32
r2  Word32
r3
    r5 :: Word32
r5  = Array32 -> Int -> Word32 -> Word32 -> Word32
type2 Array32
a Int
8  Word32
r3  Word32
r4
    r6 :: Word32
r6  = Array32 -> Int -> Word32 -> Word32 -> Word32
type3 Array32
a Int
10 Word32
r4  Word32
r5
    r7 :: Word32
r7  = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
12 Word32
r5  Word32
r6
    r8 :: Word32
r8  = Array32 -> Int -> Word32 -> Word32 -> Word32
type2 Array32
a Int
14 Word32
r6  Word32
r7
    r9 :: Word32
r9  = Array32 -> Int -> Word32 -> Word32 -> Word32
type3 Array32
a Int
16 Word32
r7  Word32
r8
    r10 :: Word32
r10 = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
18 Word32
r8  Word32
r9
    r11 :: Word32
r11 = Array32 -> Int -> Word32 -> Word32 -> Word32
type2 Array32
a Int
20 Word32
r9  Word32
r10
    r12 :: Word32
r12 = Array32 -> Int -> Word32 -> Word32 -> Word32
type3 Array32
a Int
22 Word32
r10 Word32
r11

cast_enc (K16 Array32
a) P
p = Word32 -> Word32 -> P
P Word32
r16 Word32
r15
  where
    P Word32
r12 Word32
r11 = Key -> P -> P
cast_enc (Array32 -> Key
K12 Array32
a) P
p

    r13 :: Word32
r13 = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
24 Word32
r11 Word32
r12
    r14 :: Word32
r14 = Array32 -> Int -> Word32 -> Word32 -> Word32
type2 Array32
a Int
26 Word32
r12 Word32
r13
    r15 :: Word32
r15 = Array32 -> Int -> Word32 -> Word32 -> Word32
type3 Array32
a Int
28 Word32
r13 Word32
r14
    r16 :: Word32
r16 = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
30 Word32
r14 Word32
r15

-- Decryption

-- | Decrypts a block using the specified key
decrypt :: Key -> Word64 -> Word64
decrypt :: Key -> Word64 -> Word64
decrypt Key
k = P -> Word64
comp64 (P -> Word64) -> (Word64 -> P) -> Word64 -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> P -> P
cast_dec Key
k (P -> P) -> (Word64 -> P) -> Word64 -> P
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> P
decomp64

cast_dec :: Key -> P -> P
cast_dec :: Key -> P -> P
cast_dec (K12 Array32
a) (P Word32
r12 Word32
r11) = Word32 -> Word32 -> P
P Word32
l0 Word32
r0
  where
    r10 :: Word32
r10 = Array32 -> Int -> Word32 -> Word32 -> Word32
type3 Array32
a Int
22 Word32
r12 Word32
r11
    r9 :: Word32
r9  = Array32 -> Int -> Word32 -> Word32 -> Word32
type2 Array32
a Int
20 Word32
r11 Word32
r10
    r8 :: Word32
r8  = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
18 Word32
r10 Word32
r9
    r7 :: Word32
r7  = Array32 -> Int -> Word32 -> Word32 -> Word32
type3 Array32
a Int
16 Word32
r9  Word32
r8
    r6 :: Word32
r6  = Array32 -> Int -> Word32 -> Word32 -> Word32
type2 Array32
a Int
14 Word32
r8  Word32
r7
    r5 :: Word32
r5  = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
12 Word32
r7  Word32
r6
    r4 :: Word32
r4  = Array32 -> Int -> Word32 -> Word32 -> Word32
type3 Array32
a Int
10 Word32
r6  Word32
r5
    r3 :: Word32
r3  = Array32 -> Int -> Word32 -> Word32 -> Word32
type2 Array32
a Int
8  Word32
r5  Word32
r4
    r2 :: Word32
r2  = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
6  Word32
r4  Word32
r3
    r1 :: Word32
r1  = Array32 -> Int -> Word32 -> Word32 -> Word32
type3 Array32
a Int
4  Word32
r3  Word32
r2
    r0 :: Word32
r0  = Array32 -> Int -> Word32 -> Word32 -> Word32
type2 Array32
a Int
2  Word32
r2  Word32
r1
    l0 :: Word32
l0  = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
0  Word32
r1  Word32
r0

cast_dec (K16 Array32
a) (P Word32
r16 Word32
r15) = Key -> P -> P
cast_dec (Array32 -> Key
K12 Array32
a) (Word32 -> Word32 -> P
P Word32
r12 Word32
r11)
  where
    r14 :: Word32
r14 = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
30 Word32
r16 Word32
r15
    r13 :: Word32
r13 = Array32 -> Int -> Word32 -> Word32 -> Word32
type3 Array32
a Int
28 Word32
r15 Word32
r14
    r12 :: Word32
r12 = Array32 -> Int -> Word32 -> Word32 -> Word32
type2 Array32
a Int
26 Word32
r14 Word32
r13
    r11 :: Word32
r11 = Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
a Int
24 Word32
r13 Word32
r12


-- Non-Identical Rounds

type1 :: Array32 -> Int -> Word32 -> Word32 -> Word32
type1 :: Array32 -> Int -> Word32 -> Word32 -> Word32
type1 Array32
arr Int
idx Word32
l Word32
r =
    let km :: Word32
km = Array32 -> Int -> Word32
arrayRead32 Array32
arr Int
idx
        kr :: Word32
kr = Array32 -> Int -> Word32
arrayRead32 Array32
arr (Int
idx Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
        j :: Word32
j = (Word32
km Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word32
r) Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`rotateL` Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
kr
        (Word8
ja, Word8
jb, Word8
jc, Word8
jd) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
j
     in Word32
l Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` (((Word8 -> Word32
sbox_s1 Word8
ja Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s2 Word8
jb) Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word8 -> Word32
sbox_s3 Word8
jc) Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word8 -> Word32
sbox_s4 Word8
jd)

type2 :: Array32 -> Int -> Word32 -> Word32 -> Word32
type2 :: Array32 -> Int -> Word32 -> Word32 -> Word32
type2 Array32
arr Int
idx Word32
l Word32
r =
    let km :: Word32
km = Array32 -> Int -> Word32
arrayRead32 Array32
arr Int
idx
        kr :: Word32
kr = Array32 -> Int -> Word32
arrayRead32 Array32
arr (Int
idx Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
        j :: Word32
j = (Word32
km Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word32
r) Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`rotateL` Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
kr
        (Word8
ja, Word8
jb, Word8
jc, Word8
jd) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
j
     in Word32
l Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` (((Word8 -> Word32
sbox_s1 Word8
ja Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word8 -> Word32
sbox_s2 Word8
jb) Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word8 -> Word32
sbox_s3 Word8
jc) Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s4 Word8
jd)

type3 :: Array32 -> Int -> Word32 -> Word32 -> Word32
type3 :: Array32 -> Int -> Word32 -> Word32 -> Word32
type3 Array32
arr Int
idx Word32
l Word32
r =
    let km :: Word32
km = Array32 -> Int -> Word32
arrayRead32 Array32
arr Int
idx
        kr :: Word32
kr = Array32 -> Int -> Word32
arrayRead32 Array32
arr (Int
idx Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
        j :: Word32
j = (Word32
km Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
r) Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`rotateL` Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
kr
        (Word8
ja, Word8
jb, Word8
jc, Word8
jd) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
j
     in Word32
l Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` (((Word8 -> Word32
sbox_s1 Word8
ja Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word8 -> Word32
sbox_s2 Word8
jb) Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s3 Word8
jc) Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word8 -> Word32
sbox_s4 Word8
jd)


-- Key Schedule

-- | Precompute "masking" and "rotation" subkeys
buildKey :: ByteArrayAccess key
         => Bool -- ^ @True@ for short keys that only need 12 rounds
         -> key  -- ^ Input key padded to 16 bytes
         -> Key  -- ^ Output data structure
buildKey :: forall key. ByteArrayAccess key => Bool -> key -> Key
buildKey Bool
isShort key
key =
    let P Word32
x0123 Word32
x4567 = Word64 -> P
decomp64 (BE Word64 -> Word64
forall a. ByteSwap a => BE a -> a
fromBE (BE Word64 -> Word64) -> BE Word64 -> Word64
forall a b. (a -> b) -> a -> b
$ key -> Int -> BE Word64
forall bs. ByteArrayAccess bs => bs -> Int -> BE Word64
B.toW64BE key
key Int
0)
        P Word32
x89AB Word32
xCDEF = Word64 -> P
decomp64 (BE Word64 -> Word64
forall a. ByteSwap a => BE a -> a
fromBE (BE Word64 -> Word64) -> BE Word64 -> Word64
forall a b. (a -> b) -> a -> b
$ key -> Int -> BE Word64
forall bs. ByteArrayAccess bs => bs -> Int -> BE Word64
B.toW64BE key
key Int
8)
     in Bool -> Q -> Key
keySchedule Bool
isShort (Word32 -> Word32 -> Word32 -> Word32 -> Q
Q Word32
x0123 Word32
x4567 Word32
x89AB Word32
xCDEF)

keySchedule :: Bool -> Q -> Key
keySchedule :: Bool -> Q -> Key
keySchedule Bool
isShort Q
x
    | Bool
isShort   = Array32 -> Key
K12 (Array32 -> Key) -> Array32 -> Key
forall a b. (a -> b) -> a -> b
$ Int -> (MutableArray32 -> IO ()) -> Array32
allocArray32AndFreeze Int
24 ((MutableArray32 -> IO ()) -> Array32)
-> (MutableArray32 -> IO ()) -> Array32
forall a b. (a -> b) -> a -> b
$ \MutableArray32
ma ->
        IO Q -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MutableArray32 -> Int -> Q -> IO Q
steps123 MutableArray32
ma Int
0 Q
x IO Q -> (Q -> IO Q) -> IO Q
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Q -> IO Q
skip4 IO Q -> (Q -> IO Q) -> IO Q
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MutableArray32 -> Int -> Q -> IO Q
steps123 MutableArray32
ma Int
1)

    | Bool
otherwise = Array32 -> Key
K16 (Array32 -> Key) -> Array32 -> Key
forall a b. (a -> b) -> a -> b
$ Int -> (MutableArray32 -> IO ()) -> Array32
allocArray32AndFreeze Int
32 ((MutableArray32 -> IO ()) -> Array32)
-> (MutableArray32 -> IO ()) -> Array32
forall a b. (a -> b) -> a -> b
$ \MutableArray32
ma ->
        IO Q -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MutableArray32 -> Int -> Q -> IO Q
steps123 MutableArray32
ma Int
0 Q
x IO Q -> (Q -> IO Q) -> IO Q
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MutableArray32 -> Int -> Q -> IO Q
step4 MutableArray32
ma Int
24 IO Q -> (Q -> IO Q) -> IO Q
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MutableArray32 -> Int -> Q -> IO Q
steps123 MutableArray32
ma Int
1 IO Q -> (Q -> IO Q) -> IO Q
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MutableArray32 -> Int -> Q -> IO Q
step4 MutableArray32
ma Int
25)

  where
    sbox_s56785 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56785 Word8
a Word8
b Word8
c Word8
d Word8
e = Word8 -> Word32
sbox_s5 Word8
a Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s6 Word8
b Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s7 Word8
c Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s8 Word8
d Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s5 Word8
e
    sbox_s56786 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56786 Word8
a Word8
b Word8
c Word8
d Word8
e = Word8 -> Word32
sbox_s5 Word8
a Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s6 Word8
b Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s7 Word8
c Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s8 Word8
d Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s6 Word8
e
    sbox_s56787 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56787 Word8
a Word8
b Word8
c Word8
d Word8
e = Word8 -> Word32
sbox_s5 Word8
a Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s6 Word8
b Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s7 Word8
c Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s8 Word8
d Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s7 Word8
e
    sbox_s56788 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56788 Word8
a Word8
b Word8
c Word8
d Word8
e = Word8 -> Word32
sbox_s5 Word8
a Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s6 Word8
b Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s7 Word8
c Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s8 Word8
d Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
sbox_s8 Word8
e

    steps123 :: MutableArray32 -> Int -> Q -> IO Q
steps123 MutableArray32
ma Int
off = MutableArray32 -> Int -> Q -> IO Q
step1 MutableArray32
ma Int
off (Q -> IO Q) -> (Q -> IO Q) -> Q -> IO Q
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> MutableArray32 -> Int -> Q -> IO Q
step2 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
8) (Q -> IO Q) -> (Q -> IO Q) -> Q -> IO Q
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> MutableArray32 -> Int -> Q -> IO Q
step3 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
16)

    step1 :: MutableArray32 -> Int -> Q -> IO Q
    step1 :: MutableArray32 -> Int -> Q -> IO Q
step1 MutableArray32
ma Int
off (Q Word32
x0123 Word32
x4567 Word32
x89AB Word32
xCDEF) = do
        let (Word8
x8, Word8
x9, Word8
xA, Word8
xB) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x89AB
            (Word8
xC, Word8
xD, Word8
xE, Word8
xF) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
xCDEF

            z0123 :: Word32
z0123 = Word32
x0123 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56787 Word8
xD Word8
xF Word8
xC Word8
xE Word8
x8
            z4567 :: Word32
z4567 = Word32
x89AB Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56788 Word8
z0 Word8
z2 Word8
z1 Word8
z3 Word8
xA
            z89AB :: Word32
z89AB = Word32
xCDEF Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56785 Word8
z7 Word8
z6 Word8
z5 Word8
z4 Word8
x9
            zCDEF :: Word32
zCDEF = Word32
x4567 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56786 Word8
zA Word8
z9 Word8
zB Word8
z8 Word8
xB

            (Word8
z0, Word8
z1, Word8
z2, Word8
z3) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z0123
            (Word8
z4, Word8
z5, Word8
z6, Word8
z7) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z4567
            (Word8
z8, Word8
z9, Word8
zA, Word8
zB) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z89AB
            (Word8
zC, Word8
zD, Word8
zE, Word8
zF) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
zCDEF

        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
0) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56785 Word8
z8 Word8
z9 Word8
z7 Word8
z6 Word8
z2
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56786 Word8
zA Word8
zB Word8
z5 Word8
z4 Word8
z6
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56787 Word8
zC Word8
zD Word8
z3 Word8
z2 Word8
z9
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56788 Word8
zE Word8
zF Word8
z1 Word8
z0 Word8
zC
        Q -> IO Q
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> Word32 -> Word32 -> Word32 -> Q
Q Word32
z0123 Word32
z4567 Word32
z89AB Word32
zCDEF)

    step2 :: MutableArray32 -> Int -> Q -> IO Q
    step2 :: MutableArray32 -> Int -> Q -> IO Q
step2 MutableArray32
ma Int
off (Q Word32
z0123 Word32
z4567 Word32
z89AB Word32
zCDEF) = do
        let (Word8
z0, Word8
z1, Word8
z2, Word8
z3) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z0123
            (Word8
z4, Word8
z5, Word8
z6, Word8
z7) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z4567

            x0123 :: Word32
x0123 = Word32
z89AB Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56787 Word8
z5 Word8
z7 Word8
z4 Word8
z6 Word8
z0
            x4567 :: Word32
x4567 = Word32
z0123 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56788 Word8
x0 Word8
x2 Word8
x1 Word8
x3 Word8
z2
            x89AB :: Word32
x89AB = Word32
z4567 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56785 Word8
x7 Word8
x6 Word8
x5 Word8
x4 Word8
z1
            xCDEF :: Word32
xCDEF = Word32
zCDEF Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56786 Word8
xA Word8
x9 Word8
xB Word8
x8 Word8
z3

            (Word8
x0, Word8
x1, Word8
x2, Word8
x3) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x0123
            (Word8
x4, Word8
x5, Word8
x6, Word8
x7) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x4567
            (Word8
x8, Word8
x9, Word8
xA, Word8
xB) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x89AB
            (Word8
xC, Word8
xD, Word8
xE, Word8
xF) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
xCDEF

        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
0) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56785 Word8
x3 Word8
x2 Word8
xC Word8
xD Word8
x8
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56786 Word8
x1 Word8
x0 Word8
xE Word8
xF Word8
xD
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56787 Word8
x7 Word8
x6 Word8
x8 Word8
x9 Word8
x3
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56788 Word8
x5 Word8
x4 Word8
xA Word8
xB Word8
x7
        Q -> IO Q
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> Word32 -> Word32 -> Word32 -> Q
Q Word32
x0123 Word32
x4567 Word32
x89AB Word32
xCDEF)

    step3 :: MutableArray32 -> Int -> Q -> IO Q
    step3 :: MutableArray32 -> Int -> Q -> IO Q
step3 MutableArray32
ma Int
off (Q Word32
x0123 Word32
x4567 Word32
x89AB Word32
xCDEF) = do
        let (Word8
x8, Word8
x9, Word8
xA, Word8
xB) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x89AB
            (Word8
xC, Word8
xD, Word8
xE, Word8
xF) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
xCDEF

            z0123 :: Word32
z0123 = Word32
x0123 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56787 Word8
xD Word8
xF Word8
xC Word8
xE Word8
x8
            z4567 :: Word32
z4567 = Word32
x89AB Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56788 Word8
z0 Word8
z2 Word8
z1 Word8
z3 Word8
xA
            z89AB :: Word32
z89AB = Word32
xCDEF Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56785 Word8
z7 Word8
z6 Word8
z5 Word8
z4 Word8
x9
            zCDEF :: Word32
zCDEF = Word32
x4567 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56786 Word8
zA Word8
z9 Word8
zB Word8
z8 Word8
xB

            (Word8
z0, Word8
z1, Word8
z2, Word8
z3) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z0123
            (Word8
z4, Word8
z5, Word8
z6, Word8
z7) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z4567
            (Word8
z8, Word8
z9, Word8
zA, Word8
zB) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z89AB
            (Word8
zC, Word8
zD, Word8
zE, Word8
zF) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
zCDEF

        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
0) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56785 Word8
z3 Word8
z2 Word8
zC Word8
zD Word8
z9
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56786 Word8
z1 Word8
z0 Word8
zE Word8
zF Word8
zC
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56787 Word8
z7 Word8
z6 Word8
z8 Word8
z9 Word8
z2
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56788 Word8
z5 Word8
z4 Word8
zA Word8
zB Word8
z6
        Q -> IO Q
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> Word32 -> Word32 -> Word32 -> Q
Q Word32
z0123 Word32
z4567 Word32
z89AB Word32
zCDEF)

    step4 :: MutableArray32 -> Int -> Q -> IO Q
    step4 :: MutableArray32 -> Int -> Q -> IO Q
step4 MutableArray32
ma Int
off (Q Word32
z0123 Word32
z4567 Word32
z89AB Word32
zCDEF) = do
        let (Word8
z0, Word8
z1, Word8
z2, Word8
z3) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z0123
            (Word8
z4, Word8
z5, Word8
z6, Word8
z7) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z4567

            x0123 :: Word32
x0123 = Word32
z89AB Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56787 Word8
z5 Word8
z7 Word8
z4 Word8
z6 Word8
z0
            x4567 :: Word32
x4567 = Word32
z0123 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56788 Word8
x0 Word8
x2 Word8
x1 Word8
x3 Word8
z2
            x89AB :: Word32
x89AB = Word32
z4567 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56785 Word8
x7 Word8
x6 Word8
x5 Word8
x4 Word8
z1
            xCDEF :: Word32
xCDEF = Word32
zCDEF Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56786 Word8
xA Word8
x9 Word8
xB Word8
x8 Word8
z3

            (Word8
x0, Word8
x1, Word8
x2, Word8
x3) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x0123
            (Word8
x4, Word8
x5, Word8
x6, Word8
x7) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x4567
            (Word8
x8, Word8
x9, Word8
xA, Word8
xB) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x89AB
            (Word8
xC, Word8
xD, Word8
xE, Word8
xF) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
xCDEF

        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
0) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56785 Word8
x8 Word8
x9 Word8
x7 Word8
x6 Word8
x3
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56786 Word8
xA Word8
xB Word8
x5 Word8
x4 Word8
x7
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56787 Word8
xC Word8
xD Word8
x3 Word8
x2 Word8
x8
        MutableArray32 -> Int -> Word32 -> IO ()
mutableArrayWrite32 MutableArray32
ma (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6) (Word32 -> IO ()) -> Word32 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56788 Word8
xE Word8
xF Word8
x1 Word8
x0 Word8
xD
        Q -> IO Q
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> Word32 -> Word32 -> Word32 -> Q
Q Word32
x0123 Word32
x4567 Word32
x89AB Word32
xCDEF)

    skip4 :: Q -> IO Q
    skip4 :: Q -> IO Q
skip4 (Q Word32
z0123 Word32
z4567 Word32
z89AB Word32
zCDEF) = do
        let (Word8
z0, Word8
z1, Word8
z2, Word8
z3) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z0123
            (Word8
z4, Word8
z5, Word8
z6, Word8
z7) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
z4567

            x0123 :: Word32
x0123 = Word32
z89AB Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56787 Word8
z5 Word8
z7 Word8
z4 Word8
z6 Word8
z0
            x4567 :: Word32
x4567 = Word32
z0123 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56788 Word8
x0 Word8
x2 Word8
x1 Word8
x3 Word8
z2
            x89AB :: Word32
x89AB = Word32
z4567 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56785 Word8
x7 Word8
x6 Word8
x5 Word8
x4 Word8
z1
            xCDEF :: Word32
xCDEF = Word32
zCDEF Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32
sbox_s56786 Word8
xA Word8
x9 Word8
xB Word8
x8 Word8
z3

            (Word8
x0, Word8
x1, Word8
x2, Word8
x3) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x0123
            (Word8
x4, Word8
x5, Word8
x6, Word8
x7) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x4567
            (Word8
x8, Word8
x9, Word8
xA, Word8
xB) = Word32 -> (Word8, Word8, Word8, Word8)
decomp32 Word32
x89AB

        Q -> IO Q
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> Word32 -> Word32 -> Word32 -> Q
Q Word32
x0123 Word32
x4567 Word32
x89AB Word32
xCDEF)

-- S-Boxes

sbox_s1 :: Word8 -> Word32
sbox_s1 :: Word8 -> Word32
sbox_s1 Word8
i = Array32 -> Int -> Word32
arrayRead32 Array32
t (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
  where
    t :: Array32
t = Int -> Addr# -> Array32
array32FromAddrBE Int
256
            Addr#
"\x30\xfb\x40\xd4\x9f\xa0\xff\x0b\x6b\xec\xcd\x2f\x3f\x25\x8c\x7a\x1e\x21\x3f\x2f\x9c\x00\x4d\xd3\x60\x03\xe5\x40\xcf\x9f\xc9\x49\
            \\xbf\xd4\xaf\x27\x88\xbb\xbd\xb5\xe2\x03\x40\x90\x98\xd0\x96\x75\x6e\x63\xa0\xe0\x15\xc3\x61\xd2\xc2\xe7\x66\x1d\x22\xd4\xff\x8e\
            \\x28\x68\x3b\x6f\xc0\x7f\xd0\x59\xff\x23\x79\xc8\x77\x5f\x50\xe2\x43\xc3\x40\xd3\xdf\x2f\x86\x56\x88\x7c\xa4\x1a\xa2\xd2\xbd\x2d\
            \\xa1\xc9\xe0\xd6\x34\x6c\x48\x19\x61\xb7\x6d\x87\x22\x54\x0f\x2f\x2a\xbe\x32\xe1\xaa\x54\x16\x6b\x22\x56\x8e\x3a\xa2\xd3\x41\xd0\
            \\x66\xdb\x40\xc8\xa7\x84\x39\x2f\x00\x4d\xff\x2f\x2d\xb9\xd2\xde\x97\x94\x3f\xac\x4a\x97\xc1\xd8\x52\x76\x44\xb7\xb5\xf4\x37\xa7\
            \\xb8\x2c\xba\xef\xd7\x51\xd1\x59\x6f\xf7\xf0\xed\x5a\x09\x7a\x1f\x82\x7b\x68\xd0\x90\xec\xf5\x2e\x22\xb0\xc0\x54\xbc\x8e\x59\x35\
            \\x4b\x6d\x2f\x7f\x50\xbb\x64\xa2\xd2\x66\x49\x10\xbe\xe5\x81\x2d\xb7\x33\x22\x90\xe9\x3b\x15\x9f\xb4\x8e\xe4\x11\x4b\xff\x34\x5d\
            \\xfd\x45\xc2\x40\xad\x31\x97\x3f\xc4\xf6\xd0\x2e\x55\xfc\x81\x65\xd5\xb1\xca\xad\xa1\xac\x2d\xae\xa2\xd4\xb7\x6d\xc1\x9b\x0c\x50\
            \\x88\x22\x40\xf2\x0c\x6e\x4f\x38\xa4\xe4\xbf\xd7\x4f\x5b\xa2\x72\x56\x4c\x1d\x2f\xc5\x9c\x53\x19\xb9\x49\xe3\x54\xb0\x46\x69\xfe\
            \\xb1\xb6\xab\x8a\xc7\x13\x58\xdd\x63\x85\xc5\x45\x11\x0f\x93\x5d\x57\x53\x8a\xd5\x6a\x39\x04\x93\xe6\x3d\x37\xe0\x2a\x54\xf6\xb3\
            \\x3a\x78\x7d\x5f\x62\x76\xa0\xb5\x19\xa6\xfc\xdf\x7a\x42\x20\x6a\x29\xf9\xd4\xd5\xf6\x1b\x18\x91\xbb\x72\x27\x5e\xaa\x50\x81\x67\
            \\x38\x90\x10\x91\xc6\xb5\x05\xeb\x84\xc7\xcb\x8c\x2a\xd7\x5a\x0f\x87\x4a\x14\x27\xa2\xd1\x93\x6b\x2a\xd2\x86\xaf\xaa\x56\xd2\x91\
            \\xd7\x89\x43\x60\x42\x5c\x75\x0d\x93\xb3\x9e\x26\x18\x71\x84\xc9\x6c\x00\xb3\x2d\x73\xe2\xbb\x14\xa0\xbe\xbc\x3c\x54\x62\x37\x79\
            \\x64\x45\x9e\xab\x3f\x32\x8b\x82\x77\x18\xcf\x82\x59\xa2\xce\xa6\x04\xee\x00\x2e\x89\xfe\x78\xe6\x3f\xab\x09\x50\x32\x5f\xf6\xc2\
            \\x81\x38\x3f\x05\x69\x63\xc5\xc8\x76\xcb\x5a\xd6\xd4\x99\x74\xc9\xca\x18\x0d\xcf\x38\x07\x82\xd5\xc7\xfa\x5c\xf6\x8a\xc3\x15\x11\
            \\x35\xe7\x9e\x13\x47\xda\x91\xd0\xf4\x0f\x90\x86\xa7\xe2\x41\x9e\x31\x36\x62\x41\x05\x1e\xf4\x95\xaa\x57\x3b\x04\x4a\x80\x5d\x8d\
            \\x54\x83\x00\xd0\x00\x32\x2a\x3c\xbf\x64\xcd\xdf\xba\x57\xa6\x8e\x75\xc6\x37\x2b\x50\xaf\xd3\x41\xa7\xc1\x32\x75\x91\x5a\x0b\xf5\
            \\x6b\x54\xbf\xab\x2b\x0b\x14\x26\xab\x4c\xc9\xd7\x44\x9c\xcd\x82\xf7\xfb\xf2\x65\xab\x85\xc5\xf3\x1b\x55\xdb\x94\xaa\xd4\xe3\x24\
            \\xcf\xa4\xbd\x3f\x2d\xea\xa3\xe2\x9e\x20\x4d\x02\xc8\xbd\x25\xac\xea\xdf\x55\xb3\xd5\xbd\x9e\x98\xe3\x12\x31\xb2\x2a\xd5\xad\x6c\
            \\x95\x43\x29\xde\xad\xbe\x45\x28\xd8\x71\x0f\x69\xaa\x51\xc9\x0f\xaa\x78\x6b\xf6\x22\x51\x3f\x1e\xaa\x51\xa7\x9b\x2a\xd3\x44\xcc\
            \\x7b\x5a\x41\xf0\xd3\x7c\xfb\xad\x1b\x06\x95\x05\x41\xec\xe4\x91\xb4\xc3\x32\xe6\x03\x22\x68\xd4\xc9\x60\x0a\xcc\xce\x38\x7e\x6d\
            \\xbf\x6b\xb1\x6c\x6a\x70\xfb\x78\x0d\x03\xd9\xc9\xd4\xdf\x39\xde\xe0\x10\x63\xda\x47\x36\xf4\x64\x5a\xd3\x28\xd8\xb3\x47\xcc\x96\
            \\x75\xbb\x0f\xc3\x98\x51\x1b\xfb\x4f\xfb\xcc\x35\xb5\x8b\xcf\x6a\xe1\x1f\x0a\xbc\xbf\xc5\xfe\x4a\xa7\x0a\xec\x10\xac\x39\x57\x0a\
            \\x3f\x04\x44\x2f\x61\x88\xb1\x53\xe0\x39\x7a\x2e\x57\x27\xcb\x79\x9c\xeb\x41\x8f\x1c\xac\xd6\x8d\x2a\xd3\x7c\x96\x01\x75\xcb\x9d\
            \\xc6\x9d\xff\x09\xc7\x5b\x65\xf0\xd9\xdb\x40\xd8\xec\x0e\x77\x79\x47\x44\xea\xd4\xb1\x1c\x32\x74\xdd\x24\xcb\x9e\x7e\x1c\x54\xbd\
            \\xf0\x11\x44\xf9\xd2\x24\x0e\xb1\x96\x75\xb3\xfd\xa3\xac\x37\x55\xd4\x7c\x27\xaf\x51\xc8\x5f\x4d\x56\x90\x75\x96\xa5\xbb\x15\xe6\
            \\x58\x03\x04\xf0\xca\x04\x2c\xf1\x01\x1a\x37\xea\x8d\xbf\xaa\xdb\x35\xba\x3e\x4a\x35\x26\xff\xa0\xc3\x7b\x4d\x09\xbc\x30\x6e\xd9\
            \\x98\xa5\x26\x66\x56\x48\xf7\x25\xff\x5e\x56\x9d\x0c\xed\x63\xd0\x7c\x63\xb2\xcf\x70\x0b\x45\xe1\xd5\xea\x50\xf1\x85\xa9\x28\x72\
            \\xaf\x1f\xbd\xa7\xd4\x23\x48\x70\xa7\x87\x0b\xf3\x2d\x3b\x4d\x79\x42\xe0\x41\x98\x0c\xd0\xed\xe7\x26\x47\x0d\xb8\xf8\x81\x81\x4c\
            \\x47\x4d\x6a\xd7\x7c\x0c\x5e\x5c\xd1\x23\x19\x59\x38\x1b\x72\x98\xf5\xd2\xf4\xdb\xab\x83\x86\x53\x6e\x2f\x1e\x23\x83\x71\x9c\x9e\
            \\xbd\x91\xe0\x46\x9a\x56\x45\x6e\xdc\x39\x20\x0c\x20\xc8\xc5\x71\x96\x2b\xda\x1c\xe1\xe6\x96\xff\xb1\x41\xab\x08\x7c\xca\x89\xb9\
            \\x1a\x69\xe7\x83\x02\xcc\x48\x43\xa2\xf7\xc5\x79\x42\x9e\xf4\x7d\x42\x7b\x16\x9c\x5a\xc9\xf0\x49\xdd\x8f\x0f\x00\x5c\x81\x65\xbf"#

sbox_s2 :: Word8 -> Word32
sbox_s2 :: Word8 -> Word32
sbox_s2 Word8
i = Array32 -> Int -> Word32
arrayRead32 Array32
t (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
  where
    t :: Array32
t = Int -> Addr# -> Array32
array32FromAddrBE Int
256
            Addr#
"\x1f\x20\x10\x94\xef\x0b\xa7\x5b\x69\xe3\xcf\x7e\x39\x3f\x43\x80\xfe\x61\xcf\x7a\xee\xc5\x20\x7a\x55\x88\x9c\x94\x72\xfc\x06\x51\
            \\xad\xa7\xef\x79\x4e\x1d\x72\x35\xd5\x5a\x63\xce\xde\x04\x36\xba\x99\xc4\x30\xef\x5f\x0c\x07\x94\x18\xdc\xdb\x7d\xa1\xd6\xef\xf3\
            \\xa0\xb5\x2f\x7b\x59\xe8\x36\x05\xee\x15\xb0\x94\xe9\xff\xd9\x09\xdc\x44\x00\x86\xef\x94\x44\x59\xba\x83\xcc\xb3\xe0\xc3\xcd\xfb\
            \\xd1\xda\x41\x81\x3b\x09\x2a\xb1\xf9\x97\xf1\xc1\xa5\xe6\xcf\x7b\x01\x42\x0d\xdb\xe4\xe7\xef\x5b\x25\xa1\xff\x41\xe1\x80\xf8\x06\
            \\x1f\xc4\x10\x80\x17\x9b\xee\x7a\xd3\x7a\xc6\xa9\xfe\x58\x30\xa4\x98\xde\x8b\x7f\x77\xe8\x3f\x4e\x79\x92\x92\x69\x24\xfa\x9f\x7b\
            \\xe1\x13\xc8\x5b\xac\xc4\x00\x83\xd7\x50\x35\x25\xf7\xea\x61\x5f\x62\x14\x31\x54\x0d\x55\x4b\x63\x5d\x68\x11\x21\xc8\x66\xc3\x59\
            \\x3d\x63\xcf\x73\xce\xe2\x34\xc0\xd4\xd8\x7e\x87\x5c\x67\x2b\x21\x07\x1f\x61\x81\x39\xf7\x62\x7f\x36\x1e\x30\x84\xe4\xeb\x57\x3b\
            \\x60\x2f\x64\xa4\xd6\x3a\xcd\x9c\x1b\xbc\x46\x35\x9e\x81\x03\x2d\x27\x01\xf5\x0c\x99\x84\x7a\xb4\xa0\xe3\xdf\x79\xba\x6c\xf3\x8c\
            \\x10\x84\x30\x94\x25\x37\xa9\x5e\xf4\x6f\x6f\xfe\xa1\xff\x3b\x1f\x20\x8c\xfb\x6a\x8f\x45\x8c\x74\xd9\xe0\xa2\x27\x4e\xc7\x3a\x34\
            \\xfc\x88\x4f\x69\x3e\x4d\xe8\xdf\xef\x0e\x00\x88\x35\x59\x64\x8d\x8a\x45\x38\x8c\x1d\x80\x43\x66\x72\x1d\x9b\xfd\xa5\x86\x84\xbb\
            \\xe8\x25\x63\x33\x84\x4e\x82\x12\x12\x8d\x80\x98\xfe\xd3\x3f\xb4\xce\x28\x0a\xe1\x27\xe1\x9b\xa5\xd5\xa6\xc2\x52\xe4\x97\x54\xbd\
            \\xc5\xd6\x55\xdd\xeb\x66\x70\x64\x77\x84\x0b\x4d\xa1\xb6\xa8\x01\x84\xdb\x26\xa9\xe0\xb5\x67\x14\x21\xf0\x43\xb7\xe5\xd0\x58\x60\
            \\x54\xf0\x30\x84\x06\x6f\xf4\x72\xa3\x1a\xa1\x53\xda\xdc\x47\x55\xb5\x62\x5d\xbf\x68\x56\x1b\xe6\x83\xca\x6b\x94\x2d\x6e\xd2\x3b\
            \\xec\xcf\x01\xdb\xa6\xd3\xd0\xba\xb6\x80\x3d\x5c\xaf\x77\xa7\x09\x33\xb4\xa3\x4c\x39\x7b\xc8\xd6\x5e\xe2\x2b\x95\x5f\x0e\x53\x04\
            \\x81\xed\x6f\x61\x20\xe7\x43\x64\xb4\x5e\x13\x78\xde\x18\x63\x9b\x88\x1c\xa1\x22\xb9\x67\x26\xd1\x80\x49\xa7\xe8\x22\xb7\xda\x7b\
            \\x5e\x55\x2d\x25\x52\x72\xd2\x37\x79\xd2\x95\x1c\xc6\x0d\x89\x4c\x48\x8c\xb4\x02\x1b\xa4\xfe\x5b\xa4\xb0\x9f\x6b\x1c\xa8\x15\xcf\
            \\xa2\x0c\x30\x05\x88\x71\xdf\x63\xb9\xde\x2f\xcb\x0c\xc6\xc9\xe9\x0b\xee\xff\x53\xe3\x21\x45\x17\xb4\x54\x28\x35\x9f\x63\x29\x3c\
            \\xee\x41\xe7\x29\x6e\x1d\x2d\x7c\x50\x04\x52\x86\x1e\x66\x85\xf3\xf3\x34\x01\xc6\x30\xa2\x2c\x95\x31\xa7\x08\x50\x60\x93\x0f\x13\
            \\x73\xf9\x84\x17\xa1\x26\x98\x59\xec\x64\x5c\x44\x52\xc8\x77\xa9\xcd\xff\x33\xa6\xa0\x2b\x17\x41\x7c\xba\xd9\xa2\x21\x80\x03\x6f\
            \\x50\xd9\x9c\x08\xcb\x3f\x48\x61\xc2\x6b\xd7\x65\x64\xa3\xf6\xab\x80\x34\x26\x76\x25\xa7\x5e\x7b\xe4\xe6\xd1\xfc\x20\xc7\x10\xe6\
            \\xcd\xf0\xb6\x80\x17\x84\x4d\x3b\x31\xee\xf8\x4d\x7e\x08\x24\xe4\x2c\xcb\x49\xeb\x84\x6a\x3b\xae\x8f\xf7\x78\x88\xee\x5d\x60\xf6\
            \\x7a\xf7\x56\x73\x2f\xdd\x5c\xdb\xa1\x16\x31\xc1\x30\xf6\x6f\x43\xb3\xfa\xec\x54\x15\x7f\xd7\xfa\xef\x85\x79\xcc\xd1\x52\xde\x58\
            \\xdb\x2f\xfd\x5e\x8f\x32\xce\x19\x30\x6a\xf9\x7a\x02\xf0\x3e\xf8\x99\x31\x9a\xd5\xc2\x42\xfa\x0f\xa7\xe3\xeb\xb0\xc6\x8e\x49\x06\
            \\xb8\xda\x23\x0c\x80\x82\x30\x28\xdc\xde\xf3\xc8\xd3\x5f\xb1\x71\x08\x8a\x1b\xc8\xbe\xc0\xc5\x60\x61\xa3\xc9\xe8\xbc\xa8\xf5\x4d\
            \\xc7\x2f\xef\xfa\x22\x82\x2e\x99\x82\xc5\x70\xb4\xd8\xd9\x4e\x89\x8b\x1c\x34\xbc\x30\x1e\x16\xe6\x27\x3b\xe9\x79\xb0\xff\xea\xa6\
            \\x61\xd9\xb8\xc6\x00\xb2\x48\x69\xb7\xff\xce\x3f\x08\xdc\x28\x3b\x43\xda\xf6\x5a\xf7\xe1\x97\x98\x76\x19\xb7\x2f\x8f\x1c\x9b\xa4\
            \\xdc\x86\x37\xa0\x16\xa7\xd3\xb1\x9f\xc3\x93\xb7\xa7\x13\x6e\xeb\xc6\xbc\xc6\x3e\x1a\x51\x37\x42\xef\x68\x28\xbc\x52\x03\x65\xd6\
            \\x2d\x6a\x77\xab\x35\x27\xed\x4b\x82\x1f\xd2\x16\x09\x5c\x6e\x2e\xdb\x92\xf2\xfb\x5e\xea\x29\xcb\x14\x58\x92\xf5\x91\x58\x4f\x7f\
            \\x54\x83\x69\x7b\x26\x67\xa8\xcc\x85\x19\x60\x48\x8c\x4b\xac\xea\x83\x38\x60\xd4\x0d\x23\xe0\xf9\x6c\x38\x7e\x8a\x0a\xe6\xd2\x49\
            \\xb2\x84\x60\x0c\xd8\x35\x73\x1d\xdc\xb1\xc6\x47\xac\x4c\x56\xea\x3e\xbd\x81\xb3\x23\x0e\xab\xb0\x64\x38\xbc\x87\xf0\xb5\xb1\xfa\
            \\x8f\x5e\xa2\xb3\xfc\x18\x46\x42\x0a\x03\x6b\x7a\x4f\xb0\x89\xbd\x64\x9d\xa5\x89\xa3\x45\x41\x5e\x5c\x03\x83\x23\x3e\x5d\x3b\xb9\
            \\x43\xd7\x95\x72\x7e\x6d\xd0\x7c\x06\xdf\xdf\x1e\x6c\x6c\xc4\xef\x71\x60\xa5\x39\x73\xbf\xbe\x70\x83\x87\x76\x05\x45\x23\xec\xf1"#

sbox_s3 :: Word8 -> Word32
sbox_s3 :: Word8 -> Word32
sbox_s3 Word8
i = Array32 -> Int -> Word32
arrayRead32 Array32
t (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
  where
    t :: Array32
t = Int -> Addr# -> Array32
array32FromAddrBE Int
256
            Addr#
"\x8d\xef\xc2\x40\x25\xfa\x5d\x9f\xeb\x90\x3d\xbf\xe8\x10\xc9\x07\x47\x60\x7f\xff\x36\x9f\xe4\x4b\x8c\x1f\xc6\x44\xae\xce\xca\x90\
            \\xbe\xb1\xf9\xbf\xee\xfb\xca\xea\xe8\xcf\x19\x50\x51\xdf\x07\xae\x92\x0e\x88\x06\xf0\xad\x05\x48\xe1\x3c\x8d\x83\x92\x70\x10\xd5\
            \\x11\x10\x7d\x9f\x07\x64\x7d\xb9\xb2\xe3\xe4\xd4\x3d\x4f\x28\x5e\xb9\xaf\xa8\x20\xfa\xde\x82\xe0\xa0\x67\x26\x8b\x82\x72\x79\x2e\
            \\x55\x3f\xb2\xc0\x48\x9a\xe2\x2b\xd4\xef\x97\x94\x12\x5e\x3f\xbc\x21\xff\xfc\xee\x82\x5b\x1b\xfd\x92\x55\xc5\xed\x12\x57\xa2\x40\
            \\x4e\x1a\x83\x02\xba\xe0\x7f\xff\x52\x82\x46\xe7\x8e\x57\x14\x0e\x33\x73\xf7\xbf\x8c\x9f\x81\x88\xa6\xfc\x4e\xe8\xc9\x82\xb5\xa5\
            \\xa8\xc0\x1d\xb7\x57\x9f\xc2\x64\x67\x09\x4f\x31\xf2\xbd\x3f\x5f\x40\xff\xf7\xc1\x1f\xb7\x8d\xfc\x8e\x6b\xd2\xc1\x43\x7b\xe5\x9b\
            \\x99\xb0\x3d\xbf\xb5\xdb\xc6\x4b\x63\x8d\xc0\xe6\x55\x81\x9d\x99\xa1\x97\xc8\x1c\x4a\x01\x2d\x6e\xc5\x88\x4a\x28\xcc\xc3\x6f\x71\
            \\xb8\x43\xc2\x13\x6c\x07\x43\xf1\x83\x09\x89\x3c\x0f\xed\xdd\x5f\x2f\x7f\xe8\x50\xd7\xc0\x7f\x7e\x02\x50\x7f\xbf\x5a\xfb\x9a\x04\
            \\xa7\x47\xd2\xd0\x16\x51\x19\x2e\xaf\x70\xbf\x3e\x58\xc3\x13\x80\x5f\x98\x30\x2e\x72\x7c\xc3\xc4\x0a\x0f\xb4\x02\x0f\x7f\xef\x82\
            \\x8c\x96\xfd\xad\x5d\x2c\x2a\xae\x8e\xe9\x9a\x49\x50\xda\x88\xb8\x84\x27\xf4\xa0\x1e\xac\x57\x90\x79\x6f\xb4\x49\x82\x52\xdc\x15\
            \\xef\xbd\x7d\x9b\xa6\x72\x59\x7d\xad\xa8\x40\xd8\x45\xf5\x45\x04\xfa\x5d\x74\x03\xe8\x3e\xc3\x05\x4f\x91\x75\x1a\x92\x56\x69\xc2\
            \\x23\xef\xe9\x41\xa9\x03\xf1\x2e\x60\x27\x0d\xf2\x02\x76\xe4\xb6\x94\xfd\x65\x74\x92\x79\x85\xb2\x82\x76\xdb\xcb\x02\x77\x81\x76\
            \\xf8\xaf\x91\x8d\x4e\x48\xf7\x9e\x8f\x61\x6d\xdf\xe2\x9d\x84\x0e\x84\x2f\x7d\x83\x34\x0c\xe5\xc8\x96\xbb\xb6\x82\x93\xb4\xb1\x48\
            \\xef\x30\x3c\xab\x98\x4f\xaf\x28\x77\x9f\xaf\x9b\x92\xdc\x56\x0d\x22\x4d\x1e\x20\x84\x37\xaa\x88\x7d\x29\xdc\x96\x27\x56\xd3\xdc\
            \\x8b\x90\x7c\xee\xb5\x1f\xd2\x40\xe7\xc0\x7c\xe3\xe5\x66\xb4\xa1\xc3\xe9\x61\x5e\x3c\xf8\x20\x9d\x60\x94\xd1\xe3\xcd\x9c\xa3\x41\
            \\x5c\x76\x46\x0e\x00\xea\x98\x3b\xd4\xd6\x78\x81\xfd\x47\x57\x2c\xf7\x6c\xed\xd9\xbd\xa8\x22\x9c\x12\x7d\xad\xaa\x43\x8a\x07\x4e\
            \\x1f\x97\xc0\x90\x08\x1b\xdb\x8a\x93\xa0\x7e\xbe\xb9\x38\xca\x15\x97\xb0\x3c\xff\x3d\xc2\xc0\xf8\x8d\x1a\xb2\xec\x64\x38\x0e\x51\
            \\x68\xcc\x7b\xfb\xd9\x0f\x27\x88\x12\x49\x01\x81\x5d\xe5\xff\xd4\xdd\x7e\xf8\x6a\x76\xa2\xe2\x14\xb9\xa4\x03\x68\x92\x5d\x95\x8f\
            \\x4b\x39\xff\xfa\xba\x39\xae\xe9\xa4\xff\xd3\x0b\xfa\xf7\x93\x3b\x6d\x49\x86\x23\x19\x3c\xbc\xfa\x27\x62\x75\x45\x82\x5c\xf4\x7a\
            \\x61\xbd\x8b\xa0\xd1\x1e\x42\xd1\xce\xad\x04\xf4\x12\x7e\xa3\x92\x10\x42\x8d\xb7\x82\x72\xa9\x72\x92\x70\xc4\xa8\x12\x7d\xe5\x0b\
            \\x28\x5b\xa1\xc8\x3c\x62\xf4\x4f\x35\xc0\xea\xa5\xe8\x05\xd2\x31\x42\x89\x29\xfb\xb4\xfc\xdf\x82\x4f\xb6\x6a\x53\x0e\x7d\xc1\x5b\
            \\x1f\x08\x1f\xab\x10\x86\x18\xae\xfc\xfd\x08\x6d\xf9\xff\x28\x89\x69\x4b\xcc\x11\x23\x6a\x5c\xae\x12\xde\xca\x4d\x2c\x3f\x8c\xc5\
            \\xd2\xd0\x2d\xfe\xf8\xef\x58\x96\xe4\xcf\x52\xda\x95\x15\x5b\x67\x49\x4a\x48\x8c\xb9\xb6\xa8\x0c\x5c\x8f\x82\xbc\x89\xd3\x6b\x45\
            \\x3a\x60\x94\x37\xec\x00\xc9\xa9\x44\x71\x52\x53\x0a\x87\x4b\x49\xd7\x73\xbc\x40\x7c\x34\x67\x1c\x02\x71\x7e\xf6\x4f\xeb\x55\x36\
            \\xa2\xd0\x2f\xff\xd2\xbf\x60\xc4\xd4\x3f\x03\xc0\x50\xb4\xef\x6d\x07\x47\x8c\xd1\x00\x6e\x18\x88\xa2\xe5\x3f\x55\xb9\xe6\xd4\xbc\
            \\xa2\x04\x80\x16\x97\x57\x38\x33\xd7\x20\x7d\x67\xde\x0f\x8f\x3d\x72\xf8\x7b\x33\xab\xcc\x4f\x33\x76\x88\xc5\x5d\x7b\x00\xa6\xb0\
            \\x94\x7b\x00\x01\x57\x00\x75\xd2\xf9\xbb\x88\xf8\x89\x42\x01\x9e\x42\x64\xa5\xff\x85\x63\x02\xe0\x72\xdb\xd9\x2b\xee\x97\x1b\x69\
            \\x6e\xa2\x2f\xde\x5f\x08\xae\x2b\xaf\x7a\x61\x6d\xe5\xc9\x87\x67\xcf\x1f\xeb\xd2\x61\xef\xc8\xc2\xf1\xac\x25\x71\xcc\x82\x39\xc2\
            \\x67\x21\x4c\xb8\xb1\xe5\x83\xd1\xb7\xdc\x3e\x62\x7f\x10\xbd\xce\xf9\x0a\x5c\x38\x0f\xf0\x44\x3d\x60\x6e\x6d\xc6\x60\x54\x3a\x49\
            \\x57\x27\xc1\x48\x2b\xe9\x8a\x1d\x8a\xb4\x17\x38\x20\xe1\xbe\x24\xaf\x96\xda\x0f\x68\x45\x84\x25\x99\x83\x3b\xe5\x60\x0d\x45\x7d\
            \\x28\x2f\x93\x50\x83\x34\xb3\x62\xd9\x1d\x11\x20\x2b\x6d\x8d\xa0\x64\x2b\x1e\x31\x9c\x30\x5a\x00\x52\xbc\xe6\x88\x1b\x03\x58\x8a\
            \\xf7\xba\xef\xd5\x41\x42\xed\x9c\xa4\x31\x5c\x11\x83\x32\x3e\xc5\xdf\xef\x46\x36\xa1\x33\xc5\x01\xe9\xd3\x53\x1c\xee\x35\x37\x83"#

sbox_s4 :: Word8 -> Word32
sbox_s4 :: Word8 -> Word32
sbox_s4 Word8
i = Array32 -> Int -> Word32
arrayRead32 Array32
t (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
  where
    t :: Array32
t = Int -> Addr# -> Array32
array32FromAddrBE Int
256
            Addr#
"\x9d\xb3\x04\x20\x1f\xb6\xe9\xde\xa7\xbe\x7b\xef\xd2\x73\xa2\x98\x4a\x4f\x7b\xdb\x64\xad\x8c\x57\x85\x51\x04\x43\xfa\x02\x0e\xd1\
            \\x7e\x28\x7a\xff\xe6\x0f\xb6\x63\x09\x5f\x35\xa1\x79\xeb\xf1\x20\xfd\x05\x9d\x43\x64\x97\xb7\xb1\xf3\x64\x1f\x63\x24\x1e\x4a\xdf\
            \\x28\x14\x7f\x5f\x4f\xa2\xb8\xcd\xc9\x43\x00\x40\x0c\xc3\x22\x20\xfd\xd3\x0b\x30\xc0\xa5\x37\x4f\x1d\x2d\x00\xd9\x24\x14\x7b\x15\
            \\xee\x4d\x11\x1a\x0f\xca\x51\x67\x71\xff\x90\x4c\x2d\x19\x5f\xfe\x1a\x05\x64\x5f\x0c\x13\xfe\xfe\x08\x1b\x08\xca\x05\x17\x01\x21\
            \\x80\x53\x01\x00\xe8\x3e\x5e\xfe\xac\x9a\xf4\xf8\x7f\xe7\x27\x01\xd2\xb8\xee\x5f\x06\xdf\x42\x61\xbb\x9e\x9b\x8a\x72\x93\xea\x25\
            \\xce\x84\xff\xdf\xf5\x71\x88\x01\x3d\xd6\x4b\x04\xa2\x6f\x26\x3b\x7e\xd4\x84\x00\x54\x7e\xeb\xe6\x44\x6d\x4c\xa0\x6c\xf3\xd6\xf5\
            \\x26\x49\xab\xdf\xae\xa0\xc7\xf5\x36\x33\x8c\xc1\x50\x3f\x7e\x93\xd3\x77\x20\x61\x11\xb6\x38\xe1\x72\x50\x0e\x03\xf8\x0e\xb2\xbb\
            \\xab\xe0\x50\x2e\xec\x8d\x77\xde\x57\x97\x1e\x81\xe1\x4f\x67\x46\xc9\x33\x54\x00\x69\x20\x31\x8f\x08\x1d\xbb\x99\xff\xc3\x04\xa5\
            \\x4d\x35\x18\x05\x7f\x3d\x5c\xe3\xa6\xc8\x66\xc6\x5d\x5b\xcc\xa9\xda\xec\x6f\xea\x9f\x92\x6f\x91\x9f\x46\x22\x2f\x39\x91\x46\x7d\
            \\xa5\xbf\x6d\x8e\x11\x43\xc4\x4f\x43\x95\x83\x02\xd0\x21\x4e\xeb\x02\x20\x83\xb8\x3f\xb6\x18\x0c\x18\xf8\x93\x1e\x28\x16\x58\xe6\
            \\x26\x48\x6e\x3e\x8b\xd7\x8a\x70\x74\x77\xe4\xc1\xb5\x06\xe0\x7c\xf3\x2d\x0a\x25\x79\x09\x8b\x02\xe4\xea\xbb\x81\x28\x12\x3b\x23\
            \\x69\xde\xad\x38\x15\x74\xca\x16\xdf\x87\x1b\x62\x21\x1c\x40\xb7\xa5\x1a\x9e\xf9\x00\x14\x37\x7b\x04\x1e\x8a\xc8\x09\x11\x40\x03\
            \\xbd\x59\xe4\xd2\xe3\xd1\x56\xd5\x4f\xe8\x76\xd5\x2f\x91\xa3\x40\x55\x7b\xe8\xde\x00\xea\xe4\xa7\x0c\xe5\xc2\xec\x4d\xb4\xbb\xa6\
            \\xe7\x56\xbd\xff\xdd\x33\x69\xac\xec\x17\xb0\x35\x06\x57\x23\x27\x99\xaf\xc8\xb0\x56\xc8\xc3\x91\x6b\x65\x81\x1c\x5e\x14\x61\x19\
            \\x6e\x85\xcb\x75\xbe\x07\xc0\x02\xc2\x32\x55\x77\x89\x3f\xf4\xec\x5b\xbf\xc9\x2d\xd0\xec\x3b\x25\xb7\x80\x1a\xb7\x8d\x6d\x3b\x24\
            \\x20\xc7\x63\xef\xc3\x66\xa5\xfc\x9c\x38\x28\x80\x0a\xce\x32\x05\xaa\xc9\x54\x8a\xec\xa1\xd7\xc7\x04\x1a\xfa\x32\x1d\x16\x62\x5a\
            \\x67\x01\x90\x2c\x9b\x75\x7a\x54\x31\xd4\x77\xf7\x91\x26\xb0\x31\x36\xcc\x6f\xdb\xc7\x0b\x8b\x46\xd9\xe6\x6a\x48\x56\xe5\x5a\x79\
            \\x02\x6a\x4c\xeb\x52\x43\x7e\xff\x2f\x8f\x76\xb4\x0d\xf9\x80\xa5\x86\x74\xcd\xe3\xed\xda\x04\xeb\x17\xa9\xbe\x04\x2c\x18\xf4\xdf\
            \\xb7\x74\x7f\x9d\xab\x2a\xf7\xb4\xef\xc3\x4d\x20\x2e\x09\x6b\x7c\x17\x41\xa2\x54\xe5\xb6\xa0\x35\x21\x3d\x42\xf6\x2c\x1c\x7c\x26\
            \\x61\xc2\xf5\x0f\x65\x52\xda\xf9\xd2\xc2\x31\xf8\x25\x13\x0f\x69\xd8\x16\x7f\xa2\x04\x18\xf2\xc8\x00\x1a\x96\xa6\x0d\x15\x26\xab\
            \\x63\x31\x5c\x21\x5e\x0a\x72\xec\x49\xba\xfe\xfd\x18\x79\x08\xd9\x8d\x0d\xbd\x86\x31\x11\x70\xa7\x3e\x9b\x64\x0c\xcc\x3e\x10\xd7\
            \\xd5\xca\xd3\xb6\x0c\xae\xc3\x88\xf7\x30\x01\xe1\x6c\x72\x8a\xff\x71\xea\xe2\xa1\x1f\x9a\xf3\x6e\xcf\xcb\xd1\x2f\xc1\xde\x84\x17\
            \\xac\x07\xbe\x6b\xcb\x44\xa1\xd8\x8b\x9b\x0f\x56\x01\x39\x88\xc3\xb1\xc5\x2f\xca\xb4\xbe\x31\xcd\xd8\x78\x28\x06\x12\xa3\xa4\xe2\
            \\x6f\x7d\xe5\x32\x58\xfd\x7e\xb6\xd0\x1e\xe9\x00\x24\xad\xff\xc2\xf4\x99\x0f\xc5\x97\x11\xaa\xc5\x00\x1d\x7b\x95\x82\xe5\xe7\xd2\
            \\x10\x98\x73\xf6\x00\x61\x30\x96\xc3\x2d\x95\x21\xad\xa1\x21\xff\x29\x90\x84\x15\x7f\xbb\x97\x7f\xaf\x9e\xb3\xdb\x29\xc9\xed\x2a\
            \\x5c\xe2\xa4\x65\xa7\x30\xf3\x2c\xd0\xaa\x3f\xe8\x8a\x5c\xc0\x91\xd4\x9e\x2c\xe7\x0c\xe4\x54\xa9\xd6\x0a\xcd\x86\x01\x5f\x19\x19\
            \\x77\x07\x91\x03\xde\xa0\x3a\xf6\x78\xa8\x56\x5e\xde\xe3\x56\xdf\x21\xf0\x5c\xbe\x8b\x75\xe3\x87\xb3\xc5\x06\x51\xb8\xa5\xc3\xef\
            \\xd8\xee\xb6\xd2\xe5\x23\xbe\x77\xc2\x15\x45\x29\x2f\x69\xef\xdf\xaf\xe6\x7a\xfb\xf4\x70\xc4\xb2\xf3\xe0\xeb\x5b\xd6\xcc\x98\x76\
            \\x39\xe4\x46\x0c\x1f\xda\x85\x38\x19\x87\x83\x2f\xca\x00\x73\x67\xa9\x91\x44\xf8\x29\x6b\x29\x9e\x49\x2f\xc2\x95\x92\x66\xbe\xab\
            \\xb5\x67\x6e\x69\x9b\xd3\xdd\xda\xdf\x7e\x05\x2f\xdb\x25\x70\x1c\x1b\x5e\x51\xee\xf6\x53\x24\xe6\x6a\xfc\xe3\x6c\x03\x16\xcc\x04\
            \\x86\x44\x21\x3e\xb7\xdc\x59\xd0\x79\x65\x29\x1f\xcc\xd6\xfd\x43\x41\x82\x39\x79\x93\x2b\xcd\xf6\xb6\x57\xc3\x4d\x4e\xdf\xd2\x82\
            \\x7a\xe5\x29\x0c\x3c\xb9\x53\x6b\x85\x1e\x20\xfe\x98\x33\x55\x7e\x13\xec\xf0\xb0\xd3\xff\xb3\x72\x3f\x85\xc5\xc1\x0a\xef\x7e\xd2"#

sbox_s5 :: Word8 -> Word32
sbox_s5 :: Word8 -> Word32
sbox_s5 Word8
i = Array32 -> Int -> Word32
arrayRead32 Array32
t (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
  where
    t :: Array32
t = Int -> Addr# -> Array32
array32FromAddrBE Int
256
            Addr#
"\x7e\xc9\x0c\x04\x2c\x6e\x74\xb9\x9b\x0e\x66\xdf\xa6\x33\x79\x11\xb8\x6a\x7f\xff\x1d\xd3\x58\xf5\x44\xdd\x9d\x44\x17\x31\x16\x7f\
            \\x08\xfb\xf1\xfa\xe7\xf5\x11\xcc\xd2\x05\x1b\x00\x73\x5a\xba\x00\x2a\xb7\x22\xd8\x38\x63\x81\xcb\xac\xf6\x24\x3a\x69\xbe\xfd\x7a\
            \\xe6\xa2\xe7\x7f\xf0\xc7\x20\xcd\xc4\x49\x48\x16\xcc\xf5\xc1\x80\x38\x85\x16\x40\x15\xb0\xa8\x48\xe6\x8b\x18\xcb\x4c\xaa\xde\xff\
            \\x5f\x48\x0a\x01\x04\x12\xb2\xaa\x25\x98\x14\xfc\x41\xd0\xef\xe2\x4e\x40\xb4\x8d\x24\x8e\xb6\xfb\x8d\xba\x1c\xfe\x41\xa9\x9b\x02\
            \\x1a\x55\x0a\x04\xba\x8f\x65\xcb\x72\x51\xf4\xe7\x95\xa5\x17\x25\xc1\x06\xec\xd7\x97\xa5\x98\x0a\xc5\x39\xb9\xaa\x4d\x79\xfe\x6a\
            \\xf2\xf3\xf7\x63\x68\xaf\x80\x40\xed\x0c\x9e\x56\x11\xb4\x95\x8b\xe1\xeb\x5a\x88\x87\x09\xe6\xb0\xd7\xe0\x71\x56\x4e\x29\xfe\xa7\
            \\x63\x66\xe5\x2d\x02\xd1\xc0\x00\xc4\xac\x8e\x05\x93\x77\xf5\x71\x0c\x05\x37\x2a\x57\x85\x35\xf2\x22\x61\xbe\x02\xd6\x42\xa0\xc9\
            \\xdf\x13\xa2\x80\x74\xb5\x5b\xd2\x68\x21\x99\xc0\xd4\x21\xe5\xec\x53\xfb\x3c\xe8\xc8\xad\xed\xb3\x28\xa8\x7f\xc9\x3d\x95\x99\x81\
            \\x5c\x1f\xf9\x00\xfe\x38\xd3\x99\x0c\x4e\xff\x0b\x06\x24\x07\xea\xaa\x2f\x4f\xb1\x4f\xb9\x69\x76\x90\xc7\x95\x05\xb0\xa8\xa7\x74\
            \\xef\x55\xa1\xff\xe5\x9c\xa2\xc2\xa6\xb6\x2d\x27\xe6\x6a\x42\x63\xdf\x65\x00\x1f\x0e\xc5\x09\x66\xdf\xdd\x55\xbc\x29\xde\x06\x55\
            \\x91\x1e\x73\x9a\x17\xaf\x89\x75\x32\xc7\x91\x1c\x89\xf8\x94\x68\x0d\x01\xe9\x80\x52\x47\x55\xf4\x03\xb6\x3c\xc9\x0c\xc8\x44\xb2\
            \\xbc\xf3\xf0\xaa\x87\xac\x36\xe9\xe5\x3a\x74\x26\x01\xb3\xd8\x2b\x1a\x9e\x74\x49\x64\xee\x2d\x7e\xcd\xdb\xb1\xda\x01\xc9\x49\x10\
            \\xb8\x68\xbf\x80\x0d\x26\xf3\xfd\x93\x42\xed\xe7\x04\xa5\xc2\x84\x63\x67\x37\xb6\x50\xf5\xb6\x16\xf2\x47\x66\xe3\x8e\xca\x36\xc1\
            \\x13\x6e\x05\xdb\xfe\xf1\x83\x91\xfb\x88\x7a\x37\xd6\xe7\xf7\xd4\xc7\xfb\x7d\xc9\x30\x63\xfc\xdf\xb6\xf5\x89\xde\xec\x29\x41\xda\
            \\x26\xe4\x66\x95\xb7\x56\x64\x19\xf6\x54\xef\xc5\xd0\x8d\x58\xb7\x48\x92\x54\x01\xc1\xba\xcb\x7f\xe5\xff\x55\x0f\xb6\x08\x30\x49\
            \\x5b\xb5\xd0\xe8\x87\xd7\x2e\x5a\xab\x6a\x6e\xe1\x22\x3a\x66\xce\xc6\x2b\xf3\xcd\x9e\x08\x85\xf9\x68\xcb\x3e\x47\x08\x6c\x01\x0f\
            \\xa2\x1d\xe8\x20\xd1\x8b\x69\xde\xf3\xf6\x57\x77\xfa\x02\xc3\xf6\x40\x7e\xda\xc3\xcb\xb3\xd5\x50\x17\x93\x08\x4d\xb0\xd7\x0e\xba\
            \\x0a\xb3\x78\xd5\xd9\x51\xfb\x0c\xde\xd7\xda\x56\x41\x24\xbb\xe4\x94\xca\x0b\x56\x0f\x57\x55\xd1\xe0\xe1\xe5\x6e\x61\x84\xb5\xbe\
            \\x58\x0a\x24\x9f\x94\xf7\x4b\xc0\xe3\x27\x88\x8e\x9f\x7b\x55\x61\xc3\xdc\x02\x80\x05\x68\x77\x15\x64\x6c\x6b\xd7\x44\x90\x4d\xb3\
            \\x66\xb4\xf0\xa3\xc0\xf1\x64\x8a\x69\x7e\xd5\xaf\x49\xe9\x2f\xf6\x30\x9e\x37\x4f\x2c\xb6\x35\x6a\x85\x80\x85\x73\x49\x91\xf8\x40\
            \\x76\xf0\xae\x02\x08\x3b\xe8\x4d\x28\x42\x1c\x9a\x44\x48\x94\x06\x73\x6e\x4c\xb8\xc1\x09\x29\x10\x8b\xc9\x5f\xc6\x7d\x86\x9c\xf4\
            \\x13\x4f\x61\x6f\x2e\x77\x11\x8d\xb3\x1b\x2b\xe1\xaa\x90\xb4\x72\x3c\xa5\xd7\x17\x7d\x16\x1b\xba\x9c\xad\x90\x10\xaf\x46\x2b\xa2\
            \\x9f\xe4\x59\xd2\x45\xd3\x45\x59\xd9\xf2\xda\x13\xdb\xc6\x54\x87\xf3\xe4\xf9\x4e\x17\x6d\x48\x6f\x09\x7c\x13\xea\x63\x1d\xa5\xc7\
            \\x44\x5f\x73\x82\x17\x56\x83\xf4\xcd\xc6\x6a\x97\x70\xbe\x02\x88\xb3\xcd\xcf\x72\x6e\x5d\xd2\xf3\x20\x93\x60\x79\x45\x9b\x80\xa5\
            \\xbe\x60\xe2\xdb\xa9\xc2\x31\x01\xeb\xa5\x31\x5c\x22\x4e\x42\xf2\x1c\x5c\x15\x72\xf6\x72\x1b\x2c\x1a\xd2\xff\xf3\x8c\x25\x40\x4e\
            \\x32\x4e\xd7\x2f\x40\x67\xb7\xfd\x05\x23\x13\x8e\x5c\xa3\xbc\x78\xdc\x0f\xd6\x6e\x75\x92\x22\x83\x78\x4d\x6b\x17\x58\xeb\xb1\x6e\
            \\x44\x09\x4f\x85\x3f\x48\x1d\x87\xfc\xfe\xae\x7b\x77\xb5\xff\x76\x8c\x23\x02\xbf\xaa\xf4\x75\x56\x5f\x46\xb0\x2a\x2b\x09\x28\x01\
            \\x3d\x38\xf5\xf7\x0c\xa8\x1f\x36\x52\xaf\x4a\x8a\x66\xd5\xe7\xc0\xdf\x3b\x08\x74\x95\x05\x51\x10\x1b\x5a\xd7\xa8\xf6\x1e\xd5\xad\
            \\x6c\xf6\xe4\x79\x20\x75\x81\x84\xd0\xce\xfa\x65\x88\xf7\xbe\x58\x4a\x04\x68\x26\x0f\xf6\xf8\xf3\xa0\x9c\x7f\x70\x53\x46\xab\xa0\
            \\x5c\xe9\x6c\x28\xe1\x76\xed\xa3\x6b\xac\x30\x7f\x37\x68\x29\xd2\x85\x36\x0f\xa9\x17\xe3\xfe\x2a\x24\xb7\x97\x67\xf5\xa9\x6b\x20\
            \\xd6\xcd\x25\x95\x68\xff\x1e\xbf\x75\x55\x44\x2c\xf1\x9f\x06\xbe\xf9\xe0\x65\x9a\xee\xb9\x49\x1d\x34\x01\x07\x18\xbb\x30\xca\xb8\
            \\xe8\x22\xfe\x15\x88\x57\x09\x83\x75\x0e\x62\x49\xda\x62\x7e\x55\x5e\x76\xff\xa8\xb1\x53\x45\x46\x6d\x47\xde\x08\xef\xe9\xe7\xd4"#

sbox_s6 :: Word8 -> Word32
sbox_s6 :: Word8 -> Word32
sbox_s6 Word8
i = Array32 -> Int -> Word32
arrayRead32 Array32
t (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
  where
    t :: Array32
t = Int -> Addr# -> Array32
array32FromAddrBE Int
256
            Addr#
"\xf6\xfa\x8f\x9d\x2c\xac\x6c\xe1\x4c\xa3\x48\x67\xe2\x33\x7f\x7c\x95\xdb\x08\xe7\x01\x68\x43\xb4\xec\xed\x5c\xbc\x32\x55\x53\xac\
            \\xbf\x9f\x09\x60\xdf\xa1\xe2\xed\x83\xf0\x57\x9d\x63\xed\x86\xb9\x1a\xb6\xa6\xb8\xde\x5e\xbe\x39\xf3\x8f\xf7\x32\x89\x89\xb1\x38\
            \\x33\xf1\x49\x61\xc0\x19\x37\xbd\xf5\x06\xc6\xda\xe4\x62\x5e\x7e\xa3\x08\xea\x99\x4e\x23\xe3\x3c\x79\xcb\xd7\xcc\x48\xa1\x43\x67\
            \\xa3\x14\x96\x19\xfe\xc9\x4b\xd5\xa1\x14\x17\x4a\xea\xa0\x18\x66\xa0\x84\xdb\x2d\x09\xa8\x48\x6f\xa8\x88\x61\x4a\x29\x00\xaf\x98\
            \\x01\x66\x59\x91\xe1\x99\x28\x63\xc8\xf3\x0c\x60\x2e\x78\xef\x3c\xd0\xd5\x19\x32\xcf\x0f\xec\x14\xf7\xca\x07\xd2\xd0\xa8\x20\x72\
            \\xfd\x41\x19\x7e\x93\x05\xa6\xb0\xe8\x6b\xe3\xda\x74\xbe\xd3\xcd\x37\x2d\xa5\x3c\x4c\x7f\x44\x48\xda\xb5\xd4\x40\x6d\xba\x0e\xc3\
            \\x08\x39\x19\xa7\x9f\xba\xee\xd9\x49\xdb\xcf\xb0\x4e\x67\x0c\x53\x5c\x3d\x9c\x01\x64\xbd\xb9\x41\x2c\x0e\x63\x6a\xba\x7d\xd9\xcd\
            \\xea\x6f\x73\x88\xe7\x0b\xc7\x62\x35\xf2\x9a\xdb\x5c\x4c\xdd\x8d\xf0\xd4\x8d\x8c\xb8\x81\x53\xe2\x08\xa1\x98\x66\x1a\xe2\xea\xc8\
            \\x28\x4c\xaf\x89\xaa\x92\x82\x23\x93\x34\xbe\x53\x3b\x3a\x21\xbf\x16\x43\x4b\xe3\x9a\xea\x39\x06\xef\xe8\xc3\x6e\xf8\x90\xcd\xd9\
            \\x80\x22\x6d\xae\xc3\x40\xa4\xa3\xdf\x7e\x9c\x09\xa6\x94\xa8\x07\x5b\x7c\x5e\xcc\x22\x1d\xb3\xa6\x9a\x69\xa0\x2f\x68\x81\x8a\x54\
            \\xce\xb2\x29\x6f\x53\xc0\x84\x3a\xfe\x89\x36\x55\x25\xbf\xe6\x8a\xb4\x62\x8a\xbc\xcf\x22\x2e\xbf\x25\xac\x6f\x48\xa9\xa9\x93\x87\
            \\x53\xbd\xdb\x65\xe7\x6f\xfb\xe7\xe9\x67\xfd\x78\x0b\xa9\x35\x63\x8e\x34\x2b\xc1\xe8\xa1\x1b\xe9\x49\x80\x74\x0d\xc8\x08\x7d\xfc\
            \\x8d\xe4\xbf\x99\xa1\x11\x01\xa0\x7f\xd3\x79\x75\xda\x5a\x26\xc0\xe8\x1f\x99\x4f\x95\x28\xcd\x89\xfd\x33\x9f\xed\xb8\x78\x34\xbf\
            \\x5f\x04\x45\x6d\x22\x25\x86\x98\xc9\xc4\xc8\x3b\x2d\xc1\x56\xbe\x4f\x62\x8d\xaa\x57\xf5\x5e\xc5\xe2\x22\x0a\xbe\xd2\x91\x6e\xbf\
            \\x4e\xc7\x5b\x95\x24\xf2\xc3\xc0\x42\xd1\x5d\x99\xcd\x0d\x7f\xa0\x7b\x6e\x27\xff\xa8\xdc\x8a\xf0\x73\x45\xc1\x06\xf4\x1e\x23\x2f\
            \\x35\x16\x23\x86\xe6\xea\x89\x26\x33\x33\xb0\x94\x15\x7e\xc6\xf2\x37\x2b\x74\xaf\x69\x25\x73\xe4\xe9\xa9\xd8\x48\xf3\x16\x02\x89\
            \\x3a\x62\xef\x1d\xa7\x87\xe2\x38\xf3\xa5\xf6\x76\x74\x36\x48\x53\x20\x95\x10\x63\x45\x76\x69\x8d\xb6\xfa\xd4\x07\x59\x2a\xf9\x50\
            \\x36\xf7\x35\x23\x4c\xfb\x6e\x87\x7d\xa4\xce\xc0\x6c\x15\x2d\xaa\xcb\x03\x96\xa8\xc5\x0d\xfe\x5d\xfc\xd7\x07\xab\x09\x21\xc4\x2f\
            \\x89\xdf\xf0\xbb\x5f\xe2\xbe\x78\x44\x8f\x4f\x33\x75\x46\x13\xc9\x2b\x05\xd0\x8d\x48\xb9\xd5\x85\xdc\x04\x94\x41\xc8\x09\x8f\x9b\
            \\x7d\xed\xe7\x86\xc3\x9a\x33\x73\x42\x41\x00\x05\x6a\x09\x17\x51\x0e\xf3\xc8\xa6\x89\x00\x72\xd6\x28\x20\x76\x82\xa9\xa9\xf7\xbe\
            \\xbf\x32\x67\x9d\xd4\x5b\x5b\x75\xb3\x53\xfd\x00\xcb\xb0\xe3\x58\x83\x0f\x22\x0a\x1f\x8f\xb2\x14\xd3\x72\xcf\x08\xcc\x3c\x4a\x13\
            \\x8c\xf6\x31\x66\x06\x1c\x87\xbe\x88\xc9\x8f\x88\x60\x62\xe3\x97\x47\xcf\x8e\x7a\xb6\xc8\x52\x83\x3c\xc2\xac\xfb\x3f\xc0\x69\x76\
            \\x4e\x8f\x02\x52\x64\xd8\x31\x4d\xda\x38\x70\xe3\x1e\x66\x54\x59\xc1\x09\x08\xf0\x51\x30\x21\xa5\x6c\x5b\x68\xb7\x82\x2f\x8a\xa0\
            \\x30\x07\xcd\x3e\x74\x71\x9e\xef\xdc\x87\x26\x81\x07\x33\x40\xd4\x7e\x43\x2f\xd9\x0c\x5e\xc2\x41\x88\x09\x28\x6c\xf5\x92\xd8\x91\
            \\x08\xa9\x30\xf6\x95\x7e\xf3\x05\xb7\xfb\xff\xbd\xc2\x66\xe9\x6f\x6f\xe4\xac\x98\xb1\x73\xec\xc0\xbc\x60\xb4\x2a\x95\x34\x98\xda\
            \\xfb\xa1\xae\x12\x2d\x4b\xd7\x36\x0f\x25\xfa\xab\xa4\xf3\xfc\xeb\xe2\x96\x91\x23\x25\x7f\x0c\x3d\x93\x48\xaf\x49\x36\x14\x00\xbc\
            \\xe8\x81\x6f\x4a\x38\x14\xf2\x00\xa3\xf9\x40\x43\x9c\x7a\x54\xc2\xbc\x70\x4f\x57\xda\x41\xe7\xf9\xc2\x5a\xd3\x3a\x54\xf4\xa0\x84\
            \\xb1\x7f\x55\x05\x59\x35\x7c\xbe\xed\xbd\x15\xc8\x7f\x97\xc5\xab\xba\x5a\xc7\xb5\xb6\xf6\xde\xaf\x3a\x47\x9c\x3a\x53\x02\xda\x25\
            \\x65\x3d\x7e\x6a\x54\x26\x8d\x49\x51\xa4\x77\xea\x50\x17\xd5\x5b\xd7\xd2\x5d\x88\x44\x13\x6c\x76\x04\x04\xa8\xc8\xb8\xe5\xa1\x21\
            \\xb8\x1a\x92\x8a\x60\xed\x58\x69\x97\xc5\x5b\x96\xea\xec\x99\x1b\x29\x93\x59\x13\x01\xfd\xb7\xf1\x08\x8e\x8d\xfa\x9a\xb6\xf6\xf5\
            \\x3b\x4c\xbf\x9f\x4a\x5d\xe3\xab\xe6\x05\x1d\x35\xa0\xe1\xd8\x55\xd3\x6b\x4c\xf1\xf5\x44\xed\xeb\xb0\xe9\x35\x24\xbe\xbb\x8f\xbd\
            \\xa2\xd7\x62\xcf\x49\xc9\x2f\x54\x38\xb5\xf3\x31\x71\x28\xa4\x54\x48\x39\x29\x05\xa6\x5b\x1d\xb8\x85\x1c\x97\xbd\xd6\x75\xcf\x2f"#

sbox_s7 :: Word8 -> Word32
sbox_s7 :: Word8 -> Word32
sbox_s7 Word8
i = Array32 -> Int -> Word32
arrayRead32 Array32
t (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
  where
    t :: Array32
t = Int -> Addr# -> Array32
array32FromAddrBE Int
256
            Addr#
"\x85\xe0\x40\x19\x33\x2b\xf5\x67\x66\x2d\xbf\xff\xcf\xc6\x56\x93\x2a\x8d\x7f\x6f\xab\x9b\xc9\x12\xde\x60\x08\xa1\x20\x28\xda\x1f\
            \\x02\x27\xbc\xe7\x4d\x64\x29\x16\x18\xfa\xc3\x00\x50\xf1\x8b\x82\x2c\xb2\xcb\x11\xb2\x32\xe7\x5c\x4b\x36\x95\xf2\xb2\x87\x07\xde\
            \\xa0\x5f\xbc\xf6\xcd\x41\x81\xe9\xe1\x50\x21\x0c\xe2\x4e\xf1\xbd\xb1\x68\xc3\x81\xfd\xe4\xe7\x89\x5c\x79\xb0\xd8\x1e\x8b\xfd\x43\
            \\x4d\x49\x50\x01\x38\xbe\x43\x41\x91\x3c\xee\x1d\x92\xa7\x9c\x3f\x08\x97\x66\xbe\xba\xee\xad\xf4\x12\x86\xbe\xcf\xb6\xea\xcb\x19\
            \\x26\x60\xc2\x00\x75\x65\xbd\xe4\x64\x24\x1f\x7a\x82\x48\xdc\xa9\xc3\xb3\xad\x66\x28\x13\x60\x86\x0b\xd8\xdf\xa8\x35\x6d\x1c\xf2\
            \\x10\x77\x89\xbe\xb3\xb2\xe9\xce\x05\x02\xaa\x8f\x0b\xc0\x35\x1e\x16\x6b\xf5\x2a\xeb\x12\xff\x82\xe3\x48\x69\x11\xd3\x4d\x75\x16\
            \\x4e\x7b\x3a\xff\x5f\x43\x67\x1b\x9c\xf6\xe0\x37\x49\x81\xac\x83\x33\x42\x66\xce\x8c\x93\x41\xb7\xd0\xd8\x54\xc0\xcb\x3a\x6c\x88\
            \\x47\xbc\x28\x29\x47\x25\xba\x37\xa6\x6a\xd2\x2b\x7a\xd6\x1f\x1e\x0c\x5c\xba\xfa\x44\x37\xf1\x07\xb6\xe7\x99\x62\x42\xd2\xd8\x16\
            \\x0a\x96\x12\x88\xe1\xa5\xc0\x6e\x13\x74\x9e\x67\x72\xfc\x08\x1a\xb1\xd1\x39\xf7\xf9\x58\x37\x45\xcf\x19\xdf\x58\xbe\xc3\xf7\x56\
            \\xc0\x6e\xba\x30\x07\x21\x1b\x24\x45\xc2\x88\x29\xc9\x5e\x31\x7f\xbc\x8e\xc5\x11\x38\xbc\x46\xe9\xc6\xe6\xfa\x14\xba\xe8\x58\x4a\
            \\xad\x4e\xbc\x46\x46\x8f\x50\x8b\x78\x29\x43\x5f\xf1\x24\x18\x3b\x82\x1d\xba\x9f\xaf\xf6\x0f\xf4\xea\x2c\x4e\x6d\x16\xe3\x92\x64\
            \\x92\x54\x4a\x8b\x00\x9b\x4f\xc3\xab\xa6\x8c\xed\x9a\xc9\x6f\x78\x06\xa5\xb7\x9a\xb2\x85\x6e\x6e\x1a\xec\x3c\xa9\xbe\x83\x86\x88\
            \\x0e\x08\x04\xe9\x55\xf1\xbe\x56\xe7\xe5\x36\x3b\xb3\xa1\xf2\x5d\xf7\xde\xbb\x85\x61\xfe\x03\x3c\x16\x74\x62\x33\x3c\x03\x4c\x28\
            \\xda\x6d\x0c\x74\x79\xaa\xc5\x6c\x3c\xe4\xe1\xad\x51\xf0\xc8\x02\x98\xf8\xf3\x5a\x16\x26\xa4\x9f\xee\xd8\x2b\x29\x1d\x38\x2f\xe3\
            \\x0c\x4f\xb9\x9a\xbb\x32\x57\x78\x3e\xc6\xd9\x7b\x6e\x77\xa6\xa9\xcb\x65\x8b\x5c\xd4\x52\x30\xc7\x2b\xd1\x40\x8b\x60\xc0\x3e\xb7\
            \\xb9\x06\x8d\x78\xa3\x37\x54\xf4\xf4\x30\xc8\x7d\xc8\xa7\x13\x02\xb9\x6d\x8c\x32\xeb\xd4\xe7\xbe\xbe\x8b\x9d\x2d\x79\x79\xfb\x06\
            \\xe7\x22\x53\x08\x8b\x75\xcf\x77\x11\xef\x8d\xa4\xe0\x83\xc8\x58\x8d\x6b\x78\x6f\x5a\x63\x17\xa6\xfa\x5c\xf7\xa0\x5d\xda\x00\x33\
            \\xf2\x8e\xbf\xb0\xf5\xb9\xc3\x10\xa0\xea\xc2\x80\x08\xb9\x76\x7a\xa3\xd9\xd2\xb0\x79\xd3\x42\x17\x02\x1a\x71\x8d\x9a\xc6\x33\x6a\
            \\x27\x11\xfd\x60\x43\x80\x50\xe3\x06\x99\x08\xa8\x3d\x7f\xed\xc4\x82\x6d\x2b\xef\x4e\xeb\x84\x76\x48\x8d\xcf\x25\x36\xc9\xd5\x66\
            \\x28\xe7\x4e\x41\xc2\x61\x0a\xca\x3d\x49\xa9\xcf\xba\xe3\xb9\xdf\xb6\x5f\x8d\xe6\x92\xae\xaf\x64\x3a\xc7\xd5\xe6\x9e\xa8\x05\x09\
            \\xf2\x2b\x01\x7d\xa4\x17\x3f\x70\xdd\x1e\x16\xc3\x15\xe0\xd7\xf9\x50\xb1\xb8\x87\x2b\x9f\x4f\xd5\x62\x5a\xba\x82\x6a\x01\x79\x62\
            \\x2e\xc0\x1b\x9c\x15\x48\x8a\xa9\xd7\x16\xe7\x40\x40\x05\x5a\x2c\x93\xd2\x9a\x22\xe3\x2d\xbf\x9a\x05\x87\x45\xb9\x34\x53\xdc\x1e\
            \\xd6\x99\x29\x6e\x49\x6c\xff\x6f\x1c\x9f\x49\x86\xdf\xe2\xed\x07\xb8\x72\x42\xd1\x19\xde\x7e\xae\x05\x3e\x56\x1a\x15\xad\x6f\x8c\
            \\x66\x62\x6c\x1c\x71\x54\xc2\x4c\xea\x08\x2b\x2a\x93\xeb\x29\x39\x17\xdc\xb0\xf0\x58\xd4\xf2\xae\x9e\xa2\x94\xfb\x52\xcf\x56\x4c\
            \\x98\x83\xfe\x66\x2e\xc4\x05\x81\x76\x39\x53\xc3\x01\xd6\x69\x2e\xd3\xa0\xc1\x08\xa1\xe7\x16\x0e\xe4\xf2\xdf\xa6\x69\x3e\xd2\x85\
            \\x74\x90\x46\x98\x4c\x2b\x0e\xdd\x4f\x75\x76\x56\x5d\x39\x33\x78\xa1\x32\x23\x4f\x3d\x32\x1c\x5d\xc3\xf5\xe1\x94\x4b\x26\x93\x01\
            \\xc7\x9f\x02\x2f\x3c\x99\x7e\x7e\x5e\x4f\x95\x04\x3f\xfa\xfb\xbd\x76\xf7\xad\x0e\x29\x66\x93\xf4\x3d\x1f\xce\x6f\xc6\x1e\x45\xbe\
            \\xd3\xb5\xab\x34\xf7\x2b\xf9\xb7\x1b\x04\x34\xc0\x4e\x72\xb5\x67\x55\x92\xa3\x3d\xb5\x22\x93\x01\xcf\xd2\xa8\x7f\x60\xae\xb7\x67\
            \\x18\x14\x38\x6b\x30\xbc\xc3\x3d\x38\xa0\xc0\x7d\xfd\x16\x06\xf2\xc3\x63\x51\x9b\x58\x9d\xd3\x90\x54\x79\xf8\xe6\x1c\xb8\xd6\x47\
            \\x97\xfd\x61\xa9\xea\x77\x59\xf4\x2d\x57\x53\x9d\x56\x9a\x58\xcf\xe8\x4e\x63\xad\x46\x2e\x1b\x78\x65\x80\xf8\x7e\xf3\x81\x79\x14\
            \\x91\xda\x55\xf4\x40\xa2\x30\xf3\xd1\x98\x8f\x35\xb6\xe3\x18\xd2\x3f\xfa\x50\xbc\x3d\x40\xf0\x21\xc3\xc0\xbd\xae\x49\x58\xc2\x4c\
            \\x51\x8f\x36\xb2\x84\xb1\xd3\x70\x0f\xed\xce\x83\x87\x8d\xda\xda\xf2\xa2\x79\xc7\x94\xe0\x1b\xe8\x90\x71\x6f\x4b\x95\x4b\x8a\xa3"#

sbox_s8 :: Word8 -> Word32
sbox_s8 :: Word8 -> Word32
sbox_s8 Word8
i = Array32 -> Int -> Word32
arrayRead32 Array32
t (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
  where
    t :: Array32
t = Int -> Addr# -> Array32
array32FromAddrBE Int
256
            Addr#
"\xe2\x16\x30\x0d\xbb\xdd\xff\xfc\xa7\xeb\xda\xbd\x35\x64\x80\x95\x77\x89\xf8\xb7\xe6\xc1\x12\x1b\x0e\x24\x16\x00\x05\x2c\xe8\xb5\
            \\x11\xa9\xcf\xb0\xe5\x95\x2f\x11\xec\xe7\x99\x0a\x93\x86\xd1\x74\x2a\x42\x93\x1c\x76\xe3\x81\x11\xb1\x2d\xef\x3a\x37\xdd\xdd\xfc\
            \\xde\x9a\xde\xb1\x0a\x0c\xc3\x2c\xbe\x19\x70\x29\x84\xa0\x09\x40\xbb\x24\x3a\x0f\xb4\xd1\x37\xcf\xb4\x4e\x79\xf0\x04\x9e\xed\xfd\
            \\x0b\x15\xa1\x5d\x48\x0d\x31\x68\x8b\xbb\xde\x5a\x66\x9d\xed\x42\xc7\xec\xe8\x31\x3f\x8f\x95\xe7\x72\xdf\x19\x1b\x75\x80\x33\x0d\
            \\x94\x07\x42\x51\x5c\x7d\xcd\xfa\xab\xbe\x6d\x63\xaa\x40\x21\x64\xb3\x01\xd4\x0a\x02\xe7\xd1\xca\x53\x57\x1d\xae\x7a\x31\x82\xa2\
            \\x12\xa8\xdd\xec\xfd\xaa\x33\x5d\x17\x6f\x43\xe8\x71\xfb\x46\xd4\x38\x12\x90\x22\xce\x94\x9a\xd4\xb8\x47\x69\xad\x96\x5b\xd8\x62\
            \\x82\xf3\xd0\x55\x66\xfb\x97\x67\x15\xb8\x0b\x4e\x1d\x5b\x47\xa0\x4c\xfd\xe0\x6f\xc2\x8e\xc4\xb8\x57\xe8\x72\x6e\x64\x7a\x78\xfc\
            \\x99\x86\x5d\x44\x60\x8b\xd5\x93\x6c\x20\x0e\x03\x39\xdc\x5f\xf6\x5d\x0b\x00\xa3\xae\x63\xaf\xf2\x7e\x8b\xd6\x32\x70\x10\x8c\x0c\
            \\xbb\xd3\x50\x49\x29\x98\xdf\x04\x98\x0c\xf4\x2a\x9b\x6d\xf4\x91\x9e\x7e\xdd\x53\x06\x91\x85\x48\x58\xcb\x7e\x07\x3b\x74\xef\x2e\
            \\x52\x2f\xff\xb1\xd2\x47\x08\xcc\x1c\x7e\x27\xcd\xa4\xeb\x21\x5b\x3c\xf1\xd2\xe2\x19\xb4\x7a\x38\x42\x4f\x76\x18\x35\x85\x60\x39\
            \\x9d\x17\xde\xe7\x27\xeb\x35\xe6\xc9\xaf\xf6\x7b\x36\xba\xf5\xb8\x09\xc4\x67\xcd\xc1\x89\x10\xb1\xe1\x1d\xbf\x7b\x06\xcd\x1a\xf8\
            \\x71\x70\xc6\x08\x2d\x5e\x33\x54\xd4\xde\x49\x5a\x64\xc6\xd0\x06\xbc\xc0\xc6\x2c\x3d\xd0\x0d\xb3\x70\x8f\x8f\x34\x77\xd5\x1b\x42\
            \\x26\x4f\x62\x0f\x24\xb8\xd2\xbf\x15\xc1\xb7\x9e\x46\xa5\x25\x64\xf8\xd7\xe5\x4e\x3e\x37\x81\x60\x78\x95\xcd\xa5\x85\x9c\x15\xa5\
            \\xe6\x45\x97\x88\xc3\x7b\xc7\x5f\xdb\x07\xba\x0c\x06\x76\xa3\xab\x7f\x22\x9b\x1e\x31\x84\x2e\x7b\x24\x25\x9f\xd7\xf8\xbe\xf4\x72\
            \\x83\x5f\xfc\xb8\x6d\xf4\xc1\xf2\x96\xf5\xb1\x95\xfd\x0a\xf0\xfc\xb0\xfe\x13\x4c\xe2\x50\x6d\x3d\x4f\x9b\x12\xea\xf2\x15\xf2\x25\
            \\xa2\x23\x73\x6f\x9f\xb4\xc4\x28\x25\xd0\x49\x79\x34\xc7\x13\xf8\xc4\x61\x81\x87\xea\x7a\x6e\x98\x7c\xd1\x6e\xfc\x14\x36\x87\x6c\
            \\xf1\x54\x41\x07\xbe\xde\xee\x14\x56\xe9\xaf\x27\xa0\x4a\xa4\x41\x3c\xf7\xc8\x99\x92\xec\xba\xe6\xdd\x67\x01\x6d\x15\x16\x82\xeb\
            \\xa8\x42\xee\xdf\xfd\xba\x60\xb4\xf1\x90\x7b\x75\x20\xe3\x03\x0f\x24\xd8\xc2\x9e\xe1\x39\x67\x3b\xef\xa6\x3f\xb8\x71\x87\x30\x54\
            \\xb6\xf2\xcf\x3b\x9f\x32\x64\x42\xcb\x15\xa4\xcc\xb0\x1a\x45\x04\xf1\xe4\x7d\x8d\x84\x4a\x1b\xe5\xba\xe7\xdf\xdc\x42\xcb\xda\x70\
            \\xcd\x7d\xae\x0a\x57\xe8\x5b\x7a\xd5\x3f\x5a\xf6\x20\xcf\x4d\x8c\xce\xa4\xd4\x28\x79\xd1\x30\xa4\x34\x86\xeb\xfb\x33\xd3\xcd\xdc\
            \\x77\x85\x3b\x53\x37\xef\xfc\xb5\xc5\x06\x87\x78\xe5\x80\xb3\xe6\x4e\x68\xb8\xf4\xc5\xc8\xb3\x7e\x0d\x80\x9e\xa2\x39\x8f\xeb\x7c\
            \\x13\x2a\x4f\x94\x43\xb7\x95\x0e\x2f\xee\x7d\x1c\x22\x36\x13\xbd\xdd\x06\xca\xa2\x37\xdf\x93\x2b\xc4\x24\x82\x89\xac\xf3\xeb\xc3\
            \\x57\x15\xf6\xb7\xef\x34\x78\xdd\xf2\x67\x61\x6f\xc1\x48\xcb\xe4\x90\x52\x81\x5e\x5e\x41\x0f\xab\xb4\x8a\x24\x65\x2e\xda\x7f\xa4\
            \\xe8\x7b\x40\xe4\xe9\x8e\xa0\x84\x58\x89\xe9\xe1\xef\xd3\x90\xfc\xdd\x07\xd3\x5b\xdb\x48\x56\x94\x38\xd7\xe5\xb2\x57\x72\x01\x01\
            \\x73\x0e\xde\xbc\x5b\x64\x31\x13\x94\x91\x7e\x4f\x50\x3c\x2f\xba\x64\x6f\x12\x82\x75\x23\xd2\x4a\xe0\x77\x96\x95\xf9\xc1\x7a\x8f\
            \\x7a\x5b\x21\x21\xd1\x87\xb8\x96\x29\x26\x3a\x4d\xba\x51\x0c\xdf\x81\xf4\x7c\x9f\xad\x11\x63\xed\xea\x7b\x59\x65\x1a\x00\x72\x6e\
            \\x11\x40\x30\x92\x00\xda\x6d\x77\x4a\x0c\xdd\x61\xad\x1f\x46\x03\x60\x5b\xdf\xb0\x9e\xed\xc3\x64\x22\xeb\xe6\xa8\xce\xe7\xd2\x8a\
            \\xa0\xe7\x36\xa0\x55\x64\xa6\xb9\x10\x85\x32\x09\xc7\xeb\x8f\x37\x2d\xe7\x05\xca\x89\x51\x57\x0f\xdf\x09\x82\x2b\xbd\x69\x1a\x6c\
            \\xaa\x12\xe4\xf2\x87\x45\x1c\x0f\xe0\xf6\xa2\x7a\x3a\xda\x48\x19\x4c\xf1\x76\x4f\x0d\x77\x1c\x2b\x67\xcd\xb1\x56\x35\x0d\x83\x84\
            \\x59\x38\xfa\x0f\x42\x39\x9e\xf3\x36\x99\x7b\x07\x0e\x84\x09\x3d\x4a\xa9\x3e\x61\x83\x60\xd8\x7b\x1f\xa9\x8b\x0c\x11\x49\x38\x2c\
            \\xe9\x76\x25\xa5\x06\x14\xd1\xb7\x0e\x25\x24\x4b\x0c\x76\x83\x47\x58\x9e\x8d\x82\x0d\x20\x59\xd1\xa4\x66\xbb\x1e\xf8\xda\x0a\x82\
            \\x04\xf1\x91\x30\xba\x6e\x4e\xc0\x99\x26\x51\x64\x1e\xe7\x23\x0d\x50\xb2\xad\x80\xea\xee\x68\x01\x8d\xb2\xa2\x83\xea\x8b\xf5\x9e"#