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