What do you think of P2WKH (160bit hash of pubkey) vs P2WSH (256bit hash of pubkey) security?
In P2WKH you have to re-built an unknow script, and if you want to unlock a P2WKH Tx, you have to found a sha256 collision with the lock script of this transaction.
To me, it is still very secure unless you break sha256 and then, find a way to create a new valid script corresponding to the precedent hash.
in the code I am looking at on windows the wrapper just uses
System.Security.Cryptography.SHA256 and does a double hash and I can see that the public key
gets used to to create a signature along with the double hash so how does this work ?
I just thought the hash was used as a checksum of the signature contents and don't quite understand whats going on in the code below.
public BigInteger[] GenerateSignature(BigInteger privateKey, byte[] hash, BigInteger? k)
{
for(int i = 0; i < 100; i++)
{
if (k == null)
{
byte[] kBytes = new byte[33];
rngCsp.GetBytes(kBytes);
kBytes[32] = 0;
k = new BigInteger(kBytes);
}
var z = hash.ToBigIntegerUnsigned(true);
if (k.Value.IsZero || k >= Secp256k1.N) continue;
var r = Secp256k1.G.Multiply(k.Value).X % Secp256k1.N;
if (r.IsZero) continue;
var ss = (z + r * privateKey);
var s = (ss * (k.Value.ModInverse(Secp256k1.N))) % Secp256k1.N;
if (s.IsZero) continue;
return new BigInteger[] { r, s };
}
throw new Exception("Unable to generate signature");
}
Somehow later the public key must be used to somehow validate the two bigints returned from this funtion