Skip to content

Commit

Permalink
Use ctaes instead of OpenSSL's AES in bip38 code
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzzbawls committed May 11, 2021
1 parent 86c978a commit b687f8e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/bip38.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "bip38.h"

#include "base58.h"
#include "crypto/aes.h"
#include "hash.h"
#include "pubkey.h"
#include "util.h"
#include "utilstrencodings.h"
#include "random.h"

#include <openssl/aes.h>
#include <secp256k1.h>
#include <string>

Expand All @@ -26,9 +27,7 @@

void DecryptAES(uint256 encryptedIn, uint256 decryptionKey, uint256& output)
{
AES_KEY key;
AES_set_decrypt_key(decryptionKey.begin(), 256, &key);
AES_decrypt(encryptedIn.begin(), output.begin(), &key);
AES256Decrypt(decryptionKey.begin()).Decrypt(output.begin(), encryptedIn.begin());
}

void ComputePreFactor(std::string strPassphrase, std::string strSalt, uint256& prefactor)
Expand Down Expand Up @@ -118,9 +117,8 @@ std::string BIP38_Encrypt(std::string strAddress, std::string strPassphrase, uin

//encrypt part 1
arith_uint512 encrypted1;
AES_KEY key;
AES_set_encrypt_key(derivedHalf2.begin(), 256, &key);
AES_encrypt(block1.begin(), encrypted1.begin(), &key);
AES256Encrypt enc(derivedHalf2.begin());
enc.Encrypt(encrypted1.begin(), block1.begin());

//block2 = (pointb[17...32] xor derivedhalf1[16...31]
arith_uint256 p2 = UintToArith256(privKey) >> 128;
Expand All @@ -129,7 +127,7 @@ std::string BIP38_Encrypt(std::string strAddress, std::string strPassphrase, uin

//encrypt part 2
arith_uint512 encrypted2;
AES_encrypt(block2.begin(), encrypted2.begin(), &key);
enc.Encrypt(encrypted2.begin(), block2.begin());

std::string strPrefix = "0142";
strPrefix += (fCompressed ? "E0" : "C0");
Expand Down

0 comments on commit b687f8e

Please sign in to comment.