I'm trying to understand the process of creating the children's private key and, in the case of knowing the children's private key and the left 256-bit hash result, the process of returning the parent's private key.
There is a bit more text as I have tried to explain in detail exactly what I am doing as well as to mark all the articles I refer to.
I'll explain what I'm doing through an example and link the article I'm referring to.
So let's start with that we have the left 256-bit hash result (L256B) and the parent's private key (PPK):
L256B (hex): 6539ae80b3618c22f5f8cc4171d04835570bda8db11b5bf1779afae7ec7c79c3 L256B (decimal): 45785512363230816970838539051071102444734444055822171970071151407697781094851 PPK (hex): e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35 PPK (decimal): 105366245268346348601399826821003822098691517983742654654633135381666943167285
The process of obtaining the children's private key is based on the following formula according to this:
children_private_key == (parent_private_key + lefthand_hash_output) % G
That is, on the following formula according to this (where
parse256(IL) is the left 256-bit of the hash result,
kpar is the parent's private key, and
ki denotes the child's private key):
Child private key formula -> parse256(IL) + kpar (mod n) = ki
Also, according to this again a similar formula:
The returned child key ki is parse256(IL) + kpar (mod n)
1. So my first question: is the plus (+) in all these formulas related to a normal plus operation like 2+2 = 4, 6+3 = 9, etc. or is it some kind of concatenation like 2+2 = 22, 6+3 =63 etc.? I ask because in this answer Michael Folkson said it is a concatenation…
There is concatenation where 256 bits placed next to another 256 bits makes 512 bits.
This totally confuses me.
But let's continue with the assumption that normal addition is what we have to do here.
EDIT: I misinterpreted his answer. He wrote that scalar addition is used here (as I thought), not concatenation. My mistake.
So the first thing we need to do is add L256B and PPK:
L256B (decimal): 45785512363230816970838539051071102444734444055822171970071151407697781094851 PPK (decimal): 105366245268346348601399826821003822098691517983742654654633135381666943167285 L256B + PPK (decimal): 151151757631577165572238365872074924543425962039564826624704286789364724262136
The next thing we need to do is the modulo operation with
G (whatever is the correct label).
n is (according to this):
n = 115792089237316195423570985008687907852837564279074904382605163141518161494337
So the children's private key (CPK) is:
CPK = (L256B + PPK) mod n CPK = 151151757631577165572238365872074924543425962039564826624704286789364724262136 mod 115792089237316195423570985008687907852837564279074904382605163141518161494337 CPK (decimal): 35359668394260970148667380863387016690588397760489922242099123647846562767799 CPK (hex): 4e2cdcf2f14e802810e878cf9e6411fc4e712edf19a06bcfcc5d5572e489a3b7
That's exactly what they got in example I am using.
Everything looks fine and correct (assuming the normal + operation is used here and not concatenation).
Now comes the bigger problem. In the example I'm using, they say you can get the parent's private key back from the children's private key. Formula taken from here says:
Solve for kpar -> kpar = ki - parse256(IL) (mod n)
This minus confuses me.
2. So my second question would be what does the minus mean in the formula above? Normal subtraction operation or something else?
I ask because when I try to return the parent's private key from the children's private key, I get the wrong result compared to what they get. The process I use is as follows:
PPK = (CPK - L256) mod n CPK (decimal): 35359668394260970148667380863387016690588397760489922242099123647846562767799 L256B (decimal): 45785512363230816970838539051071102444734444055822171970071151407697781094851 CPK - L256B (decimal): -10425843968969846822171158187684085754146046295332249727972027759851218327052 PPK = -10425843968969846822171158187684085754146046295332249727972027759851218327052 mod 115792089237316195423570985008687907852837564279074904382605163141518161494337 PPK (decimal): -10425843968969846822171158187684085754146046295332249727972027759851218327052 PPK (hex): -170CD18DC2130BFAE5105371D36C3639089AABAE977AF021AB3DA57507F2D60C
So as you can see, I'm not getting the correct parent private key:
-170CD18DC2130BFAE5105371D36C3639089AABAE977AF021AB3DA57507F2D60C != e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35
... unlike those who get the correct key in their solution.
What am I doing wrong? Any help would be appreciated.