Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
64bda1a
change tests using kyber to v4
thehoul Feb 2, 2026
a143d30
fix protobuf tests
thehoul Feb 5, 2026
66d7bbc
fix protobuf test for 32B by removing encoding of type "int"
thehoul Feb 5, 2026
b87fd20
remove kyberv3 no longer needed for protobuf tests
thehoul Feb 5, 2026
f27f516
add back max int32 test
thehoul Feb 25, 2026
5c3bd1a
add tests for errors in array_test.go
thehoul Feb 25, 2026
428eeed
add exported error and match on them in tests
thehoul Feb 25, 2026
cb33eb1
add max int64 test in array_test.go
thehoul Feb 25, 2026
5342ae4
initialize points in vartime encoding test to avoid testing with empt…
thehoul Feb 25, 2026
923acff
fix max int64 test
thehoul Feb 25, 2026
5711fbf
change all imports to internal protobuf
thehoul Feb 2, 2026
adbfe9e
remove protobuf from go.mod
thehoul Feb 2, 2026
d8a5d7c
add marshaling for share.PriShare
thehoul Feb 3, 2026
d73d712
add marshaling for Pedersen VSS Deal
thehoul Feb 3, 2026
126814b
add marshaling for Rabin VSS Deal
thehoul Feb 3, 2026
59db926
move Rabin VSS Deal marhsalling to vss.go
thehoul Feb 3, 2026
4f4dbeb
move Pedersen VSS Deal marhsalling to vss.go
thehoul Feb 3, 2026
0905d6c
use Marshal method in Rabin DKG instead of protobuf
thehoul Feb 3, 2026
81a587c
fix Pedersen tests
thehoul Feb 3, 2026
45d1ee0
unexport adapter structs for VSS and PriShare
thehoul Feb 6, 2026
0822b59
swap TypeOf for TypeFor
thehoul Feb 6, 2026
0a0985e
add check before casting int64 to uint32
thehoul Feb 6, 2026
1fd29b9
add doc in v3marshaling.go
thehoul Feb 20, 2026
6358fb4
add doc in vss.go for both Rabin and Pedersen
thehoul Feb 20, 2026
1743700
Update internal/v3marshaling.go
thehoul Feb 25, 2026
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
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +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
v3 go.dedis.ch/kyber/v3 v3.0.9
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
55 changes: 28 additions & 27 deletions internal/protobuf/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ package protobuf

import (
"encoding/hex"
"math"
"reflect"
"testing"

"github.com/stretchr/testify/require"
)

type ArrayTest0 struct {
A []int
}

type ArrayTest1 struct {
A []int64
}
Expand All @@ -20,48 +17,52 @@ type ArrayTest2 struct {
A []int32
}

type ArrayTest3 struct {
A int
}

func TestArray(t *testing.T) {
// largest int32 is 2147483647
var large int = 3147483647
var maxInt32 int32 = math.MaxInt32
var maxInt64 int64 = math.MaxInt64 / 2

a0 := ArrayTest0{[]int{1, 1, large}}
Comment thread
thehoul marked this conversation as resolved.
a1 := ArrayTest1{[]int64{1, 1, 1}}
a2 := ArrayTest2{[]int32{1, 1, 1}}
a3 := ArrayTest3{1}
a3 := ArrayTest2{[]int32{1, 1, maxInt32}}
a4 := ArrayTest1{[]int64{1, 1, maxInt64}}

buf1, err := Encode(&a1)
require.NoError(t, err)
buf2, err := Encode(&a2)
require.NoError(t, err)
buf3, err := Encode(&a3)
require.NoError(t, err)
buf4, err := Encode(&a4)
require.NoError(t, err)

buf0, _ := Encode(&a0)
buf1, _ := Encode(&a1)
buf2, _ := Encode(&a2)
buf3, _ := Encode(&a3)

t.Log(hex.Dump(buf0))
t.Log(hex.Dump(buf1))
t.Log(hex.Dump(buf2))
t.Log(hex.Dump(buf3))
t.Log(hex.Dump(buf4))

b0 := ArrayTest0{}
b1 := ArrayTest1{}
b2 := ArrayTest2{}
b3 := ArrayTest3{}

Decode(buf0, &b0)
t.Log(b0, reflect.TypeOf(b0))
b3 := ArrayTest2{}
b4 := ArrayTest1{}

Decode(buf1, &b1)
err = Decode(buf1, &b1)
require.NoError(t, err)
t.Log(b1, reflect.TypeOf(b1))

Decode(buf2, &b2)
err = Decode(buf2, &b2)
require.NoError(t, err)
t.Log(b2, reflect.TypeOf(b2))

Decode(buf3, &b3)
err = Decode(buf3, &b3)
require.NoError(t, err)
t.Log(b3, reflect.TypeOf(b3))

require.Equal(t, a0, b0)
err = Decode(buf4, &b4)
require.NoError(t, err)
t.Log(b4, reflect.TypeOf(b4))

require.Equal(t, a1, b1)
require.Equal(t, a2, b2)
require.Equal(t, a3, b3)
require.Equal(t, a4, b4)
}
9 changes: 7 additions & 2 deletions internal/protobuf/crashers_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package protobuf

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -33,7 +34,10 @@ func TestCrash1(t *testing.T) {
var s t2
err = Decode(in, &s)
assert.NotNil(t, err)
assert.Equal(t, "Error while decoding field {Name:T3s PkgPath: Type:[3]protobuf.t3 Tag: Offset:112 Index:[4] Anonymous:false}: append to non-slice", err.Error())
var expectedError *DecodingFieldError
if !errors.As(err, &expectedError) {
assert.Fail(t, "Expected error \"appending to non-slice\"")
}
}

