...
1
2
3
4
5
6
7 package wycheproof
8
9 import (
10 "crypto/ed25519"
11 "testing"
12 )
13
14 func TestEddsa(t *testing.T) {
15
16 type Jwk struct {
17 }
18
19
20 type Key struct {
21 }
22
23
24 type Notes struct {
25 }
26
27
28 type SignatureTestVector struct {
29
30
31 Comment string `json:"comment,omitempty"`
32
33
34 Flags []string `json:"flags,omitempty"`
35
36
37 Msg string `json:"msg,omitempty"`
38
39
40 Result string `json:"result,omitempty"`
41
42
43 Sig string `json:"sig,omitempty"`
44
45
46 TcId int `json:"tcId,omitempty"`
47 }
48
49
50 type EddsaTestGroup struct {
51
52
53 Jwk *Jwk `json:"jwk,omitempty"`
54
55
56 Key *Key `json:"key,omitempty"`
57
58
59 KeyDer string `json:"keyDer,omitempty"`
60
61
62 KeyPem string `json:"keyPem,omitempty"`
63 Tests []*SignatureTestVector `json:"tests,omitempty"`
64 Type interface{} `json:"type,omitempty"`
65 }
66
67
68 type Root struct {
69
70
71 Algorithm string `json:"algorithm,omitempty"`
72
73
74 GeneratorVersion string `json:"generatorVersion,omitempty"`
75
76
77 Header []string `json:"header,omitempty"`
78
79
80 Notes *Notes `json:"notes,omitempty"`
81
82
83 NumberOfTests int `json:"numberOfTests,omitempty"`
84 Schema interface{} `json:"schema,omitempty"`
85 TestGroups []*EddsaTestGroup `json:"testGroups,omitempty"`
86 }
87
88 var root Root
89 readTestVector(t, "eddsa_test.json", &root)
90 for _, tg := range root.TestGroups {
91 pub := decodePublicKey(tg.KeyDer).(ed25519.PublicKey)
92 for _, sig := range tg.Tests {
93 got := ed25519.Verify(pub, decodeHex(sig.Msg), decodeHex(sig.Sig))
94 if want := shouldPass(sig.Result, sig.Flags, nil); got != want {
95 t.Errorf("tcid: %d, type: %s, comment: %q, wanted success: %t", sig.TcId, sig.Result, sig.Comment, want)
96 }
97 }
98 }
99 }
100
View as plain text