diff options
| author | 2011-08-24 14:52:12 +0000 | |
|---|---|---|
| committer | 2011-08-24 14:52:12 +0000 | |
| commit | 3ac5d793bc937cb11cf6a465aa0468f11e792027 (patch) | |
| tree | 622d137f1e2bb887223ec178b6067816aa9825d1 /src/modules | |
| parent | reverted r5926: as supposed, it broke more than what it tried to fix (diff) | |
| download | KVIrc-3ac5d793bc937cb11cf6a465aa0468f11e792027.tar.gz KVIrc-3ac5d793bc937cb11cf6a465aa0468f11e792027.tar.bz2 KVIrc-3ac5d793bc937cb11cf6a465aa0468f11e792027.zip | |
droppped cryptopp dependency, as per resolution #4 of last week's ml discussion. Cryptopp will live in the 4.1-qtsockets branch and will maybe be re-merged in the future if it will catch up in sync with the openssl implementation
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5943 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/file/libkvifile.cpp | 92 | ||||
| -rw-r--r-- | src/modules/fish/libkvifish.cpp | 76 | ||||
| -rw-r--r-- | src/modules/rijndael/CMakeLists.txt | 38 | ||||
| -rw-r--r-- | src/modules/rijndael/libkvirijndael_cryptopp.cpp | 621 | ||||
| -rw-r--r-- | src/modules/rijndael/libkvirijndael_cryptopp.h | 146 | ||||
| -rw-r--r-- | src/modules/str/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/modules/str/libkvistr.cpp | 94 |
7 files changed, 27 insertions, 1046 deletions
diff --git a/src/modules/file/libkvifile.cpp b/src/modules/file/libkvifile.cpp index b0c5c8db1..5a41a63ba 100644 --- a/src/modules/file/libkvifile.cpp +++ b/src/modules/file/libkvifile.cpp @@ -44,43 +44,8 @@ #endif -#if defined(COMPILE_SSL_SUPPORT) && !defined(COMPILE_CRYPTOPP_SUPPORT) - // The current implementation +#if defined(COMPILE_SSL_SUPPORT) #include <openssl/evp.h> -#elif defined(COMPILE_CRYPTOPP_SUPPORT) - // The preferred new implementation (until QCryptographicHash supports all - // hashes we want). - // As Crypto++ is concerned for security they warn about MD5 and friends, - // but we can ignore that and therefore silence the warnings. - #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 - // Hashes (should cover most cases) - #include <cryptopp/md2.h> - #include <cryptopp/md4.h> - #include <cryptopp/md5.h> - #include <cryptopp/sha.h> - #include <cryptopp/ripemd.h> - #include <cryptopp/crc.h> - // Encoding - #include <cryptopp/hex.h> - // additional - #include <cryptopp/files.h> - #include <string> - // template function - template <typename T> - std::string CryptoPpFileHash(std::string szFileName){ - T hash; - std::string szDigest; - CryptoPP::FileSource(szFileName.c_str(), - true, - new CryptoPP::HashFilter( - hash, - new CryptoPP::HexEncoder( - new CryptoPP::StringSink(szDigest) - ) - ) - ); - return szDigest; - } #else // The fallback we can always use, but with very limited set of // functionality. @@ -1446,8 +1411,7 @@ static bool file_kvs_fnc_diskSpace(KviKvsModuleFunctionCall * c) Calculates a digest for the file identified by the given string using the algorithm passed as 2nd argument. Currently supported: md5 (default), md4, md2, sha1, mdc2, ripemd160 and dss1. - Requires OpenSSL support or (better) Crypto++, but offers a - minimal set of hashes in any case. + Requires OpenSSL support, but offers a minimal set of hashes in any case. */ static bool file_kvs_fnc_digest(KviKvsModuleFunctionCall * c) { @@ -1474,7 +1438,7 @@ static bool file_kvs_fnc_digest(KviKvsModuleFunctionCall * c) return true; } -#if defined(COMPILE_SSL_SUPPORT) && !defined(COMPILE_CRYPTOPP_SUPPORT) +#if defined(COMPILE_SSL_SUPPORT) if(szAlgo.isEmpty()) szAlgo = "md5"; EVP_MD_CTX mdctx; @@ -1506,56 +1470,6 @@ static bool file_kvs_fnc_digest(KviKvsModuleFunctionCall * c) #endif szResult.append(cBuffer); } -#elif defined(COMPILE_CRYPTOPP_SUPPORT) - // Crypto++ implementation - std::string szDigest; - std::string szMsg = szFile.toLocal8Bit().data(); - - if(szAlgo.toLower() == "sha1" || szAlgo.toLower() == "sha") - { - szDigest = CryptoPpFileHash<CryptoPP::SHA1>(szMsg); - } else if(szAlgo.toLower() == "sha224") - { - szDigest = CryptoPpFileHash<CryptoPP::SHA224>(szMsg); - } else if(szAlgo.toLower() == "sha256") - { - szDigest = CryptoPpFileHash<CryptoPP::SHA256>(szMsg); - } else if(szAlgo.toLower() == "sha384") - { - szDigest = CryptoPpFileHash<CryptoPP::SHA384>(szMsg); - } else if(szAlgo.toLower() == "sha512") - { - szDigest = CryptoPpFileHash<CryptoPP::SHA512>(szMsg); - } else if(szAlgo.toLower() == "ripemd128") - { - szDigest = CryptoPpFileHash<CryptoPP::RIPEMD128>(szMsg); - } else if(szAlgo.toLower() == "ripemd160") - { - szDigest = CryptoPpFileHash<CryptoPP::RIPEMD160>(szMsg); - } else if(szAlgo.toLower() == "ripemd256") - { - szDigest = CryptoPpFileHash<CryptoPP::RIPEMD256>(szMsg); - } else if(szAlgo.toLower() == "ripemd320") - { - szDigest = CryptoPpFileHash<CryptoPP::RIPEMD320>(szMsg); - } else if(szAlgo.toLower() == "crc32") - { - szDigest = CryptoPpFileHash<CryptoPP::CRC32>(szMsg); - } else if(szAlgo.toLower() == "md2") - { - szDigest = CryptoPpFileHash<CryptoPP::Weak::MD2>(szMsg); - } else if(szAlgo.toLower() == "md4") - { - szDigest = CryptoPpFileHash<CryptoPP::Weak::MD4>(szMsg); - } else if(szAlgo.toLower() == "md5") - { - szDigest = CryptoPpFileHash<CryptoPP::Weak::MD5>(szMsg); - } else { - c->warning(__tr2qs("Unsupported message digest.")); - return true; - } - - szResult.append(szDigest.c_str()); #else // fall back to QCryptographicHash QCryptographicHash::Algorithm qAlgo; if(szAlgo.toLower() == "sha1") diff --git a/src/modules/fish/libkvifish.cpp b/src/modules/fish/libkvifish.cpp index 2b80d2eff..fd24367d4 100644 --- a/src/modules/fish/libkvifish.cpp +++ b/src/modules/fish/libkvifish.cpp @@ -53,7 +53,7 @@ // KviApplication.cpp extern KVIRC_API KviCryptEngineManager * g_pCryptEngineManager; - #if defined(COMPILE_SSL_SUPPORT) && !defined(COMPILE_CRYPTOPP_SUPPORT) + #if defined(COMPILE_SSL_SUPPORT) #include <KviSSL.h> #include <openssl/blowfish.h> @@ -70,19 +70,6 @@ const char *g_fish_prime1080_hex="FBE1022E23D213E8ACFA9AE8B9DFADA3EA6B7AC7A7B7E95AB5EB2DF858921FEADE95E6AC7BE7DE6ADBAB8A783E7AF7A7FA6A2B7BEB1E72EAE2B72F9FA2BFB2A2EFBEFAC868BADB3E828FA8BADFADA3E4CC1BE7E8AFE85E9698A783EB68FA07A77AB6AD7BEB618ACF9CA2897EB28A6189EFA07AB99A8A7FA9AE299EFA7BA66DEAFEFBEFBF0B7D8B"; // const char *g_fish_prime1080_dec="12745216229761186769575009943944198619149164746831579719941140425076456621824834322853258804883232842877311723249782818608677050956745409379781245497526069657222703636504651898833151008222772087491045206203033063108075098874712912417029101508315117935752962862335062591404043092163187352352197487303798807791605274487594646923"; const char *g_fish_generator="2"; - - #elif defined( COMPILE_CRYPTOPP_SUPPORT ) - #include <cryptopp/dh.h> - #include <cryptopp/integer.h> - #include <cryptopp/osrng.h> - #include <cryptopp/sha.h> - - CryptoPP::DH * g_fish_dh = 0; - CryptoPP::SecByteBlock * g_fish_pubKey = 0; - CryptoPP::SecByteBlock * g_fish_privKey = 0; - - const char *g_fish_prime1080_hex="0xFBE1022E23D213E8ACFA9AE8B9DFADA3EA6B7AC7A7B7E95AB5EB2DF858921FEADE95E6AC7BE7DE6ADBAB8A783E7AF7A7FA6A2B7BEB1E72EAE2B72F9FA2BFB2A2EFBEFAC868BADB3E828FA8BADFADA3E4CC1BE7E8AFE85E9698A783EB68FA07A77AB6AD7BEB618ACF9CA2897EB28A6189EFA07AB99A8A7FA9AE299EFA7BA66DEAFEFBEFBF0B7D8B"; - const char *g_fish_generator="0x2"; #endif #define FISH_KEYLEN 180 @@ -90,7 +77,7 @@ static bool fish_DH1080_gen(unsigned char ** szPubKey, int * iLen) { - #if defined(COMPILE_SSL_SUPPORT) && !defined(COMPILE_CRYPTOPP_SUPPORT) + #if defined(COMPILE_SSL_SUPPORT) if(!g_fish_dh) { BIGNUM * dhp = BN_new(); @@ -115,33 +102,8 @@ BN_bn2bin(g_fish_dh->pub_key, *szPubKey); return true; - #elif defined( COMPILE_CRYPTOPP_SUPPORT ) - try { - if(!g_fish_dh) - { - CryptoPP::AutoSeededRandomPool rnd; - CryptoPP::Integer dhp(g_fish_prime1080_hex); - CryptoPP::Integer dhg(g_fish_generator); - - g_fish_dh = new CryptoPP::DH(); - g_fish_dh->AccessGroupParameters().Initialize(dhp, dhg); - - g_fish_pubKey = new CryptoPP::SecByteBlock(g_fish_dh->PublicKeyLength()); - g_fish_privKey = new CryptoPP::SecByteBlock(g_fish_dh->PrivateKeyLength()); - g_fish_dh->GenerateKeyPair(rnd, *g_fish_privKey, *g_fish_pubKey); - } - - *iLen = g_fish_pubKey->SizeInBytes(); - *szPubKey = (unsigned char *) KviMemory::allocate(*iLen); - KviMemory::copy(*szPubKey, g_fish_pubKey->BytePtr(), g_fish_pubKey->SizeInBytes()); - } catch(CryptoPP::Exception e) - { - qDebug("%s",__tr2qs("Crypto++ threw the following exception: %1").arg(QString(e.what())).toUtf8().data()); - return false; - } - return true; #else - qDebug("%s",__tr2qs("FiSH has been compiled without ssl or cryptopp support, unable to proceed").toUtf8().data()); + qDebug("%s",__tr2qs("FiSH has been compiled without ssl support, unable to proceed").toUtf8().data()); return false; #endif } @@ -177,8 +139,8 @@ int iMyPubKeyLen, * pMyPubKeyLen = &iMyPubKeyLen; if(!fish_DH1080_gen(&szMyPubKey, pMyPubKeyLen)) { - #if !defined(COMPILE_SSL_SUPPORT) && !defined(COMPILE_CRYPTOPP_SUPPORT) - c->warning(__tr2qs("FiSH has been compiled without ssl and crypto++ support, unable to proceed")); + #if !defined(COMPILE_SSL_SUPPORT) + c->warning(__tr2qs("FiSH has been compiled without ssl support, unable to proceed")); return false; #endif return false; @@ -236,7 +198,7 @@ KviCString szFinalKey; - #if defined(COMPILE_SSL_SUPPORT) && !defined(COMPILE_CRYPTOPP_SUPPORT) + #if defined(COMPILE_SSL_SUPPORT) unsigned char * secret=(unsigned char *) KviMemory::allocate(DH_size(g_fish_dh)); int secretLen; BIGNUM *bn = BN_bin2bn((unsigned char *) szHisPubKey.data(), szHisPubKey.size(),NULL); @@ -258,30 +220,8 @@ szFinalKey.stripRight('='); KviMemory::free(hashedSecret); - #elif defined( COMPILE_CRYPTOPP_SUPPORT ) - try { - CryptoPP::SecByteBlock byteHisPubKey((unsigned char *) szHisPubKey.data(), szHisPubKey.size()); - CryptoPP::SecByteBlock byteSharedSecret(g_fish_dh->AgreedValueLength()); - CryptoPP::SecByteBlock byteHashedSecret(g_fish_dh->AgreedValueLength()); - - if(!g_fish_dh->Agree(byteSharedSecret, *g_fish_privKey, byteHisPubKey)) - { - c->warning(__tr2qs("FiSH: error verificating peer public key (size=%1)").arg(szHisPubKey.size())); - return false; - } - - CryptoPP::SHA256().CalculateDigest(byteHashedSecret, byteSharedSecret, g_fish_dh->AgreedValueLength()); - szFinalKey.bufferToBase64((char *) byteHashedSecret.BytePtr(), SHA256_LEN); - //strip the trailing = - szFinalKey.stripRight('='); - - } catch(CryptoPP::Exception e) - { - c->warning(__tr2qs("Crypto++ threw the following exception: %1").arg(QString(e.what()))); - return false; - } #else - c->warning(__tr2qs("FiSH has been compiled without ssl and crypto++ support, unable to proceed")); + c->warning(__tr2qs("FiSH has been compiled without ssl support, unable to proceed")); return false; #endif @@ -341,7 +281,7 @@ static bool fish_module_init(KviModule * m) { #ifdef COMPILE_CRYPT_SUPPORT - #if defined( COMPILE_SSL_SUPPORT) && !defined(COMPILE_CRYPTOPP_SUPPORT) + #if defined( COMPILE_SSL_SUPPORT) KviSSL::globalSSLInit(); #endif m->kvsRegisterAppEventHandler(KviEvent_OnQueryNotice,fish_event_onQueryNotice); diff --git a/src/modules/rijndael/CMakeLists.txt b/src/modules/rijndael/CMakeLists.txt index dab16ee57..f1bbd714f 100644 --- a/src/modules/rijndael/CMakeLists.txt +++ b/src/modules/rijndael/CMakeLists.txt @@ -1,36 +1,24 @@ # CMakeLists for src/modules/rijndael -IF(WANT_CRYPTOPP OR WANT_OPENSSL) - +IF(WANT_OPENSSL) SUBDIRS(caps) - IF(WANT_CRYPTOPP) - SET(kvirijndael_SRCS - libkvirijndael_cryptopp.cpp - UglyBase64.cpp - ) - - SET(kvirijndael_MOC_HDRS - libkvirijndael_cryptopp.h - ) - ELSE(WANT_CRYPTOPP) - SET(kvirijndael_SRCS - libkvirijndael.cpp - Rijndael.cpp - BlowFish.cpp - UglyBase64.cpp - InitVectorEngine.cpp - ) + SET(kvirijndael_SRCS + libkvirijndael.cpp + Rijndael.cpp + BlowFish.cpp + UglyBase64.cpp + InitVectorEngine.cpp + ) - SET(kvirijndael_MOC_HDRS - libkvirijndael.h - ) - ENDIF(WANT_CRYPTOPP) + SET(kvirijndael_MOC_HDRS + libkvirijndael.h + ) # After this call, files will be moc'ed to moc_kvi_*.cpp QT4_WRAP_CPP(kvirijndael_MOC_SRCS ${kvirijndael_MOC_HDRS}) - SET(ADDITIONAL_COMPILE_FLAGS "${ADDITIONAL_COMPILE_FLAGS} -fno-strict-aliasing") + # SET(ADDITIONAL_COMPILE_FLAGS "${ADDITIONAL_COMPILE_FLAGS} -fno-strict-aliasing") SET(kvi_module_name kvirijndael) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/module.rules.txt) -ENDIF(WANT_CRYPTOPP OR WANT_OPENSSL) +ENDIF() diff --git a/src/modules/rijndael/libkvirijndael_cryptopp.cpp b/src/modules/rijndael/libkvirijndael_cryptopp.cpp deleted file mode 100644 index c6f0cb8a1..000000000 --- a/src/modules/rijndael/libkvirijndael_cryptopp.cpp +++ /dev/null @@ -1,621 +0,0 @@ -//============================================================================= -// -// File : libkvirijndael_cryptopp.cpp -// Creation date : Fri, 17 Jul 2009 22:04:54 +0200 by Kai Wasserbäch -// based on libkvirijndael.cpp as this aims to be a drop-in replacement -// -// This file is part of the KVIrc irc client distribution -// Copyright © 2009 Kai Wasserbäch <debian@carbon-project.org> -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -#include "libkvirijndael_cryptopp.h" - -#include "KviModule.h" -#include "kvi_debug.h" -#include "KviLocale.h" -#include "KviPointerList.h" -#include "KviCryptEngineDescription.h" -#include "KviControlCodes.h" -#include "UglyBase64.h" - -#include <cryptopp/aes.h> -#include <cryptopp/blowfish.h> -#include <cryptopp/modes.h> -#include <cryptopp/base64.h> -#include <cryptopp/hex.h> -#include <cryptopp/osrng.h> -#include <string> - - -/* - @doc: rijndael - @type: - module - @short: - The Rijndael cryptographic engines - @title: - The rijndael module - @body: - The rijndael module exports six [doc:crypt_engines]cryptographic engines[/doc] based - on the Advanced Encryptiong Standard algorithm called Rijndael. Rijndael was - originally written by Joan Daemen and Vincent Rijmen. The original Rijndael - description is available at http://www.esat.kuleuven.ac.be/~rijmen/rijndael/.[br] - It is a private key block cipher that has been designed to replace - the widely used DES, and it should provide at least a decent security against - common attacks. Theoretically the best attack that one can perform on this cipher - is the "brute force" attack that requires a really massive parallel computation: - actually out of the possibilities of a common "hacker".[br] - My implementation allows the usage of 128, 192 and 256 bit keys - on 128 bit data blocks. The encrypted binary data buffer is then converted - into an ascii-string by using the base64 conversion or hex-digit-string representation. - The six engines are the six possible combinations of the key lengths and ascii-string - conversions. -*/ - - -static KviPointerList<KviCryptEngine> * g_pEngineList = 0; - -// The following lines contain a compatible (to the embedded version) -// implementation of the KviCryptEngine for Rijndael. Therefore the output -// gets encoded the same way (Hex or ASCII) as with the embedded version. -KviRijndaelEngine::KviRijndaelEngine() -: KviCryptEngine() -{ - g_pEngineList->append(this); - m_szEncKey.clear(); - m_szDecKey.clear(); -} - -KviRijndaelEngine::~KviRijndaelEngine() -{ - g_pEngineList->removeRef(this); - m_szEncKey.clear(); - m_szDecKey.clear(); -} - -bool KviRijndaelEngine::init(const char * pcEncKey, int iEncKeyLen, const char * pcDecKey, int iDecKeyLen) -{ - if(pcEncKey && (iEncKeyLen > 0)) - { - if(!(pcDecKey && (iDecKeyLen > 0))) - { - pcDecKey = pcEncKey; - iDecKeyLen = iEncKeyLen; - } // else all - } else { - // no encrypt key specified... - if(pcDecKey && iDecKeyLen) - { - pcEncKey = pcDecKey; - iEncKeyLen = iDecKeyLen; - } else { - // both keys missing - setLastError(__tr2qs("Missing encryption and decryption key: at least one is needed")); - return false; - } - } - - m_szEncKey = pcEncKey; - m_szDecKey = pcDecKey; - - if(iEncKeyLen > getKeyLen()) - m_szEncKey = m_szEncKey.substr(0,getKeyLen()); - - if(iEncKeyLen < getKeyLen()) - m_szEncKey.resize(getKeyLen()); - - if(iDecKeyLen > getKeyLen()) - m_szDecKey = m_szDecKey.substr(0,getKeyLen()); - - if(iDecKeyLen < getKeyLen()) - m_szDecKey.resize(getKeyLen()); - - if(m_szEncKey.empty() || m_szDecKey.empty()) - return false; - else - return true; -} - -KviCryptEngine::EncryptResult KviRijndaelEngine::encrypt(const char * pcPlainText, KviCString & szOutBuffer) -{ - std::string szCipher; - // byte is a typedef by Crypto++ for unsigned char. - byte key[m_szEncKey.size()],iv[CryptoPP::AES::BLOCKSIZE]; - - for(unsigned int u=0;u<m_szEncKey.size();u++) - key[u] = m_szEncKey[u]; - - // The following is absolute shit, but the module we replace does it like - // that, so we hardcode the IV to 0 in the required length... - for(unsigned int u=0;u<sizeof(iv);u++) - iv[u] = 0x00; - - // We hardcode CBC mode here, as the embedded code is always called in - // CBC mode too (see above, line 148), no need to use the external - // cipher object. - // The padding mode is enforced to be - // CryptoPP::BlockPaddingSchemeDef::ZEROS_PADDING, as the embedded code - // does only that. - try { - CryptoPP::CBC_Mode< CryptoPP::AES >::Encryption encryptor( key, sizeof(key), iv ); - - if(getEncoding() == KVI_RIJNDAEL_HEX) - { - CryptoPP::StringSource(static_cast<std::string>(pcPlainText), true, - new CryptoPP::StreamTransformationFilter( - encryptor, new CryptoPP::HexEncoder( - new CryptoPP::StringSink( szCipher ) - ), CryptoPP::BlockPaddingSchemeDef::ZEROS_PADDING - ) - ); - } else if(getEncoding() == KVI_RIJNDAEL_B64) - { - CryptoPP::StringSource(static_cast<std::string>(pcPlainText), true, - new CryptoPP::StreamTransformationFilter( - encryptor, new CryptoPP::Base64Encoder( - new CryptoPP::StringSink( szCipher ) - ), CryptoPP::BlockPaddingSchemeDef::ZEROS_PADDING - ) - ); - } else { - setLastError(__tr2qs("Unable to determine output encoding (Hex or Base64).")); - return KviCryptEngine::EncryptError; - } - } catch(CryptoPP::Exception e) - { - QString staticErrTxt = __tr2qs("Crypto++ threw the following exception: "); - setLastError(staticErrTxt.append(QString(e.what()))); - return KviCryptEngine::EncryptError; - } - - szOutBuffer = szCipher.c_str(); - szOutBuffer.prepend(KviControlCodes::CryptEscape); - return KviCryptEngine::Encrypted; -} - -KviCryptEngine::DecryptResult KviRijndaelEngine::decrypt(const char * pcInBuffer, KviCString & szPlainText) -{ - std::string szPlain; - byte key[m_szDecKey.size()],iv[CryptoPP::AES::BLOCKSIZE]; - std::string szIn = pcInBuffer; - - for(unsigned int u=0;u<m_szDecKey.size();u++) - key[u] = m_szDecKey[u]; - - // The following is absolute shit, but the module we replace does it like - // that, so we hardcode the IV to 0 in the required length... - for(unsigned int u=0;u<sizeof(iv);u++) - iv[u] = 0x00; - - if(static_cast<int>(szIn[0]) != KviControlCodes::CryptEscape) - { - szPlainText = pcInBuffer; - return KviCryptEngine::DecryptOkWasPlainText; - } - - szIn = szIn.erase(0,1); - - if(szIn.empty()) - { - szPlainText = pcInBuffer; - return KviCryptEngine::DecryptOkWasPlainText; // empty buffer - } - - try { - CryptoPP::CBC_Mode< CryptoPP::AES >::Decryption decryptor( key, sizeof(key), iv ); - - if(getEncoding() == KVI_RIJNDAEL_HEX) - { - CryptoPP::StringSource(szIn, true, - new CryptoPP::HexDecoder( - new CryptoPP::StreamTransformationFilter( - decryptor, new CryptoPP::StringSink( szPlain ), - CryptoPP::BlockPaddingSchemeDef::ZEROS_PADDING ) - ) - ); - } else if(getEncoding() == KVI_RIJNDAEL_B64) - { - CryptoPP::StringSource(szIn, true, - new CryptoPP::Base64Decoder( - new CryptoPP::StreamTransformationFilter( - decryptor, new CryptoPP::StringSink( szPlain ), - CryptoPP::BlockPaddingSchemeDef::ZEROS_PADDING ) - ) - ); - } else { - setLastError(__tr2qs("Unable to determine input encoding (Hex or Base64).")); - return KviCryptEngine::DecryptError; - } - } catch(CryptoPP::Exception e) - { - QString staticErrTxt = __tr2qs("Crypto++ threw the following exception: "); - setLastError(staticErrTxt.append(QString(e.what()))); - return KviCryptEngine::DecryptError; - } - - szPlainText = szPlain.c_str(); - return KviCryptEngine::DecryptOkWasEncrypted; -} - -// The following is needed in either case -static KviCryptEngine * allocRijndael128HexEngine() -{ - return new KviRijndael128HexEngine(); -} - -static KviCryptEngine * allocRijndael192HexEngine() -{ - return new KviRijndael192HexEngine(); -} - -static KviCryptEngine * allocRijndael256HexEngine() -{ - return new KviRijndael256HexEngine(); -} - -static KviCryptEngine * allocRijndael128Base64Engine() -{ - return new KviRijndael128Base64Engine(); -} - -static KviCryptEngine * allocRijndael192Base64Engine() -{ - return new KviRijndael192Base64Engine(); -} - -static KviCryptEngine * allocRijndael256Base64Engine() -{ - return new KviRijndael256Base64Engine(); -} - -static void deallocRijndaelCryptEngine(KviCryptEngine * e) -{ - delete e; -} - -// Again a compatible (to the embedded version) implementation of the -// KviCryptEngine, this time for Blowfish. -KviMircryptionEngine::KviMircryptionEngine() -: KviCryptEngine() -{ - g_pEngineList->append(this); - m_szEncKey.clear(); - m_szDecKey.clear(); -} - -KviMircryptionEngine::~KviMircryptionEngine() -{ - g_pEngineList->removeRef(this); - m_szEncKey.clear(); - m_szDecKey.clear(); -} - -bool KviMircryptionEngine::init(const char * pcEncKey, int iEncKeyLen, const char * pcDecKey, int iDecKeyLen) -{ - if(pcEncKey && (iEncKeyLen > 0)) - { - if(!(pcDecKey && (iDecKeyLen > 0))) - { - pcDecKey = pcEncKey; - iDecKeyLen = iEncKeyLen; - } // else all - } else { - // no encrypt key specified... - if(pcDecKey && iDecKeyLen) - { - pcEncKey = pcDecKey; - iEncKeyLen = iDecKeyLen; - } else { - // both keys missing - setLastError(__tr2qs("Missing encryption and decryption key: at least one is needed")); - return false; - } - } - - m_szEncKey = std::string(pcEncKey,iEncKeyLen); - m_szDecKey = std::string(pcDecKey,iDecKeyLen); - - if((m_szEncKey.find("cbc:",0,4) != std::string::npos) && (m_szEncKey.size() > 4)) - { - m_szEncKey = m_szEncKey.substr(4); - m_bEncryptCBC = true; - } else { - m_bEncryptCBC = false; - } - - if((m_szDecKey.find("cbc:",0,4) != std::string::npos) && (m_szDecKey.size() > 4)) - { - m_szDecKey = m_szDecKey.substr(4); - m_bDecryptCBC = true; - } else { - m_bDecryptCBC = false; - } - - return true; -} - -KviCryptEngine::EncryptResult KviMircryptionEngine::encrypt(const char * pcPlainText, KviCString & szOutBuffer) -{ - std::string szCipher; - byte key[m_szEncKey.size()], iv[CryptoPP::Blowfish::BLOCKSIZE]; - - for(unsigned int u=0;u<m_szEncKey.size();u++) - key[u] = m_szEncKey.at(u); - - if(m_bEncryptCBC) - { - try { - for(unsigned int u=0;u<sizeof(iv);u++) - iv[u] = 0x00; - - CryptoPP::CBC_Mode< CryptoPP::Blowfish >::Encryption encryptor( key, sizeof(key), iv ); - CryptoPP::StringSource(static_cast<std::string>(pcPlainText), true, - new CryptoPP::StreamTransformationFilter( - encryptor, new CryptoPP::Base64Encoder( - new CryptoPP::StringSink( szCipher ) - ), CryptoPP::BlockPaddingSchemeDef::ZEROS_PADDING - ) - ); - } catch(CryptoPP::Exception e) - { - QString staticErrTxt = __tr2qs("Crypto++ threw the following exception: "); - setLastError(staticErrTxt.append(QString(e.what()))); - return KviCryptEngine::EncryptError; - } - szOutBuffer = szCipher.c_str(); - } else { - try { - CryptoPP::ECB_Mode< CryptoPP::Blowfish >::Encryption encryptor( key, sizeof(key) ); - CryptoPP::StringSource(static_cast<std::string>(pcPlainText), true, - new CryptoPP::StreamTransformationFilter( - encryptor, new CryptoPP::StringSink( szCipher ), - CryptoPP::BlockPaddingSchemeDef::ZEROS_PADDING - ) - ); - } catch(CryptoPP::Exception e) - { - QString staticErrTxt = __tr2qs("Crypto++ threw the following exception: "); - setLastError(staticErrTxt.append(QString(e.what()))); - return KviCryptEngine::EncryptError; - } - szOutBuffer = szCipher.c_str(); - UglyBase64::encode((const unsigned char*) szCipher.c_str(), szCipher.size() , szOutBuffer); - } - - szOutBuffer.prepend("+OK "); - - return KviCryptEngine::Encrypted; -} - -KviCryptEngine::DecryptResult KviMircryptionEngine::decrypt(const char * pcInBuffer, KviCString & szPlainText) -{ - std::string szPlain; - std::string szIn = pcInBuffer; - byte key[m_szDecKey.size()], iv[CryptoPP::Blowfish::BLOCKSIZE]; - - // various old versions - if(szIn.find("mcps ",0,5) != std::string::npos) - szIn = szIn.substr(5); - else if(szIn.find("+OK ",0,4) != std::string::npos) - szIn = szIn.substr(4); - else if(szIn.find("OK ",0,3) != std::string::npos) { - // some servers seem to strip the + at the beginning... - szIn = szIn.substr(3); - } else { - szPlainText = szIn.c_str(); - return KviCryptEngine::DecryptOkWasPlainText; - } - - for(unsigned int u=0;u<m_szDecKey.size();u++) - key[u] = m_szDecKey.at(u); - - if(m_bDecryptCBC) - { - try { - for(unsigned int u=0;u<sizeof(iv);u++) - iv[u] = 0x00; - - CryptoPP::CBC_Mode< CryptoPP::Blowfish >::Decryption decryptor( key, sizeof(key), iv ); - CryptoPP::StringSource(szIn, true, - new CryptoPP::Base64Decoder( - new CryptoPP::StreamTransformationFilter( - decryptor, - new CryptoPP::StringSink( szPlain ), - CryptoPP::BlockPaddingSchemeDef::ZEROS_PADDING - ) - ) - ); - } catch(CryptoPP::Exception e) - { - QString staticErrTxt = __tr2qs("Crypto++ threw the following exception: "); - setLastError(staticErrTxt.append(QString(e.what()))); - return KviCryptEngine::DecryptError; - } - } else { - unsigned char * buf=0; - int len; - KviCString szTmp = szIn.c_str(); - UglyBase64::decode(szTmp, &buf, &len); - szIn.assign((const char*)buf, (size_t) len); - KviMemory::free(buf); - - try { - CryptoPP::ECB_Mode< CryptoPP::Blowfish >::Decryption decryptor( key, sizeof(key) ); - CryptoPP::StringSource(szIn, true, - new CryptoPP::StreamTransformationFilter( - decryptor, new CryptoPP::StringSink( szPlain ), - CryptoPP::BlockPaddingSchemeDef::ZEROS_PADDING ) - ); - } catch(CryptoPP::Exception e) - { - QString staticErrTxt = __tr2qs("Crypto++ threw the following exception: "); - setLastError(staticErrTxt.append(QString(e.what()))); - return KviCryptEngine::DecryptError; - } - } - - szPlainText = szPlain.c_str(); - return KviCryptEngine::DecryptOkWasEncrypted; -} - -static KviCryptEngine * allocMircryptionEngine() -{ - return new KviMircryptionEngine(); -} - -// ======================================= -// module routines -// ======================================= -static bool rijndael_module_init(KviModule * m) -{ - g_pEngineList = new KviPointerList<KviCryptEngine>; - g_pEngineList->setAutoDelete(false); - - QString szFormat = __tr2qs("Cryptographic engine based on the\n" \ - "Advanced Encryption Standard (AES)\n" \ - "algorithm called Rijndael.\n" \ - "The text is first encrypted with Rijndael\n" \ - "and then converted to %1 notation.\n" \ - "The keys used are %2 bit long and will be padded\n" \ - "with zeros if you provide shorter ones.\n" \ - "If only one key is provided, this engine\n" \ - "will use it for both encryption and decryption.\n\n" \ - "This is the Crypto++ implementation which could do\n" \ - "a lot more than the current default engine, but as\n" \ - "this should be a drop-in replacement, it acts just\n" \ - "like the original one.\n" \ - "Information about the algorithm can be found at\n" \ - "<http://www.cryptolounge.org/wiki/AES>\n"); - - // FIXME: Maybe convert this repeated code to a function eh ? - - KviCryptEngineDescription * d = new KviCryptEngineDescription; - d->m_szName = "Rijndael128Hex"; - d->m_szAuthor = "Kai Wasserbäch"; - d->m_szDescription = QString(szFormat).arg(__tr2qs("hexadecimal")).arg(128); - d->m_iFlags = KviCryptEngine::CanEncrypt | KviCryptEngine::CanDecrypt | - KviCryptEngine::WantEncryptKey | KviCryptEngine::WantDecryptKey; - d->m_allocFunc = allocRijndael128HexEngine; - d->m_deallocFunc = deallocRijndaelCryptEngine; - m->registerCryptEngine(d); - - d = new KviCryptEngineDescription; - d->m_szName = "Rijndael192Hex"; - d->m_szAuthor = "Kai Wasserbäch"; - d->m_szDescription = QString(szFormat).arg(__tr2qs("hexadecimal")).arg(192); - d->m_iFlags = KviCryptEngine::CanEncrypt | KviCryptEngine::CanDecrypt | - KviCryptEngine::WantEncryptKey | KviCryptEngine::WantDecryptKey; - d->m_allocFunc = allocRijndael192HexEngine; - d->m_deallocFunc = deallocRijndaelCryptEngine; - m->registerCryptEngine(d); - - d = new KviCryptEngineDescription; - d->m_szName = "Rijndael256Hex"; - d->m_szAuthor = "Kai Wasserbäch"; - d->m_szDescription = QString(szFormat).arg(__tr2qs("hexadecimal")).arg(256); - d->m_iFlags = KviCryptEngine::CanEncrypt | KviCryptEngine::CanDecrypt | - KviCryptEngine::WantEncryptKey | KviCryptEngine::WantDecryptKey; - d->m_allocFunc = allocRijndael256HexEngine; - d->m_deallocFunc = deallocRijndaelCryptEngine; - m->registerCryptEngine(d); - - d = new KviCryptEngineDescription; - d->m_szName = "Rijndael128Base64"; - d->m_szAuthor = "Kai Wasserbäch"; - d->m_szDescription = QString(szFormat).arg(__tr2qs("base64")).arg(128); - d->m_iFlags = KviCryptEngine::CanEncrypt | KviCryptEngine::CanDecrypt | - KviCryptEngine::WantEncryptKey | KviCryptEngine::WantDecryptKey; - d->m_allocFunc = allocRijndael128Base64Engine; - d->m_deallocFunc = deallocRijndaelCryptEngine; - m->registerCryptEngine(d); - - d = new KviCryptEngineDescription; - d->m_szName = "Rijndael192Base64"; - d->m_szAuthor = "Kai Wasserbäch"; - d->m_szDescription = QString(szFormat).arg(__tr2qs("base64")).arg(192); - d->m_iFlags = KviCryptEngine::CanEncrypt | KviCryptEngine::CanDecrypt | - KviCryptEngine::WantEncryptKey | KviCryptEngine::WantDecryptKey; - d->m_allocFunc = allocRijndael192Base64Engine; - d->m_deallocFunc = deallocRijndaelCryptEngine; - m->registerCryptEngine(d); - - d = new KviCryptEngineDescription; - d->m_szName = "Rijndael256Base64"; - d->m_szAuthor = "Kai Wasserbäch"; - d->m_szDescription = QString(szFormat).arg(__tr2qs("base64")).arg(256); - d->m_iFlags = KviCryptEngine::CanEncrypt | KviCryptEngine::CanDecrypt | - KviCryptEngine::WantEncryptKey | KviCryptEngine::WantDecryptKey; - d->m_allocFunc = allocRijndael256Base64Engine; - d->m_deallocFunc = deallocRijndaelCryptEngine; - m->registerCryptEngine(d); - - d = new KviCryptEngineDescription; - d->m_szName = "Mircryption"; - d->m_szAuthor = "Kai Wasserbäch"; - d->m_szDescription = __tr2qs("Popular cryptographic engine based on the\n" \ - "old Blowfish encryption algorithm.\n" \ - "The text is first encrypted with Blowfish \n" \ - "and then base64 encoded.\n" \ - "Keys of variable length can be used and\n" \ - "are specified as character strings.\n" \ - "Keys can be up to 56 bytes (448 bits) long.\n" \ - "If only one key is provided, this engine\n" \ - "will use it for encryption and decryption.\n" \ - "This engine works in ECB mode by default,\n" \ - "if you want to use CBC mode you must prefix\n" \ - "your key(s) with \"cbc:\".\n\n" \ - "This is the Crypto++ based version, not relying on embedded code\n"); - d->m_iFlags = KviCryptEngine::CanEncrypt | KviCryptEngine::CanDecrypt | - KviCryptEngine::WantEncryptKey | KviCryptEngine::WantDecryptKey; - d->m_allocFunc = allocMircryptionEngine; - d->m_deallocFunc = deallocRijndaelCryptEngine; - m->registerCryptEngine(d); - - return true; -} - -static bool rijndael_module_cleanup(KviModule * m) -{ - while(g_pEngineList->first()) - delete g_pEngineList->first(); - delete g_pEngineList; - g_pEngineList = 0; - m->unregisterCryptEngines(); - return true; -} - -static bool rijndael_module_can_unload(KviModule *) -{ - return g_pEngineList->isEmpty(); -} - -// ======================================= -// plugin definition structure -// ======================================= -KVIRC_MODULE( - "Rijndael crypt engine", - "4.0.1", - "Copyright © 2009 Kai Wasserbäch <debian@carbon-project.org>" \ - " © 2000-2010 Szymon Stefanek <pragma at kvirc dot net>", - "Exports the rijndael crypt engine", - rijndael_module_init, - rijndael_module_can_unload, - 0, - rijndael_module_cleanup, - 0 -) diff --git a/src/modules/rijndael/libkvirijndael_cryptopp.h b/src/modules/rijndael/libkvirijndael_cryptopp.h deleted file mode 100644 index 36cd5e20c..000000000 --- a/src/modules/rijndael/libkvirijndael_cryptopp.h +++ /dev/null @@ -1,146 +0,0 @@ -#ifndef _LIBKVIRIJNDAEL_H_ -#define _LIBKVIRIJNDAEL_H_ -//============================================================================= -// -// File : libkvirijndael_cryptopp.h -// Creation date : Fri, 17 Jul 2009 22:04:54 +0200 by Kai Wasserbäch -// based on libkvirjndael.h as this is aimed as drop-in replacement. -// -// This file is part of the KVIrc irc client distribution -// Copyright © 2009 Kai Wasserbäch <debian@carbon-project.org> -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -#include "kvi_settings.h" - -//base class -#include "KviCryptEngine.h" - -// class definitions for the libcrypto++ case -#include <cryptopp/aes.h> -#include <cryptopp/blowfish.h> -#include <string> - -// The following two defines are to indicate the in-/output encoding (hex -// or Base64). -#define KVI_RIJNDAEL_HEX 0 -#define KVI_RIJNDAEL_B64 1 - -// AES/Rijndael -class KviRijndaelEngine : public KviCryptEngine -{ - Q_OBJECT -public: - KviRijndaelEngine(); - virtual ~KviRijndaelEngine(); -protected: - virtual int getKeyLen(){ return CryptoPP::AES::DEFAULT_KEYLENGTH; }; - virtual int getEncoding(){ return KVI_RIJNDAEL_HEX; }; -private: - std::string m_szEncKey; - std::string m_szDecKey; -public: - virtual bool init(const char * pcEncKey, int iEncKeyLen, const char * pcDecKey, int iDecKeyLen); - virtual KviCryptEngine::EncryptResult encrypt(const char * pcPlainText, KviCString & szOutBuffer); - virtual KviCryptEngine::DecryptResult decrypt(const char * pcInBuffer, KviCString & szPlainText); -}; - -class KviRijndael128HexEngine : public KviRijndaelEngine -{ - Q_OBJECT -public: - KviRijndael128HexEngine() : KviRijndaelEngine() {}; - virtual ~KviRijndael128HexEngine(){}; -protected: - virtual int getKeyLen(){ return CryptoPP::AES::MIN_KEYLENGTH; }; - virtual int getEncoding(){ return KVI_RIJNDAEL_HEX; }; -}; - -class KviRijndael192HexEngine : public KviRijndaelEngine -{ - Q_OBJECT -public: - KviRijndael192HexEngine() : KviRijndaelEngine() {}; - virtual ~KviRijndael192HexEngine(){}; -protected: - virtual int getKeyLen(){ return (CryptoPP::AES::MIN_KEYLENGTH + CryptoPP::AES::KEYLENGTH_MULTIPLE); }; - virtual int getEncoding() { return KVI_RIJNDAEL_HEX; }; -}; - -class KviRijndael256HexEngine : public KviRijndaelEngine -{ - Q_OBJECT -public: - KviRijndael256HexEngine() : KviRijndaelEngine() {}; - virtual ~KviRijndael256HexEngine(){}; -protected: - virtual int getKeyLen(){ return CryptoPP::AES::MAX_KEYLENGTH; }; - virtual int getEncoding() { return KVI_RIJNDAEL_HEX; }; -}; - -class KviRijndael128Base64Engine : public KviRijndaelEngine -{ - Q_OBJECT -public: - KviRijndael128Base64Engine() : KviRijndaelEngine() {}; - virtual ~KviRijndael128Base64Engine(){}; -protected: - virtual int getKeyLen(){ return CryptoPP::AES::MIN_KEYLENGTH; }; - virtual int getEncoding() { return KVI_RIJNDAEL_B64; }; -}; - -class KviRijndael192Base64Engine : public KviRijndaelEngine -{ - Q_OBJECT -public: - KviRijndael192Base64Engine() : KviRijndaelEngine() {}; - virtual ~KviRijndael192Base64Engine(){}; -protected: - virtual int getKeyLen(){ return (CryptoPP::AES::MIN_KEYLENGTH + CryptoPP::AES::KEYLENGTH_MULTIPLE); }; - virtual int getEncoding() { return KVI_RIJNDAEL_B64; }; -}; - -class KviRijndael256Base64Engine : public KviRijndaelEngine -{ - Q_OBJECT -public: - KviRijndael256Base64Engine() : KviRijndaelEngine() {}; - virtual ~KviRijndael256Base64Engine(){}; -protected: - virtual int getKeyLen(){ return CryptoPP::AES::MAX_KEYLENGTH; }; - virtual int getEncoding() { return KVI_RIJNDAEL_B64; }; -}; - -// Blowfish (named »Mircryption« to be a real drop in replacement, hopefully) -class KviMircryptionEngine : public KviCryptEngine -{ - Q_OBJECT -public: - KviMircryptionEngine(); - ~KviMircryptionEngine(); - - virtual bool init(const char * pcEncKey, int iEncKeyLen, const char * pcDecKey, int iDecKeyLen); - virtual KviCryptEngine::EncryptResult encrypt(const char * pcPlainText, KviCString & szOutBuffer); - virtual KviCryptEngine::DecryptResult decrypt(const char * pcInBuffer, KviCString & szPlainText); -private: - std::string m_szEncKey; - std::string m_szDecKey; - bool m_bEncryptCBC; - bool m_bDecryptCBC; -}; - -#endif // _LIBKVIRIJNDAEL_H_ diff --git a/src/modules/str/CMakeLists.txt b/src/modules/str/CMakeLists.txt index c0c5bbf1f..aa8fb3cf9 100644 --- a/src/modules/str/CMakeLists.txt +++ b/src/modules/str/CMakeLists.txt @@ -1,11 +1,5 @@ # CMakeLists for src/modules/str -IF(UNIX) - IF(APPLE) - LIST(APPEND LIBS -lssl -lcrypto) - ENDIF() -ENDIF() - SET(kvistr_SRCS libkvistr.cpp ) diff --git a/src/modules/str/libkvistr.cpp b/src/modules/str/libkvistr.cpp index fdd26f593..3b6de7bf3 100644 --- a/src/modules/str/libkvistr.cpp +++ b/src/modules/str/libkvistr.cpp @@ -43,44 +43,7 @@ #include <KviSSL.h> #include <openssl/evp.h> #include <openssl/pem.h> -#endif - -#ifdef COMPILE_CRYPTOPP_SUPPORT - // The preferred new implementation (until QCryptographicHash supports all - // hashes we want). - // As Crypto++ is concerned for security they warn about MD5 and friends, - // but we can ignore that and therefore silence the warnings. - #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 - // Hashes (should cover most cases) - #include <cryptopp/md2.h> - #include <cryptopp/md4.h> - #include <cryptopp/md5.h> - #include <cryptopp/sha.h> - #include <cryptopp/ripemd.h> - #include <cryptopp/crc.h> - // Encoding - #include <cryptopp/hex.h> - // additional - #include <string> - // template function - template <typename T> - std::string CryptoPpStrHash(std::string szMessage){ - T hash; - std::string szDigest; - CryptoPP::StringSource(szMessage, - true, - new CryptoPP::HashFilter( - hash, - new CryptoPP::HexEncoder( - new CryptoPP::StringSink(szDigest) - ) - ) - ); - return szDigest; - } -#endif - -#if !defined(COMPILE_SSL_SUPPORT) && !defined(COMPILE_CRYPTOPP_SUPPORT) +#else // The fallback we can always use, but with very limited set of // functionality. #include <QCryptographicHash> @@ -1395,8 +1358,7 @@ static bool str_kvs_fnc_chop(KviKvsModuleFunctionCall * c) @description: Calculates digest for given string using algorithm passed as 2nd argument. Currently supported: md5, md4, md2, sha1, mdc2, ripemd160, dss1 - Default is md5. Requires OpenSSL support or (better) Crypto++, but - offers a minimal set of hashes in any case. + Default is md5. Requires OpenSSL support, but offers a minimal set of hashes in any case. */ static bool str_kvs_fnc_digest(KviKvsModuleFunctionCall * c) { @@ -1406,7 +1368,7 @@ static bool str_kvs_fnc_digest(KviKvsModuleFunctionCall * c) KVSM_PARAMETER("algorithm",KVS_PT_NONEMPTYSTRING,KVS_PF_OPTIONAL,szType) KVSM_PARAMETERS_END(c) -#if defined(COMPILE_SSL_SUPPORT) && !defined(COMPILE_CRYPTOPP_SUPPORT) +#if defined(COMPILE_SSL_SUPPORT) if(szType.isEmpty()) szType = "md5"; EVP_MD_CTX mdctx; @@ -1440,56 +1402,6 @@ static bool str_kvs_fnc_digest(KviKvsModuleFunctionCall * c) } c->returnValue()->setString(szResult); -#elif defined(COMPILE_CRYPTOPP_SUPPORT) - // Crypto++ implementation - std::string szDigest; - std::string szMsg = szString.toLocal8Bit().data(); - - if(szType.toLower() == "sha1" || szType.toLower() == "sha") - { - szDigest = CryptoPpStrHash<CryptoPP::SHA1>(szMsg); - } else if(szType.toLower() == "sha224") - { - szDigest = CryptoPpStrHash<CryptoPP::SHA224>(szMsg); - } else if(szType.toLower() == "sha256") - { - szDigest = CryptoPpStrHash<CryptoPP::SHA256>(szMsg); - } else if(szType.toLower() == "sha384") - { - szDigest = CryptoPpStrHash<CryptoPP::SHA384>(szMsg); - } else if(szType.toLower() == "sha512") - { - szDigest = CryptoPpStrHash<CryptoPP::SHA512>(szMsg); - } else if(szType.toLower() == "ripemd128") - { - szDigest = CryptoPpStrHash<CryptoPP::RIPEMD128>(szMsg); - } else if(szType.toLower() == "ripemd160") - { - szDigest = CryptoPpStrHash<CryptoPP::RIPEMD160>(szMsg); - } else if(szType.toLower() == "ripemd256") - { - szDigest = CryptoPpStrHash<CryptoPP::RIPEMD256>(szMsg); - } else if(szType.toLower() == "ripemd320") - { - szDigest = CryptoPpStrHash<CryptoPP::RIPEMD320>(szMsg); - } else if(szType.toLower() == "crc32") - { - szDigest = CryptoPpStrHash<CryptoPP::CRC32>(szMsg); - } else if(szType.toLower() == "md2") - { - szDigest = CryptoPpStrHash<CryptoPP::Weak::MD2>(szMsg); - } else if(szType.toLower() == "md4") - { - szDigest = CryptoPpStrHash<CryptoPP::Weak::MD4>(szMsg); - } else if(szType.toLower() == "md5") - { - szDigest = CryptoPpStrHash<CryptoPP::Weak::MD5>(szMsg); - } else { - c->warning(__tr2qs("Unsupported message digest.")); - return true; - } - - c->returnValue()->setString(QString(szDigest.c_str())); #else // fall back to QCryptographicHash QCryptographicHash::Algorithm qAlgo; if(szType.toLower() == "sha1") |
