Skip to content

Commit 8ee4e39

Browse files
author
zhdllwyc
committed
update dkls
1 parent c9ffb0b commit 8ee4e39

10 files changed

+321
-339
lines changed

tss/ecdsa/dkls/ecdsaDKLS.go

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Reference: https://eprint.iacr.org/2018/499.pdf
2+
// 2 out of 2 party threhsold signature scheme
3+
// Figure 1 and Protocol 1 and 2
4+
5+
package dkls
6+
7+
import (
8+
"crypto/ecdsa"
9+
"crypto/elliptic"
10+
"crypto/rand"
11+
"errors"
12+
"math/big"
13+
14+
"github.com/cloudflare/circl/group"
15+
)
16+
17+
// Input: myGroup, the group we operate in
18+
// Input: sk, the real secret key
19+
// Output: share1, share2 the multiplicative secret key shares for 2 parties.
20+
func KeyShareGen(myGroup group.Group, sk group.Scalar) (group.Scalar, group.Scalar) {
21+
share1 := myGroup.RandomNonZeroScalar(rand.Reader)
22+
share1Inv := myGroup.NewScalar()
23+
share1Inv.Inv(share1)
24+
25+
share2 := myGroup.NewScalar()
26+
share2.Mul(share1Inv, sk)
27+
28+
return share1, share2
29+
}
30+
31+
func hashToInt(hash []byte, c elliptic.Curve) *big.Int {
32+
orderBits := c.Params().N.BitLen()
33+
orderBytes := (orderBits + 7) / 8
34+
35+
if len(hash) > orderBytes {
36+
hash = hash[:orderBytes]
37+
}
38+
39+
ret := new(big.Int).SetBytes(hash)
40+
excess := len(hash)*8 - orderBits
41+
if excess > 0 {
42+
ret.Rsh(ret, uint(excess))
43+
}
44+
return ret
45+
}
46+
47+
// ECDSA threshold signature verification
48+
// Input: (r,s), the signature
49+
// Input: hashMSG, the message
50+
// Input: publicKey, the ECDSA public key
51+
// Output: verification passed or not
52+
func Verify(r, s group.Scalar, hashMSG []byte, publicKey *ecdsa.PublicKey) error {
53+
rBig := new(big.Int)
54+
sBig := new(big.Int)
55+
56+
rByte, errByte := r.MarshalBinary()
57+
if errByte != nil {
58+
panic(errByte)
59+
}
60+
rBig.SetBytes(rByte)
61+
62+
sByte, errByte := s.MarshalBinary()
63+
if errByte != nil {
64+
panic(errByte)
65+
}
66+
sBig.SetBytes(sByte)
67+
68+
verify := ecdsa.Verify(publicKey, hashMSG, rBig, sBig)
69+
if !verify {
70+
return errors.New("ECDSA threshold verification failed")
71+
}
72+
return nil
73+
}

tss/ecdsa/ot/ecdsaTSSOTParty.go tss/ecdsa/dkls/ecdsaDKLSParty.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package ECDSAOT
1+
package dkls
22

33
import (
44
"github.com/cloudflare/circl/group"
5-
"github.com/cloudflare/circl/tss/ecdsa/ot/Fmul"
5+
"github.com/cloudflare/circl/tss/ecdsa/dkls/fmul"
66
)
77

88
// The sender of Fmul
@@ -18,10 +18,10 @@ type AlicePre struct {
1818

1919
a group.Scalar // A random blinding for beaver's triple
2020
ta group.Scalar // Additive share of a*b
21-
receivera Fmul.ReceiverFmul // Receiver of Fmul for a*b
21+
receivera fmul.ReceiverFmul // Receiver of Fmul for a*b
2222

2323
tkA group.Scalar // Additive share of 1/kA*1/kB
24-
receiverkAInv Fmul.ReceiverFmul // Receiver of Fmul for 1/kA*1/kB
24+
receiverkAInv fmul.ReceiverFmul // Receiver of Fmul for 1/kA*1/kB
2525
myGroup group.Group // The elliptic curve we operate in
2626
}
2727

@@ -37,10 +37,10 @@ type BobPre struct {
3737

3838
b group.Scalar // A random blinding for beaver's triple
3939
tb group.Scalar // Additive share of a*b
40-
senderb Fmul.SenderFmul // Sender of Fmul for a*b
40+
senderb fmul.SenderFmul // Sender of Fmul for a*b
4141

4242
tkB group.Scalar // Additive share of 1/kA*1/kB
43-
senderkBInv Fmul.SenderFmul // Sender of Fmul for 1/kA*1/kB
43+
senderkBInv fmul.SenderFmul // Sender of Fmul for 1/kA*1/kB
4444
myGroup group.Group // The elliptic curve we operate in
4545
}
4646

@@ -53,7 +53,7 @@ type Alice struct {
5353
ta group.Scalar // Additive share of a*b
5454
tkA group.Scalar // Additive share of 1/kA*1/kB
5555
Rx group.Scalar // x coordinate of point [kA][kB]G
56-
beaver group.Scalar //skA/(kA*a)
56+
beaver group.Scalar // skA/(kA*a)
5757
}
5858

5959
type Bob struct {
@@ -64,6 +64,5 @@ type Bob struct {
6464
tb group.Scalar // Additive share of a*b
6565
tkB group.Scalar // Additive share of 1/kA*1/kB
6666
Rx group.Scalar // x coordinate of point [kA][kB]G
67-
beaver group.Scalar //skB/(kB*b)
68-
67+
beaver group.Scalar // skB/(kB*b)
6968
}

0 commit comments

Comments
 (0)