btcec.mx raw

   1  // Copyright 2010 The Go Authors. All rights reserved.
   2  // Copyright 2011 ThePiachu. All rights reserved.
   3  // Copyright 2013-2014 The btcsuite developers
   4  // Use of this source code is governed by an ISC
   5  // license that can be found in the LICENSE file.
   6  
   7  package btcec
   8  
   9  // References:
  10  //   [SECG]: Recommended Elliptic Curve Domain Parameters
  11  //     http://www.secg.org/sec2-v2.pdf
  12  //
  13  //   [GECC]: Guide to Elliptic Curve Cryptography (Hankerson, Menezes, Vanstone)
  14  
  15  // This package operates, internally, on Jacobian coordinates. For a given
  16  // (x, y) position on the curve, the Jacobian coordinates are (x1, y1, z1)
  17  // where x = x1/z1² and y = y1/z1³. The greatest speedups come when the whole
  18  // calculation can be performed within the transform (as in ScalarMult and
  19  // ScalarBaseMult). But even for Add and Double, it's faster to apply and
  20  // reverse the transform than to operate in affine coordinates.
  21  
  22  import (
  23  	"smesh.lol/pkg/nostr/ec/secp256k1"
  24  )
  25  
  26  // KoblitzCurve provides an implementation for secp256k1 that fits the ECC
  27  // Curve interface from crypto/elliptic.
  28  type KoblitzCurve = secp256k1.KoblitzCurve
  29  
  30  // S256 returns a Curve which implements secp256k1.
  31  func S256() *KoblitzCurve {
  32  	return secp256k1.S256()
  33  }
  34  
  35  // CurveParams contains the parameters for the secp256k1 curve.
  36  type CurveParams = secp256k1.CurveParams
  37  
  38  // Params returns the secp256k1 curve parameters for convenience.
  39  func Params() *CurveParams {
  40  	return secp256k1.Params()
  41  }
  42  
  43  // Generator returns the public key at the Generator Point.
  44  func Generator() *PublicKey {
  45  	var (
  46  		result JacobianPoint
  47  		k      secp256k1.ModNScalar
  48  	)
  49  	k.SetInt(1)
  50  	ScalarBaseMultNonConst(&k, &result)
  51  	result.ToAffine()
  52  	return NewPublicKey(&result.X, &result.Y)
  53  }
  54