Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.dedis.ch/protobuf"
"go.dedis.ch/kyber/v4/internal/protobuf"
)

type intWrapper struct {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/kilic/bls12-381 v0.1.0
github.com/stretchr/testify v1.11.1
go.dedis.ch/fixbuf v1.0.3
go.dedis.ch/protobuf v1.0.11
golang.org/x/crypto v0.44.0
golang.org/x/sys v0.38.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
12 changes: 0 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZ
github.com/consensys/gnark-crypto v0.19.2 h1:qrEAIXq3T4egxqiliFFoNrepkIWVEeIYwt3UL0fvS80=
github.com/consensys/gnark-crypto v0.19.2/go.mod h1:rT23F0XSZqE0mUA0+pRtnL56IbPxs6gp4CeRsBk4XS0=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I=
Expand All @@ -22,23 +21,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
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/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ=
go.dedis.ch/kyber/v3 v3.0.9 h1:i0ZbOQocHUjfFasBiUql5zVeC7u/vahFd96DFA8UOWk=
go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg=
go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo=
go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4=
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/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.44.0 h1:A97SsFvM3AIwEEmTBiaxPPTYpDC47w720rdiiUvgoAU=
golang.org/x/crypto v0.44.0/go.mod h1:013i+Nw79BMiQiMsOPcVCB5ZIJbYkerPrGnOa00tvmc=
golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
Expand Down
57 changes: 57 additions & 0 deletions internal/v3marshaling.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package internal

import (
"fmt"
"math"
"reflect"

"go.dedis.ch/kyber/v4"
"go.dedis.ch/kyber/v4/internal/protobuf"
"go.dedis.ch/kyber/v4/share"
)

// Suite defines the capabilities required by the v3marshalling package.
type Suite interface {
// Group is needed for Group.Scalar
kyber.Group
}

// compatiblePriShare is a struct for PriShare used when marshaling to
// ensure compatibility with V3
type compatiblePriShare struct {
I int64
V kyber.Scalar
}

// MarshalPriShare marshals a share.PriShare into bytes or returns an error
// if the encoding did not work. Encoding is compatible with Kyber V3
func MarshalPriShare(priShare *share.PriShare) ([]byte, error) {
toEncode := &compatiblePriShare{
I: int64(priShare.I),
V: priShare.V,
}
return protobuf.Encode(toEncode)
}

// UnmarshalPriShare unmarshals a share.PriShare from bytes or returns an error
// if the decoding did not work. Decoding is compatible with Kyber V3
func UnmarshalPriShare(data []byte, suite Suite) (*share.PriShare, error) {
compatiblePriShare := &compatiblePriShare{}
constructors := make(protobuf.Constructors)
constructors[reflect.TypeFor[kyber.Scalar]()] = func() interface{} { return suite.Scalar() }
err := protobuf.DecodeWithConstructors(data, compatiblePriShare, constructors)

// Check for overflow on I
if compatiblePriShare.I < 0 || compatiblePriShare.I > math.MaxUint32 {
return nil, fmt.Errorf("cannot cast I as uint32 due to overflow")
}

if err != nil {
return nil, err
}
priShare := &share.PriShare{
I: uint32(compatiblePriShare.I),
V: compatiblePriShare.V,
}
return priShare, nil
}
2 changes: 1 addition & 1 deletion pairing/bn254/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/stretchr/testify/require"
"go.dedis.ch/kyber/v4"
"go.dedis.ch/kyber/v4/group/mod"
"go.dedis.ch/kyber/v4/internal/protobuf"
"go.dedis.ch/kyber/v4/util/random"
"go.dedis.ch/protobuf"
)

func TestScalarMarshal(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pairing/bn256/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/stretchr/testify/require"
"go.dedis.ch/kyber/v4"
"go.dedis.ch/kyber/v4/group/mod"
"go.dedis.ch/kyber/v4/internal/protobuf"
"go.dedis.ch/kyber/v4/util/random"
"go.dedis.ch/protobuf"
//nolint:staticcheck // bn256 is deprecated. We need this package for our implementation.
"golang.org/x/crypto/bn256"
)
Expand Down
3 changes: 1 addition & 2 deletions share/dkg/rabin/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"go.dedis.ch/kyber/v4/share"
vss "go.dedis.ch/kyber/v4/share/vss/rabin"
"go.dedis.ch/kyber/v4/sign/schnorr"
"go.dedis.ch/protobuf"
)

// Suite wraps the functionalities needed by the dkg package
Expand Down Expand Up @@ -681,7 +680,7 @@ func (cc *ComplaintCommits) Hash(s Suite) []byte {
_, _ = h.Write([]byte("commitcomplaint"))
_ = binary.Write(h, binary.LittleEndian, cc.Index)
_ = binary.Write(h, binary.LittleEndian, cc.DealerIndex)
buff, _ := protobuf.Encode(cc.Deal)
buff, _ := cc.Deal.Marshal()
_, _ = h.Write(buff)
return h.Sum(nil)
}
Expand Down
67 changes: 53 additions & 14 deletions share/vss/pedersen/vss.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
"reflect"

