@@ -11,9 +11,12 @@ package opaque_test
1111import (
1212 "bytes"
1313 "encoding/hex"
14+ "errors"
1415 "fmt"
1516 "testing"
1617
18+ "github.com/bytemare/crypto/group"
19+
1720 "github.com/bytemare/opaque/internal/encoding"
1821)
1922
@@ -215,3 +218,57 @@ func expectPanic(expectedError error, f func()) (bool, string) {
215218
216219 return true , ""
217220}
221+
222+ func TestSerializeScalarGroups (t * testing.T ) {
223+ // Valid Configurations
224+ for _ , conf := range confs {
225+ g := group .Group (conf .Conf .AKE )
226+ s := g .NewScalar ().Random ()
227+ if hasPanic , err := hasPanic (func () { _ = encoding .SerializeScalar (s , g ) }); hasPanic {
228+ t .Fatalf ("unexpected panic for valid group and scalar: %v" , err )
229+ }
230+ }
231+
232+ // Invalid Configuration
233+ g := group .Group (0 )
234+ expect := errors .New ("invalid group identifier" )
235+ if hasPanic , err := expectPanic (expect , func () { _ = encoding .SerializeScalar (nil , g ) }); ! hasPanic {
236+ t .Fatalf ("expected panic for invalid group and scalar:\n \t want: %v\n \t got: %v" , expect , err )
237+ }
238+ }
239+
240+ func TestSerializeScalar (t * testing.T ) {
241+ length := 16
242+ for _ , conf := range confs {
243+ g := group .Group (conf .Conf .AKE )
244+ encoded := [32 ]byte {}
245+ encoded [length ] = 1
246+ s , err := g .NewScalar ().Decode (encoded [:])
247+ if err != nil {
248+ t .Fatal (err )
249+ }
250+
251+ ser := encoding .SerializeScalar (s , g )
252+ if len (ser ) == length {
253+ t .Fatalf ("serialization did not pad correctly. Before %d / After %d" , length , len (ser ))
254+ }
255+ }
256+ }
257+
258+ func TestSerializePointGroups (t * testing.T ) {
259+ // Valid Configurations
260+ for _ , conf := range confs {
261+ g := group .Group (conf .Conf .AKE )
262+ p := g .Base ()
263+ if hasPanic , err := hasPanic (func () { _ = encoding .SerializePoint (p , g ) }); hasPanic {
264+ t .Fatalf ("unexpected panic for valid group and point: %v" , err )
265+ }
266+ }
267+
268+ // Invalid Configuration
269+ g := group .Group (0 )
270+ expect := errors .New ("invalid group identifier" )
271+ if hasPanic , err := expectPanic (expect , func () { _ = encoding .SerializePoint (nil , g ) }); ! hasPanic {
272+ t .Fatalf ("expected panic for invalid group and point:\n \t want: %v\n \t got: %v" , expect , err )
273+ }
274+ }
0 commit comments