aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-10 03:38:02 +0000
committerlloyd <[email protected]>2008-11-10 03:38:02 +0000
commit69002c47c0c4ea9ad4a8310d9f150388e10a7eb7 (patch)
treef630315f5e926d63b2f38780e2d00003a3f2c4a7
parentcabd8859a0cd87cf78ef1a48a8d59bf4a6fae81c (diff)
Make the ARC4 implementation from OpenSSL visible in arc4_openssl.h
-rw-r--r--src/libstate/engine/openssl/arc4_openssl.cpp41
-rw-r--r--src/libstate/engine/openssl/arc4_openssl.h34
-rw-r--r--src/libstate/engine/openssl/eng_ossl.cpp18
-rw-r--r--src/libstate/engine/openssl/info.txt3
-rw-r--r--src/libstate/engine/openssl/ossl_rc4.cpp92
5 files changed, 95 insertions, 93 deletions
diff --git a/src/libstate/engine/openssl/arc4_openssl.cpp b/src/libstate/engine/openssl/arc4_openssl.cpp
new file mode 100644
index 000000000..c1d0779b3
--- /dev/null
+++ b/src/libstate/engine/openssl/arc4_openssl.cpp
@@ -0,0 +1,41 @@
+/*************************************************
+* OpenSSL ARC4 Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/arc4_openssl.h>
+#include <botan/parsing.h>
+#include <openssl/rc4.h>
+
+namespace Botan {
+
+/*************************************************
+* Return the name of this type *
+*************************************************/
+std::string ARC4_OpenSSL::name() const
+ {
+ if(SKIP == 0) return "ARC4";
+ if(SKIP == 256) return "MARK-4";
+ else return "RC4_skip(" + to_string(SKIP) + ")";
+ }
+
+/*************************************************
+* ARC4 Key Schedule *
+*************************************************/
+void ARC4_OpenSSL::key_schedule(const byte key[], u32bit length)
+ {
+ RC4_set_key(&state, length, key);
+ byte dummy = 0;
+ for(u32bit j = 0; j != SKIP; j++)
+ RC4(&state, 1, &dummy, &dummy);
+ }
+
+/*************************************************
+* ARC4 Encryption *
+*************************************************/
+void ARC4_OpenSSL::cipher(const byte in[], byte out[], u32bit length)
+ {
+ RC4(&state, length, in, out);
+ }
+
+}
diff --git a/src/libstate/engine/openssl/arc4_openssl.h b/src/libstate/engine/openssl/arc4_openssl.h
new file mode 100644
index 000000000..445642c81
--- /dev/null
+++ b/src/libstate/engine/openssl/arc4_openssl.h
@@ -0,0 +1,34 @@
+/**
+* OpenSSL's ARC4
+*/
+
+#ifndef BOTAN_ARC4_OPENSSL_H__
+#define BOTAN_ARC4_OPENSSL_H__
+
+#include <botan/stream_cipher.h>
+#include <openssl/rc4.h>
+
+namespace Botan {
+
+class ARC4_OpenSSL : public StreamCipher
+ {
+ public:
+ std::string provider() const { return "openssl"; }
+
+ void clear() throw() { std::memset(&state, 0, sizeof(state)); }
+ std::string name() const;
+ StreamCipher* clone() const { return new ARC4_OpenSSL(SKIP); }
+
+ ARC4_OpenSSL(u32bit s = 0) : StreamCipher(1, 32), SKIP(s) { clear(); }
+ ~ARC4_OpenSSL() { clear(); }
+ private:
+ void cipher(const byte[], byte[], u32bit);
+ void key_schedule(const byte[], u32bit);
+
+ const u32bit SKIP;
+ RC4_KEY state;
+ };
+
+}
+
+#endif
diff --git a/src/libstate/engine/openssl/eng_ossl.cpp b/src/libstate/engine/openssl/eng_ossl.cpp
new file mode 100644
index 000000000..377332450
--- /dev/null
+++ b/src/libstate/engine/openssl/eng_ossl.cpp
@@ -0,0 +1,18 @@
+
+#include <openssl/eng_ossl.h>
+
+/**
+* Look for an OpenSSL-suported stream cipher (ARC4)
+*/
+StreamCipher*
+OpenSSL_Engine::find_stream_cipher(const std::string& algo_spec) const
+ {
+ SCAN_Name request(algo_spec);
+
+ if(request.algo_name() == "ARC4")
+ return new ARC4_OpenSSL(request.argument_as_u32bit(0, 0));
+ if(request.algo_name() == "RC4_drop")
+ return new ARC4_OpenSSL(768);
+
+ return 0;
+ }
diff --git a/src/libstate/engine/openssl/info.txt b/src/libstate/engine/openssl/info.txt
index 0f14ccc7d..38295cbf4 100644
--- a/src/libstate/engine/openssl/info.txt
+++ b/src/libstate/engine/openssl/info.txt
@@ -13,6 +13,8 @@ libstate
</requires>
<add>
+arc4_openssl.h
+arc4_openssl.cpp
bn_powm.cpp
bn_wrap.cpp
bn_wrap.h
@@ -24,5 +26,4 @@ ossl_elg.cpp
ossl_if.cpp
ossl_md.cpp
ossl_nr.cpp
-ossl_rc4.cpp
</add>
diff --git a/src/libstate/engine/openssl/ossl_rc4.cpp b/src/libstate/engine/openssl/ossl_rc4.cpp
deleted file mode 100644
index ed5c9714f..000000000
--- a/src/libstate/engine/openssl/ossl_rc4.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/*************************************************
-* OpenSSL ARC4 Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
-
-#include <botan/eng_ossl.h>
-#include <botan/parsing.h>
-#include <botan/libstate.h>
-#include <openssl/rc4.h>
-
-namespace Botan {
-
-namespace {
-
-/*************************************************
-* OpenSSL ARC4 *
-*************************************************/
-class OpenSSL_ARC4 : public StreamCipher
- {
- public:
- void clear() throw() { std::memset(&state, 0, sizeof(state)); }
- std::string name() const;
- StreamCipher* clone() const { return new OpenSSL_ARC4(SKIP); }
- OpenSSL_ARC4(u32bit s = 0) : StreamCipher(1, 32), SKIP(s) { clear(); }
- ~OpenSSL_ARC4() { clear(); }
- private:
- void cipher(const byte[], byte[], u32bit);
- void key_schedule(const byte[], u32bit);
-
- const u32bit SKIP;
- RC4_KEY state;
- };
-
-/*************************************************
-* Return the name of this type *
-*************************************************/
-std::string OpenSSL_ARC4::name() const
- {
- if(SKIP == 0) return "ARC4";
- if(SKIP == 256) return "MARK-4";
- else return "RC4_skip(" + to_string(SKIP) + ")";
- }
-
-/*************************************************
-* ARC4 Key Schedule *
-*************************************************/
-void OpenSSL_ARC4::key_schedule(const byte key[], u32bit length)
- {
- RC4_set_key(&state, length, key);
- byte dummy = 0;
- for(u32bit j = 0; j != SKIP; j++)
- RC4(&state, 1, &dummy, &dummy);
- }
-
-/*************************************************
-* ARC4 Encryption *
-*************************************************/
-void OpenSSL_ARC4::cipher(const byte in[], byte out[], u32bit length)
- {
- RC4(&state, length, in, out);
- }
-
-}
-
-/*************************************************
-* Look for an algorithm with this name *
-*************************************************/
-StreamCipher*
-OpenSSL_Engine::find_stream_cipher(const std::string& algo_spec) const
- {
- std::vector<std::string> name = parse_algorithm_name(algo_spec);
- if(name.size() == 0)
- return 0;
- const std::string algo_name = global_state().deref_alias(name[0]);
-
-#define HANDLE_TYPE_ONE_U32BIT(NAME, TYPE, DEFAULT) \
- if(algo_name == NAME) \
- { \
- if(name.size() == 1) \
- return new TYPE(DEFAULT); \
- if(name.size() == 2) \
- return new TYPE(to_u32bit(name[1])); \
- throw Invalid_Algorithm_Name(algo_spec); \
- }
-
- HANDLE_TYPE_ONE_U32BIT("ARC4", OpenSSL_ARC4, 0);
- HANDLE_TYPE_ONE_U32BIT("RC4_drop", OpenSSL_ARC4, 768);
-
- return 0;
- }
-
-}