mirror of https://github.com/gtank/ristretto255
Add encoding test vectors from the spec.
This commit is contained in:
parent
8cd2a841fc
commit
c722cc47ae
|
@ -78,7 +78,7 @@ var (
|
|||
}}
|
||||
)
|
||||
|
||||
func TestRistrettoEncoding(t *testing.T) {
|
||||
func TestRistrettoBasepointRoundTrip(t *testing.T) {
|
||||
decodedBasepoint := &Element{}
|
||||
err := decodedBasepoint.Decode(compressedRistrettoBasepoint)
|
||||
if err != nil {
|
||||
|
@ -100,6 +100,53 @@ func TestRistrettoEncoding(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRistrettoRoundtrip(t *testing.T) {
|
||||
func TestRistrettoRandomRoundtrip(t *testing.T) {
|
||||
// TODO quickcheck
|
||||
}
|
||||
|
||||
func TestRistrettoSmallMultiplesTestVectors(t *testing.T) {
|
||||
var testVectors = [16]string{
|
||||
// This is the identity point
|
||||
"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
// This is the basepoint
|
||||
"e2f2ae0a6abc4e71a884a961c500515f58e30b6aa582dd8db6a65945e08d2d76",
|
||||
// These are small multiples of the basepoint
|
||||
"6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919",
|
||||
"94741f5d5d52755ece4f23f044ee27d5d1ea1e2bd196b462166b16152a9d0259",
|
||||
"da80862773358b466ffadfe0b3293ab3d9fd53c5ea6c955358f568322daf6a57",
|
||||
"e882b131016b52c1d3337080187cf768423efccbb517bb495ab812c4160ff44e",
|
||||
"f64746d3c92b13050ed8d80236a7f0007c3b3f962f5ba793d19a601ebb1df403",
|
||||
"44f53520926ec81fbd5a387845beb7df85a96a24ece18738bdcfa6a7822a176d",
|
||||
"903293d8f2287ebe10e2374dc1a53e0bc887e592699f02d077d5263cdd55601c",
|
||||
"02622ace8f7303a31cafc63f8fc48fdc16e1c8c8d234b2f0d6685282a9076031",
|
||||
"20706fd788b2720a1ed2a5dad4952b01f413bcf0e7564de8cdc816689e2db95f",
|
||||
"bce83f8ba5dd2fa572864c24ba1810f9522bc6004afe95877ac73241cafdab42",
|
||||
"e4549ee16b9aa03099ca208c67adafcafa4c3f3e4e5303de6026e3ca8ff84460",
|
||||
"aa52e000df2e16f55fb1032fc33bc42742dad6bd5a8fc0be0167436c5948501f",
|
||||
"46376b80f409b29dc2b5f6f0c52591990896e5716f41477cd30085ab7f10301e",
|
||||
"e0c418f7c8d9c4cdd7395b93ea124f3ad99021bb681dfc3302a9d99a2e53e64e",
|
||||
}
|
||||
|
||||
// TODO need to use Ristretto addition to do this test properly, see
|
||||
// https://ristretto.group/test_vectors/ristretto255.html
|
||||
|
||||
for i := 0; i < 16; i++ {
|
||||
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{}
|
||||
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) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue