You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

package sha512
import (
"testing"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/test"
)
type Sha512Circuit struct {
in []frontend.Variable `gnark:"in"`
out []frontend.Variable `gnark:"out"`
}
func (circuit *Sha512Circuit) Define(api frontend.API) error {
res := Sha512(api, circuit.in)
for i := 0; i < 512; i++ {
api.AssertIsEqual(res[i], circuit.out[i])
}
return nil
}
func TestSha512(t *testing.T) {
assert := test.NewAssert(t)
in := toBytes("Succinct Labs")
out := toBytes("503ace098aa03f6feec1b5df0a38aee923f744a775508bc81f2b94ad139be297c2e8cd8c44af527b5d3f017a7fc929892c896604047e52e3f518924f52bff0dc")
circuit := Sha512Circuit {
in: toVariables(make([]byte, len(in))),
out: toVariables(make([]byte, len(out))),
}
witness := Sha512Circuit {
in: toVariables(in),
out: toVariables(out),
}
err := test.IsSolved(&circuit, &witness, testCurve.ScalarField())
assert.NoError(err)
}
func toVariables(arr []byte) []frontend.Variable {
result := make([]frontend.Variable, len(arr))
for i, v := range arr {
result[i] = v
}
return result
}
func toBytes(s string) []byte {
return []byte(s)
}