Bitcoin Forum
October 21, 2017, 03:55:15 AM *
News: Latest stable version of Bitcoin Core: 0.15.0.1  [Torrent]. (New!)
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: C# compute public key from private key, very slow, ~10Keys/s  (Read 1663 times)
daboehla
Sr. Member
****
Offline Offline

Activity: 397


EthTeam.com


View Profile WWW
August 02, 2015, 06:26:39 AM
 #1

Hallo out there,

I tried to compute the public key from a private key in a C# programm.
Lets say i have the priv key: 26760d07c7b06da3ac7d27946b4853e0665c50e0a8b705269b2cfd48f061de2b
so the public key would be: 1A9yKFpmH1GFFeLLv2XGhP41BKCFgRgykN

I was able to compute it with Bitcoin Address Utility (https://en.bitcoin.it/wiki/Bitcoin_Address_Utility).
But my issue is that this way is VERY slow.

I make a for loop and compute it 100 times and it takes 10s! -> 10 Keys/s...

So is there a way to compute it much faster in C# ?

Here is my loop code:
Code:
                DateTime start = DateTime.Now;
                for (int i = 0; i < 100; i++) {
                    KeyPair kp = new KeyPair(txtPrivHex.Text, compressed: compressToolStripMenuItem.Checked);
                    string pubkey = kp.AddressBase58;
                }
                double elapsedsecs = (DateTime.Now - start).TotalSeconds;

I found the command which takes 100ms:
Code:
            Org.BouncyCastle.Math.BigInteger Db = new Org.BouncyCastle.Math.BigInteger(1, _privKey);
            ECPoint dd = point.Multiply(Db);

When i look to vanitygen, they are able to compute about 1.000.000 Keys/s without problems...
So i think they are compute the public key another way?

Would be happy to have a solution Smiley

Ethereum Classic Mining Pool - Cheapest PPS - 1% - Ethteam.com - Stratum: etc-de.ethteam.com:8008 / etc-us.ethteam.com:8008
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
HugoTheSpider
Jr. Member
*
Offline Offline

Activity: 38


View Profile
August 02, 2015, 11:26:05 AM
 #2

Code:
ECPoint dd = point.Multiply(Db);
In ECDSA math, it's required to implement the multiply feature by repeatedly doing point additions and point doublings. The other reason of the slow down in your code you experience is the modular inverse operation which is called inside the Multiply() function once at least.

When you look deeper in the code of "vanitygen", you'll see vanitygen does a single point multiplication operation then just one point addition for each candidate in the current batch. The sparly documented OpenSSL function EC_POINTs_MAKE_AFFINE is also utilized by vanitygen which tells OpenSSL to apply the expensive modular inverse on the whole batch at once before vanitygen starts to extract the public keys using EC_POINT_point2oct.

What are you trying to achieve?

111111i4VTdHkzFqV2a4jntfZkdVk6B <-- only 31 chars
daboehla
Sr. Member
****
Offline Offline

Activity: 397


EthTeam.com


View Profile WWW
August 02, 2015, 12:16:05 PM
 #3

Code:
ECPoint dd = point.Multiply(Db);
In ECDSA math, it's required to implement the multiply feature by repeatedly doing point additions and point doublings. The other reason of the slow down in your code you experience is the modular inverse operation which is called inside the Multiply() function once at least.

When you look deeper in the code of "vanitygen", you'll see vanitygen does a single point multiplication operation then just one point addition for each candidate in the current batch. The sparly documented OpenSSL function EC_POINTs_MAKE_AFFINE is also utilized by vanitygen which tells OpenSSL to apply the expensive modular inverse on the whole batch at once before vanitygen starts to extract the public keys using EC_POINT_point2oct.

What are you trying to achieve?

Ok, I thought that vanitygen have a trick ^^

I wanted to build a big Brainwallet Database. Get a big password list, hash them SH256 and take this as priv. Key.
Then I want to see which are ever used, so I need the public key.
As same as http://pastebin.com/s29kk2bb does.

He have a Database with 17.000.000 entries. And if I also want to build this, it would take about 1.700.000s -> about 20 Days.
So I thought there is likely a faster way to build this.

Ethereum Classic Mining Pool - Cheapest PPS - 1% - Ethteam.com - Stratum: etc-de.ethteam.com:8008 / etc-us.ethteam.com:8008
HugoTheSpider
Jr. Member
*
Offline Offline

Activity: 38


View Profile
August 02, 2015, 01:23:35 PM
 #4

You could use multithreading to speed things up a bit.

If you want to check a bigger amount of brain wallets in a reasonable time, you have to study the underlying ECDSA math.

Just do it for satifying your curiosity, don't expect to get rich if you intent to take the funds because this bitcoin network is already being monitored by bots with very low latency network connections.

For your curiosity:
I had already checked the blockchain using a 1 500 000 000 entries wordlist and a self made cracker operating at 100000 keys/s. utilizing all CPU cores and found about ~18500 bitcoin addresses which had funds, many of them were created during a brain wallet spam attack launched on 31.08.2013.

111111i4VTdHkzFqV2a4jntfZkdVk6B <-- only 31 chars
daboehla
Sr. Member
****
Offline Offline

Activity: 397


EthTeam.com


View Profile WWW
August 02, 2015, 04:47:29 PM
 #5

Yeah sure I would use multithreading, but the only pc who is running 24/7 is a Laptop with dual-core xD

Not doing it because of the money. I know that the time I would spend on this project is not worth, if you only see the money as output ^^

Wow ok "rewriting" the ECDSA is to deep for me I think.

Ok then I will write the bitcoind first, to get new transactions. I think this is hard enough for me.

Thx for your info! Cheesy

Ethereum Classic Mining Pool - Cheapest PPS - 1% - Ethteam.com - Stratum: etc-de.ethteam.com:8008 / etc-us.ethteam.com:8008
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!