@@ -9,126 +9,47 @@ import (
9
9
"testing"
10
10
)
11
11
12
- func TestEcdsa (t * testing.T ) {
13
- // AsnSignatureTestVector
14
- type AsnSignatureTestVector struct {
15
-
12
+ func TestECDSA (t * testing.T ) {
13
+ type ASNSignatureTestVector struct {
16
14
// A brief description of the test case
17
- Comment string `json:"comment,omitempty"`
18
-
15
+ Comment string `json:"comment"`
19
16
// A list of flags
20
- Flags []string `json:"flags,omitempty"`
21
-
17
+ Flags []string `json:"flags"`
22
18
// The message to sign
23
- Msg string `json:"msg,omitempty"`
24
-
19
+ Msg string `json:"msg"`
25
20
// Test result
26
- Result string `json:"result,omitempty"`
27
-
28
- // An ASN encoded signature for msg
29
- Sig string `json:"sig,omitempty"`
30
-
21
+ Result string `json:"result"`
22
+ // An ASN.1 encoded signature for msg
23
+ Sig string `json:"sig"`
31
24
// Identifier of the test case
32
- TcId int `json:"tcId,omitempty "`
25
+ TcID int `json:"tcId"`
33
26
}
34
27
35
- // EcPublicKey
36
- type EcPublicKey struct {
37
-
38
- // the EC group used by this public key
39
- Curve interface {} `json:"curve,omitempty"`
40
-
41
- // the key size in bits
42
- KeySize int `json:"keySize,omitempty"`
43
-
44
- // the key type
45
- Type string `json:"type,omitempty"`
46
-
47
- // encoded public key point
48
- Uncompressed string `json:"uncompressed,omitempty"`
49
-
50
- // the x-coordinate of the public key point
51
- Wx string `json:"wx,omitempty"`
52
-
53
- // the y-coordinate of the public key point
54
- Wy string `json:"wy,omitempty"`
28
+ type ECPublicKey struct {
29
+ // The EC group used by this public key
30
+ Curve interface {} `json:"curve"`
55
31
}
56
32
57
- // EcUnnamedGroup
58
- type EcUnnamedGroup struct {
59
-
60
- // coefficient a of the elliptic curve equation
61
- A string `json:"a,omitempty"`
62
-
63
- // coefficient b of the elliptic curve equation
64
- B string `json:"b,omitempty"`
65
-
66
- // the x-coordinate of the generator
67
- Gx string `json:"gx,omitempty"`
68
-
69
- // the y-coordinate of the generator
70
- Gy string `json:"gy,omitempty"`
71
-
72
- // the cofactor
73
- H int `json:"h,omitempty"`
74
-
75
- // the order of the generator
76
- N string `json:"n,omitempty"`
77
-
78
- // the order of the underlying field
79
- P string `json:"p,omitempty"`
80
-
81
- // an unnamed EC group over a prime field in Weierstrass form
82
- Type string `json:"type,omitempty"`
83
- }
84
-
85
- // EcdsaTestGroup
86
- type EcdsaTestGroup struct {
87
-
88
- // unenocded EC public key
89
- Key * EcPublicKey `json:"key,omitempty"`
90
-
33
+ type ECDSATestGroup struct {
34
+ // Unencoded EC public key
35
+ Key * ECPublicKey `json:"key"`
91
36
// DER encoded public key
92
- KeyDer string `json:"keyDer,omitempty"`
93
-
94
- // Pem encoded public key
95
- KeyPem string `json:"keyPem,omitempty"`
96
-
37
+ KeyDER string `json:"keyDer"`
97
38
// the hash function used for ECDSA
98
- Sha string `json:"sha,omitempty"`
99
- Tests []* AsnSignatureTestVector `json:"tests,omitempty"`
100
- Type interface {} `json:"type,omitempty"`
101
- }
102
-
103
- // Notes a description of the labels used in the test vectors
104
- type Notes struct {
39
+ SHA string `json:"sha"`
40
+ Tests []* ASNSignatureTestVector `json:"tests"`
105
41
}
106
42
107
- // Root
108
43
type Root struct {
109
-
110
- // the primitive tested in the test file
111
- Algorithm string `json:"algorithm,omitempty"`
112
-
113
- // the version of the test vectors.
114
- GeneratorVersion string `json:"generatorVersion,omitempty"`
115
-
116
- // additional documentation
117
- Header []string `json:"header,omitempty"`
118
-
119
- // a description of the labels used in the test vectors
120
- Notes * Notes `json:"notes,omitempty"`
121
-
122
- // the number of test vectors in this test
123
- NumberOfTests int `json:"numberOfTests,omitempty"`
124
- Schema interface {} `json:"schema,omitempty"`
125
- TestGroups []* EcdsaTestGroup `json:"testGroups,omitempty"`
44
+ TestGroups []* ECDSATestGroup `json:"testGroups"`
126
45
}
127
46
128
47
flagsShouldPass := map [string ]bool {
129
- // An encoded ASN.1 integer missing a leading zero is invalid, but accepted by some implementations.
48
+ // An encoded ASN.1 integer missing a leading zero is invalid, but
49
+ // accepted by some implementations.
130
50
"MissingZero" : false ,
131
- // A signature using a weaker hash than the EC params is not a security risk, as long as the hash is secure.
51
+ // A signature using a weaker hash than the EC params is not a security
52
+ // risk, as long as the hash is secure.
132
53
// https://www.imperialviolet.org/2014/05/25/strengthmatching.html
133
54
"WeakHash" : true ,
134
55
}
@@ -149,15 +70,15 @@ func TestEcdsa(t *testing.T) {
149
70
if ! supportedCurves [curve ] {
150
71
continue
151
72
}
152
- pub := decodePublicKey (tg .KeyDer ).(* ecdsa.PublicKey )
153
- h := parseHash (tg .Sha ).New ()
73
+ pub := decodePublicKey (tg .KeyDER ).(* ecdsa.PublicKey )
74
+ h := parseHash (tg .SHA ).New ()
154
75
for _ , sig := range tg .Tests {
155
76
h .Reset ()
156
77
h .Write (decodeHex (sig .Msg ))
157
78
hashed := h .Sum (nil )
158
- got := verifyASN1 (pub , hashed , decodeHex (sig .Sig ))
79
+ got := ecdsa . VerifyASN1 (pub , hashed , decodeHex (sig .Sig ))
159
80
if want := shouldPass (sig .Result , sig .Flags , flagsShouldPass ); got != want {
160
- t .Errorf ("tcid: %d, type: %s, comment: %q, wanted success: %t" , sig .TcId , sig .Result , sig .Comment , want )
81
+ t .Errorf ("tcid: %d, type: %s, comment: %q, wanted success: %t" , sig .TcID , sig .Result , sig .Comment , want )
161
82
}
162
83
}
163
84
}
0 commit comments