🖋️ECDSA
Elliptic Curve Digital Signature Algorithm
Signature algorithm
Use the secret scalar to compute the public point, by doing a scalar multiplication with : .
Pick a random (secret) scalar , and perform a scalar multiplication with to get a random point.
Use the above variables in the general equation of ECDSA is: , where, , is the 256-bit message being signed
Simplify the resulting equation to get the component of the signature:
from random import randint
@dataclass
class PrivateKey:
secret: int
def sign(self, z: int) -> "Signature":
e = self.secret
k = randint(0, N)
R = k * G
r = R.x.value
k_inv = pow(k, -1, N) # Python 3.8+
s = ((z + r*e) * k_inv) % N
return Signature(r, s)Apart from the fact that e is a secret number, the security of ECDSA also relies on the condition that k is also very random and secret.
We'll learn about the consequences of not having a random kin the next section.
Verification algorithm
Given: (r, s) is the signature, z is the 256 bit message being signed, and P is the public key of the signer.
Calculate: , .
Calculate .
Signature is valid is is equal to .
Testing our ECDSA implementation
Resources
Last updated
Was this helpful?