Update the small-multiples encoding to check additions.

This commit is contained in:
Henry de Valence 2019-04-19 13:09:12 -07:00
parent c722cc47ae
commit 68ecd88eb2
2 changed files with 19 additions and 6 deletions

View File

@ -282,3 +282,9 @@ func (v *Element) Neg(p *Element) *Element {
v.r.Neg(&p.r)
return v
}
// Zero sets v to the identity element of the group, and returns v.
func (v *Element) Zero() *Element {
v.r.Zero()
return v
}

View File

@ -127,26 +127,33 @@ func TestRistrettoSmallMultiplesTestVectors(t *testing.T) {
"e0c418f7c8d9c4cdd7395b93ea124f3ad99021bb681dfc3302a9d99a2e53e64e",
}
// TODO need to use Ristretto addition to do this test properly, see
// https://ristretto.group/test_vectors/ristretto255.html
basepointMultiple := Element{}
basepointMultiple.Zero()
for i := 0; i < 16; i++ {
// Grab the bytes of the encoding
encoding, err := hex.DecodeString(testVectors[i])
if err != nil {
t.Error("Bad hex encoding in test vector")
}
// Decode the test vector to a ristretto255 element
decodedPoint := &Element{}
decodedPoint := Element{}
err = decodedPoint.Decode(encoding)
if err != nil {
t.Error("Could not decode test vector")
}
// Re-encode and check round trips
roundtripPoint := decodedPoint.Encode()
if !bytes.Equal(encoding, roundtripPoint) {
roundtripEncoding := decodedPoint.Encode(nil)
if !bytes.Equal(encoding, roundtripEncoding) {
t.Errorf("decode<>encode roundtrip failed on test vector %d", i)
}
// Check that the test vector encodes i * B
// TODO add this (need addition, see above)
if basepointMultiple.Equal(&decodedPoint) != 1 {
t.Errorf("decoded small multiple %d * B is not %d * B", i, i)
}
// Ensure basepointMultiple = i * B in the next iteration
basepointMultiple.Add(&basepointMultiple, &ristrettoBasepoint)
}
}