diff options
author | lloyd <[email protected]> | 2010-10-13 00:38:07 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-13 00:38:07 +0000 |
commit | c59d960db6d69bd9c479ec674768b7ec371830b5 (patch) | |
tree | 250385bd1c9c5b4a2afac27cc47d10031965f84b /src/stream/arc4 | |
parent | 2e42b5aaaf8d817f612518afa91a5bc9d1465eb7 (diff) |
s/u32bit/size_t/ in stream
Diffstat (limited to 'src/stream/arc4')
-rw-r--r-- | src/stream/arc4/arc4.cpp | 32 | ||||
-rw-r--r-- | src/stream/arc4/arc4.h | 12 |
2 files changed, 25 insertions, 19 deletions
diff --git a/src/stream/arc4/arc4.cpp b/src/stream/arc4/arc4.cpp index 97364bd1a..92a9ac092 100644 --- a/src/stream/arc4/arc4.cpp +++ b/src/stream/arc4/arc4.cpp @@ -14,7 +14,7 @@ namespace Botan { /* * Combine cipher stream with message */ -void ARC4::cipher(const byte in[], byte out[], u32bit length) +void ARC4::cipher(const byte in[], byte out[], size_t length) { while(length >= buffer.size() - position) { @@ -33,25 +33,25 @@ void ARC4::cipher(const byte in[], byte out[], u32bit length) */ void ARC4::generate() { - u32bit SX, SY; - for(u32bit j = 0; j != buffer.size(); j += 4) + byte SX, SY; + for(size_t i = 0; i != buffer.size(); i += 4) { SX = state[X+1]; Y = (Y + SX) % 256; SY = state[Y]; state[X+1] = SY; state[Y] = SX; - buffer[j] = state[(SX + SY) % 256]; + buffer[i] = state[(SX + SY) % 256]; SX = state[X+2]; Y = (Y + SX) % 256; SY = state[Y]; state[X+2] = SY; state[Y] = SX; - buffer[j+1] = state[(SX + SY) % 256]; + buffer[i+1] = state[(SX + SY) % 256]; SX = state[X+3]; Y = (Y + SX) % 256; SY = state[Y]; state[X+3] = SY; state[Y] = SX; - buffer[j+2] = state[(SX + SY) % 256]; + buffer[i+2] = state[(SX + SY) % 256]; X = (X + 4) % 256; SX = state[X]; Y = (Y + SX) % 256; SY = state[Y]; state[X] = SY; state[Y] = SX; - buffer[j+3] = state[(SX + SY) % 256]; + buffer[i+3] = state[(SX + SY) % 256]; } position = 0; } @@ -62,15 +62,19 @@ void ARC4::generate() void ARC4::key_schedule(const byte key[], u32bit length) { clear(); - for(u32bit j = 0; j != 256; ++j) - state[j] = j; - for(u32bit j = 0, state_index = 0; j != 256; ++j) + + for(size_t i = 0; i != 256; ++i) + state[i] = i; + + for(size_t i = 0, state_index = 0; i != 256; ++i) { - state_index = (state_index + key[j % length] + state[j]) % 256; - std::swap(state[j], state[state_index]); + state_index = (state_index + key[i % length] + state[i]) % 256; + std::swap(state[i], state[state_index]); } - for(u32bit j = 0; j <= SKIP; j += buffer.size()) + + for(size_t i = 0; i <= SKIP; i += buffer.size()) generate(); + position += (SKIP % buffer.size()); } @@ -97,7 +101,7 @@ void ARC4::clear() /* * ARC4 Constructor */ -ARC4::ARC4(u32bit s) : StreamCipher(1, 256), SKIP(s), +ARC4::ARC4(size_t s) : StreamCipher(1, 256), SKIP(s), state(256), buffer(DEFAULT_BUFFERSIZE) { clear(); diff --git a/src/stream/arc4/arc4.h b/src/stream/arc4/arc4.h index 1b8684e75..aa1c39331 100644 --- a/src/stream/arc4/arc4.h +++ b/src/stream/arc4/arc4.h @@ -19,7 +19,7 @@ namespace Botan { class BOTAN_DLL ARC4 : public StreamCipher { public: - void cipher(const byte in[], byte out[], u32bit length); + void cipher(const byte in[], byte out[], size_t length); void clear(); std::string name() const; @@ -29,18 +29,20 @@ class BOTAN_DLL ARC4 : public StreamCipher /** * @param skip skip this many initial bytes in the keystream */ - ARC4(u32bit skip = 0); + ARC4(size_t skip = 0); ~ARC4() { clear(); } private: void key_schedule(const byte[], u32bit); void generate(); - const u32bit SKIP; + const size_t SKIP; + + byte X, Y; + SecureVector<byte> state; - SecureVector<u32bit> state; SecureVector<byte> buffer; - u32bit X, Y, position; + size_t position; }; } |