13 AssertValidKeyLength(length);
18 T[length/4] = length/4;
20 for (
unsigned int j=0; j<4; j++)
25 T[i] = T[i] ^
rotlFixed(T[(i+8)%15] ^ T[(i+13)%15], 3) ^ (4*i+j);
28 for (
unsigned int k=0; k<4; k++)
30 T[i] =
rotlFixed(T[i] + Sbox[T[(i+14)%15]%512], 9);
34 m_k[10*j+i] = T[4*i%15];
38 for(
unsigned int i = 5; i < 37; i += 2)
41 m = (~w ^ (w<<1)) & (~w ^ (w>>1)) & 0x7ffffffe;
42 m &= m>>1; m &= m>>2; m &= m>>4;
43 m |= m<<1; m |= m<<2; m |= m<<4;
45 w ^=
rotlMod(Sbox[265 + (m_k[i] & 3)], m_k[i-1]) & m;
50 #define S(a) Sbox[(a)&0x1ff] 51 #define S0(a) Sbox[(a)&0xff] 52 #define S1(a) Sbox[((a)&0xff) + 256] 64 a += k[0]; b += k[1]; c += k[2]; d += k[3];
68 b = (b ^
S0(a)) +
S1(a>>8);
72 a += (i%4==0) ? d : 0;
73 a += (i%4==1) ? b : 0;
74 t =
a; a =
b; b =
c; c =
d; d = t;
86 a =
b; b =
c; c =
d; d = t;
91 a -= (i%4==2) ? d : 0;
92 a -= (i%4==3) ? b : 0;
96 d = (d -
S1(a>>16)) ^
S0(t);
97 a =
b; b =
c; c =
d; d = t;
100 a -= k[36]; b -= k[37]; c -= k[38]; d -= k[39];
113 d += k[36]; c += k[37]; b += k[38]; a += k[39];
117 b = (b ^
S0(a)) +
S1(a>>8);
121 a += (i%4==0) ? d : 0;
122 a += (i%4==1) ? b : 0;
123 t =
a; a =
b; b =
c; c =
d; d = t;
135 a =
b; b =
c; c =
d; d = t;
140 a -= (i%4==2) ? d : 0;
141 a -= (i%4==3) ? b : 0;
145 d = (d -
S1(a>>16)) ^
S0(t);
146 a =
b; b =
c; c =
d; d = t;
149 d -= k[0]; c -= k[1]; b -= k[2]; a -= k[3];
void GetUserKey(ByteOrder order, T *out, size_t outlen, const byte *in, size_t inlen)
Utility functions for the Crypto++ library.
T rotlFixed(T x, unsigned int y)
Performs a left rotate.
#define NAMESPACE_BEGIN(x)
static GetBlock< T, B, GA > Get(const void *block)
Access a block of memory.
byte order is little-endian
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
Encrypt or decrypt a block.
Classes for the MARS block cipher (IBM AES submission)
BlockGetAndPut< word32, LittleEndian > Block
FixedSizeSecBlock< word32, 40 > m_k
Fixed size stack-based SecBlock.
iterator begin()
Provides an iterator pointing to the first element in the memory block.
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
Encrypt or decrypt a block.
T rotlMod(T x, unsigned int y)
Performs a left rotate.
T rotrFixed(T x, unsigned int y)
Performs a right rotate.
Interface for retrieving values given their names.