mirror of https://github.com/gtank/ristretto255
ristretto255: add Encode test
This commit is contained in:
parent
b5155ea127
commit
1a1e45849a
|
@ -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)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ristretto255
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
|
||||
|
@ -64,20 +65,20 @@ 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")
|
||||
var (
|
||||
// The encoding of Ristretto element that can be represented internally by the Curve25519 base point.
|
||||
compressedRistrettoBasepoint, _ = hex.DecodeString("e2f2ae0a6abc4e71a884a961c500515f58e30b6aa582dd8db6a65945e08d2d76")
|
||||
|
||||
// The representative Ristretto basepoint in extended coordinates.
|
||||
ristrettoBasepoint = Element{r: edwards25519.ExtendedGroupElement{
|
||||
X: radix51.FieldElement([5]uint64{426475514619346, 2063872706840040, 14628272888959, 107677749330612, 288339085807592}),
|
||||
Y: radix51.FieldElement([5]uint64{1934594822876571, 2049809580636559, 1991994783322914, 1758681962032007, 380046701118659}),
|
||||
Z: radix51.FieldElement([5]uint64{1, 0, 0, 0, 0}),
|
||||
T: radix51.FieldElement([5]uint64{410445769351754, 2235400917701188, 1495825632738689, 1351628537510093, 430502003771208}),
|
||||
}}
|
||||
)
|
||||
// The representative Ristretto basepoint in extended coordinates.
|
||||
ristrettoBasepoint = Element{r: edwards25519.ExtendedGroupElement{
|
||||
X: radix51.FieldElement([5]uint64{426475514619346, 2063872706840040, 14628272888959, 107677749330612, 288339085807592}),
|
||||
Y: radix51.FieldElement([5]uint64{1934594822876571, 2049809580636559, 1991994783322914, 1758681962032007, 380046701118659}),
|
||||
Z: radix51.FieldElement([5]uint64{1, 0, 0, 0, 0}),
|
||||
T: radix51.FieldElement([5]uint64{410445769351754, 2235400917701188, 1495825632738689, 1351628537510093, 430502003771208}),
|
||||
}}
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue