This is a slight variation of the shared nonce problem. We do have a lot more shared information between two nonces.
Given a random $k$:
$$
k_1 = ka,
k_2 = kb
$$
I am now signing two messages, which gives me $s_1,r_1,s_2,r_2$
Based on my understanding of the base equation for signatures in ECDSA
(with given generator $G$, private key $d$)
$$
r=kG,
s=k^-1(h+rd)
$$
So now I have two equations, which I can use to resolve $k$:
$$
\begin{align}
s_1-s_2&=k_1^{-1}(h_1+r_1d)-k_2^{-1}(h_2+r_2d) \\
s_1-s_2&=k_1^{-1}h_1+k_1^{-1}r_1d-k_2^{-1}h_2-k_2^{-1}r_2d &&\text{expand $k_1,k_2$}\\
s_1-s_2&=k^{-1}a^{-1}h_1 + k^{-1}a^{-1}r_1d - k^{-1}b^{-1}h_2 - k^{-1}b^{-1}r_2d &&\text{expand $r_1,r_2$}\\
s_1-s_2&=k^{-1}a^{-1}h_1 + k^-1a^{-1}(kaG)d - k^{-1}b^{-1}h_2 - k^{-1}b^{-1}(kbG)d \\
s_1-s_2&=k^{-1}a^{-1}h_1 + k^{-1}ka^{-1}aGd - k^{-1}b^{-1}h_2 - k^{-1}kb^{-1}bGd \\
s_1-s_2&=k^{-1}a^{-1}h_1 + k^{-1}ka^{-1}aGd - k^{-1}kb^{-1}bGd -k^{-1}b^{-1}h_2 \\
s_1-s_2&=k^{-1}a^{-1}h_1 + Gd - Gd -k^{-1}b^{-1}h_2 \\
s_1-s_2&=k^{-1}a^{-1}h_1 -k^{-1}b^{-1}h_2 \\
k(s_1-s_2)&=a^{-1}h_1 - b^{-1}h_2 \\
k&=(a^{-1}h_1 - b^{-1}h_2)(s_1-s_2)^{-1}
\end{align}
$$
I tried implementing this in python:
import ecdsa
import random
import libnum
import hashlib
import sys
G = ecdsa.ecdsa.generator_256
order = G.order()
priv1 = random.randrange(1,order)
Public_key = ecdsa.ecdsa.Public_key(G, G * priv1)
x1 = ecdsa.ecdsa.Private_key(Public_key, priv1)
k = random.randrange(1, 2**127)
msg1="testmessage one"
msg2="testmessage two"
h1 = bytes_to_long(hashlib.sha1(msg1.encode()).digest())
h2 = bytes_to_long(hashlib.sha1(msg2.encode()).digest())
a=101
b=197
sig1 = x1.sign(h1, k*a)
sig2 = x1.sign(h2, k*b)
r1,s1 = sig1.r,sig1.s
r2,s2 = sig2.r,sig2.s
k_recovered = (((libnum.invmod(int(a),order)*(h1))%order-(libnum.invmod(int(b),order)*(h2)%order))*libnum.invmod( (s1-s2),order))%order
print ("\nk: \t\t",k)
print ("k recovered \t",k_recovered)
Which gives me a wrong k
k: 11380758029406828810642876408403002369
k recovered 92413802760778512715100399489368323379693045694765104020036290177818159224142
I've been staring at this way too long and could use a second pair of eyes. Am I missing something in the base math or did I mess up the implementation?
(ps, this is somewhat similar to the problems discussed here