Skip to content

Use CryptoPP library for RC4 / SHA1 / MD5 algorithms instead of deploying our own implementations #181

Description

@danim7

Please tell me i'm wrong on this:

RC4Encrypt.cpp contains our own implementation of the RC4 algorithm.
SHA.cpp contains our own implementation of the SHA algorithm.
libs/common/MD5Sum.cpp contains our own implementation of the MD5 algorithm.

If we grep the code for the CryptoPP library, we can see it is only used for RSA and MD4, but not for the above algorithms:

./ClientCreditsList.cpp:#include "CryptoPP_Inc.h"	// Needed for Crypto functions
./ClientCreditsList.cpp:	delete static_cast<CryptoPP::RSASSA_PKCS1v15_SHA_Signer *>(m_pSignkey);
./ClientCreditsList.cpp:		CryptoPP::AutoSeededX917RNG<CryptoPP::DES_EDE3> rng;
./ClientCreditsList.cpp:		CryptoPP::InvertibleRSAFunction privkey;
./ClientCreditsList.cpp:		CryptoPP::FileSink *fileSink = new CryptoPP::FileSink(filename);
./ClientCreditsList.cpp:		CryptoPP::Base64Encoder *privkeysink = new CryptoPP::Base64Encoder(fileSink);
./ClientCreditsList.cpp:	} catch(const CryptoPP::Exception& e) {
./ClientCreditsList.cpp:		CryptoPP::FileSource filesource(filename2char(thePrefs::GetConfigDir() + CRYPTKEY_FILENAME), true, new CryptoPP::Base64Decoder);
./ClientCreditsList.cpp:		m_pSignkey = new CryptoPP::RSASSA_PKCS1v15_SHA_Signer(filesource);
./ClientCreditsList.cpp:		CryptoPP::RSASSA_PKCS1v15_SHA_Verifier pubkey(*static_cast<CryptoPP::RSASSA_PKCS1v15_SHA_Signer *>(m_pSignkey));
./ClientCreditsList.cpp:		CryptoPP::ArraySink asink(m_abyMyPublicKey, 80);
./ClientCreditsList.cpp:	} catch (const CryptoPP::Exception& e) {
./ClientCreditsList.cpp:		delete static_cast<CryptoPP::RSASSA_PKCS1v15_SHA_Signer *>(m_pSignkey);
./ClientCreditsList.cpp:	CryptoPP::RSASSA_PKCS1v15_SHA_Signer* signer =
./ClientCreditsList.cpp:		static_cast<CryptoPP::RSASSA_PKCS1v15_SHA_Signer *>(sigkey);
./ClientCreditsList.cpp:		signer = static_cast<CryptoPP::RSASSA_PKCS1v15_SHA_Signer *>(m_pSignkey);
./ClientCreditsList.cpp:		CryptoPP::SecByteBlock sbbSignature(signer->SignatureLength());
./ClientCreditsList.cpp:		CryptoPP::AutoSeededX917RNG<CryptoPP::DES_EDE3> rng;
./ClientCreditsList.cpp:		CryptoPP::ArraySink asink(pachOutput, nMaxSize);
./ClientCreditsList.cpp:	} catch (const CryptoPP::Exception& e) {
./ClientCreditsList.cpp:		CryptoPP::StringSource ss_Pubkey((uint8_t*)pTarget->GetSecureIdent(),pTarget->GetSecIDKeyLen(),true,0);
./ClientCreditsList.cpp:		CryptoPP::RSASSA_PKCS1v15_SHA_Verifier pubkey(ss_Pubkey);
./ClientCreditsList.cpp:	} catch (const CryptoPP::Exception& e) {
./ClientCreditsList.cpp:	CryptoPP::AutoSeededX917RNG<CryptoPP::DES_EDE3> rng;
./ClientCreditsList.cpp:	CryptoPP::RSASSA_PKCS1v15_SHA_Signer priv(rng, 384);
./ClientCreditsList.cpp:	CryptoPP::RSASSA_PKCS1v15_SHA_Verifier pub(priv);
./ClientCreditsList.cpp:	CryptoPP::ArraySink asink(abyPublicKey, 80);
./EncryptedDatagramSocket.cpp:#include "CryptoPP_Inc.h"	// Needed for Crypto functions
./EncryptedStreamSocket.cpp:		m_cryptDHA.Randomize((CryptoPP::AutoSeededRandomPool&)GetRandomPool(), DHAGREEMENT_A_BITS); // our random a
./EncryptedStreamSocket.cpp:		CryptoPP::Integer cryptDHPrime((uint8_t*)dh768_p, PRIMESIZE_BYTES);  // our fixed prime
./EncryptedStreamSocket.cpp:		CryptoPP::Integer cryptDHGexpAmodP = a_exp_b_mod_c(CryptoPP::Integer(2), m_cryptDHA, cryptDHPrime);
./EncryptedStreamSocket.cpp:					CryptoPP::Integer cryptDHAnswer((uint8_t*)aBuffer, PRIMESIZE_BYTES);
./EncryptedStreamSocket.cpp:					CryptoPP::Integer cryptDHPrime((uint8_t*)dh768_p, PRIMESIZE_BYTES);  // our fixed prime
./EncryptedStreamSocket.cpp:					CryptoPP::Integer cryptResult = a_exp_b_mod_c(cryptDHAnswer, m_cryptDHA, cryptDHPrime);
./utils/fileview/KadFiles.cpp:#include "../../CryptoPP_Inc.h"
./utils/fileview/KadFiles.cpp:	CryptoPP::Weak::MD4 md4_hasher;
./utils/scripts/sanity:	(filename =~ /CryptoPP/)
./ClientCreditsList.h:	// A void* to avoid having to include the large CryptoPP.h file
./EncryptedStreamSocket.h:#include "CryptoPP_Inc.h"	// Needed for Crypto functions
./EncryptedStreamSocket.h:	CryptoPP::Integer	m_cryptDHA;
./RandomFunctions.cpp:#include "CryptoPP_Inc.h"	// Needed for Crypto functions
./RandomFunctions.cpp:static CryptoPP::AutoSeededRandomPool cryptRandomGen;
./RandomFunctions.cpp:const CryptoPP::AutoSeededRandomPool& GetRandomPool() { return cryptRandomGen; }
./webserver/src/WebServer.cpp:#include <cryptopp/osrng.h>	// CryptoPP::AutoSeededRandomPool, for the session-token CSPRNG
./webserver/src/WebServer.cpp:		static CryptoPP::AutoSeededRandomPool s_sessionPool;
./webserver/src/WebServer.cpp:			s_sessionPool.GenerateBlock(reinterpret_cast<CryptoPP::byte *>(&fresh), sizeof(fresh));
./webserver/src/WebServer.h:	// Sourced from CryptoPP::AutoSeededRandomPool when a new session
./kademlia/kademlia/Kademlia.cpp:#include "../../CryptoPP_Inc.h"
./kademlia/kademlia/Kademlia.cpp:	CryptoPP::Weak::MD4 md4_hasher;
./KnownFile.cpp:#include "CryptoPP_Inc.h"       // Needed for MD4
./KnownFile.cpp:		CryptoPP::Weak::MD4 md4_hasher;
./RandomFunctions.h:namespace CryptoPP {
./RandomFunctions.h:const CryptoPP::AutoSeededRandomPool& GetRandomPool();

Why we are not using the CryptoPP library for ALL crypto algorithms? Is there any reason for that?
It is a bad practice in security to re-implement the crypto algorithms. And also we are surely paying a performance issue (SHA CPU instructions not being used, missing potential assembly code for certain architectures provided by the library, etc...?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependenciesPull requests that update a dependency fileenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions