Bitcoin Forum
May 17, 2024, 06:51:15 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Compressed private keys: how to get Y from X  (Read 4857 times)
casascius (OP)
Mike Caldwell
VIP
Legendary
*
Offline Offline

Activity: 1386
Merit: 1136


The Casascius 1oz 10BTC Silver Round (w/ Gold B)


View Profile WWW
October 31, 2012, 03:50:12 AM
 #1

I am wondering if anyone would be willing to give me the quick tl;dr for how to get an elliptic curve point's Y given X.  Or in other words get the uncompressed version of a compressed point.

My understanding is that for every X, there's two possible Y's, and they differ in some trivial way (such as one is odd and one is even), and which to use is denoted by the byte that comes in front of X.  Further, I understand that the equation y^2=x^3+ax+b is involved, but am not clear how to wrap my head around that and the finite field arithmetic, and my main objective is to upgrade my Casascius Bitcoin Address Utility to support compressed keys.

I'm using BouncyCastle.  Would someone be so kind as to point me in the right direction or offer the code snippet that does this?  Perhaps this functionality (or some primitive it's based upon) is built into BouncyCastle and I just don't know it.  For example, I'm able to find things like this http://www.item.ntnu.no/europki08/presentations/europki08-brumley.pdf but would prefer to use tested code instead of reinventing the wheel.  Thanks in advance.

Edit: I think I'm probably warm with BouncyCastle's decodePoint

Companies claiming they got hacked and lost your coins sounds like fraud so perfect it could be called fashionable.  I never believe them.  If I ever experience the misfortune of a real intrusion, I declare I have been honest about the way I have managed the keys in Casascius Coins.  I maintain no ability to recover or reproduce the keys, not even under limitless duress or total intrusion.  Remember that trusting strangers with your coins without any recourse is, as a matter of principle, not a best practice.  Don't keep coins online. Use paper or hardware wallets instead.
casascius (OP)
Mike Caldwell
VIP
Legendary
*
Offline Offline

Activity: 1386
Merit: 1136


The Casascius 1oz 10BTC Silver Round (w/ Gold B)


View Profile WWW
October 31, 2012, 06:37:24 AM
 #2

OK, I was able to figure this all out.  My utility as tested seems to handle compressed private keys just fine, and produces identical results to BitAddress.org's screens that do the same thing.

Now, I went to BitAddress.org to use the "Vanity Wallet" screen as a test reference, expecting this screen does EC multiplication.

