# Elliptic Curve DSA

Template:Use mdy dates In cryptography, the Elliptic Curve Digital Signature Algorithm (ECDSA) offers a variant of the Digital Signature Algorithm (DSA) which uses elliptic curve cryptography.

## Key and signature-size comparison to DSA

As with elliptic curve cryptography in general, the bit size of the public key believed to be needed for ECDSA is about twice the size of the security level, in bits. By comparison, at a security level of 80 bits (meaning an attacker requires the equivalent of about ${\displaystyle 2^{80}}$ operations to find the private key) the size of a DSA public key is at least 1024 bits, whereas the size of an ECDSA public key would be 160 bits. On the other hand, the signature size is the same for both DSA and ECDSA: ${\displaystyle 4t}$ bits, where ${\displaystyle t}$ is the security level measured in bits, that is, about 320 bits for a security level of 80 bits.

## Signature generation algorithm

Suppose Alice wants to send a signed message to Bob. Initially, they must agree on the curve parameters ${\displaystyle ({\textrm {CURVE}},G,n)}$. In addition to the field and equation of the curve, we need ${\displaystyle G}$, a base point of prime order on the curve; ${\displaystyle n}$ is the multiplicative order of the point ${\displaystyle G}$.

Parameter
CURVE the elliptic curve field and equation used
G elliptic curve base point, a generator of the elliptic curve with large prime order n
n integer order of G, means that ${\displaystyle n\times G=O}$

Alice creates a key pair, consisting of a private key integer ${\displaystyle d_{A}}$, randomly selected in the interval ${\displaystyle [1,n-1]}$; and a public key curve point ${\displaystyle Q_{A}=d_{A}\times G}$. We use ${\displaystyle \times }$ to denote elliptic curve point multiplication by a scalar.

For Alice to sign a message ${\displaystyle m}$, she follows these steps:

1. Calculate ${\displaystyle e={\textrm {HASH}}(m)}$, where HASH is a cryptographic hash function, such as SHA-1.
2. Let ${\displaystyle z}$ be the ${\displaystyle L_{n}}$ leftmost bits of ${\displaystyle e}$, where ${\displaystyle L_{n}}$ is the bit length of the group order ${\displaystyle n}$.
3. Select a random integer ${\displaystyle k}$ from ${\displaystyle [1,n-1]}$.
4. Calculate the curve point ${\displaystyle (x_{1},y_{1})=k\times G}$.
5. Calculate ${\displaystyle r=x_{1}\,{\bmod {\,}}n}$. If ${\displaystyle r=0}$, go back to step 3.
6. Calculate ${\displaystyle s=k^{-1}(z+rd_{A})\,{\bmod {\,}}n}$. If ${\displaystyle s=0}$, go back to step 3.
7. The signature is the pair ${\displaystyle (r,s)}$.

When computing ${\displaystyle s}$, the string ${\displaystyle z}$ resulting from ${\displaystyle {\textrm {HASH}}(m)}$ shall be converted to an integer. Note that ${\displaystyle z}$ can be greater than ${\displaystyle n}$ but not longer.[1]

As the standard notes, it is crucial to select different ${\displaystyle k}$ for different signatures, otherwise the equation in step 6 can be solved for ${\displaystyle d_{A}}$, the private key: Given two signatures ${\displaystyle (r,s)}$ and ${\displaystyle (r,s')}$, employing the same unknown ${\displaystyle k}$ for different known messages ${\displaystyle m}$ and ${\displaystyle m'}$, an attacker can calculate ${\displaystyle z}$ and ${\displaystyle z'}$, and since ${\displaystyle s-s'=k^{-1}(z-z')}$ (all operations in this paragraph are done modulo ${\displaystyle n}$) the attacker can find ${\displaystyle k={\frac {z-z'}{s-s'}}}$. Since ${\displaystyle s=k^{-1}(z+rd_{A})}$, the attacker can now calculate the private key ${\displaystyle d_{A}={\frac {sk-z}{r}}}$. This implementation failure was used, for example, to extract the signing key used in the PlayStation 3 gaming-console.[2]

## Signature verification algorithm

For Bob to authenticate Alice's signature, he must have a copy of her public-key curve point ${\displaystyle Q_{A}}$. Bob can verify ${\displaystyle Q_{A}}$ is a valid curve point as follows:

1. Check that ${\displaystyle Q_{A}}$ is not equal to the identity element ${\displaystyle O}$, and its coordinates are otherwise valid
2. Check that ${\displaystyle Q_{A}}$ lies on the curve
3. Check that ${\displaystyle n\times Q_{A}=O}$

After that, Bob follows these steps:

1. Verify that ${\displaystyle r}$ and ${\displaystyle s}$ are integers in ${\displaystyle [1,n-1]}$. If not, the signature is invalid.
2. Calculate ${\displaystyle e={\textrm {HASH}}(m)}$, where HASH is the same function used in the signature generation.
3. Let ${\displaystyle z}$ be the ${\displaystyle L_{n}}$ leftmost bits of ${\displaystyle e}$.
4. Calculate ${\displaystyle w=s^{-1}\,{\bmod {\,}}n}$.
5. Calculate ${\displaystyle u_{1}=zw\,{\bmod {\,}}n}$ and ${\displaystyle u_{2}=rw\,{\bmod {\,}}n}$.
6. Calculate the curve point ${\displaystyle (x_{1},y_{1})=u_{1}\times G+u_{2}\times Q_{A}}$.
7. The signature is valid if ${\displaystyle r\equiv x_{1}{\pmod {n}}}$, invalid otherwise.

Note that using Straus's algorithm (also known as Shamir's trick) a sum of two scalar multiplications ${\displaystyle u_{1}\times G+u_{2}\times Q_{A}}$ can be calculated faster than with two scalar multiplications.[3]

## Correctness of the algorithm

It is not immediately obvious why verification even functions correctly. To see why, denote as ${\displaystyle C}$ the curve point computed in step 6 of verification,

From the definition of the public key as ${\displaystyle Q_{A}=d_{A}\times G}$,

Because elliptic curve scalar multiplication distributes over addition,

Expanding the definition of ${\displaystyle u_{1}}$ and ${\displaystyle u_{2}}$ from verification step 4,

Collecting the common term ${\displaystyle s^{-1}}$,

Expanding the definition of ${\displaystyle s}$ from signature step 6,

Since the inverse of an inverse is the original element, and the product of an element's inverse and the element is the identity, we are left with

From the definition of ${\displaystyle r}$, this is verification step 6.

This shows only that a correctly signed message will verify correctly; many other properties are required for a secure signature algorithm.

## Security

In December 2010, a group calling itself fail0verflow announced recovery of the ECDSA private key used by Sony to sign software for the PlayStation 3 game console. However, this attack only worked because Sony did not properly implement the algorithm, because ${\displaystyle k}$ was static instead of random. As pointed out in the Signature generation algorithm Section above, this makes ${\displaystyle d_{A}}$ solvable and the entire algorithm useless.[4]

On March 29, 2011, two researchers published an IACR paper[5] demonstrating that it is possible to retrieve a TLS private key of a server using OpenSSL that authenticates with Elliptic Curves DSA over a binary field via a timing attack.[6] The vulnerability was fixed in OpenSSL 1.0.0e.[7]

In August 2013, it was revealed that bugs in some implementations of the Java class SecureRandom sometimes generated collisions in the k value. As discussed above, this allowed solution of the private key, in turn allowing stealing bitcoins from the containing wallet on Android app implementations, which use Java and rely on ECDSA to authenticate transactions.[8]

This issue can be prevented by deterministic generation of k, as described by RFC 6979.