diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-10-31 00:59:47 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-10-31 00:59:47 +0000 |
commit | af146490bb04205107cb23e301ec7a8ff927b5fc (patch) | |
tree | 13beeaed3698c61903fe93fb1ce70bd9b18d4e7f /libgo/go/crypto/elliptic | |
parent | 725e1be3406315d9bcc8195d7eef0a7082b3c7cc (diff) | |
download | gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.zip gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.tar.gz gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.tar.bz2 |
runtime: Remove now unnecessary pad field from ParFor.
It is not needed due to the removal of the ctx field.
Reviewed-on: https://go-review.googlesource.com/16525
From-SVN: r229616
Diffstat (limited to 'libgo/go/crypto/elliptic')
-rw-r--r-- | libgo/go/crypto/elliptic/elliptic.go | 13 | ||||
-rw-r--r-- | libgo/go/crypto/elliptic/elliptic_test.go | 13 | ||||
-rw-r--r-- | libgo/go/crypto/elliptic/p224.go | 2 | ||||
-rw-r--r-- | libgo/go/crypto/elliptic/p256.go | 2 |
4 files changed, 24 insertions, 6 deletions
diff --git a/libgo/go/crypto/elliptic/elliptic.go b/libgo/go/crypto/elliptic/elliptic.go index ba673f8..e6b59c5 100644 --- a/libgo/go/crypto/elliptic/elliptic.go +++ b/libgo/go/crypto/elliptic/elliptic.go @@ -24,7 +24,7 @@ import ( type Curve interface { // Params returns the parameters for the curve. Params() *CurveParams - // IsOnCurve returns true if the given (x,y) lies on the curve. + // IsOnCurve reports whether the given (x,y) lies on the curve. IsOnCurve(x, y *big.Int) bool // Add returns the sum of (x1,y1) and (x2,y2) Add(x1, y1, x2, y2 *big.Int) (x, y *big.Int) @@ -45,6 +45,7 @@ type CurveParams struct { B *big.Int // the constant of the curve equation Gx, Gy *big.Int // (x,y) of the base point BitSize int // the size of the underlying field + Name string // the canonical name of the curve } func (curve *CurveParams) Params() *CurveParams { @@ -307,7 +308,8 @@ func Marshal(curve Curve, x, y *big.Int) []byte { return ret } -// Unmarshal converts a point, serialized by Marshal, into an x, y pair. On error, x = nil. +// Unmarshal converts a point, serialized by Marshal, into an x, y pair. +// It is an error if the point is not on the curve. On error, x = nil. func Unmarshal(curve Curve, data []byte) (x, y *big.Int) { byteLen := (curve.Params().BitSize + 7) >> 3 if len(data) != 1+2*byteLen { @@ -318,6 +320,9 @@ func Unmarshal(curve Curve, data []byte) (x, y *big.Int) { } x = new(big.Int).SetBytes(data[1 : 1+byteLen]) y = new(big.Int).SetBytes(data[1+byteLen:]) + if !curve.IsOnCurve(x, y) { + x, y = nil, nil + } return } @@ -334,7 +339,7 @@ func initAll() { func initP384() { // See FIPS 186-3, section D.2.4 - p384 = new(CurveParams) + p384 = &CurveParams{Name: "P-384"} p384.P, _ = new(big.Int).SetString("39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319", 10) p384.N, _ = new(big.Int).SetString("39402006196394479212279040100143613805079739270465446667946905279627659399113263569398956308152294913554433653942643", 10) p384.B, _ = new(big.Int).SetString("b3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef", 16) @@ -345,7 +350,7 @@ func initP384() { func initP521() { // See FIPS 186-3, section D.2.5 - p521 = new(CurveParams) + p521 = &CurveParams{Name: "P-521"} p521.P, _ = new(big.Int).SetString("6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151", 10) p521.N, _ = new(big.Int).SetString("6864797660130609714981900799081393217269435300143305409394463459185543183397655394245057746333217197532963996371363321113864768612440380340372808892707005449", 10) p521.B, _ = new(big.Int).SetString("051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00", 16) diff --git a/libgo/go/crypto/elliptic/elliptic_test.go b/libgo/go/crypto/elliptic/elliptic_test.go index 4dc27c9..7e27913 100644 --- a/libgo/go/crypto/elliptic/elliptic_test.go +++ b/libgo/go/crypto/elliptic/elliptic_test.go @@ -19,6 +19,19 @@ func TestOnCurve(t *testing.T) { } } +func TestOffCurve(t *testing.T) { + p224 := P224() + x, y := new(big.Int).SetInt64(1), new(big.Int).SetInt64(1) + if p224.IsOnCurve(x, y) { + t.Errorf("FAIL: point off curve is claimed to be on the curve") + } + b := Marshal(p224, x, y) + x1, y1 := Unmarshal(p224, b) + if x1 != nil || y1 != nil { + t.Errorf("FAIL: unmarshalling a point not on the curve succeeded") + } +} + type baseMultTest struct { k string x, y string diff --git a/libgo/go/crypto/elliptic/p224.go b/libgo/go/crypto/elliptic/p224.go index 1f7ff3f..2d3fac7 100644 --- a/libgo/go/crypto/elliptic/p224.go +++ b/libgo/go/crypto/elliptic/p224.go @@ -22,7 +22,7 @@ type p224Curve struct { func initP224() { // See FIPS 186-3, section D.2.2 - p224.CurveParams = new(CurveParams) + p224.CurveParams = &CurveParams{Name: "P-224"} p224.P, _ = new(big.Int).SetString("26959946667150639794667015087019630673557916260026308143510066298881", 10) p224.N, _ = new(big.Int).SetString("26959946667150639794667015087019625940457807714424391721682722368061", 10) p224.B, _ = new(big.Int).SetString("b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4", 16) diff --git a/libgo/go/crypto/elliptic/p256.go b/libgo/go/crypto/elliptic/p256.go index 82be51e..82bc7b3 100644 --- a/libgo/go/crypto/elliptic/p256.go +++ b/libgo/go/crypto/elliptic/p256.go @@ -23,7 +23,7 @@ var ( func initP256() { // See FIPS 186-3, section D.2.3 - p256.CurveParams = new(CurveParams) + p256.CurveParams = &CurveParams{Name: "P-256"} p256.P, _ = new(big.Int).SetString("115792089210356248762697446949407573530086143415290314195533631308867097853951", 10) p256.N, _ = new(big.Int).SetString("115792089210356248762697446949407573529996955224135760342422259061068512044369", 10) p256.B, _ = new(big.Int).SetString("5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", 16) |