I noticed that if I used the ECDsa.SignData Method I always get different ECDSA signature.
So I wonder if it is possible to conclude from the ECDSA signature to the used key?
If Alice sends a message to Bob1 and Bob2, can Eve determine without the public from Alice that the signatures are from the same sender?
public static byte[] SignData(KeyPair privateKeyPair, byte[] data)
{
var ecDsa = ECDsa.Create(ECCurve.NamedCurves.brainpoolP320r1);
ecDsa.ImportParameters(privateKeyPair.CreateECParameters());
return ecDsa.SignData(data, HashAlgorithmName.SHA512);
}
public static bool VerifyData(KeyPair signedKeyPair, byte[] data, byte[] signature)
{
var ecDsa = ECDsa.Create(ECCurve.NamedCurves.brainpoolP320r1);
ecDsa.ImportParameters(signedKeyPair.CreateECParameters());
return ecDsa.VerifyData(data,signature, HashAlgorithmName.SHA512);
}
var plainMsg = Encoding.UTF8.GetBytes("Hello World");
var keyPair = BrainpoolKeyGenerator.CreateKeyPair(true);
var signature1 = SignData(keyPair, plainMsg);
var signature2 = SignData(keyPair, plainMsg);
Assert.That(signature1,Is.Not.EquivalentTo(signature2), "Signature #1 and #2 are NOT equal");
Assert.That(VerifyData(keyPair.ExportPublicKey(), plainMsg, signature1), "Signature of #1 is valid");
Assert.That(VerifyData(keyPair.ExportPublicKey(), plainMsg, signature2), "Signature of #2 is valid");
No, having two ECDSA signatures over the same data doesn't reveal if it was signed by the same party twice or two different parties.
In order to talk about how ECDSA works we need some quick (loosely defined) terms:
G, the Generator, is a point on the curve.d) for a curve isd * G, using curve math we won't talk about here.xandyin RFC5639, section 3.5.n, the curve Order, is the biggest legal value fordgivenG.q, but most everything else calls itn.There's a breakdown of ECDSA on Wikipedia, but the gist of the formula is:
ksuch that0 < k < nris an integer equal to the X coordinate of the EC Pointk * Gzbe the message digest interpreted as a number (with some trimming/extension)kInvbe the inverse ofkmodulon(see also the Extended Euclidean Algorithm).sbekInv * (z + (r * d)) mod nr,s).rand the second half iss, their lengths determined by the curve.So, the first half of the signature is effectively a random number. Elliptic Curve Cryptography is based on the fact that it's hard to compute
Q / G(where Q is the public key, aka a point on the curve), so recoveringkfromris hard.The second half of the signature (
s) is the only part where the signer key is involved, but it gets beat up a lot byk.The signature verification algorithm then checks if
Qandz'(the verifier's version ofz), combined withrandsmake a formula balance. If it doesn't, there's no indication of whether it was because the hash/digest was wrong or the public key was wrong.