Bitcoin Forum
March 28, 2024, 10:00:28 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Development & Technical Discussion / AES-256-CBC and Private Key on: September 23, 2019, 07:41:28 PM
I am at the final stage. I am now working on checking the encryption for the private keys inside the wallet.

      Why does the calculation not work for decrypting private key?


I have the correct private key which was derived from Bitcoin string within Bitcoin2john.py script for wallet.dat.
I have double sha 256 public key for the above address.
I have gotten the unencrypted master key data from the following function in crypter.cpp:

bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext)

        std::string MasterKey (vMasterKey.begin(), vMasterKey.end());

The error I am getting is as follows: Given final block not properly padded. Such issues can arise if a bad key is used during decryption. Any help on this will be greatly appreciated with a small tip of thanks to your address.
2  Bitcoin / Development & Technical Discussion / Salt Explanation. on: September 23, 2019, 12:24:52 AM
I have added several print statements throughout the source code to follow the path of encryption/decryption on the wallet. My questions are as follows:

     1. Why is the salt not the same in the bitcoin source code as the python program below? 6ec1691c413b52bb vs 0x26cde4d5880(salt)
 
Using bitcoin2john.py, I get the following string from wallet.dat.
$bitcoin
$64$
e8a8aa1de3da38001410635516891bc3d092063bd386acd867df457c8d842beb
$16$
6ec1691c413b52bb
$83782
$96$
d307ed1e99a72541b60cbcd6b9636e3f1d26b2311eb781f0c6d8b659895e5fe7b53af45edb312c3 764df8ccaac7b8a74
$66$
03fffeb3444e21170d74dcc58290e0914e59ec2b51dfac6a67465ba6dd6a7d262d

I have set several stream statements in the function to follow the path in crypter.cpp: The source code was pulled from github bitcoin source code location.

bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector<unsigned char>& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
{
    int roundcount = nRounds;
    int cryptokeysize = WALLET_CRYPTO_KEY_SIZE;
    int derivationmethod = nDerivationMethod;
    
    std::ofstream file3;
    file3.open ("C:\\workspace\\bitcoin\\usr\\local\\3.txt");
    file3 << "Made it here...Line3. (chsalt, strKeyData, nRounds, vchKey.data(), vchIV.data() \n";
    file3 << (int)roundcount;
    file3 << "(nrounds)\n";
    file3 << (int)cryptokeysize;
    file3 << "(keysize)\n";
    file3 << (int)derivationmethod;
    file3 << "(derivations)\n";

    if (nRounds < 1 )
        return false;

    int i = 0;
    if (nDerivationMethod == 0)
        i = BytesToKeySHA512AES(chSalt, strKeyData, nRounds, vchKey.data(), vchIV.data());

    file3 << i;
    file3 << "(nderivationmethod)\n";
    file3 << &vchKey;
    file3 << "(vchKey- memory cleanse)\n";
    file3 << vchKey.size();
    file3 << "(key size)\n";
    file3 << &vchIV;
    file3 << "(iv- memory cleanse)\n";
    file3 << vchIV.size();
    file3 << "(iv size)\n";
    file3 << &chSalt;
    file3 << "(salt)\n";
    file3 << chSalt.size();
    file3 << "(salt size)\n";
    file3 << &strKeyData;
    file3 << "(strkey)\n";
    file3 << strKeyData.size();
    file3 << "(strKeyData size)\n";

    if (i != (int)WALLET_CRYPTO_KEY_SIZE)
    {
        file3 << &vchKey;
        file3 << "(vchKey- memory cleanse2)\n";
        file3 << vchKey.size();
        file3 << "(key size2)\n";
    
        file3 << &vchIV;
        file3 << "(iv- memory cleanse2)\n";
        file3 << vchIV.size();
        file3 << "(iv size2)\n";

        memory_cleanse(vchKey.data(), vchKey.size());
        memory_cleanse(vchIV.data(), vchIV.size());
        return false;
    }
    
    file3 << (int)derivationmethod;
    file3 << "(derivation)\n";
      
    fKeySet = true;

    file3 << fKeySet;
    file3 << "(fKeySet)\n";
    file3.close();
    return true;
}

