@@ -72,14 +72,14 @@ func ValidatePrivateKey(b []byte) (bool, error) {
7272 if len (b ) != voied25519 .PrivateKeySize {
7373 return false , fmt .Errorf ("invalid private key size, expected %v, got %d" , voied25519 .PrivateKeySize , len (b ))
7474 }
75- << << << < HEAD
76- // check if the public key is on the ed25519 curve
77- == == == =
78- // check if the public key is on the voied25519 curve
79- >> >> >> > f4f19e0 ( rename )
80- pub := voied25519 . PrivateKey ( b ). Public ().(voied25519. PublicKey )
81- if ! IsOnCurve ( pub ) {
82- return false , errors .New ("the corresponding public key is NOT on the voied25519 curve " )
75+
76+ // ed25519 private keys are seed(32) + public(32); ensure they match.
77+ derived := voied25519 . NewKeyFromSeed ( b [: voied25519 . SeedSize ])
78+ if ! bytes . Equal ( derived , b ) {
79+ if ! IsOnCurve ( b [ voied25519 . SeedSize :]) {
80+ return false , errors . New ( "invalid private key: seed/public key mismatch (provided public key is NOT on the ed25519 curve)" )
81+ }
82+ return false , errors .New ("invalid private key: seed/ public key mismatch " )
8383 }
8484 return true , nil
8585}
@@ -156,11 +156,7 @@ func (k PrivateKey) PublicKey() PublicKey {
156156// PK is a convenience alias for PublicKey
157157type PK = PublicKey
158158
159- << << << < HEAD
160- // done to keep verify the same as stdlib crypto/ed25519
161- == == == =
162159// done to keep verify the same as stdlib crypto/voied25519
163- >> >> >> > f4f19e0 (rename )
164160var verifyOptsStdLib = & voied25519.Options {
165161 Verify : voied25519 .VerifyOptionsStdLib ,
166162}
0 commit comments