ristretto255: add TestRistrettoFromUniformBytesTestVectors

This commit is contained in:
Filippo Valsorda 2019-04-19 16:42:43 -04:00 committed by Henry de Valence
parent 928989ab04
commit 971fdbf516
1 changed files with 31 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package ristretto255
import (
"bytes"
"crypto/sha512"
"encoding/hex"
"testing"
@ -219,3 +220,33 @@ func TestRistrettoBadEncodingsTestVectors(t *testing.T) {
}
}
}
func TestRistrettoFromUniformBytesTestVectors(t *testing.T) {
inputs := []string{
"Ristretto is traditionally a short shot of espresso coffee",
"made with the normal amount of ground coffee but extracted with",
"about half the amount of water in the same amount of time",
"by using a finer grind.",
"This produces a concentrated shot of coffee per volume.",
"Just pulling a normal shot short will produce a weaker shot",
"and is not a Ristretto as some believe.",
}
elements := []string{
"3066f82a1a747d45120d1740f14358531a8f04bbffe6a819f86dfe50f44a0a46",
"f26e5b6f7d362d2d2a94c5d0e7602cb4773c95a2e5c31a64f133189fa76ed61b",
"006ccd2a9e6867e6a2c5cea83d3302cc9de128dd2a9a57dd8ee7b9d7ffe02826",
"f8f0c87cf237953c5890aec3998169005dae3eca1fbb04548c635953c817f92a",
"ae81e7dedf20a497e10c304a765c1767a42d6e06029758d2d7e8ef7cc4c41179",
"e2705652ff9f5e44d3e841bf1c251cf7dddb77d140870d1ab2ed64f1a9ce8628",
"80bd07262511cdde4863f8a7434cef696750681cb9510eea557088f76d9e5065",
}
var element Element
for i, input := range inputs {
hash := sha512.Sum512([]byte(input))
element.FromUniformBytes(hash[:])
if encoding := hex.EncodeToString(element.Encode(nil)); encoding != elements[i] {
t.Errorf("#%d: expected %q, got %q", i, elements[i], encoding)
}
}
}