9 #include <botan/loadstor.h>
10 #include <botan/rotate.h>
11 #include <botan/parsing.h>
21 const size_t rounds = (S.
size() - 2) / 2;
23 for(
size_t i = 0; i != blocks; ++i)
29 for(
size_t j = 0; j != rounds; j += 4)
56 const size_t rounds = (S.
size() - 2) / 2;
58 for(
size_t i = 0; i != blocks; ++i)
63 for(
size_t j = rounds; j != 0; j -= 4)
89 void RC5::key_schedule(
const byte key[],
size_t length)
91 const size_t WORD_KEYLENGTH = (((length - 1) / 4) + 1);
92 const size_t MIX_ROUNDS = 3 * std::max(WORD_KEYLENGTH, S.
size());
95 for(
size_t i = 1; i != S.size(); ++i)
96 S[i] = S[i-1] + 0x9E3779B9;
100 for(
s32bit i = length-1; i >= 0; --i)
101 K[i/4] = (K[i/4] << 8) + key[i];
105 for(
size_t i = 0; i != MIX_ROUNDS; ++i)
108 B =
rotate_left(K[i % WORD_KEYLENGTH] + A + B, (A + B) % 32);
110 K[i % WORD_KEYLENGTH] = B;
119 return "RC5(" +
to_string(get_rounds()) +
")";
127 if(rounds < 8 || rounds > 32 || (rounds % 4 != 0))
131 S.resize(2*rounds + 2);
void store_le(u16bit in, byte out[2])
T rotate_left(T input, size_t rot)
std::invalid_argument Invalid_Argument
void decrypt_n(const byte in[], byte out[], size_t blocks) const
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
std::string to_string(u64bit n, size_t min_len)