func TestCrash2(t *testing.T) {
Expand All @@ -42,5 +46,6 @@ func TestCrash2(t *testing.T) {
var s t2
err := Decode(in, &s)
assert.NotNil(t, err)
assert.Equal(t, "Error while decoding field {Name:X PkgPath: Type:protobuf.t1 Tag: Offset:0 Index:[0] Anonymous:false}: array length and buffer length differ", err.Error())
var expectedError *DecodingFieldError
assert.ErrorAs(t, err, &expectedError)
}
25 changes: 22 additions & 3 deletions internal/protobuf/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ func (c *Constructors) String() string {
return s
}

type DecodingFieldError struct {
Field string
Err error
}

// Implement error interface
func (e *DecodingFieldError) Error() string {
return fmt.Sprintf("Error while decoding field %s. Reason: %v", e.Field, e.Err)
}

func (e *DecodingFieldError) Unwrap() error {
return e.Err
}

func newDecodingFieldError(field string, err error) *DecodingFieldError {
return &DecodingFieldError{field, err}
}

// Decoder is the main struct used to decode a protobuf blob.
type decoder struct {
nm Constructors
Expand Down Expand Up @@ -57,7 +75,7 @@ func DecodeWithConstructors(buf []byte, structPtr interface{}, cons Constructors
case error:
err = e
default:
err = errors.New("Failed to decode the field")
err = newDecodingFieldError("unknown", errors.New("failed to decode the field"))
}
}
}()
Expand Down Expand Up @@ -104,7 +122,8 @@ func (de *decoder) message(buf []byte, sval reflect.Value) error {
// Parse the key
key, n := binary.Uvarint(buf)
if n <= 0 {
return errors.New("bad protobuf field key")
return newDecodingFieldError(fmt.Sprintf("%+v", fields[fieldi].Field),
errors.New("bad protobuf field key"))
}
buf = buf[n:]
wiretype := int(key & 7)
Expand Down Expand Up @@ -140,7 +159,7 @@ func (de *decoder) message(buf []byte, sval reflect.Value) error {
rem, err := de.value(wiretype, buf, field)
if err != nil {
if fieldi < len(fields) && fields[fieldi] != nil {
return fmt.Errorf("Error while decoding field %+v: %v", fields[fieldi].Field, err)
return newDecodingFieldError(fmt.Sprintf("%+v", fields[fieldi].Field), err)
}

return err
Expand Down
23 changes: 9 additions & 14 deletions internal/protobuf/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.dedis.ch/kyber/v3"
"go.dedis.ch/kyber/v3/suites"
"go.dedis.ch/kyber/v4"
"go.dedis.ch/kyber/v4/suites"
)

type Number interface {
Expand Down Expand Up @@ -64,18 +64,18 @@ func TestBinaryMarshaler(t *testing.T) {
}

type NumberNoMarshal interface {
Value() int
Value() int32
}

func NewNumberNoMarshal(n int) NumberNoMarshal {
func NewNumberNoMarshal(n int32) NumberNoMarshal {
return &IntNoMarshal{n}
}

type IntNoMarshal struct {
N int
N int32
}

func (i *IntNoMarshal) Value() int {
func (i *IntNoMarshal) Value() int32 {
return i.N
}

Expand All @@ -92,7 +92,7 @@ func TestNoBinaryMarshaler(t *testing.T) {
err = Decode(buf, &wrapper2)

assert.Nil(t, err)
assert.Equal(t, 99, wrapper2.N.Value())
assert.Equal(t, int32(99), wrapper2.N.Value())
}

type WrongSliceInt struct {
Expand Down Expand Up @@ -230,18 +230,14 @@ func TestArrayKey(t *testing.T) {
func TestInterface(t *testing.T) {
type Points struct {
P1 kyber.Point
P2 kyber.Point
}

bn256 := suites.MustFind("bn256.adapter")
ed25519 := suites.MustFind("ed25519")

RegisterInterface(func() interface{} { return bn256.Point() })
RegisterInterface(func() interface{} { return ed25519.Point() })

pp := Points{
P1: bn256.Point(),
P2: ed25519.Point(),
P1: ed25519.Point(),
}

buf, err := Encode(&pp)
Expand All @@ -251,7 +247,6 @@ func TestInterface(t *testing.T) {
err = Decode(buf, &dpp)
require.NoError(t, err)
require.Equal(t, pp.P1.String(), dpp.P1.String())
require.Equal(t, pp.P2.String(), dpp.P2.String())
}

type dummyInterface interface {
Expand Down Expand Up @@ -326,7 +321,7 @@ type canMarshal struct{ private string }

type hasInternalCanMarshal struct {
CM canMarshal
SomethingElse int
SomethingElse int32
}

func (cm canMarshal) MarshalBinary() ([]byte, error) {
Expand Down
40 changes: 40 additions & 0 deletions internal/protobuf/encoding_vartime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//go:build !constantTime

package protobuf

import (
"testing"

"github.com/stretchr/testify/require"
"go.dedis.ch/kyber/v4"
"go.dedis.ch/kyber/v4/suites"
)

// TestInterfaceVartime runs the same test as TestInterface but using a suite available
// only in vartime (bn256)
func TestInterfaceVartime(t *testing.T) {
type Points struct {
P1 kyber.Point
P2 kyber.Point
}

bn256 := suites.MustFind("bn256.adapter")
ed25519 := suites.MustFind("ed25519")

RegisterInterface(func() interface{} { return bn256.Point() })
RegisterInterface(func() interface{} { return ed25519.Point() })

pp := Points{
P1: bn256.Point().Pick(bn256.XOF([]byte("test"))),
P2: ed25519.Point().Pick(ed25519.XOF([]byte("test"))),
}

buf, err := Encode(&pp)
require.NoError(t, err)

var dpp Points
err = Decode(buf, &dpp)
require.NoError(t, err)
require.Equal(t, pp.P1.String(), dpp.P1.String())
require.Equal(t, pp.P2.String(), dpp.P2.String())
}
29 changes: 14 additions & 15 deletions internal/protobuf/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ func TestGenerate(t *testing.T) {
expected := `
message test {
optional bool boolean = 1;
required sint64 i = 2;
required sint32 i32 = 3;
required sint64 i64 = 4;
required uint32 u32 = 5;
required uint64 u64 = 6;
required sfixed32 sx32 = 7;
required sfixed64 sx64 = 8;
required fixed32 ux32 = 9;
required ufixed64 ux64 = 10;
required float f32 = 11;
required double f64 = 12;
required bytes bytes = 13;
required bytes array = 14;
required string string = 15;
required emb struct = 16;
required sint32 i32 = 2;
required sint64 i64 = 3;
required uint32 u32 = 4;
required uint64 u64 = 5;
required sfixed32 sx32 = 6;
required sfixed64 sx64 = 7;
required fixed32 ux32 = 8;
required ufixed64 ux64 = 9;
required float f32 = 10;
required double f64 = 11;
required bytes bytes = 12;
required bytes array = 13;
required string string = 14;
required emb struct = 15;
optional bool obool = 50;
optional sint32 oi32 = 51;
optional sint64 oi64 = 52;
Expand Down
4 changes: 2 additions & 2 deletions internal/protobuf/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ValueInt interface {
}

type A struct {
Value int
Value int32
}

func (a *A) MarshalBinary() ([]byte, error) {
Expand All @@ -25,7 +25,7 @@ func (a *A) Print() string {

type B struct {
AValue A
AInt int
AInt int32
}

func TestMarshal(t *testing.T) {
Expand Down
Loading
Loading