ristretto255: add Encode test

This commit is contained in:
George Tankersley 2019-03-31 00:37:13 +00:00 committed by Filippo Valsorda
parent b5155ea127
commit 1a1e45849a
2 changed files with 28 additions and 13 deletions

View File

@ -133,7 +133,7 @@ func mapToPoint(out *edwards25519.ExtendedGroupElement, t *radix51.FieldElement)
}
// Encode encodes a Ristretto group element to its canonical bytestring.
func (e *Element) Encode(ee *Element) []byte {
func (ee *Element) Encode() []byte {
tmp := &radix51.FieldElement{}
// u1 = (z0 + y0) * (z0 - y0)

View File

@ -1,6 +1,7 @@
package ristretto255
import (
"bytes"
"encoding/hex"
"testing"
@ -64,7 +65,6 @@ func TestSqrtRatioM1(t *testing.T) {
}
}
func TestRistrettoBasepointDecode(t *testing.T) {
var (
// The encoding of Ristretto element that can be represented internally by the Curve25519 base point.
compressedRistrettoBasepoint, _ = hex.DecodeString("e2f2ae0a6abc4e71a884a961c500515f58e30b6aa582dd8db6a65945e08d2d76")
@ -78,6 +78,7 @@ func TestRistrettoBasepointDecode(t *testing.T) {
}}
)
func TestRistrettoEncoding(t *testing.T) {
decodedBasepoint := &Element{}
err := decodedBasepoint.Decode(compressedRistrettoBasepoint)
if err != nil {
@ -87,4 +88,18 @@ func TestRistrettoBasepointDecode(t *testing.T) {
if decodedBasepoint.Equal(&ristrettoBasepoint) != 1 {
t.Error("decode succeeded, but got wrong point")
}
roundtripBasepoint := decodedBasepoint.Encode()
if !bytes.Equal(compressedRistrettoBasepoint, roundtripBasepoint) {
t.Error("decode<>encode roundtrip produced different results")
}
encodedBasepoint := ristrettoBasepoint.Encode()
if !bytes.Equal(compressedRistrettoBasepoint, encodedBasepoint) {
t.Error("point encode produced different results")
}
}
func TestRistrettoRoundtrip(t *testing.T) {
// TODO quickcheck
}