Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 0 additions & 118 deletions src/crypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
unsigned char chKeyGridcoin[256];
unsigned char chIVGridcoin[256];
bool fKeySetGridcoin;
std::string getHardwareID();
std::string RetrieveMd5(std::string s1);

bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector<unsigned char>& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
Expand Down Expand Up @@ -211,62 +210,6 @@ bool GridDecrypt(const std::vector<unsigned char>& vchCiphertext,std::vector<uns
return true;
}





bool GridEncryptWithSalt(std::vector<unsigned char> vchPlaintext, std::vector<unsigned char> &vchCiphertext, std::string salt)
{
LoadGridKey("gridcoin",salt);
int nLen = vchPlaintext.size();
int nCLen = nLen + AES_BLOCK_SIZE, nFLen = 0;
vchCiphertext = std::vector<unsigned char> (nCLen);
bool fOk = true;
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
if(!ctx)
throw std::runtime_error("Error allocating cipher context");

if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKeyGridcoin, chIVGridcoin);
if (fOk) fOk = EVP_EncryptUpdate(ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen);
if (fOk) fOk = EVP_EncryptFinal_ex(ctx, (&vchCiphertext[0])+nCLen, &nFLen);
EVP_CIPHER_CTX_free(ctx);
if (!fOk) return false;
vchCiphertext.resize(nCLen + nFLen);
return true;
}


bool GridDecryptWithSalt(const std::vector<unsigned char>& vchCiphertext,std::vector<unsigned char>& vchPlaintext, std::string salt)
{
LoadGridKey("gridcoin",salt);
int nLen = vchCiphertext.size();
int nPLen = nLen, nFLen = 0;
bool fOk = true;

// Allocate data for the plaintext string. This is always equal to lower
// than the length of the encrypted string. Stray data is discarded
// after successfully decrypting.
vchPlaintext.resize(nLen);

EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
if(!ctx)
throw std::runtime_error("Error allocating cipher context");

if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKeyGridcoin, chIVGridcoin);
if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0])+nPLen, &nFLen);
EVP_CIPHER_CTX_free(ctx);
if (!fOk) return false;

vchPlaintext.resize(nPLen + nFLen);
return true;
}






char FromUnsigned( unsigned char ch )
{
return static_cast< char >( ch );
Expand Down Expand Up @@ -325,64 +268,3 @@ std::string AdvancedDecrypt(std::string boinchash_encrypted)
return "";
}
}


std::string AdvancedCryptWithHWID(std::string data)
{
std::string HWID = getHardwareID();
std::string enc = "";
std::string salt = HWID;
for (unsigned int i = 0; i < 9; i++)
{
std::string old_salt = salt;
salt = RetrieveMd5(old_salt);
}
enc = AdvancedCryptWithSalt(data,salt);
return enc;
}

std::string AdvancedDecryptWithHWID(std::string data)
{
std::string HWID = getHardwareID();
std::string salt = HWID;
for (unsigned int i = 0; i < 9; i++)
{
std::string old_salt = salt;
salt = RetrieveMd5(old_salt);
}
std::string dec = AdvancedDecryptWithSalt(data,salt);
return dec;
}

std::string AdvancedCryptWithSalt(std::string boinchash, std::string salt)
{
try
{
std::vector<unsigned char> vchSecret( boinchash.begin(), boinchash.end() );
std::vector<unsigned char> vchCryptedSecret;
GridEncryptWithSalt(vchSecret, vchCryptedSecret,salt);
std::string encrypted = EncodeBase64(UnsignedVectorToString(vchCryptedSecret));

return encrypted;
} catch (std::exception &e)
{
LogPrintf("Error while encrypting %s",boinchash);
return "";
}
}

std::string AdvancedDecryptWithSalt(std::string boinchash_encrypted, std::string salt)
{
try{
std::string pre_encrypted_boinchash = DecodeBase64(boinchash_encrypted);
std::vector<unsigned char> vchCryptedSecret(pre_encrypted_boinchash.begin(),pre_encrypted_boinchash.end());
std::vector<unsigned char> vchPlaintext;
GridDecryptWithSalt(vchCryptedSecret,vchPlaintext,salt);
std::string decrypted = UnsignedVectorToString(vchPlaintext);
return decrypted;
} catch (std::exception &e)
{
LogPrintf("Error while decrypting %s",boinchash_encrypted);
return "";
}
}
8 changes: 0 additions & 8 deletions src/crypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,8 @@ bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned

