Skip to content

Commit

Permalink
fix generic.go with left problems
Browse files Browse the repository at this point in the history
  • Loading branch information
hurae committed Apr 25, 2020
1 parent 2013cdc commit b0af819
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.11.x
- 1.14.x
- master

branches:
Expand Down
13 changes: 7 additions & 6 deletions generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (g genericCurve) Params() CurveParams {
}

func (g genericCurve) PublicKey(private crypto.PrivateKey) (public crypto.PublicKey) {
key, ok := checkPrivateKey(private)
key, ok := CheckKey(private)
if !ok {
panic("ecdh: unexpected type of private key")
}
Expand All @@ -70,26 +70,27 @@ func (g genericCurve) PublicKey(private crypto.PrivateKey) (public crypto.Public
}

func (g genericCurve) Check(peersPublic crypto.PublicKey) (err error) {
key, ok := checkPublicKey(peersPublic)
key, ok := CheckKey(peersPublic)
if !ok {
err = errors.New("unexpected type of peers public key")
}
if !g.curve.IsOnCurve(key.X, key.Y) {
x, y := elliptic.Unmarshal(g.curve, key)
if !g.curve.IsOnCurve(x, y) {
err = errors.New("peer's public key is not on curve")
}
return
}

func (g genericCurve) ComputeSecret(private crypto.PrivateKey, peersPublic crypto.PublicKey) (secret []byte) {
priKey, ok := checkKey(private)
priKey, ok := CheckKey(private)
if !ok {
panic("ecdh: unexpected type of private key")
}
pubKey, ok := checkKey(peersPublic)
pubKey, ok := CheckKey(peersPublic)
if !ok {
panic("ecdh: unexpected type of peers public key")
}
x, y := elliptic.Unmarshal(pubKey)
x, y := elliptic.Unmarshal(g.curve, pubKey)

sX, _ := g.curve.ScalarMult(x, y, priKey)

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/hurae/ecdh

go 1.14

require golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5

0 comments on commit b0af819

Please sign in to comment.