8 #include <botan/arc4.h>
9 #include <botan/internal/xor_buf.h>
10 #include <botan/parsing.h>
19 while(length >= buffer.
size() - position)
21 xor_buf(out, in, &buffer[position], buffer.
size() - position);
22 length -= (buffer.
size() - position);
23 in += (buffer.
size() - position);
24 out += (buffer.
size() - position);
27 xor_buf(out, in, &buffer[position], length);
37 for(
size_t i = 0; i != buffer.
size(); i += 4)
39 SX = state[X+1]; Y = (Y + SX) % 256; SY = state[Y];
40 state[X+1] = SY; state[Y] = SX;
41 buffer[i] = state[(SX + SY) % 256];
43 SX = state[X+2]; Y = (Y + SX) % 256; SY = state[Y];
44 state[X+2] = SY; state[Y] = SX;
45 buffer[i+1] = state[(SX + SY) % 256];
47 SX = state[X+3]; Y = (Y + SX) % 256; SY = state[Y];
48 state[X+3] = SY; state[Y] = SX;
49 buffer[i+2] = state[(SX + SY) % 256];
52 SX = state[X]; Y = (Y + SX) % 256; SY = state[Y];
53 state[X] = SY; state[Y] = SX;
54 buffer[i+3] = state[(SX + SY) % 256];
62 void ARC4::key_schedule(
const byte key[],
size_t length)
66 for(
size_t i = 0; i != 256; ++i)
67 state[i] = static_cast<byte>(i);
69 for(
size_t i = 0, state_index = 0; i != 256; ++i)
71 state_index = (state_index + key[i % length] + state[i]) % 256;
75 for(
size_t i = 0; i <= SKIP; i += buffer.
size())
78 position += (SKIP % buffer.
size());
86 if(SKIP == 0)
return "ARC4";
87 if(SKIP == 256)
return "MARK-4";
88 else return "RC4_skip(" +
to_string(SKIP) +
")";
106 buffer(DEFAULT_BUFFERSIZE)
std::string to_string(u64bit n, size_t min_len)
void swap(Botan::MemoryRegion< T > &x, Botan::MemoryRegion< T > &y)
void cipher(const byte in[], byte out[], size_t length)
void xor_buf(byte out[], const byte in[], size_t length)
void zeroise(MemoryRegion< T > &vec)