From c3dc90cddef937914579076388445db1bcae8850 Mon Sep 17 00:00:00 2001 From: Andrej Zavgorodnij Date: Wed, 12 Feb 2020 18:59:31 +0300 Subject: [PATCH] feat: dkg-rewrite --- go.sum | 7 +++---- share/dkg/pedersen/dkg.go | 8 ++++++++ share/dkg/pedersen/structs.go | 15 ++++++++++++++- share/vss/pedersen/vss.go | 4 ++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/go.sum b/go.sum index dcae93e4..2a22ca0e 100644 --- a/go.sum +++ b/go.sum @@ -9,14 +9,13 @@ go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs= go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw= go.dedis.ch/kyber/v3 v3.0.4 h1:FDuC/S3STkvwxZ0ooo3gcp56QkUKsN7Jy7cpzBxL+vQ= go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= -go.dedis.ch/kyber/v4 v4.0.0-pre1 h1:1f5OPESkyxK6kPaCSV3J9BlpnoysIpbGLNujX9Ov8m4= -go.dedis.ch/kyber/v4 v4.0.0-pre1/go.mod h1:cFStqSeD4d3Y7mal8kCRSq7I7QPeTBA0f5cRl1pqEWA= +go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg= go.dedis.ch/protobuf v1.0.5 h1:EbF1czEKICxf5KY8Tm7wMF28hcOQbB6yk4IybIFWTYE= go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo= go.dedis.ch/protobuf v1.0.7 h1:wRUEiq3u0/vBhLjcw9CmAVrol+BnDyq2M0XLukdphyI= go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4= -go.dedis.ch/protobuf v1.0.10 h1:/8plWfioYRf9sBQdCvoNfLf+XHuQWF1ctC1gWzzmojk= -go.dedis.ch/protobuf v1.0.10/go.mod h1:oIXBd4PkP3jxrN9t/eslifGU2tTeG9JuMUjMFrgfcEc= +go.dedis.ch/protobuf v1.0.11 h1:FTYVIEzY/bfl37lu3pR4lIj+F9Vp1jE8oh91VmxKgLo= +go.dedis.ch/protobuf v1.0.11/go.mod h1:97QR256dnkimeNdfmURz0wAMNVbd1VmLXhG1CrTYrJ4= golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b h1:Elez2XeF2p9uyVj0yEUDqQ56NFcDtcBNkYP7yv8YbUE= golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/sys v0.0.0-20190124100055-b90733256f2e h1:3GIlrlVLfkoipSReOMNAgApI0ajnalyLa/EZHHca/XI= diff --git a/share/dkg/pedersen/dkg.go b/share/dkg/pedersen/dkg.go index 76a88cce..22e6681a 100644 --- a/share/dkg/pedersen/dkg.go +++ b/share/dkg/pedersen/dkg.go @@ -252,6 +252,14 @@ func NewDistKeyGenerator(suite Suite, longterm kyber.Scalar, participants []kybe return NewDistKeyHandler(c) } +func (d *DistKeyGenerator) GetConfig() *Config { + return d.c +} + +func (d *DistKeyGenerator) GetDealer() *vss.Dealer { + return d.dealer +} + // Deals returns all the deals that must be broadcasted to all participants in // the new list. The deal corresponding to this DKG is already added to this DKG // and is ommitted from the returned map. To know which participant a deal diff --git a/share/dkg/pedersen/structs.go b/share/dkg/pedersen/structs.go index 6ffab89a..4009dd96 100644 --- a/share/dkg/pedersen/structs.go +++ b/share/dkg/pedersen/structs.go @@ -1,9 +1,10 @@ package dkg import ( + "fmt" "bytes" "encoding/binary" - + "encoding/json" "go.dedis.ch/kyber/v3" "go.dedis.ch/kyber/v3/share" vss "go.dedis.ch/kyber/v3/share/vss/pedersen" @@ -58,6 +59,18 @@ func (d *Deal) MarshalBinary() ([]byte, error) { return b.Bytes(), nil } +func (d *Deal) Encode() ([]byte, error) { + return json.Marshal(d) +} + +func (d *Deal) Decode(data []byte) error { + if err := json.Unmarshal(data, d); err != nil { + return fmt.Errorf("failed to decode deal: %w", err) + } + + return nil +} + // Response holds the Response from another participant as well as the index of // the target Dealer. type Response struct { diff --git a/share/vss/pedersen/vss.go b/share/vss/pedersen/vss.go index 91c9ec63..0441870a 100644 --- a/share/vss/pedersen/vss.go +++ b/share/vss/pedersen/vss.go @@ -353,7 +353,7 @@ func NewVerifier(suite Suite, longterm kyber.Scalar, dealerKey kyber.Point, // If the deal has already been received, or the signature generation of the // response failed, it returns an error without any responses. func (v *Verifier) ProcessEncryptedDeal(e *EncryptedDeal) (*Response, error) { - d, err := v.decryptDeal(e) + d, err := v.DecryptDeal(e) if err != nil { return nil, err } @@ -391,7 +391,7 @@ func (v *Verifier) ProcessEncryptedDeal(e *EncryptedDeal) (*Response, error) { return r, nil } -func (v *Verifier) decryptDeal(e *EncryptedDeal) (*Deal, error) { +func (v *Verifier) DecryptDeal(e *EncryptedDeal) (*Deal, error) { // verify signature if err := schnorr.Verify(v.suite, v.dealer, e.DHKey, e.Signature); err != nil { return nil, err