interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / om / ed25519 / test / gen / oracle / main.go

44 lines · 1076 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Test referee only (never part of the om/ed25519 implementation): reads lines
3// "PKHEX SIGHEX MSGHEX" and prints "S C", the results of Go crypto/ed25519.Verify (S)
4// and github.com/hdevalence/ed25519consensus.Verify (C), 1 valid / 0 invalid.
5package main
6
7import (
8 "bufio"
9 "crypto/ed25519"
10 "encoding/hex"
11 "fmt"
12 "os"
13 "strings"
14
15 "github.com/hdevalence/ed25519consensus"
16)
17
18func b(v bool) int {
19 if v {
20 return 1
21 }
22 return 0
23}
24
25func main() {
26 in := bufio.NewScanner(os.Stdin)
27 in.Buffer(make([]byte, 1<<20), 1<<20)
28 out := bufio.NewWriter(os.Stdout)
29 defer out.Flush()
30 for in.Scan() {
31 f := strings.Split(in.Text(), " ")
32 for len(f) < 3 {
33 f = append(f, "")
34 }
35 pk, e1 := hex.DecodeString(f[0])
36 sig, e2 := hex.DecodeString(f[1])
37 msg, e3 := hex.DecodeString(f[2])
38 if e1 != nil || e2 != nil || e3 != nil || len(pk) != 32 || len(sig) != 64 {
39 fmt.Fprintln(os.Stderr, "oracle: bad line")
40 os.Exit(2)
41 }
42 fmt.Fprintf(out, "%d %d\n", b(ed25519.Verify(pk, msg, sig)), b(ed25519consensus.Verify(pk, msg, sig)))
43 }
44}