4.4 Digital signatures
ECDSA
ECDSA stands for elliptic curve digital signature algorithm. It is used to verify that a message was signed by a certain user.
Consider a curve E over a field Fq and a subgroup of a prime size r with generator G (r should be large). All these parameters are public. Then a signer generates a private key s∈Fr and reveals a public key K=[s]G.
Assume a signer wants to sign a message m with hash H(m)∈Fr (both m and H(m) is public). Then he chooses a random k∈Fr∗, computes R:=[k]G=(xR,yR) and a signature sg:=k−1(H(m)+sxR)(modr). Then he publishes:
(R,sg)
The verifier generates H(m) and then computes u1=sg−1H(m) and u2=sg−1xR. Then computes V=[u1]G+[u2]K. The signature is valid if V=R.
Let's check that it's indeed the case:
V=[u1]G+[u2]K=[sg−1H(m)]G+[sg−1xRs]G=[sg−1]([H(m)]G+[xRs]G)=[sg−1sgk]G=[k]G=R
BLS 12-381
BLS 12-381 is named after Barreto-Lynn-Scott with 12 being the embedding degree of the elliptic curve and 381 is the number of bits that's needed to encode field size (q). It is a more advanced algorithm than ECDSA and allows having aggregated and threshold signatures.
Setup
This algorithm relies heavily on pairings, so let's describe the setup. First, it's based on a family of elliptic curves with the folowing attributes:
q(x):=31(x−1)2(x4−x2+1)+xr(x):=Φ12(x)=x4−x2+1t(x)=x+1
So we can pick some parameter x and then find an elliptic curve with these attributes, namely q - finite field size, r - the size of the torsion subgroup, t:=∣E(Fq)−q−1∣ - trace of the curve.
In a specific case of BLS 12-381 we take
x=−15132376222941642752q=4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787r=52435875175126190479447740508185965837690552500527637822603658699938581184513t=−15132376222941642751
Or in hexadecimal:
x=−0xd201000000010000q=0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaabr=0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001t=−0xd20100000000ffff
In this case we have embedding degree is 12 (we can check r∣q12−1).
Then we define a field extension Fq12 in the following way:
Fq2:=Fq(α),i2+1=0Fq6:=Fq2(β),β3−i−1=0Fq12:=Fq6(γ),γ2−β=0
Next we define two curves: the prime curve and it's sextic twist:
y2=x3+4y2=x3+4(1+i)
Note they have both the same j-invariant (j=0) and hence isomorphic. Moreover u=γ and u6=1+i∈Fq2 so this is indeed a sextic twist.
Then we can define an Ate pairing:
αλ:E[r]Fqk×EFqk/[r]EFqk→μr
with λ=q(modr).
But we take the first torsion to be from Fq since r∣∣EFq∣ and the second from Fq2 of the twisted curve. We can do it since d=6 and k=12 but the question is why do we have an r-torsion subgroup in a twist over Fq2? It can be derived that if ∣EFq∣=q+1−t then ∣EFq2∣=q+1−t2=q+1−(t2−2q). But for twist we have t′=−t so t2′=(−t2)2−2q=t2. So we have the same number of points in both curves over Fq2 but r∣∣EFq2∣ since the r-torsion subgroup over Fq is still in Fq2. So we have r-torsion subgroup in a twist as well. To sum up out Ate pairing is defined in:
αλ:E[r]Fq×EFq2/[r]EFq2→μr
So we limit ourselves to arithmetic in Fq2 only. But μr is in Fq12 so how come we're limited only to Fq2? The thing is we actually aren't. We're just doing all arithmetics in on elliptic curves in Fq2 but then we need to map it back to Fq12 via isomopshism and make a final expontiation in this field.
The following generators for two torsion groups are used:
G1:=⟨P⟩G,G2:=⟨Q⟩GP=(xP,yP),Q=(xQ,yQ)xP=0x04yP=0x0a989badd40d6212b33cffc3f3763e9bc760f988c9926b26da9dd85e928483446346b8ed00e1de5d5ea93e354abe706cxQ=0x02yQ=0x013a59858b6809fca4d9a3b6539246a70051a3c88899964a42bc9a69cf9acdd9dd387cfa9086b894185b9a46a402be73+0x02d27e0ec3356299a346a09ad7dc4ef68a483c3aed53f9139d2f929a3eecebf72082e5e58c6da24ee32e03040c406d4f⋅i
Hashing
To implement a digital signature we first need to find a way to hash a message into a point of the group G2. We use the following algorithm:
- Make a hash h into a number mod q
- Check if there's a point S in E′(Fq2) with real part of x-coordinate being h and imaginary part being 0.
- If there is then G:=[∣E′(Fq2)∣/r]S is the point in E[r] and we can use the anti-trace map to map it to G2 and that is our hash
- If not: add 1 to message and goto 1.
This is a basic hashing algorithm that involve some trial-and-error check and thus doesn't have explicit guarantees on the time of the hashing (though in practice it works fine - 20 iterations in the worst random message in 1 000 000 messages).
Currently more advanced algorithms like SWU (The simplified Shallue–van de Woestijne–Ulas map of Brier) are used.
Single signature
We take private key to be any number
s:0≤s≤r−1
Then public key
K:=[s]P
Then we take a hash of the message m to be H(m). Then the signature of the message is
S=[s]H(m)
Now we can easily verify this signature. It's valid iff:
αλ(P,S)=αλ(K,H(m))
Note that we can always do this check as all the arguments in the pairing are public. But in order to make this signature S correct, the signer needs to know private key s. Why does this check work?
αλ(P,S)=αλ(P,[s]H(m))=αλ(P,H(m))s=αλ([s]P,H(m))=αλ(K,H(m))
Aggregated signatures
If we want the same message to be signed by n parties we don't need to check pairing equations n times. We can actually do it once. If we have keys Ki=[si]P and signatures Si=[si]H(m) then we can calculate that combined key K=∑Ki and combined signature S=∑Si. Then
αλ(P,S)=αλ(P,∑Si)=αλ(P,∑[si]H(m))=αλ(∑[si]P,H(m))=αλ(K,H(m))
Threshold signatures
Now we want to verify that message is signed by k out of n parties. To do that we generate a private key s and then use a technique called Shamir Secret Sharing.
First, we take n values of xi∈Fr (this could be arbitrary like 1,2,…,n or some roots of unity). Then we assume that a0=s take k−1 random values ai∈Fr(i=1,2,…,k−1) and calculate a polynomial f(x)=a0+a1x+…+ak−1xk−1.
Next we calculate n points (xi,si:=f(xi)) and give si to each signing party. Each (xi,si:=f(xi)) is a private key. K:=[s]P is public key that we make available to verifiers. Note that having k private keys (xi,si) we can recover the private key s using Lagrange interpolation:
s=a0=f(0)=j=0∑k−1sji=0,i=j∏k−1xi−xjxi
This is how Shamir Secret Sharing works. In essence we take n≥k points of a polynomial of degree k−1. Knowing k points we can reconstruct this polynomial and thus find a0 which is our private key. At the same time having less than k points is not enough to infer anything.
Now we use this technique for threshold signatures. Assume we have k out of n signatures:
(xi,Si:=[si]H(m))
Then the verifier has the following data:
m,H(m),K(xi1,Si1),…,(xik,Sik)
The verification procedure then:
αλ(K,H(m))=αλ([s]P,H(m))=αλ(P,[s]H(m))=αλ(P,[j=0∑k−1sji=0,i=j∏k−1xi−xjxi]H(m))=αλ(P,[j=0∑k−1bjsj]H(m))=αλ(P,j=0∑k−1[bj]Sj)
So all the verifier needs to check is:
αλ(K,H(m))=αλ(P,j=0∑k−1[i=0,i=j∏k−1xi−xjxi]Sj)
then we have correct k out of n signatures.