Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Richy_T on November 27, 2013, 02:10:51 AM



Title: [Solved]Problem with hashing, public keys and the wiki - Wiki information incomp
Post by: Richy_T on November 27, 2013, 02:10:51 AM
EDIT: Nevermind, it looks like hex2bin must be used first. The wiki really needs updating.


So I'm working through the wiki

https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses

I am at this point...

Quote
1 - Take the corresponding public key generated with it (65 bytes, 1 byte 0x04, 32 bytes corresponding to X coordinate, 32 bytes corresponding to Y coordinate)

   0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A 299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6

2 - Perform SHA-256 hashing on the public key

   600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408


I got the public key OK, prepended the 04, didn't get the value. Needs an uppercase right? Still no value. So I cut and paste it directly from the page and put it in my code.

Code:
print hash('sha256',"0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6") . "<br>";

Which gives

32511e82d56dcea68eb774094e25bab0f8bdd9bc1eca1ceeda38c7a43aceddce

Which, nicely enough is what I got from the uppercase value I generated so I'm not totally off-base but is not the value listed in the wiki. I'm sure I'm missing something. Can anyone tell me what?

Thanks





Title: Re: [Solved]Problem with hashing, public keys and the wiki - Wiki information incomp
Post by: Foxpup on November 27, 2013, 04:34:27 AM
The wiki really needs updating.
Why? It says "Take the corresponding public key generated with it (65 bytes...)" and "0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A 299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6" is obviously not 65 bytes if you treat it as an ASCII string. Hell, "18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725" isn't even a valid private key to start with if treated as ASCII. Wherever hex values are mentioned (not just in the Wiki, but everywhere else on the Internet), it's implied that they're, well, actual hex values, and not an ASCII string.


Title: Re: [Solved]Problem with hashing, public keys and the wiki - Wiki information incomp
Post by: Richy_T on November 27, 2013, 05:57:14 AM
The wiki really needs updating.
Why? It says "Take the corresponding public key generated with it (65 bytes...)" and "0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A 299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6" is obviously not 65 bytes if you treat it as an ASCII string. Hell, "18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725" isn't even a valid private key to start with if treated as ASCII. Wherever hex values are mentioned (not just in the Wiki, but everywhere else on the Internet), it's implied that they're, well, actual hex values, and not an ASCII string.

Sure, the hex string represents those bytes but it is ambiguous as to whether you are meant to operate on the string or the bytes themselves. Typically when hex numbers are represented, they'll be written as 0xFFFF notation or FFFFh. If a string, it will be placed in quotes. On the Wiki, neither is the case. Given that other people have had this issue, some clarification would likely not be amiss.

What probably helped throw me off was that my first task was to generate a minikey. For that, you perform the hashing on the string that is the minikey. Now, obviously (I believe) minikeys are a later addition to Bitcoin and shouldn't be looked to for guidance but it did put me in a certain frame of mind. I've also been working with weakly typed languages a lot recently which may have contributed to a certain way of looking at things.

I'll be sharing my code when done so hopefully that will help others.

Edit: Just going back and looking at the wiki page again, I note that the page itself uses 0x notation when referring to bytes in several places. Lack of consistency adds to confusion.


Title: Re: [Solved]Problem with hashing, public keys and the wiki - Wiki information incomp
Post by: Remember remember the 5th of November on November 27, 2013, 07:45:31 AM
A year ago I faced the same problem. I was operating on the string rather than the bytes.