From c9bb67966b6725ff68735bdc2c79d3923a92d5e7 Mon Sep 17 00:00:00 2001 From: William Schwartz Date: Thu, 24 May 2018 14:30:42 -0700 Subject: [PATCH] crypto: made changes to fix golint warnings --- crypto/bn256/cloudflare/bn256.go | 376 +++++++++++++++---------------- crypto/bn256/cloudflare/gfp12.go | 6 +- crypto/bn256/google/bn256.go | 302 ++++++++++++------------- crypto/bn256/google/constants.go | 2 +- crypto/bn256/google/curve.go | 10 +- crypto/bn256/google/gfp12.go | 6 +- crypto/bn256/google/gfp2.go | 6 +- crypto/bn256/google/gfp6.go | 12 +- crypto/bn256/google/optate.go | 8 +- crypto/bn256/google/twist.go | 8 +- crypto/ecies/ecies.go | 14 +- crypto/ecies/ecies_test.go | 3 +- 12 files changed, 376 insertions(+), 377 deletions(-) diff --git a/crypto/bn256/cloudflare/bn256.go b/crypto/bn256/cloudflare/bn256.go index c6ea2d07e0..7f4eda9396 100644 --- a/crypto/bn256/cloudflare/bn256.go +++ b/crypto/bn256/cloudflare/bn256.go @@ -3,7 +3,7 @@ // // Bilinear groups are the basis of many of the new cryptographic protocols that // have been proposed over the past decade. They consist of a triplet of groups -// (G₁, G₂ and GT) such that there exists a function e(g₁ˣ,g₂ʸ)=gTˣʸ (where gₓ +// (G₁, G₂ and GT) such that there exists a function g(g₁ˣ,g₂ʸ)=gTˣʸ (where gₓ // is a generator of the respective group). That function is called a pairing // function. // @@ -49,108 +49,108 @@ func (g *G1) String() string { return "bn256.G1" + g.p.String() } -// ScalarBaseMult sets e to g*k where g is the generator of the group and then -// returns e. -func (e *G1) ScalarBaseMult(k *big.Int) *G1 { - if e.p == nil { - e.p = &curvePoint{} +// ScalarBaseMult sets g to g*k where g is the generator of the group and then +// returns g. +func (g *G1) ScalarBaseMult(k *big.Int) *G1 { + if g.p == nil { + g.p = &curvePoint{} } - e.p.Mul(curveGen, k) - return e + g.p.Mul(curveGen, k) + return g } -// ScalarMult sets e to a*k and then returns e. -func (e *G1) ScalarMult(a *G1, k *big.Int) *G1 { - if e.p == nil { - e.p = &curvePoint{} +// ScalarMult sets g to a*k and then returns g. +func (g *G1) ScalarMult(a *G1, k *big.Int) *G1 { + if g.p == nil { + g.p = &curvePoint{} } - e.p.Mul(a.p, k) - return e + g.p.Mul(a.p, k) + return g } -// Add sets e to a+b and then returns e. -func (e *G1) Add(a, b *G1) *G1 { - if e.p == nil { - e.p = &curvePoint{} +// Add sets g to a+b and then returns g. +func (g *G1) Add(a, b *G1) *G1 { + if g.p == nil { + g.p = &curvePoint{} } - e.p.Add(a.p, b.p) - return e + g.p.Add(a.p, b.p) + return g } -// Neg sets e to -a and then returns e. -func (e *G1) Neg(a *G1) *G1 { - if e.p == nil { - e.p = &curvePoint{} +// Neg sets g to -a and then returns g. +func (g *G1) Neg(a *G1) *G1 { + if g.p == nil { + g.p = &curvePoint{} } - e.p.Neg(a.p) - return e + g.p.Neg(a.p) + return g } -// Set sets e to a and then returns e. -func (e *G1) Set(a *G1) *G1 { - if e.p == nil { - e.p = &curvePoint{} +// Set sets g to a and then returns g. +func (g *G1) Set(a *G1) *G1 { + if g.p == nil { + g.p = &curvePoint{} } - e.p.Set(a.p) - return e + g.p.Set(a.p) + return g } -// Marshal converts e to a byte slice. -func (e *G1) Marshal() []byte { +// Marshal converts g to a byte slice. +func (g *G1) Marshal() []byte { // Each value is a 256-bit number. const numBytes = 256 / 8 - e.p.MakeAffine() + g.p.MakeAffine() ret := make([]byte, numBytes*2) - if e.p.IsInfinity() { + if g.p.IsInfinity() { return ret } temp := &gfP{} - montDecode(temp, &e.p.x) + montDecode(temp, &g.p.x) temp.Marshal(ret) - montDecode(temp, &e.p.y) + montDecode(temp, &g.p.y) temp.Marshal(ret[numBytes:]) return ret } -// Unmarshal sets e to the result of converting the output of Marshal back into -// a group element and then returns e. -func (e *G1) Unmarshal(m []byte) ([]byte, error) { +// Unmarshal sets g to the result of converting the output of Marshal back into +// a group element and then returns g. +func (g *G1) Unmarshal(m []byte) ([]byte, error) { // Each value is a 256-bit number. const numBytes = 256 / 8 if len(m) < 2*numBytes { return nil, errors.New("bn256: not enough data") } // Unmarshal the points and check their caps - if e.p == nil { - e.p = &curvePoint{} + if g.p == nil { + g.p = &curvePoint{} } else { - e.p.x, e.p.y = gfP{0}, gfP{0} + g.p.x, g.p.y = gfP{0}, gfP{0} } var err error - if err = e.p.x.Unmarshal(m); err != nil { + if err = g.p.x.Unmarshal(m); err != nil { return nil, err } - if err = e.p.y.Unmarshal(m[numBytes:]); err != nil { + if err = g.p.y.Unmarshal(m[numBytes:]); err != nil { return nil, err } // Encode into Montgomery form and ensure it's on the curve - montEncode(&e.p.x, &e.p.x) - montEncode(&e.p.y, &e.p.y) + montEncode(&g.p.x, &g.p.x) + montEncode(&g.p.y, &g.p.y) zero := gfP{0} - if e.p.x == zero && e.p.y == zero { + if g.p.x == zero && g.p.y == zero { // This is the point at infinity. - e.p.y = *newGFp(1) - e.p.z = gfP{0} - e.p.t = gfP{0} + g.p.y = *newGFp(1) + g.p.z = gfP{0} + g.p.t = gfP{0} } else { - e.p.z = *newGFp(1) - e.p.t = *newGFp(1) + g.p.z = *newGFp(1) + g.p.t = *newGFp(1) - if !e.p.IsOnCurve() { + if !g.p.IsOnCurve() { return nil, errors.New("bn256: malformed point") } } @@ -173,125 +173,125 @@ func RandomG2(r io.Reader) (*big.Int, *G2, error) { return k, new(G2).ScalarBaseMult(k), nil } -func (e *G2) String() string { - return "bn256.G2" + e.p.String() +func (g *G2) String() string { + return "bn256.G2" + g.p.String() } -// ScalarBaseMult sets e to g*k where g is the generator of the group and then +// ScalarBaseMult sets g to g*k where g is the generator of the group and then // returns out. -func (e *G2) ScalarBaseMult(k *big.Int) *G2 { - if e.p == nil { - e.p = &twistPoint{} +func (g *G2) ScalarBaseMult(k *big.Int) *G2 { + if g.p == nil { + g.p = &twistPoint{} } - e.p.Mul(twistGen, k) - return e + g.p.Mul(twistGen, k) + return g } -// ScalarMult sets e to a*k and then returns e. -func (e *G2) ScalarMult(a *G2, k *big.Int) *G2 { - if e.p == nil { - e.p = &twistPoint{} +// ScalarMult sets g to a*k and then returns g. +func (g *G2) ScalarMult(a *G2, k *big.Int) *G2 { + if g.p == nil { + g.p = &twistPoint{} } - e.p.Mul(a.p, k) - return e + g.p.Mul(a.p, k) + return g } -// Add sets e to a+b and then returns e. -func (e *G2) Add(a, b *G2) *G2 { - if e.p == nil { - e.p = &twistPoint{} +// Add sets g to a+b and then returns g. +func (g *G2) Add(a, b *G2) *G2 { + if g.p == nil { + g.p = &twistPoint{} } - e.p.Add(a.p, b.p) - return e + g.p.Add(a.p, b.p) + return g } -// Neg sets e to -a and then returns e. -func (e *G2) Neg(a *G2) *G2 { - if e.p == nil { - e.p = &twistPoint{} +// Neg sets g to -a and then returns g. +func (g *G2) Neg(a *G2) *G2 { + if g.p == nil { + g.p = &twistPoint{} } - e.p.Neg(a.p) - return e + g.p.Neg(a.p) + return g } -// Set sets e to a and then returns e. -func (e *G2) Set(a *G2) *G2 { - if e.p == nil { - e.p = &twistPoint{} +// Set sets g to a and then returns g. +func (g *G2) Set(a *G2) *G2 { + if g.p == nil { + g.p = &twistPoint{} } - e.p.Set(a.p) - return e + g.p.Set(a.p) + return g } -// Marshal converts e into a byte slice. -func (e *G2) Marshal() []byte { +// Marshal converts g into a byte slice. +func (g *G2) Marshal() []byte { // Each value is a 256-bit number. const numBytes = 256 / 8 - if e.p == nil { - e.p = &twistPoint{} + if g.p == nil { + g.p = &twistPoint{} } - e.p.MakeAffine() + g.p.MakeAffine() ret := make([]byte, numBytes*4) - if e.p.IsInfinity() { + if g.p.IsInfinity() { return ret } temp := &gfP{} - montDecode(temp, &e.p.x.x) + montDecode(temp, &g.p.x.x) temp.Marshal(ret) - montDecode(temp, &e.p.x.y) + montDecode(temp, &g.p.x.y) temp.Marshal(ret[numBytes:]) - montDecode(temp, &e.p.y.x) + montDecode(temp, &g.p.y.x) temp.Marshal(ret[2*numBytes:]) - montDecode(temp, &e.p.y.y) + montDecode(temp, &g.p.y.y) temp.Marshal(ret[3*numBytes:]) return ret } -// Unmarshal sets e to the result of converting the output of Marshal back into -// a group element and then returns e. -func (e *G2) Unmarshal(m []byte) ([]byte, error) { +// Unmarshal sets g to the result of converting the output of Marshal back into +// a group element and then returns g. +func (g *G2) Unmarshal(m []byte) ([]byte, error) { // Each value is a 256-bit number. const numBytes = 256 / 8 if len(m) < 4*numBytes { return nil, errors.New("bn256: not enough data") } // Unmarshal the points and check their caps - if e.p == nil { - e.p = &twistPoint{} + if g.p == nil { + g.p = &twistPoint{} } var err error - if err = e.p.x.x.Unmarshal(m); err != nil { + if err = g.p.x.x.Unmarshal(m); err != nil { return nil, err } - if err = e.p.x.y.Unmarshal(m[numBytes:]); err != nil { + if err = g.p.x.y.Unmarshal(m[numBytes:]); err != nil { return nil, err } - if err = e.p.y.x.Unmarshal(m[2*numBytes:]); err != nil { + if err = g.p.y.x.Unmarshal(m[2*numBytes:]); err != nil { return nil, err } - if err = e.p.y.y.Unmarshal(m[3*numBytes:]); err != nil { + if err = g.p.y.y.Unmarshal(m[3*numBytes:]); err != nil { return nil, err } // Encode into Montgomery form and ensure it's on the curve - montEncode(&e.p.x.x, &e.p.x.x) - montEncode(&e.p.x.y, &e.p.x.y) - montEncode(&e.p.y.x, &e.p.y.x) - montEncode(&e.p.y.y, &e.p.y.y) + montEncode(&g.p.x.x, &g.p.x.x) + montEncode(&g.p.x.y, &g.p.x.y) + montEncode(&g.p.y.x, &g.p.y.x) + montEncode(&g.p.y.y, &g.p.y.y) - if e.p.x.IsZero() && e.p.y.IsZero() { + if g.p.x.IsZero() && g.p.y.IsZero() { // This is the point at infinity. - e.p.y.SetOne() - e.p.z.SetZero() - e.p.t.SetZero() + g.p.y.SetOne() + g.p.z.SetZero() + g.p.t.SetZero() } else { - e.p.z.SetOne() - e.p.t.SetOne() + g.p.z.SetOne() + g.p.t.SetOne() - if !e.p.IsOnCurve() { + if !g.p.IsOnCurve() { return nil, errors.New("bn256: malformed point") } } @@ -334,88 +334,88 @@ func (g *GT) String() string { return "bn256.GT" + g.p.String() } -// ScalarMult sets e to a*k and then returns e. -func (e *GT) ScalarMult(a *GT, k *big.Int) *GT { - if e.p == nil { - e.p = &gfP12{} +// ScalarMult sets g to a*k and then returns g. +func (g *GT) ScalarMult(a *GT, k *big.Int) *GT { + if g.p == nil { + g.p = &gfP12{} } - e.p.Exp(a.p, k) - return e + g.p.Exp(a.p, k) + return g } -// Add sets e to a+b and then returns e. -func (e *GT) Add(a, b *GT) *GT { - if e.p == nil { - e.p = &gfP12{} +// Add sets g to a+b and then returns g. +func (g *GT) Add(a, b *GT) *GT { + if g.p == nil { + g.p = &gfP12{} } - e.p.Mul(a.p, b.p) - return e + g.p.Mul(a.p, b.p) + return g } -// Neg sets e to -a and then returns e. -func (e *GT) Neg(a *GT) *GT { - if e.p == nil { - e.p = &gfP12{} +// Neg sets g to -a and then returns g. +func (g *GT) Neg(a *GT) *GT { + if g.p == nil { + g.p = &gfP12{} } - e.p.Conjugate(a.p) - return e + g.p.Conjugate(a.p) + return g } -// Set sets e to a and then returns e. -func (e *GT) Set(a *GT) *GT { - if e.p == nil { - e.p = &gfP12{} +// Set sets g to a and then returns g. +func (g *GT) Set(a *GT) *GT { + if g.p == nil { + g.p = &gfP12{} } - e.p.Set(a.p) - return e + g.p.Set(a.p) + return g } // Finalize is a linear function from F_p^12 to GT. -func (e *GT) Finalize() *GT { - ret := finalExponentiation(e.p) - e.p.Set(ret) - return e +func (g *GT) Finalize() *GT { + ret := finalExponentiation(g.p) + g.p.Set(ret) + return g } -// Marshal converts e into a byte slice. -func (e *GT) Marshal() []byte { +// Marshal converts g into a byte slice. +func (g *GT) Marshal() []byte { // Each value is a 256-bit number. const numBytes = 256 / 8 ret := make([]byte, numBytes*12) temp := &gfP{} - montDecode(temp, &e.p.x.x.x) + montDecode(temp, &g.p.x.x.x) temp.Marshal(ret) - montDecode(temp, &e.p.x.x.y) + montDecode(temp, &g.p.x.x.y) temp.Marshal(ret[numBytes:]) - montDecode(temp, &e.p.x.y.x) + montDecode(temp, &g.p.x.y.x) temp.Marshal(ret[2*numBytes:]) - montDecode(temp, &e.p.x.y.y) + montDecode(temp, &g.p.x.y.y) temp.Marshal(ret[3*numBytes:]) - montDecode(temp, &e.p.x.z.x) + montDecode(temp, &g.p.x.z.x) temp.Marshal(ret[4*numBytes:]) - montDecode(temp, &e.p.x.z.y) + montDecode(temp, &g.p.x.z.y) temp.Marshal(ret[5*numBytes:]) - montDecode(temp, &e.p.y.x.x) + montDecode(temp, &g.p.y.x.x) temp.Marshal(ret[6*numBytes:]) - montDecode(temp, &e.p.y.x.y) + montDecode(temp, &g.p.y.x.y) temp.Marshal(ret[7*numBytes:]) - montDecode(temp, &e.p.y.y.x) + montDecode(temp, &g.p.y.y.x) temp.Marshal(ret[8*numBytes:]) - montDecode(temp, &e.p.y.y.y) + montDecode(temp, &g.p.y.y.y) temp.Marshal(ret[9*numBytes:]) - montDecode(temp, &e.p.y.z.x) + montDecode(temp, &g.p.y.z.x) temp.Marshal(ret[10*numBytes:]) - montDecode(temp, &e.p.y.z.y) + montDecode(temp, &g.p.y.z.y) temp.Marshal(ret[11*numBytes:]) return ret } -// Unmarshal sets e to the result of converting the output of Marshal back into -// a group element and then returns e. -func (e *GT) Unmarshal(m []byte) ([]byte, error) { +// Unmarshal sets g to the result of converting the output of Marshal back into +// a group element and then returns g. +func (g *GT) Unmarshal(m []byte) ([]byte, error) { // Each value is a 256-bit number. const numBytes = 256 / 8 @@ -423,59 +423,59 @@ func (e *GT) Unmarshal(m []byte) ([]byte, error) { return nil, errors.New("bn256: not enough data") } - if e.p == nil { - e.p = &gfP12{} + if g.p == nil { + g.p = &gfP12{} } var err error - if err = e.p.x.x.x.Unmarshal(m); err != nil { + if err = g.p.x.x.x.Unmarshal(m); err != nil { return nil, err } - if err = e.p.x.x.y.Unmarshal(m[numBytes:]); err != nil { + if err = g.p.x.x.y.Unmarshal(m[numBytes:]); err != nil { return nil, err } - if err = e.p.x.y.x.Unmarshal(m[2*numBytes:]); err != nil { + if err = g.p.x.y.x.Unmarshal(m[2*numBytes:]); err != nil { return nil, err } - if err = e.p.x.y.y.Unmarshal(m[3*numBytes:]); err != nil { + if err = g.p.x.y.y.Unmarshal(m[3*numBytes:]); err != nil { return nil, err } - if err = e.p.x.z.x.Unmarshal(m[4*numBytes:]); err != nil { + if err = g.p.x.z.x.Unmarshal(m[4*numBytes:]); err != nil { return nil, err } - if err = e.p.x.z.y.Unmarshal(m[5*numBytes:]); err != nil { + if err = g.p.x.z.y.Unmarshal(m[5*numBytes:]); err != nil { return nil, err } - if err = e.p.y.x.x.Unmarshal(m[6*numBytes:]); err != nil { + if err = g.p.y.x.x.Unmarshal(m[6*numBytes:]); err != nil { return nil, err } - if err = e.p.y.x.y.Unmarshal(m[7*numBytes:]); err != nil { + if err = g.p.y.x.y.Unmarshal(m[7*numBytes:]); err != nil { return nil, err } - if err = e.p.y.y.x.Unmarshal(m[8*numBytes:]); err != nil { + if err = g.p.y.y.x.Unmarshal(m[8*numBytes:]); err != nil { return nil, err } - if err = e.p.y.y.y.Unmarshal(m[9*numBytes:]); err != nil { + if err = g.p.y.y.y.Unmarshal(m[9*numBytes:]); err != nil { return nil, err } - if err = e.p.y.z.x.Unmarshal(m[10*numBytes:]); err != nil { + if err = g.p.y.z.x.Unmarshal(m[10*numBytes:]); err != nil { return nil, err } - if err = e.p.y.z.y.Unmarshal(m[11*numBytes:]); err != nil { + if err = g.p.y.z.y.Unmarshal(m[11*numBytes:]); err != nil { return nil, err } - montEncode(&e.p.x.x.x, &e.p.x.x.x) - montEncode(&e.p.x.x.y, &e.p.x.x.y) - montEncode(&e.p.x.y.x, &e.p.x.y.x) - montEncode(&e.p.x.y.y, &e.p.x.y.y) - montEncode(&e.p.x.z.x, &e.p.x.z.x) - montEncode(&e.p.x.z.y, &e.p.x.z.y) - montEncode(&e.p.y.x.x, &e.p.y.x.x) - montEncode(&e.p.y.x.y, &e.p.y.x.y) - montEncode(&e.p.y.y.x, &e.p.y.y.x) - montEncode(&e.p.y.y.y, &e.p.y.y.y) - montEncode(&e.p.y.z.x, &e.p.y.z.x) - montEncode(&e.p.y.z.y, &e.p.y.z.y) + montEncode(&g.p.x.x.x, &g.p.x.x.x) + montEncode(&g.p.x.x.y, &g.p.x.x.y) + montEncode(&g.p.x.y.x, &g.p.x.y.x) + montEncode(&g.p.x.y.y, &g.p.x.y.y) + montEncode(&g.p.x.z.x, &g.p.x.z.x) + montEncode(&g.p.x.z.y, &g.p.x.z.y) + montEncode(&g.p.y.x.x, &g.p.y.x.x) + montEncode(&g.p.y.x.y, &g.p.y.x.y) + montEncode(&g.p.y.y.x, &g.p.y.y.x) + montEncode(&g.p.y.y.y, &g.p.y.y.y) + montEncode(&g.p.y.z.x, &g.p.y.z.x) + montEncode(&g.p.y.z.y, &g.p.y.z.y) return m[12*numBytes:], nil } diff --git a/crypto/bn256/cloudflare/gfp12.go b/crypto/bn256/cloudflare/gfp12.go index 93fb368a7b..287b8be1f6 100644 --- a/crypto/bn256/cloudflare/gfp12.go +++ b/crypto/bn256/cloudflare/gfp12.go @@ -110,7 +110,7 @@ func (e *gfP12) MulScalar(a *gfP12, b *gfP6) *gfP12 { return e } -func (c *gfP12) Exp(a *gfP12, power *big.Int) *gfP12 { +func (e *gfP12) Exp(a *gfP12, power *big.Int) *gfP12 { sum := (&gfP12{}).SetOne() t := &gfP12{} @@ -123,8 +123,8 @@ func (c *gfP12) Exp(a *gfP12, power *big.Int) *gfP12 { } } - c.Set(sum) - return c + e.Set(sum) + return e } func (e *gfP12) Square(a *gfP12) *gfP12 { diff --git a/crypto/bn256/google/bn256.go b/crypto/bn256/google/bn256.go index 5da83e033a..7fb5690997 100644 --- a/crypto/bn256/google/bn256.go +++ b/crypto/bn256/google/bn256.go @@ -6,7 +6,7 @@ // // Bilinear groups are the basis of many of the new cryptographic protocols // that have been proposed over the past decade. They consist of a triplet of -// groups (G₁, G₂ and GT) such that there exists a function e(g₁ˣ,g₂ʸ)=gTˣʸ +// groups (G₁, G₂ and GT) such that there exists a function g(g₁ˣ,g₂ʸ)=gTˣʸ // (where gₓ is a generator of the respective group). That function is called // a pairing function. // @@ -55,54 +55,54 @@ func (g *G1) String() string { } // CurvePoints returns p's curve points in big integer -func (e *G1) CurvePoints() (*big.Int, *big.Int, *big.Int, *big.Int) { - return e.p.x, e.p.y, e.p.z, e.p.t +func (g *G1) CurvePoints() (*big.Int, *big.Int, *big.Int, *big.Int) { + return g.p.x, g.p.y, g.p.z, g.p.t } -// ScalarBaseMult sets e to g*k where g is the generator of the group and -// then returns e. -func (e *G1) ScalarBaseMult(k *big.Int) *G1 { - if e.p == nil { - e.p = newCurvePoint(nil) +// ScalarBaseMult sets g to g*k where g is the generator of the group and +// then returns g. +func (g *G1) ScalarBaseMult(k *big.Int) *G1 { + if g.p == nil { + g.p = newCurvePoint(nil) } - e.p.Mul(curveGen, k, new(bnPool)) - return e + g.p.Mul(curveGen, k, new(bnPool)) + return g } -// ScalarMult sets e to a*k and then returns e. -func (e *G1) ScalarMult(a *G1, k *big.Int) *G1 { - if e.p == nil { - e.p = newCurvePoint(nil) +// ScalarMult sets g to a*k and then returns g. +func (g *G1) ScalarMult(a *G1, k *big.Int) *G1 { + if g.p == nil { + g.p = newCurvePoint(nil) } - e.p.Mul(a.p, k, new(bnPool)) - return e + g.p.Mul(a.p, k, new(bnPool)) + return g } -// Add sets e to a+b and then returns e. +// Add sets g to a+b and then returns g. // BUG(agl): this function is not complete: a==b fails. -func (e *G1) Add(a, b *G1) *G1 { - if e.p == nil { - e.p = newCurvePoint(nil) +func (g *G1) Add(a, b *G1) *G1 { + if g.p == nil { + g.p = newCurvePoint(nil) } - e.p.Add(a.p, b.p, new(bnPool)) - return e + g.p.Add(a.p, b.p, new(bnPool)) + return g } -// Neg sets e to -a and then returns e. -func (e *G1) Neg(a *G1) *G1 { - if e.p == nil { - e.p = newCurvePoint(nil) +// Neg sets g to -a and then returns g. +func (g *G1) Neg(a *G1) *G1 { + if g.p == nil { + g.p = newCurvePoint(nil) } - e.p.Negative(a.p) - return e + g.p.Negative(a.p) + return g } -// Marshal converts n to a byte slice. -func (n *G1) Marshal() []byte { - n.p.MakeAffine(nil) +// Marshal converts g to a byte slice. +func (g *G1) Marshal() []byte { + g.p.MakeAffine(nil) - xBytes := new(big.Int).Mod(n.p.x, P).Bytes() - yBytes := new(big.Int).Mod(n.p.y, P).Bytes() + xBytes := new(big.Int).Mod(g.p.x, P).Bytes() + yBytes := new(big.Int).Mod(g.p.y, P).Bytes() // Each value is a 256-bit number. const numBytes = 256 / 8 @@ -114,37 +114,37 @@ func (n *G1) Marshal() []byte { return ret } -// Unmarshal sets e to the result of converting the output of Marshal back into -// a group element and then returns e. -func (e *G1) Unmarshal(m []byte) ([]byte, error) { +// Unmarshal sets g to the result of converting the output of Marshal back into +// a group element and then returns g. +func (g *G1) Unmarshal(m []byte) ([]byte, error) { // Each value is a 256-bit number. const numBytes = 256 / 8 if len(m) != 2*numBytes { return nil, errors.New("bn256: not enough data") } // Unmarshal the points and check their caps - if e.p == nil { - e.p = newCurvePoint(nil) + if g.p == nil { + g.p = newCurvePoint(nil) } - e.p.x.SetBytes(m[0*numBytes : 1*numBytes]) - if e.p.x.Cmp(P) >= 0 { + g.p.x.SetBytes(m[0*numBytes : 1*numBytes]) + if g.p.x.Cmp(P) >= 0 { return nil, errors.New("bn256: coordinate exceeds modulus") } - e.p.y.SetBytes(m[1*numBytes : 2*numBytes]) - if e.p.y.Cmp(P) >= 0 { + g.p.y.SetBytes(m[1*numBytes : 2*numBytes]) + if g.p.y.Cmp(P) >= 0 { return nil, errors.New("bn256: coordinate exceeds modulus") } // Ensure the point is on the curve - if e.p.x.Sign() == 0 && e.p.y.Sign() == 0 { + if g.p.x.Sign() == 0 && g.p.y.Sign() == 0 { // This is the point at infinity. - e.p.y.SetInt64(1) - e.p.z.SetInt64(0) - e.p.t.SetInt64(0) + g.p.y.SetInt64(1) + g.p.z.SetInt64(0) + g.p.t.SetInt64(0) } else { - e.p.z.SetInt64(1) - e.p.t.SetInt64(1) + g.p.z.SetInt64(1) + g.p.t.SetInt64(1) - if !e.p.IsOnCurve() { + if !g.p.IsOnCurve() { return nil, errors.New("bn256: malformed point") } } @@ -157,7 +157,7 @@ type G2 struct { p *twistPoint } -// RandomG1 returns x and g₂ˣ where x is a random, non-zero number read from r. +// RandomG2 returns x and g₂ˣ where x is a random, non-zero number read from r. func RandomG2(r io.Reader) (*big.Int, *G2, error) { var k *big.Int var err error @@ -181,47 +181,47 @@ func (g *G2) String() string { // CurvePoints returns the curve points of p which includes the real // and imaginary parts of the curve point. -func (e *G2) CurvePoints() (*gfP2, *gfP2, *gfP2, *gfP2) { - return e.p.x, e.p.y, e.p.z, e.p.t +func (g *G2) CurvePoints() (*gfP2, *gfP2, *gfP2, *gfP2) { + return g.p.x, g.p.y, g.p.z, g.p.t } -// ScalarBaseMult sets e to g*k where g is the generator of the group and +// ScalarBaseMult sets g to g*k where g is the generator of the group and // then returns out. -func (e *G2) ScalarBaseMult(k *big.Int) *G2 { - if e.p == nil { - e.p = newTwistPoint(nil) +func (g *G2) ScalarBaseMult(k *big.Int) *G2 { + if g.p == nil { + g.p = newTwistPoint(nil) } - e.p.Mul(twistGen, k, new(bnPool)) - return e + g.p.Mul(twistGen, k, new(bnPool)) + return g } -// ScalarMult sets e to a*k and then returns e. -func (e *G2) ScalarMult(a *G2, k *big.Int) *G2 { - if e.p == nil { - e.p = newTwistPoint(nil) +// ScalarMult sets g to a*k and then returns g. +func (g *G2) ScalarMult(a *G2, k *big.Int) *G2 { + if g.p == nil { + g.p = newTwistPoint(nil) } - e.p.Mul(a.p, k, new(bnPool)) - return e + g.p.Mul(a.p, k, new(bnPool)) + return g } -// Add sets e to a+b and then returns e. +// Add sets g to a+b and then returns g. // BUG(agl): this function is not complete: a==b fails. -func (e *G2) Add(a, b *G2) *G2 { - if e.p == nil { - e.p = newTwistPoint(nil) +func (g *G2) Add(a, b *G2) *G2 { + if g.p == nil { + g.p = newTwistPoint(nil) } - e.p.Add(a.p, b.p, new(bnPool)) - return e + g.p.Add(a.p, b.p, new(bnPool)) + return g } -// Marshal converts n into a byte slice. -func (n *G2) Marshal() []byte { - n.p.MakeAffine(nil) +// Marshal converts g into a byte slice. +func (g *G2) Marshal() []byte { + g.p.MakeAffine(nil) - xxBytes := new(big.Int).Mod(n.p.x.x, P).Bytes() - xyBytes := new(big.Int).Mod(n.p.x.y, P).Bytes() - yxBytes := new(big.Int).Mod(n.p.y.x, P).Bytes() - yyBytes := new(big.Int).Mod(n.p.y.y, P).Bytes() + xxBytes := new(big.Int).Mod(g.p.x.x, P).Bytes() + xyBytes := new(big.Int).Mod(g.p.x.y, P).Bytes() + yxBytes := new(big.Int).Mod(g.p.y.x, P).Bytes() + yyBytes := new(big.Int).Mod(g.p.y.y, P).Bytes() // Each value is a 256-bit number. const numBytes = 256 / 8 @@ -235,48 +235,48 @@ func (n *G2) Marshal() []byte { return ret } -// Unmarshal sets e to the result of converting the output of Marshal back into -// a group element and then returns e. -func (e *G2) Unmarshal(m []byte) ([]byte, error) { +// Unmarshal sets g to the result of converting the output of Marshal back into +// a group element and then returns g. +func (g *G2) Unmarshal(m []byte) ([]byte, error) { // Each value is a 256-bit number. const numBytes = 256 / 8 if len(m) != 4*numBytes { return nil, errors.New("bn256: not enough data") } // Unmarshal the points and check their caps - if e.p == nil { - e.p = newTwistPoint(nil) + if g.p == nil { + g.p = newTwistPoint(nil) } - e.p.x.x.SetBytes(m[0*numBytes : 1*numBytes]) - if e.p.x.x.Cmp(P) >= 0 { + g.p.x.x.SetBytes(m[0*numBytes : 1*numBytes]) + if g.p.x.x.Cmp(P) >= 0 { return nil, errors.New("bn256: coordinate exceeds modulus") } - e.p.x.y.SetBytes(m[1*numBytes : 2*numBytes]) - if e.p.x.y.Cmp(P) >= 0 { + g.p.x.y.SetBytes(m[1*numBytes : 2*numBytes]) + if g.p.x.y.Cmp(P) >= 0 { return nil, errors.New("bn256: coordinate exceeds modulus") } - e.p.y.x.SetBytes(m[2*numBytes : 3*numBytes]) - if e.p.y.x.Cmp(P) >= 0 { + g.p.y.x.SetBytes(m[2*numBytes : 3*numBytes]) + if g.p.y.x.Cmp(P) >= 0 { return nil, errors.New("bn256: coordinate exceeds modulus") } - e.p.y.y.SetBytes(m[3*numBytes : 4*numBytes]) - if e.p.y.y.Cmp(P) >= 0 { + g.p.y.y.SetBytes(m[3*numBytes : 4*numBytes]) + if g.p.y.y.Cmp(P) >= 0 { return nil, errors.New("bn256: coordinate exceeds modulus") } // Ensure the point is on the curve - if e.p.x.x.Sign() == 0 && - e.p.x.y.Sign() == 0 && - e.p.y.x.Sign() == 0 && - e.p.y.y.Sign() == 0 { + if g.p.x.x.Sign() == 0 && + g.p.x.y.Sign() == 0 && + g.p.y.x.Sign() == 0 && + g.p.y.y.Sign() == 0 { // This is the point at infinity. - e.p.y.SetOne() - e.p.z.SetZero() - e.p.t.SetZero() + g.p.y.SetOne() + g.p.z.SetZero() + g.p.t.SetZero() } else { - e.p.z.SetOne() - e.p.t.SetOne() + g.p.z.SetOne() + g.p.t.SetOne() - if !e.p.IsOnCurve() { + if !g.p.IsOnCurve() { return nil, errors.New("bn256: malformed point") } } @@ -293,49 +293,49 @@ func (g *GT) String() string { return "bn256.GT" + g.p.String() } -// ScalarMult sets e to a*k and then returns e. -func (e *GT) ScalarMult(a *GT, k *big.Int) *GT { - if e.p == nil { - e.p = newGFp12(nil) +// ScalarMult sets g to a*k and then returns g. +func (g *GT) ScalarMult(a *GT, k *big.Int) *GT { + if g.p == nil { + g.p = newGFp12(nil) } - e.p.Exp(a.p, k, new(bnPool)) - return e + g.p.Exp(a.p, k, new(bnPool)) + return g } -// Add sets e to a+b and then returns e. -func (e *GT) Add(a, b *GT) *GT { - if e.p == nil { - e.p = newGFp12(nil) +// Add sets g to a+b and then returns g. +func (g *GT) Add(a, b *GT) *GT { + if g.p == nil { + g.p = newGFp12(nil) } - e.p.Mul(a.p, b.p, new(bnPool)) - return e + g.p.Mul(a.p, b.p, new(bnPool)) + return g } -// Neg sets e to -a and then returns e. -func (e *GT) Neg(a *GT) *GT { - if e.p == nil { - e.p = newGFp12(nil) +// Neg sets g to -a and then returns g. +func (g *GT) Neg(a *GT) *GT { + if g.p == nil { + g.p = newGFp12(nil) } - e.p.Invert(a.p, new(bnPool)) - return e + g.p.Invert(a.p, new(bnPool)) + return g } -// Marshal converts n into a byte slice. -func (n *GT) Marshal() []byte { - n.p.Minimal() +// Marshal converts g into a byte slice. +func (g *GT) Marshal() []byte { + g.p.Minimal() - xxxBytes := n.p.x.x.x.Bytes() - xxyBytes := n.p.x.x.y.Bytes() - xyxBytes := n.p.x.y.x.Bytes() - xyyBytes := n.p.x.y.y.Bytes() - xzxBytes := n.p.x.z.x.Bytes() - xzyBytes := n.p.x.z.y.Bytes() - yxxBytes := n.p.y.x.x.Bytes() - yxyBytes := n.p.y.x.y.Bytes() - yyxBytes := n.p.y.y.x.Bytes() - yyyBytes := n.p.y.y.y.Bytes() - yzxBytes := n.p.y.z.x.Bytes() - yzyBytes := n.p.y.z.y.Bytes() + xxxBytes := g.p.x.x.x.Bytes() + xxyBytes := g.p.x.x.y.Bytes() + xyxBytes := g.p.x.y.x.Bytes() + xyyBytes := g.p.x.y.y.Bytes() + xzxBytes := g.p.x.z.x.Bytes() + xzyBytes := g.p.x.z.y.Bytes() + yxxBytes := g.p.y.x.x.Bytes() + yxyBytes := g.p.y.x.y.Bytes() + yyxBytes := g.p.y.y.x.Bytes() + yyyBytes := g.p.y.y.y.Bytes() + yzxBytes := g.p.y.z.x.Bytes() + yzyBytes := g.p.y.z.y.Bytes() // Each value is a 256-bit number. const numBytes = 256 / 8 @@ -357,9 +357,9 @@ func (n *GT) Marshal() []byte { return ret } -// Unmarshal sets e to the result of converting the output of Marshal back into -// a group element and then returns e. -func (e *GT) Unmarshal(m []byte) (*GT, bool) { +// Unmarshal sets g to the result of converting the output of Marshal back into +// a group element and then returns g. +func (g *GT) Unmarshal(m []byte) (*GT, bool) { // Each value is a 256-bit number. const numBytes = 256 / 8 @@ -367,24 +367,24 @@ func (e *GT) Unmarshal(m []byte) (*GT, bool) { return nil, false } - if e.p == nil { - e.p = newGFp12(nil) + if g.p == nil { + g.p = newGFp12(nil) } - e.p.x.x.x.SetBytes(m[0*numBytes : 1*numBytes]) - e.p.x.x.y.SetBytes(m[1*numBytes : 2*numBytes]) - e.p.x.y.x.SetBytes(m[2*numBytes : 3*numBytes]) - e.p.x.y.y.SetBytes(m[3*numBytes : 4*numBytes]) - e.p.x.z.x.SetBytes(m[4*numBytes : 5*numBytes]) - e.p.x.z.y.SetBytes(m[5*numBytes : 6*numBytes]) - e.p.y.x.x.SetBytes(m[6*numBytes : 7*numBytes]) - e.p.y.x.y.SetBytes(m[7*numBytes : 8*numBytes]) - e.p.y.y.x.SetBytes(m[8*numBytes : 9*numBytes]) - e.p.y.y.y.SetBytes(m[9*numBytes : 10*numBytes]) - e.p.y.z.x.SetBytes(m[10*numBytes : 11*numBytes]) - e.p.y.z.y.SetBytes(m[11*numBytes : 12*numBytes]) + g.p.x.x.x.SetBytes(m[0*numBytes : 1*numBytes]) + g.p.x.x.y.SetBytes(m[1*numBytes : 2*numBytes]) + g.p.x.y.x.SetBytes(m[2*numBytes : 3*numBytes]) + g.p.x.y.y.SetBytes(m[3*numBytes : 4*numBytes]) + g.p.x.z.x.SetBytes(m[4*numBytes : 5*numBytes]) + g.p.x.z.y.SetBytes(m[5*numBytes : 6*numBytes]) + g.p.y.x.x.SetBytes(m[6*numBytes : 7*numBytes]) + g.p.y.x.y.SetBytes(m[7*numBytes : 8*numBytes]) + g.p.y.y.x.SetBytes(m[8*numBytes : 9*numBytes]) + g.p.y.y.y.SetBytes(m[9*numBytes : 10*numBytes]) + g.p.y.z.x.SetBytes(m[10*numBytes : 11*numBytes]) + g.p.y.z.y.SetBytes(m[11*numBytes : 12*numBytes]) - return e, true + return g, true } // Pair calculates an Optimal Ate pairing. diff --git a/crypto/bn256/google/constants.go b/crypto/bn256/google/constants.go index ab649d7f3f..eba0d837a1 100644 --- a/crypto/bn256/google/constants.go +++ b/crypto/bn256/google/constants.go @@ -16,7 +16,7 @@ func bigFromBase10(s string) *big.Int { // u is the BN parameter that determines the prime: 1868033³. var u = bigFromBase10("4965661367192848881") -// p is a prime over which we form a basic field: 36u⁴+36u³+24u²+6u+1. +// P is a prime over which we form a basic field: 36u⁴+36u³+24u²+6u+1. var P = bigFromBase10("21888242871839275222246405745257275088696311157297823662689037894645226208583") // Order is the number of elements in both G₁ and G₂: 36u⁴+36u³+18u²+6u+1. diff --git a/crypto/bn256/google/curve.go b/crypto/bn256/google/curve.go index 3e679fdc7e..9ff5838845 100644 --- a/crypto/bn256/google/curve.go +++ b/crypto/bn256/google/curve.go @@ -186,14 +186,14 @@ func (c *curvePoint) Double(a *curvePoint, pool *bnPool) { A.Mod(A, P) B := pool.Get().Mul(a.y, a.y) B.Mod(B, P) - C_ := pool.Get().Mul(B, B) - C_.Mod(C_, P) + _C := pool.Get().Mul(B, B) + _C.Mod(_C, P) t := pool.Get().Add(a.x, B) t2 := pool.Get().Mul(t, t) t2.Mod(t2, P) t.Sub(t2, A) - t2.Sub(t, C_) + t2.Sub(t, _C) d := pool.Get().Add(t2, t2) t.Add(A, A) e := pool.Get().Add(t, A) @@ -203,7 +203,7 @@ func (c *curvePoint) Double(a *curvePoint, pool *bnPool) { t.Add(d, d) c.x.Sub(f, t) - t.Add(C_, C_) + t.Add(_C, _C) t2.Add(t, t) t.Add(t2, t2) c.y.Sub(d, c.x) @@ -217,7 +217,7 @@ func (c *curvePoint) Double(a *curvePoint, pool *bnPool) { pool.Put(A) pool.Put(B) - pool.Put(C_) + pool.Put(_C) pool.Put(t) pool.Put(t2) pool.Put(d) diff --git a/crypto/bn256/google/gfp12.go b/crypto/bn256/google/gfp12.go index f084eddf21..f615e65344 100644 --- a/crypto/bn256/google/gfp12.go +++ b/crypto/bn256/google/gfp12.go @@ -130,7 +130,7 @@ func (e *gfP12) MulScalar(a *gfP12, b *gfP6, pool *bnPool) *gfP12 { return e } -func (c *gfP12) Exp(a *gfP12, power *big.Int, pool *bnPool) *gfP12 { +func (e *gfP12) Exp(a *gfP12, power *big.Int, pool *bnPool) *gfP12 { sum := newGFp12(pool) sum.SetOne() t := newGFp12(pool) @@ -144,12 +144,12 @@ func (c *gfP12) Exp(a *gfP12, power *big.Int, pool *bnPool) *gfP12 { } } - c.Set(sum) + e.Set(sum) sum.Put(pool) t.Put(pool) - return c + return e } func (e *gfP12) Square(a *gfP12, pool *bnPool) *gfP12 { diff --git a/crypto/bn256/google/gfp2.go b/crypto/bn256/google/gfp2.go index 3981f6cb4f..67a294fab8 100644 --- a/crypto/bn256/google/gfp2.go +++ b/crypto/bn256/google/gfp2.go @@ -102,7 +102,7 @@ func (e *gfP2) Double(a *gfP2) *gfP2 { return e } -func (c *gfP2) Exp(a *gfP2, power *big.Int, pool *bnPool) *gfP2 { +func (e *gfP2) Exp(a *gfP2, power *big.Int, pool *bnPool) *gfP2 { sum := newGFp2(pool) sum.SetOne() t := newGFp2(pool) @@ -116,12 +116,12 @@ func (c *gfP2) Exp(a *gfP2, power *big.Int, pool *bnPool) *gfP2 { } } - c.Set(sum) + e.Set(sum) sum.Put(pool) t.Put(pool) - return c + return e } // See "Multiplication and Squaring in Pairing-Friendly Fields", diff --git a/crypto/bn256/google/gfp6.go b/crypto/bn256/google/gfp6.go index 218856617c..2fbdb3849f 100644 --- a/crypto/bn256/google/gfp6.go +++ b/crypto/bn256/google/gfp6.go @@ -266,13 +266,13 @@ func (e *gfP6) Invert(a *gfP6, pool *bnPool) *gfP6 { t1.Mul(a.y, a.z, pool) B.Sub(B, t1) - C_ := newGFp2(pool) - C_.Square(a.y, pool) + _C := newGFp2(pool) + _C.Square(a.y, pool) t1.Mul(a.x, a.z, pool) - C_.Sub(C_, t1) + _C.Sub(_C, t1) F := newGFp2(pool) - F.Mul(C_, a.y, pool) + F.Mul(_C, a.y, pool) F.MulXi(F, pool) t1.Mul(A, a.z, pool) F.Add(F, t1) @@ -282,14 +282,14 @@ func (e *gfP6) Invert(a *gfP6, pool *bnPool) *gfP6 { F.Invert(F, pool) - e.x.Mul(C_, F, pool) + e.x.Mul(_C, F, pool) e.y.Mul(B, F, pool) e.z.Mul(A, F, pool) t1.Put(pool) A.Put(pool) B.Put(pool) - C_.Put(pool) + _C.Put(pool) F.Put(pool) return e diff --git a/crypto/bn256/google/optate.go b/crypto/bn256/google/optate.go index 9d6957062e..5f54dc8e79 100644 --- a/crypto/bn256/google/optate.go +++ b/crypto/bn256/google/optate.go @@ -88,12 +88,12 @@ func lineFunctionDouble(r *twistPoint, q *curvePoint, pool *bnPool) (a, b, c *gf A := newGFp2(pool).Square(r.x, pool) B := newGFp2(pool).Square(r.y, pool) - C_ := newGFp2(pool).Square(B, pool) + _C := newGFp2(pool).Square(B, pool) D := newGFp2(pool).Add(r.x, B) D.Square(D, pool) D.Sub(D, A) - D.Sub(D, C_) + D.Sub(D, _C) D.Add(D, D) E := newGFp2(pool).Add(A, A) @@ -112,7 +112,7 @@ func lineFunctionDouble(r *twistPoint, q *curvePoint, pool *bnPool) (a, b, c *gf rOut.y.Sub(D, rOut.x) rOut.y.Mul(rOut.y, E, pool) - t := newGFp2(pool).Add(C_, C_) + t := newGFp2(pool).Add(_C, _C) t.Add(t, t) t.Add(t, t) rOut.y.Sub(rOut.y, t) @@ -142,7 +142,7 @@ func lineFunctionDouble(r *twistPoint, q *curvePoint, pool *bnPool) (a, b, c *gf A.Put(pool) B.Put(pool) - C_.Put(pool) + _C.Put(pool) D.Put(pool) E.Put(pool) G.Put(pool) diff --git a/crypto/bn256/google/twist.go b/crypto/bn256/google/twist.go index 1f5a4d9deb..14240cd8fa 100644 --- a/crypto/bn256/google/twist.go +++ b/crypto/bn256/google/twist.go @@ -171,12 +171,12 @@ func (c *twistPoint) Double(a *twistPoint, pool *bnPool) { // See http://hyperelliptic.org/EFD/g1p/auto-code/shortw/jacobian-0/doubling/dbl-2009-l.op3 A := newGFp2(pool).Square(a.x, pool) B := newGFp2(pool).Square(a.y, pool) - C_ := newGFp2(pool).Square(B, pool) + _C := newGFp2(pool).Square(B, pool) t := newGFp2(pool).Add(a.x, B) t2 := newGFp2(pool).Square(t, pool) t.Sub(t2, A) - t2.Sub(t, C_) + t2.Sub(t, _C) d := newGFp2(pool).Add(t2, t2) t.Add(A, A) e := newGFp2(pool).Add(t, A) @@ -185,7 +185,7 @@ func (c *twistPoint) Double(a *twistPoint, pool *bnPool) { t.Add(d, d) c.x.Sub(f, t) - t.Add(C_, C_) + t.Add(_C, _C) t2.Add(t, t) t.Add(t2, t2) c.y.Sub(d, c.x) @@ -197,7 +197,7 @@ func (c *twistPoint) Double(a *twistPoint, pool *bnPool) { A.Put(pool) B.Put(pool) - C_.Put(pool) + _C.Put(pool) t.Put(pool) t2.Put(pool) d.Put(pool) diff --git a/crypto/ecies/ecies.go b/crypto/ecies/ecies.go index 1474181482..07bda36325 100644 --- a/crypto/ecies/ecies.go +++ b/crypto/ecies/ecies.go @@ -58,12 +58,12 @@ type PublicKey struct { Params *ECIESParams } -// Export an ECIES public key as an ECDSA public key. +//ExportECDSA exports an ECIES public key as an ECDSA public key. func (pub *PublicKey) ExportECDSA() *ecdsa.PublicKey { return &ecdsa.PublicKey{Curve: pub.Curve, X: pub.X, Y: pub.Y} } -// Import an ECDSA public key as an ECIES public key. +//ImportECDSAPublic imports an ECDSA public key as an ECIES public key. func ImportECDSAPublic(pub *ecdsa.PublicKey) *PublicKey { return &PublicKey{ X: pub.X, @@ -79,21 +79,21 @@ type PrivateKey struct { D *big.Int } -// Export an ECIES private key as an ECDSA private key. +// ExportECDSA exports an ECIES private key as an ECDSA private key. func (prv *PrivateKey) ExportECDSA() *ecdsa.PrivateKey { pub := &prv.PublicKey pubECDSA := pub.ExportECDSA() return &ecdsa.PrivateKey{PublicKey: *pubECDSA, D: prv.D} } -// Import an ECDSA private key as an ECIES private key. +//ImportECDSA imports an ECDSA private key as an ECIES private key. func ImportECDSA(prv *ecdsa.PrivateKey) *PrivateKey { pub := ImportECDSAPublic(&prv.PublicKey) return &PrivateKey{*pub, prv.D} } -// Generate an elliptic curve public / private keypair. If params is nil, -// the recommended default parameters for the key will be chosen. +// GenerateKey generates an elliptic curve public / private keypair. +// If params is nil,the recommended default parameters for the key will be chosen. func GenerateKey(rand io.Reader, curve elliptic.Curve, params *ECIESParams) (prv *PrivateKey, err error) { pb, x, y, err := elliptic.GenerateKey(curve, rand) if err != nil { @@ -117,7 +117,7 @@ func MaxSharedKeyLength(pub *PublicKey) int { return (pub.Curve.Params().BitSize + 7) / 8 } -// ECDH key agreement method used to establish secret keys for encryption. +//GenerateShared is the ECDH key agreement method used to establish secret keys for encryption. func (prv *PrivateKey) GenerateShared(pub *PublicKey, skLen, macLen int) (sk []byte, err error) { if prv.PublicKey.Curve != pub.Curve { return nil, ErrInvalidCurve diff --git a/crypto/ecies/ecies_test.go b/crypto/ecies/ecies_test.go index f33f204d5b..48e57aff28 100644 --- a/crypto/ecies/ecies_test.go +++ b/crypto/ecies/ecies_test.go @@ -101,9 +101,8 @@ func cmpPrivate(prv1, prv2 *PrivateKey) bool { return false } else if prv1.D.Cmp(prv2.D) != 0 { return false - } else { - return cmpPublic(prv1.PublicKey, prv2.PublicKey) } + return cmpPublic(prv1.PublicKey, prv2.PublicKey) } // Validate the ECDH component.