std::string AdvancedCrypt(std::string boinchash);
std::string AdvancedDecrypt(std::string boinchash_encrypted);
std::string AdvancedCryptWithSalt(std::string boinchash, std::string salt);
std::string AdvancedDecryptWithSalt(std::string boinchash_encrypted, std::string salt);
std::string AdvancedCryptWithHWID(std::string data);
std::string AdvancedDecryptWithHWID(std::string data);

bool GridDecrypt(const std::vector<unsigned char>& vchCiphertext,std::vector<unsigned char>& vchPlaintext);
bool GridEncrypt(std::vector<unsigned char> vchPlaintext, std::vector<unsigned char> &vchCiphertext);

bool GridDecryptWithSalt(const std::vector<unsigned char>& vchCiphertext,std::vector<unsigned char>& vchPlaintext, std::string salt);
bool GridEncryptWithSalt(std::vector<unsigned char> vchPlaintext, std::vector<unsigned char> &vchCiphertext, std::string salt);


#endif
79 changes: 0 additions & 79 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ bool TallyResearchAverages_retired(CBlockIndex* index);
bool TallyResearchAverages_v9(CBlockIndex* index);
extern void IncrementCurrentNeuralNetworkSupermajority(std::string NeuralHash, std::string GRCAddress, double distance);
extern MiningCPID GetInitializedMiningCPID(std::string name, std::map<std::string, MiningCPID>& vRef);
extern std::string getHardDriveSerial();
extern double ExtractMagnitudeFromExplainMagnitude();
extern void GridcoinServices();
extern double SnapToGrid(double d);
Expand All @@ -65,7 +64,6 @@ std::string ExtractValue(std::string data, std::string delimiter, int pos);
UniValue MagnitudeReport(std::string cpid);
void RemoveCPIDBlockHash(const std::string& cpid, const CBlockIndex* pindex);
void ZeroOutResearcherTotals(StructCPID& stCpid);
extern std::string getCpuHash();
bool CPIDAcidTest2(std::string bpk, std::string externalcpid);
extern bool BlockNeedsChecked(int64_t BlockTime);
int64_t GetEarliestWalletTransaction();
Expand Down Expand Up @@ -8432,83 +8430,6 @@ std::string GetQuorumHash(const std::string& data)
return RetrieveMd5(sHashIn);
}


std::string getHardwareID()
{
std::string ele1 = "?";
/*#ifdef QT_GUI
ele1 = getMacAddress();
#endif*/
ele1 += ":" + getCpuHash();
ele1 += ":" + getHardDriveSerial();

std::string hwid = RetrieveMd5(ele1);
return hwid;
}

#ifdef WIN32
static void getCpuid( unsigned int* p, unsigned int ax )
{
__asm __volatile
( "movl %%ebx, %%esi\n\t"
"cpuid\n\t"
"xchgl %%ebx, %%esi"
: "=a" (p[0]), "=S" (p[1]),
"=c" (p[2]), "=d" (p[3])
: "0" (ax)
);
}
#endif

std::string getCpuHash()
{
std::string n = boost::asio::ip::host_name();
#ifdef WIN32
unsigned int cpuinfo[4] = { 0, 0, 0, 0 };
getCpuid( cpuinfo, 0 );
unsigned short hash = 0;
unsigned int* ptr = (&cpuinfo[0]);
for ( unsigned int i = 0; i < 4; i++ )
hash += (ptr[i] & 0xFFFF) + ( ptr[i] >> 16 );
double dHash = (double)hash;
return n + ";" + RoundToString(dHash,0);
#else
return n;
#endif
}



std::string SystemCommand(const char* cmd)
{
FILE* pipe = popen(cmd, "r");
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
while(!feof(pipe))
{
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe);
return result;
}


std::string getHardDriveSerial()
{
if (!msHDDSerial.empty()) return msHDDSerial;
std::string cmd1 = "";
#ifdef WIN32
cmd1 = "wmic path win32_physicalmedia get SerialNumber";
#else
cmd1 = "ls /dev/disk/by-uuid";
#endif
std::string result = SystemCommand(cmd1.c_str());
msHDDSerial = result;
return result;
}

bool IsContract(CBlockIndex* pIndex)
{
return pIndex->nIsContract==1 ? true : false;
Expand Down
44 changes: 0 additions & 44 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,47 +104,6 @@ class TxPriorityCompare
}
};


