bool EcdsaProvider::PrivateToPublic( const proto::Ciphertext& privateKey, Data& publicKey) const { BinarySecret plaintextKey(crypto_.AES().InstantiateBinarySecretSP()); OTPasswordData password(__FUNCTION__); const bool decrypted = DecryptPrivateKey(privateKey, password, *plaintextKey); if (!decrypted) { return false; } return ScalarBaseMultiply(*plaintextKey, publicKey); }
std::shared_ptr<HDNode> TrezorCrypto::SerializedToHDNode( const proto::AsymmetricKey& serialized) const { std::shared_ptr<HDNode> node = std::make_shared<HDNode>(); OTPassword::safe_memcpy( &(node->chain_code[0]), sizeof(node->chain_code), serialized.chaincode().c_str(), serialized.chaincode().size(), false); if (proto::KEYMODE_PRIVATE == serialized.mode()) { OTData encryptedKey( serialized.key().c_str(), serialized.key().size()); BinarySecret plaintextKey( App::Me().Crypto().AES().InstantiateBinarySecretSP()); BinarySecret masterPassword( App::Me().Crypto().AES().InstantiateBinarySecretSP()); masterPassword = CryptoSymmetric::GetMasterKey(""); Libsecp256k1::DecryptPrivateKey( encryptedKey, *masterPassword, *plaintextKey); OTPassword::safe_memcpy( &(node->private_key[0]), sizeof(node->private_key), plaintextKey->getMemory(), plaintextKey->getMemorySize(), false); } else { OTPassword::safe_memcpy( &(node->public_key[0]), sizeof(node->public_key), serialized.key().c_str(), serialized.key().size(), false); } return node; }