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.
DateKeys-App/scripts/bls12381-go-verdicts.go

64 lines
1.6 KiB

//go:build ignore
// Prints the Go reference verdict for every encoding in
// src/lib/dkc/testing/bls12381-vectors.json, as a JSON object from label to
// "point", "identity" or "invalid". The decoding is the one profile.Validate
// uses: the KeyGroup of the drand crypto scheme (G1 for the unchained scheme,
// G2 for bls-unchained-g1-rfc9380, Quicknet), whose UnmarshalBinary is
// kyber-bls12381 over kilic/bls12-381 FromCompressed, and Equal(Null()) for the
// identity. Run it from a scratch module that requires the reference
// implementation (replace g.activething.com/go/DateKeys => ../datekeys-go and
// GOFLAGS=-mod=mod), passing the path of the vectors file:
//
// go run bls12381-go-verdicts.go path/to/bls12381-vectors.json
package main
import (
"encoding/hex"
"encoding/json"
"fmt"
"os"
"github.com/drand/drand/v2/crypto"
)
func main() {
raw, err := os.ReadFile(os.Args[1])
if err != nil {
panic(err)
}
var file struct {
Vectors []struct{ Label, Group, Hex string }
}
if err := json.Unmarshal(raw, &file); err != nil {
panic(err)
}
g1, _ := crypto.GetSchemeByID(crypto.UnchainedSchemeID)
g2, _ := crypto.GetSchemeByID(crypto.SigsOnG1ID)
out := map[string]string{}
for _, v := range file.Vectors {
s := g1
if v.Group == "G2" {
s = g2
}
b, err := hex.DecodeString(v.Hex)
if err != nil {
panic(err)
}
k := s.KeyGroup.Point()
switch {
case k.UnmarshalBinary(b) != nil:
out[v.Label] = "invalid"
case k.Equal(k.Null()):
out[v.Label] = "identity"
default:
out[v.Label] = "point"
}
}
j, err := json.MarshalIndent(out, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(j))
}

Powered by TurnKey Linux.