// Verify returns true iff vrf=Compute(m, sk) for the sk that corresponds to pk. func Verify(pkBytes, m, vrfBytes, proof []byte) bool { if len(proof) != ProofSize || len(vrfBytes) != Size || len(pkBytes) != PublicKeySize { return false } var pk, c, cRef, t, vrf, iiB, ABytes, BBytes [32]byte copy(vrf[:], vrfBytes) copy(pk[:], pkBytes) copy(c[:32], proof[:32]) copy(t[:32], proof[32:64]) copy(iiB[:], proof[64:96]) hash := sha3.NewShake256() hash.Write(iiB[:]) // const length hash.Write(m) var hCheck [Size]byte hash.Read(hCheck[:]) if !bytes.Equal(hCheck[:], vrf[:]) { return false } hash.Reset() var P, B, ii, iic edwards25519.ExtendedGroupElement var A, hmtP, iicP edwards25519.ProjectiveGroupElement if !P.FromBytesBaseGroup(&pk) { return false } if !ii.FromBytesBaseGroup(&iiB) { return false } edwards25519.GeDoubleScalarMultVartime(&A, &c, &P, &t) A.ToBytes(&ABytes) hm := hashToCurve(m) edwards25519.GeDoubleScalarMultVartime(&hmtP, &t, hm, &[32]byte{}) edwards25519.GeDoubleScalarMultVartime(&iicP, &c, &ii, &[32]byte{}) iicP.ToExtended(&iic) hmtP.ToExtended(&B) edwards25519.GeAdd(&B, &B, &iic) B.ToBytes(&BBytes) var cH [64]byte hash.Write(ABytes[:]) // const length hash.Write(BBytes[:]) // const length hash.Write(m) hash.Read(cH[:]) edwards25519.ScReduce(&cRef, &cH) return cRef == c }
// Verify returns true iff sig is a valid signature of message by publicKey. func Verify(publicKey *[PublicKeySize]byte, message []byte, sig *[SignatureSize]byte) bool { if sig[63]&224 != 0 { return false } var A edwards25519.ExtendedGroupElement if !A.FromBytes(publicKey) { return false } edwards25519.FeNeg(&A.X, &A.X) edwards25519.FeNeg(&A.T, &A.T) h := sha512.New() h.Write(sig[:32]) h.Write(publicKey[:]) h.Write(message) var digest [64]byte h.Sum(digest[:0]) var hReduced [32]byte edwards25519.ScReduce(&hReduced, &digest) var R edwards25519.ProjectiveGroupElement var b [32]byte copy(b[:], sig[32:]) edwards25519.GeDoubleScalarMultVartime(&R, &hReduced, &A, &b) var checkR [32]byte R.ToBytes(&checkR) return subtle.ConstantTimeCompare(sig[:32], checkR[:]) == 1 }