Introduction
In the last article we have seen the essentials of elliptic curve cryptography I promised that we would see about digital signatures in the next article. Without digital signatures, cryptocurrencies as we know won’t exist.
Digital Signatures
Let’s say you want to prove to someone that you are the author of certain message, how do you do it using public-key cryptography. Turns out you can digitally sign the message to prove that you indeed published the message. In short, digital signatures can be used to verify that the author or the origin of a message is indeed a legitimate user.
How do you digitally sign a message?
Let’s say a prover wants to prove a message to a verifier who verifies the message.
It just so happens that the names of the prover and verifier are Alice and Bob
respectively. We need to come up with an algorithm that can do this. To start off we
need a base point G that is publicly agreed upon. Here is how the algorithm goes:
- Alice generates a private key
privKeyand keeps it a secret. - She then calculates her public key
pubKeyby multiplyingprivKeywith the base pointG. - She then sends her public key
pubKeyto Bob. - Alice then chooses another random number
rjust like she chose herprivKey. - She then computes a new point
Rby multiplyingrandG. - She also computes a number
sumby adding the two numbersprivKeyandr. - She then sends them off to Bob for him to verify.
- Bob then verifies that
sum * G == pubKey + R. (this is possible because its a property of elliptic curves, if you are not familiar check out my previous article on the same).
But this algorithm allows someone else to trick Bob without knowing Alice’s private
key privKey. Give it a thought on how one can possibly deceive Bob.
Since the other person knows that Bob will calculate sum * G == pubKey + R in order to verify,
she can just compute R as follows R = r*G - pubKey and just set sum = r. Now the
equation works out to be sum * G == pubKey + r*G - pubKey (once we replacesum with r and
expand R) and that in turn works out to r*G == r*G
Well it’s really sad that we can cheat using this algorithm. But there is a fix.
The fix is that instead of adding pubKey to R once, Bob chooses to add pubKey
x times to R. So in the updated algorithm Bob calculates RHS as follows (x*pubKey) + R,
and then send Alice the number x so that she can calculate and send back the number
sum = (x*privkey) + r and Bob will compute the LHS as follows sum * G and verify that it
is indeed Alice. The updated algorithm would be:
- Alice chooses a random number
rand send the pointRby calculatingr*G. - Bob then chooses a number
xand send it to Alice. - Alice knows that Bob would add
pubKeytoRxtimes, so she does the same with the numbers, she calculatessum = (x*privKey) + r. She then sends the numbersumto Bob. - Bob then verifies by computing
sum * G == (x*pubKey) + R.
It’s really not practical to communicate these many times while verifying. So to make the process
a little more non-interactive the number x is usually set to the hash of the point R. But the
hash function should be deemed good so that others can’t trick the hash function. Note that Alice
can’t compute x efficiently if the hash function is deemed good, this is because of the preimage
resistance property of hash functions. Meaning she can’t cheat because x = hash(R) and to compute
a fake R that cancels out pubKey in the equation she needs to a number which is dependent on the
point R.