...

Source file src/golang.org/x/crypto/internal/wycheproof/eddsa_test.go

Documentation: golang.org/x/crypto/internal/wycheproof

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package wycheproof
     6  
     7  import (
     8  	"crypto/ed25519"
     9  	"testing"
    10  )
    11  
    12  func TestEddsa(t *testing.T) {
    13  	// Jwk the private key in webcrypto format
    14  	type Jwk struct {
    15  	}
    16  
    17  	// Key unencoded key pair
    18  	type Key struct {
    19  	}
    20  
    21  	// Notes a description of the labels used in the test vectors
    22  	type Notes struct {
    23  	}
    24  
    25  	// SignatureTestVector
    26  	type SignatureTestVector struct {
    27  
    28  		// A brief description of the test case
    29  		Comment string `json:"comment,omitempty"`
    30  
    31  		// A list of flags
    32  		Flags []string `json:"flags,omitempty"`
    33  
    34  		// The message to sign
    35  		Msg string `json:"msg,omitempty"`
    36  
    37  		// Test result
    38  		Result string `json:"result,omitempty"`
    39  
    40  		// A signature for msg
    41  		Sig string `json:"sig,omitempty"`
    42  
    43  		// Identifier of the test case
    44  		TcId int `json:"tcId,omitempty"`
    45  	}
    46  
    47  	// EddsaTestGroup
    48  	type EddsaTestGroup struct {
    49  
    50  		// the private key in webcrypto format
    51  		Jwk *Jwk `json:"jwk,omitempty"`
    52  
    53  		// unencoded key pair
    54  		Key *Key `json:"key,omitempty"`
    55  
    56  		// Asn encoded public key
    57  		KeyDer string `json:"keyDer,omitempty"`
    58  
    59  		// Pem encoded public key
    60  		KeyPem string                 `json:"keyPem,omitempty"`
    61  		Tests  []*SignatureTestVector `json:"tests,omitempty"`
    62  		Type   interface{}            `json:"type,omitempty"`
    63  	}
    64  
    65  	// Root
    66  	type Root struct {
    67  
    68  		// the primitive tested in the test file
    69  		Algorithm string `json:"algorithm,omitempty"`
    70  
    71  		// the version of the test vectors.
    72  		GeneratorVersion string `json:"generatorVersion,omitempty"`
    73  
    74  		// additional documentation
    75  		Header []string `json:"header,omitempty"`
    76  
    77  		// a description of the labels used in the test vectors
    78  		Notes *Notes `json:"notes,omitempty"`
    79  
    80  		// the number of test vectors in this test
    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