diff options
Diffstat (limited to 'llgo/third_party/gofrontend/libgo/go/crypto/elliptic/elliptic.go')
| -rw-r--r-- | llgo/third_party/gofrontend/libgo/go/crypto/elliptic/elliptic.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/llgo/third_party/gofrontend/libgo/go/crypto/elliptic/elliptic.go b/llgo/third_party/gofrontend/libgo/go/crypto/elliptic/elliptic.go index ba673f80ca6..e6b59c5f436 100644 --- a/llgo/third_party/gofrontend/libgo/go/crypto/elliptic/elliptic.go +++ b/llgo/third_party/gofrontend/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) |

