aboutsummaryrefslogtreecommitdiffstats
path: root/src/block
diff options
context:
space:
mode:
Diffstat (limited to 'src/block')
-rw-r--r--src/block/aes/aes.cpp8
-rw-r--r--src/block/blowfish/blowfish.cpp35
-rw-r--r--src/block/blowfish/blowfish.h3
-rw-r--r--src/block/cast/cast128.cpp9
-rw-r--r--src/block/cast/cast128.h3
-rw-r--r--src/block/des/des.cpp16
-rw-r--r--src/block/idea/idea.cpp4
-rw-r--r--src/block/idea_sse2/idea_sse2.cpp8
-rw-r--r--src/block/kasumi/kasumi.cpp4
-rw-r--r--src/block/lion/lion.cpp14
-rw-r--r--src/block/lubyrack/lubyrack.cpp30
-rw-r--r--src/block/misty1/misty1.cpp4
-rw-r--r--src/block/noekeon/noekeon.cpp8
-rw-r--r--src/block/rc2/rc2.cpp3
-rw-r--r--src/block/serpent/serpent.cpp2
-rw-r--r--src/block/serpent_simd/serp_simd.cpp8
-rw-r--r--src/block/skipjack/skipjack.cpp74
-rw-r--r--src/block/twofish/twofish.cpp2
-rw-r--r--src/block/xtea/xtea.cpp4
19 files changed, 129 insertions, 110 deletions
diff --git a/src/block/aes/aes.cpp b/src/block/aes/aes.cpp
index 2485fc1a1..93f7f4363 100644
--- a/src/block/aes/aes.cpp
+++ b/src/block/aes/aes.cpp
@@ -661,12 +661,12 @@ void AES::key_schedule(const byte key[], u32bit length)
for(u32bit j = 0; j != 4; ++j)
{
- store_be(XEK[j+4*ROUNDS], ME + 4*j);
- store_be(XEK[j], MD + 4*j);
+ store_be(XEK[j+4*ROUNDS], &ME[4*j]);
+ store_be(XEK[j], &MD[4*j]);
}
- EK.copy(XEK, length + 24);
- DK.copy(XDK, length + 24);
+ EK.copy(&XEK[0], length + 24);
+ DK.copy(&XDK[0], length + 24);
}
/*
diff --git a/src/block/blowfish/blowfish.cpp b/src/block/blowfish/blowfish.cpp
index d0b182a84..6e4ad5b28 100644
--- a/src/block/blowfish/blowfish.cpp
+++ b/src/block/blowfish/blowfish.cpp
@@ -15,10 +15,10 @@ namespace Botan {
*/
void Blowfish::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
- const u32bit* S1 = S + 0;
- const u32bit* S2 = S + 256;
- const u32bit* S3 = S + 512;
- const u32bit* S4 = S + 768;
+ const u32bit* S1 = &S[0];
+ const u32bit* S2 = &S[256];
+ const u32bit* S3 = &S[512];
+ const u32bit* S4 = &S[768];
for(u32bit i = 0; i != blocks; ++i)
{
@@ -50,10 +50,10 @@ void Blowfish::encrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void Blowfish::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
- const u32bit* S1 = S + 0;
- const u32bit* S2 = S + 256;
- const u32bit* S3 = S + 512;
- const u32bit* S4 = S + 768;
+ const u32bit* S1 = &S[0];
+ const u32bit* S2 = &S[256];
+ const u32bit* S3 = &S[512];
+ const u32bit* S4 = &S[768];
for(u32bit i = 0; i != blocks; ++i)
{
@@ -92,22 +92,22 @@ void Blowfish::key_schedule(const byte key[], u32bit length)
key[(k+2) % length], key[(k+3) % length]);
u32bit L = 0, R = 0;
- generate_sbox(P, 18, L, R);
- generate_sbox(S, 1024, L, R);
+ generate_sbox(P, L, R);
+ generate_sbox(S, L, R);
}
/*
* Generate one of the Sboxes
*/
-void Blowfish::generate_sbox(u32bit Box[], u32bit size,
+void Blowfish::generate_sbox(MemoryRegion<u32bit>& box,
u32bit& L, u32bit& R) const
{
- const u32bit* S1 = S + 0;
- const u32bit* S2 = S + 256;
- const u32bit* S3 = S + 512;
- const u32bit* S4 = S + 768;
+ const u32bit* S1 = &S[0];
+ const u32bit* S2 = &S[256];
+ const u32bit* S3 = &S[512];
+ const u32bit* S4 = &S[768];
- for(u32bit j = 0; j != size; j += 2)
+ for(u32bit j = 0; j != box.size(); j += 2)
{
for(u32bit k = 0; k != 16; k += 2)
{
@@ -121,7 +121,8 @@ void Blowfish::generate_sbox(u32bit Box[], u32bit size,
}
u32bit T = R; R = L ^ P[16]; L = T ^ P[17];
- Box[j] = L; Box[j+1] = R;
+ box[j] = L;
+ box[j+1] = R;
}
}
diff --git a/src/block/blowfish/blowfish.h b/src/block/blowfish/blowfish.h
index a178ec488..88122aed8 100644
--- a/src/block/blowfish/blowfish.h
+++ b/src/block/blowfish/blowfish.h
@@ -28,7 +28,8 @@ class BOTAN_DLL Blowfish : public BlockCipher
Blowfish() : BlockCipher(8, 1, 56) {}
private:
void key_schedule(const byte[], u32bit);
- void generate_sbox(u32bit[], u32bit, u32bit&, u32bit&) const;
+ void generate_sbox(MemoryRegion<u32bit>& box,
+ u32bit& L, u32bit& R) const;
static const u32bit P_INIT[18];
static const u32bit S_INIT[1024];
diff --git a/src/block/cast/cast128.cpp b/src/block/cast/cast128.cpp
index cabde4b4f..b68b7abd7 100644
--- a/src/block/cast/cast128.cpp
+++ b/src/block/cast/cast128.cpp
@@ -123,8 +123,8 @@ void CAST_128::key_schedule(const byte key[], u32bit length)
for(u32bit j = 0; j != length; ++j)
X[j/4] = (X[j/4] << 8) + key[j];
- key_schedule(MK, X);
- key_schedule(RK, X);
+ cast_ks(MK, X);
+ cast_ks(RK, X);
for(u32bit j = 0; j != 16; ++j)
RK[j] %= 32;
@@ -133,7 +133,8 @@ void CAST_128::key_schedule(const byte key[], u32bit length)
/*
* S-Box Based Key Expansion
*/
-void CAST_128::key_schedule(u32bit K[16], u32bit X[4])
+void CAST_128::cast_ks(MemoryRegion<u32bit>& K,
+ MemoryRegion<u32bit>& X)
{
class ByteReader
{
@@ -145,7 +146,7 @@ void CAST_128::key_schedule(u32bit K[16], u32bit X[4])
};
SecureVector<u32bit, 4> Z;
- ByteReader x(X), z(Z);
+ ByteReader x(&X[0]), z(&Z[0]);
Z[0] = X[0] ^ S5[x(13)] ^ S6[x(15)] ^ S7[x(12)] ^ S8[x(14)] ^ S7[x( 8)];
Z[1] = X[2] ^ S5[z( 0)] ^ S6[z( 2)] ^ S7[z( 1)] ^ S8[z( 3)] ^ S8[x(10)];
diff --git a/src/block/cast/cast128.h b/src/block/cast/cast128.h
index e5d4a884b..425eb46cc 100644
--- a/src/block/cast/cast128.h
+++ b/src/block/cast/cast128.h
@@ -29,7 +29,8 @@ class BOTAN_DLL CAST_128 : public BlockCipher
private:
void key_schedule(const byte[], u32bit);
- static void key_schedule(u32bit[16], u32bit[4]);
+ static void cast_ks(MemoryRegion<u32bit>& ks,
+ MemoryRegion<u32bit>& user_key);
static const u32bit S5[256];
static const u32bit S6[256];
diff --git a/src/block/des/des.cpp b/src/block/des/des.cpp
index a24a1d445..37424cd35 100644
--- a/src/block/des/des.cpp
+++ b/src/block/des/des.cpp
@@ -152,7 +152,7 @@ void DES::encrypt_n(const byte in[], byte out[], u32bit blocks) const
u32bit L = static_cast<u32bit>(T >> 32);
u32bit R = static_cast<u32bit>(T);
- des_encrypt(L, R, round_key);
+ des_encrypt(L, R, &round_key[0]);
T = (DES_FPTAB1[get_byte(0, L)] << 5) | (DES_FPTAB1[get_byte(1, L)] << 3) |
(DES_FPTAB1[get_byte(2, L)] << 1) | (DES_FPTAB2[get_byte(3, L)] << 1) |
@@ -182,7 +182,7 @@ void DES::decrypt_n(const byte in[], byte out[], u32bit blocks) const
u32bit L = static_cast<u32bit>(T >> 32);
u32bit R = static_cast<u32bit>(T);
- des_decrypt(L, R, round_key);
+ des_decrypt(L, R, &round_key[0]);
T = (DES_FPTAB1[get_byte(0, L)] << 5) | (DES_FPTAB1[get_byte(1, L)] << 3) |
(DES_FPTAB1[get_byte(2, L)] << 1) | (DES_FPTAB2[get_byte(3, L)] << 1) |
@@ -221,9 +221,9 @@ void TripleDES::encrypt_n(const byte in[], byte out[], u32bit blocks) const
u32bit L = static_cast<u32bit>(T >> 32);
u32bit R = static_cast<u32bit>(T);
- des_encrypt(L, R, round_key);
- des_decrypt(R, L, round_key + 32);
- des_encrypt(L, R, round_key + 64);
+ des_encrypt(L, R, &round_key[0]);
+ des_decrypt(R, L, &round_key[32]);
+ des_encrypt(L, R, &round_key[64]);
T = (DES_FPTAB1[get_byte(0, L)] << 5) | (DES_FPTAB1[get_byte(1, L)] << 3) |
(DES_FPTAB1[get_byte(2, L)] << 1) | (DES_FPTAB2[get_byte(3, L)] << 1) |
@@ -254,9 +254,9 @@ void TripleDES::decrypt_n(const byte in[], byte out[], u32bit blocks) const
u32bit L = static_cast<u32bit>(T >> 32);
u32bit R = static_cast<u32bit>(T);
- des_decrypt(L, R, round_key + 64);
- des_encrypt(R, L, round_key + 32);
- des_decrypt(L, R, round_key);
+ des_decrypt(L, R, &round_key[64]);
+ des_encrypt(R, L, &round_key[32]);
+ des_decrypt(L, R, &round_key[0]);
T = (DES_FPTAB1[get_byte(0, L)] << 5) | (DES_FPTAB1[get_byte(1, L)] << 3) |
(DES_FPTAB1[get_byte(2, L)] << 1) | (DES_FPTAB2[get_byte(3, L)] << 1) |
diff --git a/src/block/idea/idea.cpp b/src/block/idea/idea.cpp
index 0c5dfed42..7673ead7e 100644
--- a/src/block/idea/idea.cpp
+++ b/src/block/idea/idea.cpp
@@ -111,7 +111,7 @@ void idea_op(const byte in[], byte out[], u32bit blocks, const u16bit K[52])
*/
void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
- idea_op(in, out, blocks, EK);
+ idea_op(in, out, blocks, &EK[0]);
}
/*
@@ -119,7 +119,7 @@ void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void IDEA::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
- idea_op(in, out, blocks, DK);
+ idea_op(in, out, blocks, &DK[0]);
}
/*
diff --git a/src/block/idea_sse2/idea_sse2.cpp b/src/block/idea_sse2/idea_sse2.cpp
index a7ded37e1..857869115 100644
--- a/src/block/idea_sse2/idea_sse2.cpp
+++ b/src/block/idea_sse2/idea_sse2.cpp
@@ -196,9 +196,11 @@ void idea_op_8(const byte in[64], byte out[64], const u16bit EK[52])
*/
void IDEA_SSE2::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
+ const u16bit* KS = &this->get_EK()[0];
+
while(blocks >= 8)
{
- idea_op_8(in, out, this->get_EK());
+ idea_op_8(in, out, KS);
in += 8 * BLOCK_SIZE;
out += 8 * BLOCK_SIZE;
blocks -= 8;
@@ -213,9 +215,11 @@ void IDEA_SSE2::encrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void IDEA_SSE2::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
+ const u16bit* KS = &this->get_DK()[0];
+
while(blocks >= 8)
{
- idea_op_8(in, out, this->get_DK());
+ idea_op_8(in, out, KS);
in += 8 * BLOCK_SIZE;
out += 8 * BLOCK_SIZE;
blocks -= 8;
diff --git a/src/block/kasumi/kasumi.cpp b/src/block/kasumi/kasumi.cpp
index d7f981b20..8dcdff716 100644
--- a/src/block/kasumi/kasumi.cpp
+++ b/src/block/kasumi/kasumi.cpp
@@ -120,7 +120,7 @@ void KASUMI::encrypt_n(const byte in[], byte out[], u32bit blocks) const
for(u32bit j = 0; j != 8; j += 2)
{
- const u16bit* K = EK + 8*j;
+ const u16bit* K = &EK[8*j];
u16bit R = B1 ^ (rotate_left(B0, 1) & K[0]);
u16bit L = B0 ^ (rotate_left(R, 1) | K[1]);
@@ -164,7 +164,7 @@ void KASUMI::decrypt_n(const byte in[], byte out[], u32bit blocks) const
for(u32bit j = 0; j != 8; j += 2)
{
- const u16bit* K = EK + 8*(6-j);
+ const u16bit* K = &EK[8*(6-j)];
u16bit L = B2, R = B3;
diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp
index 45e051ada..9d0dff297 100644
--- a/src/block/lion/lion.cpp
+++ b/src/block/lion/lion.cpp
@@ -16,11 +16,12 @@ namespace Botan {
*/
void Lion::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
- SecureVector<byte> buffer(LEFT_SIZE);
+ SecureVector<byte> buffer_vec(LEFT_SIZE);
+ byte* buffer = &buffer_vec[0];
for(u32bit i = 0; i != blocks; ++i)
{
- xor_buf(buffer, in, key1, LEFT_SIZE);
+ xor_buf(buffer, in, &key1[0], LEFT_SIZE);
cipher->set_key(buffer, LEFT_SIZE);
cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
@@ -28,7 +29,7 @@ void Lion::encrypt_n(const byte in[], byte out[], u32bit blocks) const
hash->final(buffer);
xor_buf(out, in, buffer, LEFT_SIZE);
- xor_buf(buffer, out, key2, LEFT_SIZE);
+ xor_buf(buffer, out, &key2[0], LEFT_SIZE);
cipher->set_key(buffer, LEFT_SIZE);
cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
@@ -42,11 +43,12 @@ void Lion::encrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void Lion::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
- SecureVector<byte> buffer(LEFT_SIZE);
+ SecureVector<byte> buffer_vec(LEFT_SIZE);
+ byte* buffer = &buffer_vec[0];
for(u32bit i = 0; i != blocks; ++i)
{
- xor_buf(buffer, in, key2, LEFT_SIZE);
+ xor_buf(buffer, in, &key2[0], LEFT_SIZE);
cipher->set_key(buffer, LEFT_SIZE);
cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
@@ -54,7 +56,7 @@ void Lion::decrypt_n(const byte in[], byte out[], u32bit blocks) const
hash->final(buffer);
xor_buf(out, in, buffer, LEFT_SIZE);
- xor_buf(buffer, out, key1, LEFT_SIZE);
+ xor_buf(buffer, out, &key1[0], LEFT_SIZE);
cipher->set_key(buffer, LEFT_SIZE);
cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
diff --git a/src/block/lubyrack/lubyrack.cpp b/src/block/lubyrack/lubyrack.cpp
index 4dd0d5c8a..99f8e6da1 100644
--- a/src/block/lubyrack/lubyrack.cpp
+++ b/src/block/lubyrack/lubyrack.cpp
@@ -15,29 +15,30 @@ namespace Botan {
*/
void LubyRackoff::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
+ const u32bit len = hash->OUTPUT_LENGTH;
+
+ SecureVector<byte> buffer(len);
+
for(u32bit i = 0; i != blocks; ++i)
{
- const u32bit len = hash->OUTPUT_LENGTH;
-
- SecureVector<byte> buffer(len);
hash->update(K1);
hash->update(in, len);
- hash->final(buffer);
+ hash->final(&buffer[0]);
xor_buf(out + len, in + len, buffer, len);
hash->update(K2);
hash->update(out + len, len);
- hash->final(buffer);
+ hash->final(&buffer[0]);
xor_buf(out, in, buffer, len);
hash->update(K1);
hash->update(out, len);
- hash->final(buffer);
+ hash->final(&buffer[0]);
xor_buf(out + len, buffer, len);
hash->update(K2);
hash->update(out + len, len);
- hash->final(buffer);
+ hash->final(&buffer[0]);
xor_buf(out, buffer, len);
in += BLOCK_SIZE;
@@ -50,29 +51,30 @@ void LubyRackoff::encrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void LubyRackoff::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
+ const u32bit len = hash->OUTPUT_LENGTH;
+
+ SecureVector<byte> buffer(len);
+
for(u32bit i = 0; i != blocks; ++i)
{
- const u32bit len = hash->OUTPUT_LENGTH;
-
- SecureVector<byte> buffer(len);
hash->update(K2);
hash->update(in + len, len);
- hash->final(buffer);
+ hash->final(&buffer[0]);
xor_buf(out, in, buffer, len);
hash->update(K1);
hash->update(out, len);
- hash->final(buffer);
+ hash->final(&buffer[0]);
xor_buf(out + len, in + len, buffer, len);
hash->update(K2);
hash->update(out + len, len);
- hash->final(buffer);
+ hash->final(&buffer[0]);
xor_buf(out, buffer, len);
hash->update(K1);
hash->update(out, len);
- hash->final(buffer);
+ hash->final(&buffer[0]);
xor_buf(out + len, buffer, len);
in += BLOCK_SIZE;
diff --git a/src/block/misty1/misty1.cpp b/src/block/misty1/misty1.cpp
index 9ab4d11f4..d5d3513a2 100644
--- a/src/block/misty1/misty1.cpp
+++ b/src/block/misty1/misty1.cpp
@@ -113,7 +113,7 @@ void MISTY1::encrypt_n(const byte in[], byte out[], u32bit blocks) const
for(u32bit j = 0; j != 12; j += 3)
{
- const u16bit* RK = EK + 8 * j;
+ const u16bit* RK = &EK[8 * j];
B1 ^= B0 & RK[0];
B0 ^= B1 | RK[1];
@@ -163,7 +163,7 @@ void MISTY1::decrypt_n(const byte in[], byte out[], u32bit blocks) const
for(u32bit j = 0; j != 12; j += 3)
{
- const u16bit* RK = DK + 8 * j;
+ const u16bit* RK = &DK[8 * j];
B2 ^= B3 | RK[0];
B3 ^= B2 & RK[1];
diff --git a/src/block/noekeon/noekeon.cpp b/src/block/noekeon/noekeon.cpp
index 95178a62b..a24153a29 100644
--- a/src/block/noekeon/noekeon.cpp
+++ b/src/block/noekeon/noekeon.cpp
@@ -96,7 +96,7 @@ void Noekeon::encrypt_n(const byte in[], byte out[], u32bit blocks) const
for(u32bit j = 0; j != 16; ++j)
{
A0 ^= RC[j];
- theta(A0, A1, A2, A3, EK);
+ theta(A0, A1, A2, A3, &EK[0]);
A1 = rotate_left(A1, 1);
A2 = rotate_left(A2, 5);
@@ -110,7 +110,7 @@ void Noekeon::encrypt_n(const byte in[], byte out[], u32bit blocks) const
}
A0 ^= RC[16];
- theta(A0, A1, A2, A3, EK);
+ theta(A0, A1, A2, A3, &EK[0]);
store_be(out, A0, A1, A2, A3);
@@ -133,7 +133,7 @@ void Noekeon::decrypt_n(const byte in[], byte out[], u32bit blocks) const
for(u32bit j = 16; j != 0; --j)
{
- theta(A0, A1, A2, A3, DK);
+ theta(A0, A1, A2, A3, &DK[0]);
A0 ^= RC[j];
A1 = rotate_left(A1, 1);
@@ -147,7 +147,7 @@ void Noekeon::decrypt_n(const byte in[], byte out[], u32bit blocks) const
A3 = rotate_right(A3, 2);
}
- theta(A0, A1, A2, A3, DK);
+ theta(A0, A1, A2, A3, &DK[0]);
A0 ^= RC[0];
store_be(out, A0, A1, A2, A3);
diff --git a/src/block/rc2/rc2.cpp b/src/block/rc2/rc2.cpp
index 3114c6055..4657d7b6c 100644
--- a/src/block/rc2/rc2.cpp
+++ b/src/block/rc2/rc2.cpp
@@ -133,8 +133,7 @@ void RC2::key_schedule(const byte key[], u32bit length)
for(s32bit j = 127-length; j >= 0; --j)
L[j] = TABLE[L[j+1] ^ L[j+length]];
- for(u32bit j = 0; j != 64; ++j)
- K[j] = load_le<u16bit>(L, j);
+ load_le<u16bit>(&K[0], &L[0], 64);
}
/*
diff --git a/src/block/serpent/serpent.cpp b/src/block/serpent/serpent.cpp
index b93326e58..4979ecbab 100644
--- a/src/block/serpent/serpent.cpp
+++ b/src/block/serpent/serpent.cpp
@@ -379,7 +379,7 @@ void Serpent::key_schedule(const byte key[], u32bit length)
SBoxE8(W[120],W[121],W[122],W[123]); SBoxE7(W[124],W[125],W[126],W[127]);
SBoxE6(W[128],W[129],W[130],W[131]); SBoxE5(W[132],W[133],W[134],W[135]);
SBoxE4(W[136],W[137],W[138],W[139]);
- round_key.copy(W + 8, 132);
+ round_key.copy(&W[8], 132);
}
}
diff --git a/src/block/serpent_simd/serp_simd.cpp b/src/block/serpent_simd/serp_simd.cpp
index c64514de1..a4143804a 100644
--- a/src/block/serpent_simd/serp_simd.cpp
+++ b/src/block/serpent_simd/serp_simd.cpp
@@ -180,9 +180,11 @@ void serpent_decrypt_4(const byte in[64],
*/
void Serpent_SIMD::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
+ const u32bit* KS = &(this->get_round_keys()[0]);
+
while(blocks >= 4)
{
- serpent_encrypt_4(in, out, this->get_round_keys());
+ serpent_encrypt_4(in, out, KS);
in += 4 * BLOCK_SIZE;
out += 4 * BLOCK_SIZE;
blocks -= 4;
@@ -197,9 +199,11 @@ void Serpent_SIMD::encrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void Serpent_SIMD::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
+ const u32bit* KS = &(this->get_round_keys()[0]);
+
while(blocks >= 4)
{
- serpent_decrypt_4(in, out, this->get_round_keys());
+ serpent_decrypt_4(in, out, KS);
in += 4 * BLOCK_SIZE;
out += 4 * BLOCK_SIZE;
blocks -= 4;
diff --git a/src/block/skipjack/skipjack.cpp b/src/block/skipjack/skipjack.cpp
index dda984e4c..2a1901230 100644
--- a/src/block/skipjack/skipjack.cpp
+++ b/src/block/skipjack/skipjack.cpp
@@ -77,6 +77,8 @@ void step_Bi(u16bit& W2, u16bit& W3, u32bit round, const byte FTAB[])
*/
void Skipjack::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
+ const byte* ftab = &FTAB[0];
+
for(u32bit i = 0; i != blocks; ++i)
{
u16bit W1 = load_le<u16bit>(in, 3);
@@ -84,25 +86,25 @@ void Skipjack::encrypt_n(const byte in[], byte out[], u32bit blocks) const
u16bit W3 = load_le<u16bit>(in, 1);
u16bit W4 = load_le<u16bit>(in, 0);
- step_A(W1, W4, 1, FTAB); step_A(W4, W3, 2, FTAB);
- step_A(W3, W2, 3, FTAB); step_A(W2, W1, 4, FTAB);
- step_A(W1, W4, 5, FTAB); step_A(W4, W3, 6, FTAB);
- step_A(W3, W2, 7, FTAB); step_A(W2, W1, 8, FTAB);
+ step_A(W1, W4, 1, ftab); step_A(W4, W3, 2, ftab);
+ step_A(W3, W2, 3, ftab); step_A(W2, W1, 4, ftab);
+ step_A(W1, W4, 5, ftab); step_A(W4, W3, 6, ftab);
+ step_A(W3, W2, 7, ftab); step_A(W2, W1, 8, ftab);
- step_B(W1, W2, 9, FTAB); step_B(W4, W1, 10, FTAB);
- step_B(W3, W4, 11, FTAB); step_B(W2, W3, 12, FTAB);
- step_B(W1, W2, 13, FTAB); step_B(W4, W1, 14, FTAB);
- step_B(W3, W4, 15, FTAB); step_B(W2, W3, 16, FTAB);
+ step_B(W1, W2, 9, ftab); step_B(W4, W1, 10, ftab);
+ step_B(W3, W4, 11, ftab); step_B(W2, W3, 12, ftab);
+ step_B(W1, W2, 13, ftab); step_B(W4, W1, 14, ftab);
+ step_B(W3, W4, 15, ftab); step_B(W2, W3, 16, ftab);
- step_A(W1, W4, 17, FTAB); step_A(W4, W3, 18, FTAB);
- step_A(W3, W2, 19, FTAB); step_A(W2, W1, 20, FTAB);
- step_A(W1, W4, 21, FTAB); step_A(W4, W3, 22, FTAB);
- step_A(W3, W2, 23, FTAB); step_A(W2, W1, 24, FTAB);
+ step_A(W1, W4, 17, ftab); step_A(W4, W3, 18, ftab);
+ step_A(W3, W2, 19, ftab); step_A(W2, W1, 20, ftab);
+ step_A(W1, W4, 21, ftab); step_A(W4, W3, 22, ftab);
+ step_A(W3, W2, 23, ftab); step_A(W2, W1, 24, ftab);
- step_B(W1, W2, 25, FTAB); step_B(W4, W1, 26, FTAB);
- step_B(W3, W4, 27, FTAB); step_B(W2, W3, 28, FTAB);
- step_B(W1, W2, 29, FTAB); step_B(W4, W1, 30, FTAB);
- step_B(W3, W4, 31, FTAB); step_B(W2, W3, 32, FTAB);
+ step_B(W1, W2, 25, ftab); step_B(W4, W1, 26, ftab);
+ step_B(W3, W4, 27, ftab); step_B(W2, W3, 28, ftab);
+ step_B(W1, W2, 29, ftab); step_B(W4, W1, 30, ftab);
+ step_B(W3, W4, 31, ftab); step_B(W2, W3, 32, ftab);
store_le(out, W4, W3, W2, W1);
@@ -116,6 +118,8 @@ void Skipjack::encrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void Skipjack::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
+ const byte* ftab = &FTAB[0];
+
for(u32bit i = 0; i != blocks; ++i)
{
u16bit W1 = load_le<u16bit>(in, 3);
@@ -123,25 +127,25 @@ void Skipjack::decrypt_n(const byte in[], byte out[], u32bit blocks) const
u16bit W3 = load_le<u16bit>(in, 1);
u16bit W4 = load_le<u16bit>(in, 0);
- step_Bi(W2, W3, 32, FTAB); step_Bi(W3, W4, 31, FTAB);
- step_Bi(W4, W1, 30, FTAB); step_Bi(W1, W2, 29, FTAB);
- step_Bi(W2, W3, 28, FTAB); step_Bi(W3, W4, 27, FTAB);
- step_Bi(W4, W1, 26, FTAB); step_Bi(W1, W2, 25, FTAB);
-
- step_Ai(W1, W2, 24, FTAB); step_Ai(W2, W3, 23, FTAB);
- step_Ai(W3, W4, 22, FTAB); step_Ai(W4, W1, 21, FTAB);
- step_Ai(W1, W2, 20, FTAB); step_Ai(W2, W3, 19, FTAB);
- step_Ai(W3, W4, 18, FTAB); step_Ai(W4, W1, 17, FTAB);
-
- step_Bi(W2, W3, 16, FTAB); step_Bi(W3, W4, 15, FTAB);
- step_Bi(W4, W1, 14, FTAB); step_Bi(W1, W2, 13, FTAB);
- step_Bi(W2, W3, 12, FTAB); step_Bi(W3, W4, 11, FTAB);
- step_Bi(W4, W1, 10, FTAB); step_Bi(W1, W2, 9, FTAB);
-
- step_Ai(W1, W2, 8, FTAB); step_Ai(W2, W3, 7, FTAB);
- step_Ai(W3, W4, 6, FTAB); step_Ai(W4, W1, 5, FTAB);
- step_Ai(W1, W2, 4, FTAB); step_Ai(W2, W3, 3, FTAB);
- step_Ai(W3, W4, 2, FTAB); step_Ai(W4, W1, 1, FTAB);
+ step_Bi(W2, W3, 32, ftab); step_Bi(W3, W4, 31, ftab);
+ step_Bi(W4, W1, 30, ftab); step_Bi(W1, W2, 29, ftab);
+ step_Bi(W2, W3, 28, ftab); step_Bi(W3, W4, 27, ftab);
+ step_Bi(W4, W1, 26, ftab); step_Bi(W1, W2, 25, ftab);
+
+ step_Ai(W1, W2, 24, ftab); step_Ai(W2, W3, 23, ftab);
+ step_Ai(W3, W4, 22, ftab); step_Ai(W4, W1, 21, ftab);
+ step_Ai(W1, W2, 20, ftab); step_Ai(W2, W3, 19, ftab);
+ step_Ai(W3, W4, 18, ftab); step_Ai(W4, W1, 17, ftab);
+
+ step_Bi(W2, W3, 16, ftab); step_Bi(W3, W4, 15, ftab);
+ step_Bi(W4, W1, 14, ftab); step_Bi(W1, W2, 13, ftab);
+ step_Bi(W2, W3, 12, ftab); step_Bi(W3, W4, 11, ftab);
+ step_Bi(W4, W1, 10, ftab); step_Bi(W1, W2, 9, ftab);
+
+ step_Ai(W1, W2, 8, ftab); step_Ai(W2, W3, 7, ftab);
+ step_Ai(W3, W4, 6, ftab); step_Ai(W4, W1, 5, ftab);
+ step_Ai(W1, W2, 4, ftab); step_Ai(W2, W3, 3, ftab);
+ step_Ai(W3, W4, 2, ftab); step_Ai(W4, W1, 1, ftab);
store_le(out, W4, W3, W2, W1);
diff --git a/src/block/twofish/twofish.cpp b/src/block/twofish/twofish.cpp
index 375590af1..805695087 100644
--- a/src/block/twofish/twofish.cpp
+++ b/src/block/twofish/twofish.cpp
@@ -121,7 +121,7 @@ void Twofish::key_schedule(const byte key[], u32bit length)
SecureVector<byte, 16> S;
for(u32bit j = 0; j != length; ++j)
- rs_mul(S + 4*(j/8), key[j], j);
+ rs_mul(&S[4*(j/8)], key[j], j);
if(length == 16)
{
diff --git a/src/block/xtea/xtea.cpp b/src/block/xtea/xtea.cpp
index bb1a30374..03e9f628c 100644
--- a/src/block/xtea/xtea.cpp
+++ b/src/block/xtea/xtea.cpp
@@ -63,7 +63,7 @@ void XTEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
while(blocks >= 4)
{
- xtea_encrypt_4(in, out, this->EK);
+ xtea_encrypt_4(in, out, &(this->EK[0]));
in += 4 * BLOCK_SIZE;
out += 4 * BLOCK_SIZE;
blocks -= 4;
@@ -93,7 +93,7 @@ void XTEA::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
while(blocks >= 4)
{
- xtea_decrypt_4(in, out, this->EK);
+ xtea_decrypt_4(in, out, &(this->EK[0]));
in += 4 * BLOCK_SIZE;
out += 4 * BLOCK_SIZE;
blocks -= 4;