The results are as follows:
Made it here...Line3. (chsalt, strKeyData, nRounds, vchKey.data(), vchIV.data()
83782(nrounds)
32(keysize)
0(derivations)
32(nderivationmethod)
0xbd8edfa270(vchKey- memory cleanse)
32(key size)
0xbd8edfa288(iv- memory cleanse)
16(iv size)
0x26cde4d5880(salt)
8(salt size)
0xbd8edfa9c0(strkey)
16(strKeyData size)
0(derivation)
1(fKeySet)
3  Bitcoin / Bitcoin Technical Support / Wallet passphrase and salt encryption on: September 21, 2019, 02:41:36 AM
My question is as follows: When encrypting BTC Core wallet, is the format as follows: Sha512(passphrase+salt) or Sha512(salt+passphrase) before encrypting with AES256CBC for the wallet? Thanks.
4  Bitcoin / Bitcoin Technical Support / Wallet Passphrase Change Function on: September 17, 2019, 03:12:42 PM
In the Bitcoin source code from github, RPCwallet.cpp is my question is centered. The questions are as follows:

     1. Is this the only function where the wallet passphrase can be changed? Meaning, does the gui for askpassphrase point to this same location?
     2. Do anyone know the exact variable which is referenced for the oldpassphrase comparison?

I have attached the function below for reference. The reason for the question, I want to complete a stand-a-lone work around for when I forget or type my password in incorrectly for my current wallet. Thanks for all your help in advance. Please leave address for tip receipt for all answers that help me on this task.

static UniValue walletpassphrasechange(const JSONRPCRequest& request)
{
    std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
    CWallet* const pwallet = wallet.get();

    if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
        return NullUniValue;
    }

            RPCHelpMan{"walletpassphrasechange",
                "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n",
                {
                    {"oldpassphrase", RPCArg::Type::STR, RPCArg::Optional::NO, "The current passphrase"},
                    {"newpassphrase", RPCArg::Type::STR, RPCArg::Optional::NO, "The new passphrase"},
                },
                RPCResults{},
                RPCExamples{
                    HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"")
            + HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"")
                },
            }.Check(request);

    auto locked_chain = pwallet->chain().lock();
    LOCK(pwallet->cs_wallet);

    if (!pwallet->IsCrypted()) {
        throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
    }

    // TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
    // Alternately, find a way to make request.params[0] mlock()'d to begin with.
    SecureString strOldWalletPass;
    strOldWalletPass.reserve(100);
    strOldWalletPass = request.params[0].get_str().c_str();

    SecureString strNewWalletPass;
    strNewWalletPass.reserve(100);
    strNewWalletPass = request.params[1].get_str().c_str();

    if (strOldWalletPass.empty() || strNewWalletPass.empty()) {
        throw JSONRPCError(RPC_INVALID_PARAMETER, "passphrase can not be empty");
    }

    if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) {
        throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
    }

    return NullUniValue;
}
5  Bitcoin / Bitcoin Technical Support / Re: Master Key Key on: September 16, 2019, 05:41:18 PM
Thanks for the answers to my questions. I have one final question on this topic. When the software client loads the wallet, all variables (majority) contained in wallet.dat file load into program memory and are updated as required, is this a fair assumption?
6  Bitcoin / Bitcoin Technical Support / Master Key Key on: September 16, 2019, 03:49:30 AM
Following path in source code for the creation of master key in crypter.cpp/.h. The program comment states Wallet Private Keys are encrypted with double sha 256 of public key as the IV and the master key's key as the encryption key. Is the encryption key the variable vchCryptedKey which is a part of the class CMasterKey or is it chKey from private class CCrypter? A second question since the IV is stored in the wallet.dat file, it is safe to assume this encryption key is stored in wallet.dat also? Please advise if I am incorrect? Thanks.
7  Economy / Services / Re: Crack my bitcoin wallet address and get 0.155 btc + 0.5BTC on: July 24, 2018, 10:14:33 AM
Good Day Mate,

If this is not solved yet, email k.martin@stgna.com. I can help you.

Kind Regards.
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!