diff options
author | Keith Isdale <keith.isdale@nokia.com> | 2010-07-26 14:56:53 +1000 |
---|---|---|
committer | Keith Isdale <keith.isdale@nokia.com> | 2010-07-26 14:56:53 +1000 |
commit | 9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch) | |
tree | 63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/src/engine/openssl/arc4_openssl.cpp | |
parent | 619d92cfef29e653bfdf852e83888e50cfc4348f (diff) | |
parent | 65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff) |
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/src/engine/openssl/arc4_openssl.cpp')
-rw-r--r-- | botan/src/engine/openssl/arc4_openssl.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/botan/src/engine/openssl/arc4_openssl.cpp b/botan/src/engine/openssl/arc4_openssl.cpp new file mode 100644 index 0000000..08ed3eb --- /dev/null +++ b/botan/src/engine/openssl/arc4_openssl.cpp @@ -0,0 +1,82 @@ +/* +* OpenSSL ARC4 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/eng_ossl.h> +#include <botan/parsing.h> +#include <openssl/rc4.h> + +namespace Botan { + +namespace { + +/** +* ARC4 as implemented by OpenSSL +*/ +class ARC4_OpenSSL : public StreamCipher + { + public: + 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; + }; + +/* +* 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); + } + +} + +/** +* Look for an OpenSSL-suported stream cipher (ARC4) +*/ +StreamCipher* +OpenSSL_Engine::find_stream_cipher(const SCAN_Name& request, + Algorithm_Factory&) const + { + if(request.algo_name() == "ARC4") + return new ARC4_OpenSSL(request.arg_as_u32bit(0, 0)); + if(request.algo_name() == "RC4_drop") + return new ARC4_OpenSSL(768); + + return 0; + } + +} |