9 #include <botan/loadstor.h>
10 #include <botan/rotate.h>
20 for(
size_t i = 0; i != blocks; ++i)
29 for(
size_t j = 0; j != 20; j += 4)
54 A += S[42]; C += S[43];
68 for(
size_t i = 0; i != blocks; ++i)
75 C -= S[43]; A -= S[42];
77 for(
size_t j = 0; j != 20; j += 4)
102 D -= S[1]; B -= S[0];
114 void RC6::key_schedule(
const byte key[],
size_t length)
116 const size_t WORD_KEYLENGTH = (((length - 1) / 4) + 1);
117 const size_t MIX_ROUNDS = 3 * std::max(WORD_KEYLENGTH, S.
size());
120 for(
size_t i = 1; i != S.size(); ++i)
121 S[i] = S[i-1] + 0x9E3779B9;
125 for(
s32bit i = length-1; i >= 0; --i)
126 K[i/4] = (K[i/4] << 8) + key[i];
129 for(
size_t i = 0; i != MIX_ROUNDS; ++i)
132 B =
rotate_left(K[i % WORD_KEYLENGTH] + A + B, (A + B) % 32);
134 K[i % WORD_KEYLENGTH] = B;
void decrypt_n(const byte in[], byte out[], size_t blocks) const
void store_le(u16bit in, byte out[2])
T rotate_left(T input, size_t rot)
T rotate_right(T input, size_t rot)
u32bit load_le< u32bit >(const byte in[], size_t off)
void encrypt_n(const byte in[], byte out[], size_t blocks) const