"go.dedis.ch/kyber/v4"
"go.dedis.ch/kyber/v4/internal"
"go.dedis.ch/kyber/v4/internal/protobuf"
"go.dedis.ch/kyber/v4/share"
"go.dedis.ch/kyber/v4/sign/schnorr"
"go.dedis.ch/protobuf"
)

// Suite defines the capabilities required by the vss package.
Expand Down Expand Up @@ -58,6 +59,53 @@ type Deal struct {
Commitments []kyber.Point
}

// pedersenCompatibleDeal is a struct for Deal used when marshaling
// to ensure compatibility with Kyber V3.
type pedersenCompatibleDeal struct {
SessionID []byte
SecShare []byte
T uint32
Commitments []kyber.Point
}

// Marshal marshals a Deal into bytes or return an error if encoding failed.
// This encoding should always be preferred as it is compatible with Kyber V3.
func (d *Deal) Marshal() ([]byte, error) {
secShareBytes, err := internal.MarshalPriShare(d.SecShare)
if err != nil {
return nil, err
}
compatibleDeal := &pedersenCompatibleDeal{
SessionID: d.SessionID,
SecShare: secShareBytes,
T: d.T,
Commitments: d.Commitments,
}
return protobuf.Encode(compatibleDeal)
}

// Unmarshal unmarshals a Deal from bytes or return an error if decoding failed.
// This decoding should always be preferred as it is compatible with Kyber V3.
func (d *Deal) Unmarshal(data []byte, suite Suite) error {
compatibleDeal := &pedersenCompatibleDeal{}
constructors := make(protobuf.Constructors)
constructors[reflect.TypeFor[kyber.Point]()] = func() interface{} { return suite.Point() }
err := protobuf.DecodeWithConstructors(data, compatibleDeal, constructors)
if err != nil {
return err
}
secShare, err := internal.UnmarshalPriShare(compatibleDeal.SecShare, suite)
if err != nil {
return err
}

d.SessionID = compatibleDeal.SessionID
d.T = compatibleDeal.T
d.SecShare = secShare
d.Commitments = compatibleDeal.Commitments
return nil
}

// EncryptedDeal contains the deal in a encrypted form only decipherable by the
// correct recipient. The encryption is performed in a similar manner as what is
// done in TLS. The dealer generates a temporary key pair, signs it with its
Expand All @@ -67,7 +115,7 @@ type EncryptedDeal struct {
DHKey []byte
// Signature of the DH key by the longterm key of the dealer
Signature []byte
// AEAD encryption of the deal marshalled by protobuf
// AEAD encryption of the deal marshalled
Cipher []byte
}

Expand Down Expand Up @@ -193,7 +241,7 @@ func (d *Dealer) EncryptedDeal(i int) (*EncryptedDeal, error) {
}

nonce := make([]byte, gcm.NonceSize())
dealBuff, err := protobuf.Encode(d.deals[i])
dealBuff, err := d.deals[i].Marshal()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -408,7 +456,7 @@ func (v *Verifier) decryptDeal(e *EncryptedDeal) (*Deal, error) {
return nil, err
}
deal := &Deal{}
err = deal.decode(v.suite, decrypted)
err = deal.Unmarshal(decrypted, v.suite)
return deal, err
}

Expand Down Expand Up @@ -772,22 +820,13 @@ func (r *Response) Hash(s Suite) []byte {
return h.Sum(nil)
}

func (d *Deal) decode(s Suite, buff []byte) error {
constructors := make(protobuf.Constructors)
var point kyber.Point
var secret kyber.Scalar
constructors[reflect.TypeOf(&point).Elem()] = func() interface{} { return s.Point() }
constructors[reflect.TypeOf(&secret).Elem()] = func() interface{} { return s.Scalar() }
return protobuf.DecodeWithConstructors(buff, d, constructors)
}

// Hash returns the hash of a Justification.
func (j *Justification) Hash(s Suite) []byte {
h := s.Hash()
_, _ = h.Write([]byte("justification"))
_, _ = h.Write(j.SessionID)
_ = binary.Write(h, binary.LittleEndian, j.Index)
buff, _ := protobuf.Encode(j.Deal)
buff, _ := j.Deal.Marshal()
_, _ = h.Write(buff)
return h.Sum(nil)
}
2 changes: 1 addition & 1 deletion share/vss/pedersen/vss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/stretchr/testify/require"
"go.dedis.ch/kyber/v4"
"go.dedis.ch/kyber/v4/group/edwards25519"
"go.dedis.ch/kyber/v4/internal/protobuf"
"go.dedis.ch/kyber/v4/sign/schnorr"
"go.dedis.ch/kyber/v4/xof/blake2xb"
"go.dedis.ch/protobuf"
)

var rng = blake2xb.New(nil)
Expand Down
Loading
Loading