Source file
src/crypto/ed25519/ed25519_wycheproof_test.go
1
2
3
4 package ed25519_test
5
6 import (
7 "crypto/ed25519"
8 "crypto/internal/cryptotest/wycheproof"
9 "crypto/x509"
10 "fmt"
11 "testing"
12 )
13
14 func TestEd25519Wycheproof(t *testing.T) {
15 file := "ed25519_test.json"
16 var testdata wycheproof.EddsaVerifySchemaV1Json
17 wycheproof.LoadVectorFile(t, file, &testdata)
18
19 parseSPKIPub := func(p []byte) (ed25519.PublicKey, error) {
20 pubKeyAny, err := x509.ParsePKIXPublicKey(p)
21 if err != nil {
22 return nil, err
23 }
24 pub, ok := pubKeyAny.(ed25519.PublicKey)
25 if !ok {
26 return nil, fmt.Errorf("unexpected key type %T", pubKeyAny)
27 }
28 return pub, nil
29 }
30
31 for tgIdx, tg := range testdata.TestGroups {
32 pubkey, err := parseSPKIPub(wycheproof.MustDecodeHex(tg.PublicKeyDer))
33 if err != nil {
34 t.Fatalf("test group %d invalid DER encoded public key: %v", tgIdx+1, err)
35 }
36
37 for _, tv := range tg.Tests {
38 t.Run(wycheproof.TestName(file, tv), func(t *testing.T) {
39 t.Parallel()
40
41 got := ed25519.Verify(
42 pubkey, wycheproof.MustDecodeHex(tv.Msg), wycheproof.MustDecodeHex(tv.Sig))
43 want := wycheproof.ShouldPass(t, tv.Result, tv.Flags, nil)
44 if got != want {
45 t.Errorf("Verify wanted success: %t", want)
46 }
47 })
48 }
49 }
50 }
51
View as plain text