void MinerAutoUnlockFeature(CWallet *pwallet)
{
/////////////////////// Auto Unlock Feature for Research Miner
if (pwallet->IsLocked())
{
//11-5-2014 R Halford - If wallet is locked - see if user has an encrypted password stored:
std::string passphrase = "";
if (mapArgs.count("-autounlock"))
{
passphrase = GetArg("-autounlock", "");
}
if (passphrase.length() > 1)
{
std::string decrypted = AdvancedDecryptWithHWID(passphrase);
//Unlock the wallet for 10 days (Equivalent to: walletpassphrase mylongpass 999999) FOR STAKING ONLY!
int64_t nSleepTime = 9999999;
SecureString strWalletPass;
strWalletPass.reserve(100);
strWalletPass = decrypted.c_str();
if (strWalletPass.length() > 0)
{
if (!pwallet->Unlock(strWalletPass))
{
LogPrintf("GridcoinResearchMiner:AutoUnlock:Error: The wallet passphrase entered was incorrect.");
}
else
{
NewThread(ThreadTopUpKeyPool,NULL);
int64_t* pnSleepTime = new int64_t(nSleepTime);
NewThread(ThreadCleanWalletPassphrase, pnSleepTime);
fWalletUnlockStakingOnly = true;
}
}
}
}
return;
// End of AutoUnlock Feature
}


// CreateRestOfTheBlock: collect transactions into block and fill in header
bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev)
{
Expand Down Expand Up @@ -1223,12 +1182,9 @@ bool IsMiningAllowed(CWallet *pwallet)

void StakeMiner(CWallet *pwallet)
{

// Make this thread recognisable as the mining thread
RenameThread("grc-stake-miner");

MinerAutoUnlockFeature(pwallet);

// Parse StakeSplit and SideStaking flags.
bool fEnableStakeSplit = GetBoolArg("-enablestakesplit");
LogPrintf("StakeMiner: fEnableStakeSplit = %u", fEnableStakeSplit);
Expand Down
33 changes: 0 additions & 33 deletions src/test/crypter_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,4 @@ BOOST_AUTO_TEST_CASE(crypter_GridDecryptShouldDecryptValidInput)
BOOST_CHECK_EQUAL(PLAINTEXT, decrypted_message);
}

BOOST_AUTO_TEST_CASE(crypter_GridEncryptWithSaltShouldProduceCorrectOutput)
{
const std::vector<unsigned char> plaintext(PLAINTEXT.begin(), PLAINTEXT.end());
std::vector<unsigned char> encrypted;

BOOST_CHECK(GridEncryptWithSalt(plaintext, encrypted, SALT));

// Convert encrypted message to Base64 for easier verification.
std::string encrypted_message(encrypted.begin(), encrypted.end());
BOOST_CHECK_EQUAL(EncodeBase64(encrypted_message),
"bFCPuKw6yUO2tSMsRlAfaza/bBrYFJFA4ke4S0lEbvH1gMwayuRzbBJ7ZFzAawTIXWpXe+JTvuMQHI6H0kDg6A==");
}

BOOST_AUTO_TEST_CASE(crypter_GridDecryptWithSaltShouldDecryptValidInput)
{
const std::vector<unsigned char> encrypted =
DecodeBase64("bFCPuKw6yUO2tSMsRlAfaza/bBrYFJFA4ke4S0lEbvH1gMwayuRzbBJ7ZFzAawTIXWpXe+JTvuMQHI6H0kDg6A==");

// GridEncrypt allocates memory in destination while GridDecrypt doesn't.
std::vector<unsigned char> plaintext(encrypted.size());
BOOST_CHECK(GridDecryptWithSalt(encrypted, plaintext, SALT));
const std::string decrypted_message(plaintext.begin(), plaintext.end());
BOOST_CHECK_EQUAL(PLAINTEXT, decrypted_message);
}

BOOST_AUTO_TEST_CASE(crypter_AdvancedDecryptWithSaltShouldNotCrash)
{
const std::string boinchash_encrypted("HOVtyXamA5H5IWJl6TtwJr9iD5GGSOClvyb9l08ZYCAG2OkS22sGEH6jUt8NlrDQVto/8eBMz1TxPqWCv3bA+o38H25ysTEGHOijlPby2A1VhzQTjFzNYSNaXC4kIaHMgvwgoHCU/Io1LsCBgVK+atiZRuhXDSpbJLHpLmjHokAon0cELZGP3X2g0kQXhImh");
const std::string salt("\235\002\353\071A\244*\303\b\274\271\221");
const std::string result = AdvancedDecryptWithSalt(boinchash_encrypted, salt);
}


BOOST_AUTO_TEST_SUITE_END()