github.com/gopherjs/gopherjs@v1.19.0-beta1.0.20240506212314-27071a8796e4/compiler/natives/src/crypto/elliptic/nistec.go (about) 1 //go:build js 2 // +build js 3 4 package elliptic 5 6 import ( 7 "crypto/internal/nistec" 8 "math/big" 9 ) 10 11 // nistPoint uses generics so must be removed for generic-less GopherJS. 12 // All the following code changes in this file are to make p224, p256, 13 // p521, and p384 still function correctly without this generic struct. 14 // 15 //gopherjs:purge for go1.19 without generics 16 type nistPoint[T any] interface{} 17 18 // nistCurve replaces the generics with a version using the wrappedPoint 19 // interface, then update all the method signatures to also use wrappedPoint. 20 type nistCurve struct { 21 newPoint func() nistec.WrappedPoint 22 params *CurveParams 23 } 24 25 //gopherjs:override-signature 26 func (curve *nistCurve) Params() *CurveParams 27 28 //gopherjs:override-signature 29 func (curve *nistCurve) IsOnCurve(x, y *big.Int) bool 30 31 //gopherjs:override-signature 32 func (curve *nistCurve) pointFromAffine(x, y *big.Int) (p nistec.WrappedPoint, err error) 33 34 //gopherjs:override-signature 35 func (curve *nistCurve) pointToAffine(p nistec.WrappedPoint) (x, y *big.Int) 36 37 //gopherjs:override-signature 38 func (curve *nistCurve) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int) 39 40 //gopherjs:override-signature 41 func (curve *nistCurve) Double(x1, y1 *big.Int) (*big.Int, *big.Int) 42 43 //gopherjs:override-signature 44 func (curve *nistCurve) normalizeScalar(scalar []byte) []byte 45 46 //gopherjs:override-signature 47 func (curve *nistCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int, *big.Int) 48 49 //gopherjs:override-signature 50 func (curve *nistCurve) ScalarBaseMult(scalar []byte) (*big.Int, *big.Int) 51 52 //gopherjs:override-signature 53 func (curve *nistCurve) CombinedMult(Px, Py *big.Int, s1, s2 []byte) (x, y *big.Int) 54 55 //gopherjs:override-signature 56 func (curve *nistCurve) Unmarshal(data []byte) (x, y *big.Int) 57 58 //gopherjs:override-signature 59 func (curve *nistCurve) UnmarshalCompressed(data []byte) (x, y *big.Int) 60 61 var p224 = &nistCurve{ 62 newPoint: nistec.NewP224WrappedPoint, 63 } 64 65 type p256Curve struct { 66 nistCurve 67 } 68 69 var p256 = &p256Curve{ 70 nistCurve: nistCurve{ 71 newPoint: nistec.NewP256WrappedPoint, 72 }, 73 } 74 75 var p521 = &nistCurve{ 76 newPoint: nistec.NewP521WrappedPoint, 77 } 78 79 var p384 = &nistCurve{ 80 newPoint: nistec.NewP384WrappedPoint, 81 }