...

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