aboutsummaryrefslogtreecommitdiffstats
path: root/src/cipher/serpent_ia32
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-29 17:43:36 +0000
committerlloyd <[email protected]>2008-09-29 17:43:36 +0000
commit26abd45c61294aacdd59fa4763ff1cd78aefbc7c (patch)
tree3ef4a44cd659d0b5442d2c6d8b3e9539fc23bb05 /src/cipher/serpent_ia32
parentba722ad52627163f945fd9fa97ff98f0df8452d1 (diff)
Make asm implementations distinctly named objects, for instance MD5_IA32,
rather than silently replacing the C++ versions. Instead they are silently replaced (currently, at least) at the lookup level: we switch off the set of feature macros set to choose the best implementation in the current build configuration. So you can have (and benchmark) MD5 and MD5_IA32 directly against each other in the same program with no hassles, but if you ask for "MD5", you'll get maybe an MD5 or maybe MD5_IA32. Also make the canonical asm names (which aren't guarded by C++ namespaces) of the form botan_<algo>_<arch>_<func> as in botan_sha160_ia32_compress, to avoid namespace collisions. This change has another bonus that it should in many cases be possible to derive the asm specializations directly from the original implementation, saving some code (and of course logically SHA_160_IA32 is a SHA_160, just one with a faster implementation of the compression function, so this seems reasonable anyway).
Diffstat (limited to 'src/cipher/serpent_ia32')
-rw-r--r--src/cipher/serpent_ia32/info.txt34
-rw-r--r--src/cipher/serpent_ia32/serp_ia32.cpp (renamed from src/cipher/serpent_ia32/serpent.cpp)22
-rw-r--r--src/cipher/serpent_ia32/serp_ia32.h33
-rw-r--r--src/cipher/serpent_ia32/serp_ia32_imp.S (renamed from src/cipher/serpent_ia32/serp_asm.S)14
4 files changed, 85 insertions, 18 deletions
diff --git a/src/cipher/serpent_ia32/info.txt b/src/cipher/serpent_ia32/info.txt
new file mode 100644
index 000000000..67f18beee
--- /dev/null
+++ b/src/cipher/serpent_ia32/info.txt
@@ -0,0 +1,34 @@
+realname "Serpent (IA-32)"
+
+define SERPENT_IA32
+
+load_on auto
+
+<add>
+serp_ia32_imp.S
+serp_ia32.cpp
+serp_ia32.h
+</add>
+
+<required>
+asm_ia32
+utils
+</required>
+
+<arch>
+ia32
+</arch>
+
+<cc>
+gcc
+icc
+</cc>
+
+# ELF systems
+<os>
+linux
+freebsd
+netbsd
+openbsd
+solaris
+</os>
diff --git a/src/cipher/serpent_ia32/serpent.cpp b/src/cipher/serpent_ia32/serp_ia32.cpp
index aacb72b0f..2cd607c18 100644
--- a/src/cipher/serpent_ia32/serpent.cpp
+++ b/src/cipher/serpent_ia32/serp_ia32.cpp
@@ -1,48 +1,48 @@
/*************************************************
-* Serpent Source File *
+* IA-32 Serpent Source File *
* (C) 1999-2007 Jack Lloyd *
*************************************************/
-#include <botan/serpent.h>
+#include <botan/serp_ia32.h>
#include <botan/loadstor.h>
namespace Botan {
extern "C" {
-void serpent_encrypt(const byte[16], byte[16], const u32bit[132]);
-void serpent_decrypt(const byte[16], byte[16], const u32bit[132]);
-void serpent_key_schedule(u32bit[140]);
+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]);
}
/*************************************************
* Serpent Encryption *
*************************************************/
-void Serpent::enc(const byte in[], byte out[]) const
+void Serpent_IA32::enc(const byte in[], byte out[]) const
{
- serpent_encrypt(in, out, round_key);
+ botan_serpent_ia32_encrypt(in, out, round_key);
}
/*************************************************
* Serpent Decryption *
*************************************************/
-void Serpent::dec(const byte in[], byte out[]) const
+void Serpent_IA32::dec(const byte in[], byte out[]) const
{
- serpent_decrypt(in, out, round_key);
+ botan_serpent_ia32_decrypt(in, out, round_key);
}
/*************************************************
* Serpent Key Schedule *
*************************************************/
-void Serpent::key(const byte key[], u32bit length)
+void Serpent_IA32::key(const byte key[], u32bit length)
{
SecureBuffer<u32bit, 140> W;
for(u32bit j = 0; j != length / 4; ++j)
W[j] = make_u32bit(key[4*j+3], key[4*j+2], key[4*j+1], key[4*j]);
W[length / 4] |= u32bit(1) << ((length%4)*8);
- serpent_key_schedule(W);
+ botan_serpent_ia32_key_schedule(W);
round_key.copy(W + 8, 132);
}
diff --git a/src/cipher/serpent_ia32/serp_ia32.h b/src/cipher/serpent_ia32/serp_ia32.h
new file mode 100644
index 000000000..26f870188
--- /dev/null
+++ b/src/cipher/serpent_ia32/serp_ia32.h
@@ -0,0 +1,33 @@
+/*************************************************
+* Serpent (IA-32) Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_SERPENT_IA32_H__
+#define BOTAN_SERPENT_IA32_H__
+
+#include <botan/base.h>
+
+namespace Botan {
+
+/*************************************************
+* Serpent *
+*************************************************/
+class BOTAN_DLL Serpent_IA32 : public BlockCipher
+ {
+ public:
+ void clear() throw() { round_key.clear(); }
+ std::string name() const { return "Serpent"; }
+ BlockCipher* clone() const { return new Serpent_IA32; }
+ Serpent_IA32() : BlockCipher(16, 16, 32, 8) {}
+ private:
+ void enc(const byte[], byte[]) const;
+ void dec(const byte[], byte[]) const;
+ void key(const byte[], u32bit);
+
+ SecureBuffer<u32bit, 132> round_key;
+ };
+
+}
+
+#endif
diff --git a/src/cipher/serpent_ia32/serp_asm.S b/src/cipher/serpent_ia32/serp_ia32_imp.S
index c8915382d..ddfcc7806 100644
--- a/src/cipher/serpent_ia32/serp_asm.S
+++ b/src/cipher/serpent_ia32/serp_ia32_imp.S
@@ -5,7 +5,7 @@
#include <botan/asm_macr.h>
-START_LISTING(serp_asm.S)
+START_LISTING(serp_ia32.S)
#define SBOX_E1(A, B, C, D, T) \
XOR(D, A) ; \
@@ -439,7 +439,7 @@ START_LISTING(serp_asm.S)
/*************************************************
* Serpent Encryption *
*************************************************/
-START_FUNCTION(serpent_encrypt)
+START_FUNCTION(botan_serpent_ia32_encrypt)
SPILL_REGS()
#define PUSHED 4
@@ -505,12 +505,12 @@ START_FUNCTION(serpent_encrypt)
RESTORE_REGS()
#undef PUSHED
-END_FUNCTION(serpent_encrypt)
+END_FUNCTION(botan_serpent_ia32_encrypt)
/*************************************************
* Serpent Decryption *
*************************************************/
-START_FUNCTION(serpent_decrypt)
+START_FUNCTION(botan_serpent_ia32_decrypt)
SPILL_REGS()
#define PUSHED 4
@@ -576,12 +576,12 @@ START_FUNCTION(serpent_decrypt)
RESTORE_REGS()
#undef PUSHED
-END_FUNCTION(serpent_decrypt)
+END_FUNCTION(botan_serpent_ia32_decrypt)
/*************************************************
* Serpent Key Schedule *
*************************************************/
-START_FUNCTION(serpent_key_schedule)
+START_FUNCTION(botan_serpent_ia32_key_schedule)
SPILL_REGS()
#define PUSHED 4
@@ -664,4 +664,4 @@ LOOP_UNTIL_EQ(ESI, 140, .EXPANSION)
RESTORE_REGS()
#undef PUSHED
-END_FUNCTION(serpent_key_schedule)
+END_FUNCTION(botan_serpent_ia32_key_schedule)