Seems to me I'm wrong and that it actually does EC addition - something I thought we decided was vulnerable.  I guess it's not vulnerable if the vanity generator has to cough up the private key, but still, I'm surprised we're doing EC addition when implementing EC multiplication is just as simple (assuming it's all a library call anyway).

Companies claiming they got hacked and lost your coins sounds like fraud so perfect it could be called fashionable.  I never believe them.  If I ever experience the misfortune of a real intrusion, I declare I have been honest about the way I have managed the keys in Casascius Coins.  I maintain no ability to recover or reproduce the keys, not even under limitless duress or total intrusion.  Remember that trusting strangers with your coins without any recourse is, as a matter of principle, not a best practice.  Don't keep coins online. Use paper or hardware wallets instead.
casascius (OP)
Mike Caldwell
VIP
Legendary
*
Offline Offline

Activity: 1386
Merit: 1136


The Casascius 1oz 10BTC Silver Round (w/ Gold B)


View Profile WWW
October 31, 2012, 07:26:28 AM
 #3

I just published my work on my Casascius Bitcoin Address Utility to fully support compressed private keys.  This new version features a key combiner, which can combine two keys via EC-multiplication and EC-addition.

Feel free to test it.  I'll call it Alpha, because most of the classes have been totally refactored and not thoroughly tested (but the results were correct for the cases I tested)

https://casascius.com/btcaddress-alpha.zip (Windows, binary with C# source - Visual Studio 2010)

Companies claiming they got hacked and lost your coins sounds like fraud so perfect it could be called fashionable.  I never believe them.  If I ever experience the misfortune of a real intrusion, I declare I have been honest about the way I have managed the keys in Casascius Coins.  I maintain no ability to recover or reproduce the keys, not even under limitless duress or total intrusion.  Remember that trusting strangers with your coins without any recourse is, as a matter of principle, not a best practice.  Don't keep coins online. Use paper or hardware wallets instead.
nibor
Sr. Member
****
Offline Offline

Activity: 438
Merit: 291


View Profile
October 31, 2012, 11:11:38 PM
 #4

Seems to me I'm wrong and that it actually does EC addition - something I thought we decided was vulnerable. 

Yes bitaddress.org does addition. This is because that is what vanitygen.exe -P does.

Why do you say addition is more vulnerable? I can not think of any reason for that.
casascius (OP)
Mike Caldwell
VIP
Legendary
*
Offline Offline

Activity: 1386
Merit: 1136


The Casascius 1oz 10BTC Silver Round (w/ Gold B)


View Profile WWW
November 01, 2012, 01:41:16 AM
 #5

The vulnerability is related to the fact that point addition can be reversed and point multiplication cannot.  Exploiting it involves passing a specially crafted public key generated through "point subtraction"- and may not affect vanitygen because of the fact that a private key is passed to the buyer immediately.

Companies claiming they got hacked and lost your coins sounds like fraud so perfect it could be called fashionable.  I never believe them.  If I ever experience the misfortune of a real intrusion, I declare I have been honest about the way I have managed the keys in Casascius Coins.  I maintain no ability to recover or reproduce the keys, not even under limitless duress or total intrusion.  Remember that trusting strangers with your coins without any recourse is, as a matter of principle, not a best practice.  Don't keep coins online. Use paper or hardware wallets instead.
casascius (OP)
Mike Caldwell
VIP
Legendary
*
Offline Offline

Activity: 1386
Merit: 1136


The Casascius 1oz 10BTC Silver Round (w/ Gold B)


View Profile WWW
November 01, 2012, 03:40:16 AM
 #6

It occurs to me why addition might be used in vanitygen... point addition is the way vanitygen achieves acceleration past simply brute-forcing random private keys.  If I think about it, it occurs to me that if vanitygen had to use multiplication, it would suffer a major performance cost.  If the security risk inherent in addition doesn't apply because the buyer of the vanitygen service gets his private key immediately (something an attacker wouldn't be able to provide), then it's clear that addition is the right solution.

I have written my utility so it can do both addition and multiplication.

Companies claiming they got hacked and lost your coins sounds like fraud so perfect it could be called fashionable.  I never believe them.  If I ever experience the misfortune of a real intrusion, I declare I have been honest about the way I have managed the keys in Casascius Coins.  I maintain no ability to recover or reproduce the keys, not even under limitless duress or total intrusion.  Remember that trusting strangers with your coins without any recourse is, as a matter of principle, not a best practice.  Don't keep coins online. Use paper or hardware wallets instead.
etotheipi
Legendary
*
expert
Offline Offline

Activity: 1428
Merit: 1093


Core Armory Developer


View Profile WWW
November 02, 2012, 12:39:16 AM
 #7

Not sure it matters anymore, but I did program an ECDSA calculator into Armory, under "Tools->EC Calculator".  You can multiply scalars mod N (where N is the modulus of the secp256k1 curve), point-addition, and scalar-point multiplication.  It works for doing shared keys like you talk about it your thread on 2-factor physical coins:  you can start Armory in offline mode, create a new wallet, create two addresses, copy&paste the private and public keys, then plug them into the calculator using scalar-point multiplication and verify that A*B' == A'*B.  Then calculate A*B and A*B*G to see that you get what you expect.




Founder and CEO of Armory Technologies, Inc.
Armory Bitcoin Wallet: Bringing cold storage to the average user!
Only use Armory software signed by the Armory Offline Signing Key (0x98832223)

Please donate to the Armory project by clicking here!    (or donate directly via 1QBDLYTDFHHZAABYSKGKPWKLSXZWCCJQBX -- yes, it's a real address!)
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!