diff options
author | lloyd <lloyd@randombit.net> | 2010-10-13 00:38:07 +0000 |
---|---|---|
committer | lloyd <lloyd@randombit.net> | 2010-10-13 00:38:07 +0000 |
commit | c59d960db6d69bd9c479ec674768b7ec371830b5 (patch) | |
tree | 250385bd1c9c5b4a2afac27cc47d10031965f84b /src/stream | |
parent | 2e42b5aaaf8d817f612518afa91a5bc9d1465eb7 (diff) |
s/u32bit/size_t/ in stream
Diffstat (limited to 'src/stream')
-rw-r--r-- | src/stream/arc4/arc4.cpp | 32 | ||||
-rw-r--r-- | src/stream/arc4/arc4.h | 12 | ||||
-rw-r--r-- | src/stream/ctr/ctr.cpp | 14 | ||||
-rw-r--r-- | src/stream/ctr/ctr.h | 8 | ||||
-rw-r--r-- | src/stream/ofb/ofb.cpp | 4 | ||||
-rw-r--r-- | src/stream/ofb/ofb.h | 8 | ||||
-rw-r--r-- | src/stream/salsa20/salsa20.cpp | 8 | ||||
-rw-r--r-- | src/stream/salsa20/salsa20.h | 8 | ||||
-rw-r--r-- | src/stream/stream_cipher.cpp | 4 | ||||
-rw-r--r-- | src/stream/stream_cipher.h | 8 | ||||
-rw-r--r-- | src/stream/turing/turing.cpp | 52 | ||||
-rw-r--r-- | src/stream/turing/turing.h | 8 | ||||
-rw-r--r-- | src/stream/wid_wake/wid_wake.cpp | 50 | ||||
-rw-r--r-- | src/stream/wid_wake/wid_wake.h | 10 |
14 files changed, 118 insertions, 108 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; }; } diff --git a/src/stream/ctr/ctr.cpp b/src/stream/ctr/ctr.cpp index bf546da9a..f1b73a8c3 100644 --- a/src/stream/ctr/ctr.cpp +++ b/src/stream/ctr/ctr.cpp @@ -67,7 +67,7 @@ std::string CTR_BE::name() const /* * CTR-BE Encryption/Decryption */ -void CTR_BE::cipher(const byte in[], byte out[], u32bit length) +void CTR_BE::cipher(const byte in[], byte out[], size_t length) { while(length >= buffer.size() - position) { @@ -84,20 +84,20 @@ void CTR_BE::cipher(const byte in[], byte out[], u32bit length) /* * Set CTR-BE IV */ -void CTR_BE::set_iv(const byte iv[], u32bit iv_len) +void CTR_BE::set_iv(const byte iv[], size_t iv_len) { if(!valid_iv_length(iv_len)) throw Invalid_IV_Length(name(), iv_len); - const u32bit BLOCK_SIZE = permutation->BLOCK_SIZE; + const size_t BLOCK_SIZE = permutation->BLOCK_SIZE; zeroise(counter); counter.copy(0, iv, iv_len); - const u32bit PARALLEL_BLOCKS = counter.size() / BLOCK_SIZE; + const size_t PARALLEL_BLOCKS = counter.size() / BLOCK_SIZE; - for(u32bit i = 1; i != PARALLEL_BLOCKS; ++i) + for(size_t i = 1; i != PARALLEL_BLOCKS; ++i) { counter.copy(i*BLOCK_SIZE, &counter[(i-1)*BLOCK_SIZE], @@ -117,9 +117,9 @@ void CTR_BE::set_iv(const byte iv[], u32bit iv_len) */ void CTR_BE::increment_counter() { - const u32bit PARALLEL_BLOCKS = counter.size() / permutation->BLOCK_SIZE; + const size_t PARALLEL_BLOCKS = counter.size() / permutation->BLOCK_SIZE; - for(u32bit i = 0; i != PARALLEL_BLOCKS; ++i) + for(size_t i = 0; i != PARALLEL_BLOCKS; ++i) { byte* this_ctr = &counter[i * permutation->BLOCK_SIZE]; diff --git a/src/stream/ctr/ctr.h b/src/stream/ctr/ctr.h index fc7ba522f..45a3e29e2 100644 --- a/src/stream/ctr/ctr.h +++ b/src/stream/ctr/ctr.h @@ -19,11 +19,11 @@ namespace Botan { class BOTAN_DLL CTR_BE : public StreamCipher { public: - void cipher(const byte in[], byte out[], u32bit length); + void cipher(const byte in[], byte out[], size_t length); - void set_iv(const byte iv[], u32bit iv_len); + void set_iv(const byte iv[], size_t iv_len); - bool valid_iv_length(u32bit iv_len) const + bool valid_iv_length(size_t iv_len) const { return (iv_len <= permutation->BLOCK_SIZE); } std::string name() const; @@ -44,7 +44,7 @@ class BOTAN_DLL CTR_BE : public StreamCipher BlockCipher* permutation; SecureVector<byte> counter, buffer; - u32bit position; + size_t position; }; } diff --git a/src/stream/ofb/ofb.cpp b/src/stream/ofb/ofb.cpp index 6fc8e4b68..1b1a066ee 100644 --- a/src/stream/ofb/ofb.cpp +++ b/src/stream/ofb/ofb.cpp @@ -64,7 +64,7 @@ std::string OFB::name() const /* * CTR-BE Encryption/Decryption */ -void OFB::cipher(const byte in[], byte out[], u32bit length) +void OFB::cipher(const byte in[], byte out[], size_t length) { while(length >= buffer.size() - position) { @@ -82,7 +82,7 @@ void OFB::cipher(const byte in[], byte out[], u32bit length) /* * Set CTR-BE IV */ -void OFB::set_iv(const byte iv[], u32bit iv_len) +void OFB::set_iv(const byte iv[], size_t iv_len) { if(!valid_iv_length(iv_len)) throw Invalid_IV_Length(name(), iv_len); diff --git a/src/stream/ofb/ofb.h b/src/stream/ofb/ofb.h index 2871dd8ee..832b93287 100644 --- a/src/stream/ofb/ofb.h +++ b/src/stream/ofb/ofb.h @@ -19,11 +19,11 @@ namespace Botan { class BOTAN_DLL OFB : public StreamCipher { public: - void cipher(const byte in[], byte out[], u32bit length); + void cipher(const byte in[], byte out[], size_t length); - void set_iv(const byte iv[], u32bit iv_len); + void set_iv(const byte iv[], size_t iv_len); - bool valid_iv_length(u32bit iv_len) const + bool valid_iv_length(size_t iv_len) const { return (iv_len <= permutation->BLOCK_SIZE); } std::string name() const; @@ -43,7 +43,7 @@ class BOTAN_DLL OFB : public StreamCipher BlockCipher* permutation; SecureVector<byte> buffer; - u32bit position; + size_t position; }; } diff --git a/src/stream/salsa20/salsa20.cpp b/src/stream/salsa20/salsa20.cpp index 58626fb2f..7f76276bb 100644 --- a/src/stream/salsa20/salsa20.cpp +++ b/src/stream/salsa20/salsa20.cpp @@ -32,7 +32,7 @@ void hsalsa20(u32bit output[8], const u32bit input[16]) x08 = input[ 8], x09 = input[ 9], x10 = input[10], x11 = input[11], x12 = input[12], x13 = input[13], x14 = input[14], x15 = input[15]; - for(u32bit i = 0; i != 10; ++i) + for(size_t i = 0; i != 10; ++i) { SALSA20_QUARTER_ROUND(x00, x04, x08, x12); SALSA20_QUARTER_ROUND(x05, x09, x13, x01); @@ -65,7 +65,7 @@ void salsa20(byte output[64], const u32bit input[16]) x08 = input[ 8], x09 = input[ 9], x10 = input[10], x11 = input[11], x12 = input[12], x13 = input[13], x14 = input[14], x15 = input[15]; - for(u32bit i = 0; i != 10; ++i) + for(size_t i = 0; i != 10; ++i) { SALSA20_QUARTER_ROUND(x00, x04, x08, x12); SALSA20_QUARTER_ROUND(x05, x09, x13, x01); @@ -101,7 +101,7 @@ void salsa20(byte output[64], const u32bit input[16]) /* * Combine cipher stream with message */ -void Salsa20::cipher(const byte in[], byte out[], u32bit length) +void Salsa20::cipher(const byte in[], byte out[], size_t length) { while(length >= buffer.size() - position) { @@ -174,7 +174,7 @@ void Salsa20::key_schedule(const byte key[], u32bit length) /* * Return the name of this type */ -void Salsa20::set_iv(const byte iv[], u32bit length) +void Salsa20::set_iv(const byte iv[], size_t length) { if(!valid_iv_length(length)) throw Invalid_IV_Length(name(), length); diff --git a/src/stream/salsa20/salsa20.h b/src/stream/salsa20/salsa20.h index 7e6c523cd..2addee9a9 100644 --- a/src/stream/salsa20/salsa20.h +++ b/src/stream/salsa20/salsa20.h @@ -18,11 +18,11 @@ namespace Botan { class BOTAN_DLL Salsa20 : public StreamCipher { public: - void cipher(const byte in[], byte out[], u32bit length); + void cipher(const byte in[], byte out[], size_t length); - void set_iv(const byte iv[], u32bit iv_len); + void set_iv(const byte iv[], size_t iv_len); - bool valid_iv_length(u32bit iv_len) const + bool valid_iv_length(size_t iv_len) const { return (iv_len == 8 || iv_len == 24); } void clear(); @@ -36,7 +36,7 @@ class BOTAN_DLL Salsa20 : public StreamCipher SecureVector<u32bit> state; SecureVector<byte> buffer; - u32bit position; + size_t position; }; } diff --git a/src/stream/stream_cipher.cpp b/src/stream/stream_cipher.cpp index 9ae548a9e..7dbd3e2e3 100644 --- a/src/stream/stream_cipher.cpp +++ b/src/stream/stream_cipher.cpp @@ -9,14 +9,14 @@ namespace Botan { -void StreamCipher::set_iv(const byte[], u32bit iv_len) +void StreamCipher::set_iv(const byte[], size_t iv_len) { if(iv_len) throw Invalid_Argument("The stream cipher " + name() + " does not support resyncronization"); } -bool StreamCipher::valid_iv_length(u32bit iv_len) const +bool StreamCipher::valid_iv_length(size_t iv_len) const { return (iv_len == 0); } diff --git a/src/stream/stream_cipher.h b/src/stream/stream_cipher.h index edeb1aff5..26bbfe160 100644 --- a/src/stream/stream_cipher.h +++ b/src/stream/stream_cipher.h @@ -24,14 +24,14 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm * @param out the byte array to hold the output, i.e. the ciphertext * @param len the length of both in and out in bytes */ - virtual void cipher(const byte in[], byte out[], u32bit len) = 0; + virtual void cipher(const byte in[], byte out[], size_t len) = 0; /** * Encrypt or decrypt a message * @param buf the plaintext / ciphertext * @param len the length of buf in bytes */ - void cipher1(byte buf[], u32bit len) + void cipher1(byte buf[], size_t len) { cipher(buf, buf, len); } /** @@ -39,13 +39,13 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm * @param iv the initialization vector * @param iv_len the length of the IV in bytes */ - virtual void set_iv(const byte iv[], u32bit iv_len); + virtual void set_iv(const byte iv[], size_t iv_len); /** * @param iv_len the length of the IV in bytes * @return if the length is valid for this algorithm */ - virtual bool valid_iv_length(u32bit iv_len) const; + virtual bool valid_iv_length(size_t iv_len) const; /** * Get a new object representing the same algorithm as *this diff --git a/src/stream/turing/turing.cpp b/src/stream/turing/turing.cpp index 9fa38d863..160d07a65 100644 --- a/src/stream/turing/turing.cpp +++ b/src/stream/turing/turing.cpp @@ -20,13 +20,13 @@ namespace { inline void PHT(MemoryRegion<u32bit>& B) { u32bit sum = 0; - for(u32bit i = 0; i < B.size() - 1; ++i) + for(size_t i = 0; i < B.size() - 1; ++i) sum += B[i]; B[B.size()-1] += sum; sum = B[B.size()-1]; - for(u32bit i = 0; i < B.size() - 1; ++i) + for(size_t i = 0; i < B.size() - 1; ++i) B[i] += sum; } @@ -35,7 +35,7 @@ inline void PHT(MemoryRegion<u32bit>& B) /* * Combine cipher stream with message */ -void Turing::cipher(const byte in[], byte out[], u32bit length) +void Turing::cipher(const byte in[], byte out[], size_t length) { while(length >= buffer.size() - position) { @@ -130,9 +130,9 @@ void Turing::generate() 7, 8, 9, 10, 11, 12, 13, 14, 15, 2, 4, 5, 6, 12, 13, 14, 15, 16, 0, 1, 2, 3, 7, 9, 10, 11 }; - for(u32bit j = 0; j != 17; ++j) + for(size_t i = 0; i != 17; ++i) { - const byte* R_off = OFFSETS + 13*j; + const byte* R_off = OFFSETS + 13*i; u32bit R0 = R[R_off[0]]; u32bit R1 = R[R_off[1]]; @@ -195,11 +195,11 @@ void Turing::generate() C += R9; D += R5; - store_be(A, &buffer[20*j + 0]); - store_be(B, &buffer[20*j + 4]); - store_be(C, &buffer[20*j + 8]); - store_be(D, &buffer[20*j + 12]); - store_be(E, &buffer[20*j + 16]); + store_be(A, &buffer[20*i + 0]); + store_be(B, &buffer[20*i + 4]); + store_be(C, &buffer[20*i + 8]); + store_be(D, &buffer[20*i + 12]); + store_be(E, &buffer[20*i + 16]); } position = 0; @@ -210,12 +210,12 @@ void Turing::generate() */ u32bit Turing::fixedS(u32bit W) { - for(u32bit j = 0; j != 4; ++j) + for(size_t i = 0; i != 4; ++i) { - byte B = SBOX[get_byte(j, W)]; - W ^= rotate_left(Q_BOX[B], j*8); - W &= rotate_right(0x00FFFFFF, j*8); - W |= B << (24-j*8); + byte B = SBOX[get_byte(i, W)]; + W ^= rotate_left(Q_BOX[B], i*8); + W &= rotate_right(0x00FFFFFF, i*8); + W |= B << (24-i*8); } return W; } @@ -226,22 +226,22 @@ u32bit Turing::fixedS(u32bit W) void Turing::key_schedule(const byte key[], u32bit length) { K.resize(length / 4); - for(u32bit j = 0; j != length; ++j) - K[j/4] = (K[j/4] << 8) + key[j]; + for(size_t i = 0; i != length; ++i) + K[i/4] = (K[i/4] << 8) + key[i]; - for(u32bit j = 0; j != K.size(); ++j) - K[j] = fixedS(K[j]); + for(size_t i = 0; i != K.size(); ++i) + K[i] = fixedS(K[i]); PHT(K); - for(u32bit i = 0; i != 256; ++i) + for(size_t i = 0; i != 256; ++i) { u32bit W0 = 0, C0 = i; u32bit W1 = 0, C1 = i; u32bit W2 = 0, C2 = i; u32bit W3 = 0, C3 = i; - for(u32bit j = 0; j < K.size(); ++j) + for(size_t j = 0; j < K.size(); ++j) { C0 = SBOX[get_byte(0, K[j]) ^ C0]; C1 = SBOX[get_byte(1, K[j]) ^ C1]; @@ -266,24 +266,24 @@ void Turing::key_schedule(const byte key[], u32bit length) /* * Resynchronization */ -void Turing::set_iv(const byte iv[], u32bit length) +void Turing::set_iv(const byte iv[], size_t length) { if(!valid_iv_length(length)) throw Invalid_IV_Length(name(), length); SecureVector<u32bit> IV(length / 4); - for(u32bit i = 0; i != length; ++i) + for(size_t i = 0; i != length; ++i) IV[i/4] = (IV[i/4] << 8) + iv[i]; - for(u32bit i = 0; i != IV.size(); ++i) + for(size_t i = 0; i != IV.size(); ++i) R[i] = IV[i] = fixedS(IV[i]); - for(u32bit i = 0; i != K.size(); ++i) + for(size_t i = 0; i != K.size(); ++i) R[i+IV.size()] = K[i]; R[K.size() + IV.size()] = (0x010203 << 8) | (K.size() << 4) | IV.size(); - for(u32bit i = K.size() + IV.size() + 1; i != 17; ++i) + for(size_t i = K.size() + IV.size() + 1; i != 17; ++i) { const u32bit W = R[i-K.size()-IV.size()-1] + R[i-1]; R[i] = S0[get_byte(0, W)] ^ S1[get_byte(1, W)] ^ diff --git a/src/stream/turing/turing.h b/src/stream/turing/turing.h index c0b11fd7b..f270c291a 100644 --- a/src/stream/turing/turing.h +++ b/src/stream/turing/turing.h @@ -18,10 +18,10 @@ namespace Botan { class BOTAN_DLL Turing : public StreamCipher { public: - void cipher(const byte in[], byte out[], u32bit length); - void set_iv(const byte iv[], u32bit iv_length); + void cipher(const byte in[], byte out[], size_t length); + void set_iv(const byte iv[], size_t iv_length); - bool valid_iv_length(u32bit iv_len) const + bool valid_iv_length(size_t iv_len) const { return (iv_len % 4 == 0 && iv_len <= 16); } void clear(); @@ -46,7 +46,7 @@ class BOTAN_DLL Turing : public StreamCipher SecureVector<u32bit> R; SecureVector<u32bit> K; SecureVector<byte> buffer; - u32bit position; + size_t position; }; } diff --git a/src/stream/wid_wake/wid_wake.cpp b/src/stream/wid_wake/wid_wake.cpp index 17b0df557..3db87214e 100644 --- a/src/stream/wid_wake/wid_wake.cpp +++ b/src/stream/wid_wake/wid_wake.cpp @@ -14,7 +14,7 @@ namespace Botan { /* * Combine cipher stream with message */ -void WiderWake_41_BE::cipher(const byte in[], byte out[], u32bit length) +void WiderWake_41_BE::cipher(const byte in[], byte out[], size_t length) { while(length >= buffer.size() - position) { @@ -31,17 +31,17 @@ void WiderWake_41_BE::cipher(const byte in[], byte out[], u32bit length) /* * Generate cipher stream */ -void WiderWake_41_BE::generate(u32bit length) +void WiderWake_41_BE::generate(size_t length) { u32bit R0 = state[0], R1 = state[1], R2 = state[2], R3 = state[3], R4 = state[4]; - for(u32bit j = 0; j != length; j += 8) + for(size_t i = 0; i != length; i += 8) { u32bit R0a; - store_be(R3, &buffer[j]); + store_be(R3, &buffer[i]); R0a = R4 + R3; R3 += R2; R2 += R1; R1 += R0; R0a = (R0a >> 8) ^ T[(R0a & 0xFF)]; @@ -50,7 +50,7 @@ void WiderWake_41_BE::generate(u32bit length) R3 = (R3 >> 8) ^ T[(R3 & 0xFF)]; R4 = R0; R0 = R0a; - store_be(R3, &buffer[j + 4]); + store_be(R3, &buffer[i + 4]); R0a = R4 + R3; R3 += R2; R2 += R1; R1 += R0; R0a = (R0a >> 8) ^ T[(R0a & 0xFF)]; @@ -74,38 +74,41 @@ void WiderWake_41_BE::generate(u32bit length) */ void WiderWake_41_BE::key_schedule(const byte key[], u32bit) { - for(u32bit j = 0; j != 4; ++j) - t_key[j] = load_be<u32bit>(key, j); + for(size_t i = 0; i != 4; ++i) + t_key[i] = load_be<u32bit>(key, i); static const u32bit MAGIC[8] = { 0x726A8F3B, 0xE69A3B5C, 0xD3C71FE5, 0xAB3C73D2, 0x4D3A8EB3, 0x0396D6E8, 0x3D4C2F7A, 0x9EE27CF3 }; - for(u32bit j = 0; j != 4; ++j) - T[j] = t_key[j]; - for(u32bit j = 4; j != 256; ++j) + for(size_t i = 0; i != 4; ++i) + T[i] = t_key[i]; + + for(size_t i = 4; i != 256; ++i) { - u32bit X = T[j-1] + T[j-4]; - T[j] = (X >> 3) ^ MAGIC[X % 8]; + u32bit X = T[i-1] + T[i-4]; + T[i] = (X >> 3) ^ MAGIC[X % 8]; } - for(u32bit j = 0; j != 23; ++j) - T[j] += T[j+89]; + + for(size_t i = 0; i != 23; ++i) + T[i] += T[i+89]; u32bit X = T[33]; u32bit Z = (T[59] | 0x01000001) & 0xFF7FFFFF; - for(u32bit j = 0; j != 256; ++j) + for(size_t i = 0; i != 256; ++i) { X = (X & 0xFF7FFFFF) + Z; - T[j] = (T[j] & 0x00FFFFFF) ^ X; + T[i] = (T[i] & 0x00FFFFFF) ^ X; } + X = (T[X & 0xFF] ^ X) & 0xFF; Z = T[0]; T[0] = T[X]; - for(u32bit j = 1; j != 256; ++j) + for(size_t i = 1; i != 256; ++i) { - T[X] = T[j]; - X = (T[j ^ X] ^ X) & 0xFF; - T[j] = T[X]; + T[X] = T[i]; + X = (T[i ^ X] ^ X) & 0xFF; + T[i] = T[X]; } T[X] = Z; @@ -118,13 +121,14 @@ void WiderWake_41_BE::key_schedule(const byte key[], u32bit) /* * Resynchronization */ -void WiderWake_41_BE::set_iv(const byte iv[], u32bit length) +void WiderWake_41_BE::set_iv(const byte iv[], size_t length) { if(!valid_iv_length(length)) throw Invalid_IV_Length(name(), length); - for(u32bit j = 0; j != 4; ++j) - state[j] = t_key[j]; + for(size_t i = 0; i != 4; ++i) + state[i] = t_key[i]; + state[4] = load_be<u32bit>(iv, 0); state[0] ^= state[4]; state[2] ^= load_be<u32bit>(iv, 1); diff --git a/src/stream/wid_wake/wid_wake.h b/src/stream/wid_wake/wid_wake.h index 88f5690bf..ac8d8e2d6 100644 --- a/src/stream/wid_wake/wid_wake.h +++ b/src/stream/wid_wake/wid_wake.h @@ -21,10 +21,10 @@ namespace Botan { class BOTAN_DLL WiderWake_41_BE : public StreamCipher { public: - void cipher(const byte[], byte[], u32bit); - void set_iv(const byte[], u32bit); + void cipher(const byte[], byte[], size_t); + void set_iv(const byte[], size_t); - bool valid_iv_length(u32bit iv_len) const + bool valid_iv_length(size_t iv_len) const { return (iv_len == 8); } void clear(); @@ -39,13 +39,13 @@ class BOTAN_DLL WiderWake_41_BE : public StreamCipher private: void key_schedule(const byte[], u32bit); - void generate(u32bit); + void generate(size_t); SecureVector<u32bit> T; SecureVector<u32bit> state; SecureVector<u32bit> t_key; SecureVector<byte> buffer; - u32bit position; + size_t position; }; } |