aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-28 23:58:33 +0000
committerlloyd <[email protected]>2008-09-28 23:58:33 +0000
commitc14cca7ef7338de3a8da784dd0865634b4110539 (patch)
tree069b52098e789d9cb7d0ee3fe889d9c8f860b0e9 /src
parent3bf4dc81e4b75a0dafacdc947089b3ec21193153 (diff)
Move mode padding schemes to modes/mode_pad module
Diffstat (limited to 'src')
-rw-r--r--src/def_alg.cpp8
-rw-r--r--src/modes/mode_pad/mode_pad.cpp (renamed from src/mode_pad.cpp)0
-rw-r--r--src/modes/mode_pad/mode_pad.h79
-rw-r--r--src/modes/mode_pad/modinfo.txt10
4 files changed, 95 insertions, 2 deletions
diff --git a/src/def_alg.cpp b/src/def_alg.cpp
index 80d3a771f..b13439fe2 100644
--- a/src/def_alg.cpp
+++ b/src/def_alg.cpp
@@ -7,8 +7,6 @@
#include <botan/libstate.h>
#include <botan/parsing.h>
-#include <botan/mode_pad.h>
-
#if defined(BOTAN_HAS_AES)
#include <botan/aes.h>
#endif
@@ -118,6 +116,10 @@
#include <botan/wid_wake.h>
#endif
+#if defined(BOTAN_HAS_CIPHER_MODE_PADDING)
+ #include <botan/mode_pad.h>
+#endif
+
#if defined(BOTAN_HAS_ADLER32)
#include <botan/adler32.h>
#endif
@@ -559,10 +561,12 @@ Default_Engine::find_bc_pad(const std::string& algo_spec) const
const std::string algo_name = global_state().deref_alias(name[0]);
+#if defined(BOTAN_HAS_CIPHER_MODE_PADDING)
HANDLE_TYPE_NO_ARGS("PKCS7", PKCS7_Padding);
HANDLE_TYPE_NO_ARGS("OneAndZeros", OneAndZeros_Padding);
HANDLE_TYPE_NO_ARGS("X9.23", ANSI_X923_Padding);
HANDLE_TYPE_NO_ARGS("NoPadding", Null_Padding);
+#endif
return 0;
}
diff --git a/src/mode_pad.cpp b/src/modes/mode_pad/mode_pad.cpp
index 3a07afcb4..3a07afcb4 100644
--- a/src/mode_pad.cpp
+++ b/src/modes/mode_pad/mode_pad.cpp
diff --git a/src/modes/mode_pad/mode_pad.h b/src/modes/mode_pad/mode_pad.h
new file mode 100644
index 000000000..4041efcdc
--- /dev/null
+++ b/src/modes/mode_pad/mode_pad.h
@@ -0,0 +1,79 @@
+/*************************************************
+* CBC Padding Methods Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_CBC_PADDING_H__
+#define BOTAN_CBC_PADDING_H__
+
+#include <botan/base.h>
+#include <string>
+
+namespace Botan {
+
+/*************************************************
+* Block Cipher Mode Padding Method *
+*************************************************/
+class BOTAN_DLL BlockCipherModePaddingMethod
+ {
+ public:
+ virtual void pad(byte[], u32bit, u32bit) const = 0;
+ virtual u32bit unpad(const byte[], u32bit) const = 0;
+ virtual u32bit pad_bytes(u32bit, u32bit) const;
+ virtual bool valid_blocksize(u32bit) const = 0;
+ virtual std::string name() const = 0;
+ virtual ~BlockCipherModePaddingMethod() {}
+ };
+
+/*************************************************
+* PKCS#7 Padding *
+*************************************************/
+class BOTAN_DLL PKCS7_Padding : public BlockCipherModePaddingMethod
+ {
+ public:
+ void pad(byte[], u32bit, u32bit) const;
+ u32bit unpad(const byte[], u32bit) const;
+ bool valid_blocksize(u32bit) const;
+ std::string name() const { return "PKCS7"; }
+ };
+
+/*************************************************
+* ANSI X9.23 Padding *
+*************************************************/
+class BOTAN_DLL ANSI_X923_Padding : public BlockCipherModePaddingMethod
+ {
+ public:
+ void pad(byte[], u32bit, u32bit) const;
+ u32bit unpad(const byte[], u32bit) const;
+ bool valid_blocksize(u32bit) const;
+ std::string name() const { return "X9.23"; }
+ };
+
+/*************************************************
+* One And Zeros Padding *
+*************************************************/
+class BOTAN_DLL OneAndZeros_Padding : public BlockCipherModePaddingMethod
+ {
+ public:
+ void pad(byte[], u32bit, u32bit) const;
+ u32bit unpad(const byte[], u32bit) const;
+ bool valid_blocksize(u32bit) const;
+ std::string name() const { return "OneAndZeros"; }
+ };
+
+/*************************************************
+* Null Padding *
+*************************************************/
+class BOTAN_DLL Null_Padding : public BlockCipherModePaddingMethod
+ {
+ public:
+ void pad(byte[], u32bit, u32bit) const { return; }
+ u32bit unpad(const byte[], u32bit size) const { return size; }
+ u32bit pad_bytes(u32bit, u32bit) const { return 0; }
+ bool valid_blocksize(u32bit) const { return true; }
+ std::string name() const { return "NoPadding"; }
+ };
+
+}
+
+#endif
diff --git a/src/modes/mode_pad/modinfo.txt b/src/modes/mode_pad/modinfo.txt
new file mode 100644
index 000000000..f22cf7411
--- /dev/null
+++ b/src/modes/mode_pad/modinfo.txt
@@ -0,0 +1,10 @@
+realname "Cipher Mode Padding Method"
+
+define CIPHER_MODE_PADDING
+
+load_on auto
+
+<add>
+mode_pad.cpp
+mode_pad.h
+</add>