File tree 1 file changed +33
-0
lines changed 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,39 @@ func (pub *PublicKey) Equal(x crypto.PublicKey) bool {
83
83
pub .Curve == xx .Curve
84
84
}
85
85
86
+ // IsValid reports where pub is a valid public key on the curve
87
+ //
88
+ // Valid Elliptic Curve Public Keys have the properties according to
89
+ // 'Validation of Elliptic Curve Public Keys' 2003 by Antipa, Brown, Menezes, and
90
+ // Vanstone as well as NIST SP 800-56A Section 5.6.2.3.
91
+ func (pub * PublicKey ) IsValid () bool {
92
+
93
+ // IsOnCurve will return false if The public Key:
94
+ // - is an infinity point, O
95
+ // - is on the curve
96
+ // If either is false the Public key is invalid
97
+ if ! pub .Curve .IsOnCurve (pub .X , pub .Y ) {
98
+ return false
99
+ }
100
+
101
+ // is each coordinate in pub
102
+ // >0 and <P
103
+ // else invalid
104
+ params := pub .Curve .Params ()
105
+ if pub .X .Sign () < 0 ||
106
+ pub .Y .Sign () < 0 ||
107
+ pub .X .Cmp (params .P ) > 0 ||
108
+ pub .Y .Cmp (params .P ) > 0 {
109
+ return false
110
+ }
111
+
112
+ // The fourth condition only applies to
113
+ // curves with cofactors > 1 like Curve25519
114
+ // right now there is no interface to determine that
115
+
116
+ return true
117
+ }
118
+
86
119
// PrivateKey represents an ECDSA private key.
87
120
type PrivateKey struct {
88
121
PublicKey
You can’t perform that action at this time.
0 commit comments