aboutsummaryrefslogtreecommitdiffstats
path: root/src/block
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-06-22 13:43:18 +0000
committerlloyd <[email protected]>2010-06-22 13:43:18 +0000
commit54bac11c5d4e051f996951feb6a037b1de001329 (patch)
tree8cfa3b72ae36dcd156c4ab4dae1066ee3e021830 /src/block
parent991f744c5a3e9610a2e4af70ae5daeb7a943a38e (diff)
parent238869aed29c3d703650ce55404929dc7e3f31fb (diff)
propagate from branch 'net.randombit.botan' (head 647eeb4f4cf8fa4cf487cdc463d48f09fe18658e)
to branch 'net.randombit.botan.c++0x' (head 2539675db91883b11895ddc5244721e93c413321)
Diffstat (limited to 'src/block')
-rw-r--r--src/block/idea/idea.h13
-rw-r--r--src/block/idea_sse2/idea_sse2.cpp4
-rw-r--r--src/block/noekeon/noekeon.h17
-rw-r--r--src/block/noekeon_simd/noekeon_simd.cpp4
-rw-r--r--src/block/serpent/serpent.h16
-rw-r--r--src/block/serpent_ia32/serp_ia32.cpp35
-rw-r--r--src/block/serpent_simd/serp_simd.cpp4
-rw-r--r--src/block/xtea/xtea.h6
-rw-r--r--src/block/xtea_simd/xtea_simd.cpp4
9 files changed, 84 insertions, 19 deletions
diff --git a/src/block/idea/idea.h b/src/block/idea/idea.h
index e9ccf366d..aed3be3ea 100644
--- a/src/block/idea/idea.h
+++ b/src/block/idea/idea.h
@@ -26,10 +26,19 @@ class BOTAN_DLL IDEA : public BlockCipher
BlockCipher* clone() const { return new IDEA; }
IDEA() : BlockCipher(8, 16) {}
+ protected:
+ /**
+ * @return const reference to encryption subkeys
+ */
+ const SecureVector<u16bit, 52>& get_EK() const { return EK; }
+
+ /**
+ * @return const reference to decryption subkeys
+ */
+ const SecureVector<u16bit, 52>& get_DK() const { return DK; }
+
private:
void key_schedule(const byte[], u32bit);
-
- protected: // for IDEA_SSE2
SecureVector<u16bit, 52> EK, DK;
};
diff --git a/src/block/idea_sse2/idea_sse2.cpp b/src/block/idea_sse2/idea_sse2.cpp
index 0fe35112d..0948bf46a 100644
--- a/src/block/idea_sse2/idea_sse2.cpp
+++ b/src/block/idea_sse2/idea_sse2.cpp
@@ -198,7 +198,7 @@ void IDEA_SSE2::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
while(blocks >= 8)
{
- idea_op_8(in, out, this->EK);
+ idea_op_8(in, out, this->get_EK());
in += 8 * BLOCK_SIZE;
out += 8 * BLOCK_SIZE;
blocks -= 8;
@@ -214,7 +214,7 @@ void IDEA_SSE2::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
while(blocks >= 8)
{
- idea_op_8(in, out, this->DK);
+ idea_op_8(in, out, this->get_DK());
in += 8 * BLOCK_SIZE;
out += 8 * BLOCK_SIZE;
blocks -= 8;
diff --git a/src/block/noekeon/noekeon.h b/src/block/noekeon/noekeon.h
index 018c1d1fd..2e524f8b8 100644
--- a/src/block/noekeon/noekeon.h
+++ b/src/block/noekeon/noekeon.h
@@ -26,15 +26,24 @@ class BOTAN_DLL Noekeon : public BlockCipher
BlockCipher* clone() const { return new Noekeon; }
Noekeon() : BlockCipher(16, 16) {}
- private:
- void key_schedule(const byte[], u32bit);
- protected: // for access by SIMD subclass
-
+ protected:
/**
* The Noekeon round constants
*/
static const byte RC[17];
+ /**
+ * @return const reference to encryption subkeys
+ */
+ const SecureVector<u32bit, 4>& get_EK() const { return EK; }
+
+ /**
+ * @return const reference to decryption subkeys
+ */
+ const SecureVector<u32bit, 4>& get_DK() const { return DK; }
+
+ private:
+ void key_schedule(const byte[], u32bit);
SecureVector<u32bit, 4> EK, DK;
};
diff --git a/src/block/noekeon_simd/noekeon_simd.cpp b/src/block/noekeon_simd/noekeon_simd.cpp
index f44104901..c36f269a4 100644
--- a/src/block/noekeon_simd/noekeon_simd.cpp
+++ b/src/block/noekeon_simd/noekeon_simd.cpp
@@ -55,6 +55,8 @@ namespace Botan {
*/
void Noekeon_SIMD::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
+ const SecureVector<u32bit, 4>& EK = this->get_EK();
+
SIMD_32 K0 = SIMD_32(EK[0]);
SIMD_32 K1 = SIMD_32(EK[1]);
SIMD_32 K2 = SIMD_32(EK[2]);
@@ -109,6 +111,8 @@ void Noekeon_SIMD::encrypt_n(const byte in[], byte out[], u32bit blocks) const
*/
void Noekeon_SIMD::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
+ const SecureVector<u32bit, 4>& DK = this->get_DK();
+
SIMD_32 K0 = SIMD_32(DK[0]);
SIMD_32 K1 = SIMD_32(DK[1]);
SIMD_32 K2 = SIMD_32(DK[2]);
diff --git a/src/block/serpent/serpent.h b/src/block/serpent/serpent.h
index 1c13d00f9..dc81d4178 100644
--- a/src/block/serpent/serpent.h
+++ b/src/block/serpent/serpent.h
@@ -26,8 +26,22 @@ class BOTAN_DLL Serpent : public BlockCipher
BlockCipher* clone() const { return new Serpent; }
Serpent() : BlockCipher(16, 16, 32, 8) {}
protected:
+ /**
+ * For use by subclasses using SIMD, asm, etc
+ * @return const reference to the key schedule
+ */
+ const SecureVector<u32bit, 132>& get_round_keys() const
+ { return round_key; }
+
+ /**
+ * For use by subclasses that implement the key schedule
+ * @param ks is the new key schedule value to set
+ */
+ void set_round_keys(const u32bit ks[132])
+ { round_key.set(ks, 132); }
+
+ private:
void key_schedule(const byte key[], u32bit length);
-
SecureVector<u32bit, 132> round_key;
};
diff --git a/src/block/serpent_ia32/serp_ia32.cpp b/src/block/serpent_ia32/serp_ia32.cpp
index ff454ab4c..ecdfec9b1 100644
--- a/src/block/serpent_ia32/serp_ia32.cpp
+++ b/src/block/serpent_ia32/serp_ia32.cpp
@@ -12,9 +12,32 @@ namespace Botan {
extern "C" {
-void botan_serpent_ia32_encrypt(const byte[16], byte[16], const u32bit[132]);
-void botan_serpent_ia32_decrypt(const byte[16], byte[16], const u32bit[132]);
-void botan_serpent_ia32_key_schedule(u32bit[140]);
+/**
+* Entry point for Serpent encryption in x86 asm
+* @param in the input block
+* @param out the output block
+* @param ks the key schedule
+*/
+void botan_serpent_ia32_encrypt(const byte in[16],
+ byte out[16],
+ const u32bit ks[132]);
+
+/**
+* Entry point for Serpent decryption in x86 asm
+* @param in the input block
+* @param out the output block
+* @param ks the key schedule
+*/
+void botan_serpent_ia32_decrypt(const byte in[16],
+ byte out[16],
+ const u32bit ks[132]);
+
+/**
+* Entry point for Serpent key schedule in x86 asm
+* @param ks holds the initial working key (padded), and is set to the
+ final key schedule
+*/
+void botan_serpent_ia32_key_schedule(u32bit ks[140]);
}
@@ -25,7 +48,7 @@ void Serpent_IA32::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
for(u32bit i = 0; i != blocks; ++i)
{
- botan_serpent_ia32_encrypt(in, out, round_key);
+ botan_serpent_ia32_encrypt(in, out, this->get_round_keys());
in += BLOCK_SIZE;
out += BLOCK_SIZE;
}
@@ -38,7 +61,7 @@ void Serpent_IA32::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
for(u32bit i = 0; i != blocks; ++i)
{
- botan_serpent_ia32_decrypt(in, out, round_key);
+ botan_serpent_ia32_decrypt(in, out, this->get_round_keys());
in += BLOCK_SIZE;
out += BLOCK_SIZE;
}
@@ -55,7 +78,7 @@ void Serpent_IA32::key_schedule(const byte key[], u32bit length)
W[length / 4] |= u32bit(1) << ((length%4)*8);
botan_serpent_ia32_key_schedule(W);
- round_key.copy(W + 8, 132);
+ this->set_round_keys(W + 8);
}
}
diff --git a/src/block/serpent_simd/serp_simd.cpp b/src/block/serpent_simd/serp_simd.cpp
index 0a535c9a0..ba587e93d 100644
--- a/src/block/serpent_simd/serp_simd.cpp
+++ b/src/block/serpent_simd/serp_simd.cpp
@@ -182,7 +182,7 @@ void Serpent_SIMD::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
while(blocks >= 4)
{
- serpent_encrypt_4(in, out, this->round_key);
+ serpent_encrypt_4(in, out, this->get_round_keys());
in += 4 * BLOCK_SIZE;
out += 4 * BLOCK_SIZE;
blocks -= 4;
@@ -198,7 +198,7 @@ void Serpent_SIMD::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
while(blocks >= 4)
{
- serpent_decrypt_4(in, out, this->round_key);
+ serpent_decrypt_4(in, out, this->get_round_keys());
in += 4 * BLOCK_SIZE;
out += 4 * BLOCK_SIZE;
blocks -= 4;
diff --git a/src/block/xtea/xtea.h b/src/block/xtea/xtea.h
index b16cdf555..d15108939 100644
--- a/src/block/xtea/xtea.h
+++ b/src/block/xtea/xtea.h
@@ -27,6 +27,12 @@ class BOTAN_DLL XTEA : public BlockCipher
XTEA() : BlockCipher(8, 16) {}
protected:
+ /**
+ * @return const reference to the key schedule
+ */
+ const SecureVector<u32bit, 64>& get_EK() const { return EK; }
+
+ private:
void key_schedule(const byte[], u32bit);
SecureVector<u32bit, 64> EK;
};
diff --git a/src/block/xtea_simd/xtea_simd.cpp b/src/block/xtea_simd/xtea_simd.cpp
index 264d4f949..44a4e81b6 100644
--- a/src/block/xtea_simd/xtea_simd.cpp
+++ b/src/block/xtea_simd/xtea_simd.cpp
@@ -96,7 +96,7 @@ void XTEA_SIMD::encrypt_n(const byte in[], byte out[], u32bit blocks) const
{
while(blocks >= 8)
{
- xtea_encrypt_8(in, out, this->EK);
+ xtea_encrypt_8(in, out, this->get_EK());
in += 8 * BLOCK_SIZE;
out += 8 * BLOCK_SIZE;
blocks -= 8;
@@ -112,7 +112,7 @@ void XTEA_SIMD::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
while(blocks >= 8)
{
- xtea_decrypt_8(in, out, this->EK);
+ xtea_decrypt_8(in, out, this->get_EK());
in += 8 * BLOCK_SIZE;
out += 8 * BLOCK_SIZE;
blocks -= 8;