github.com/chain5j/chain5j-pkg@v1.0.7/crypto/signature/config.go (about)

     1  // Package signature
     2  //
     3  // @author: xwc1125
     4  package signature
     5  
     6  import (
     7  	"crypto/elliptic"
     8  
     9  	"github.com/chain5j/chain5j-pkg/crypto/signature/secp256k1/btcecv1"
    10  	"github.com/chain5j/logger"
    11  	"github.com/tjfoc/gmsm/sm2"
    12  )
    13  
    14  const (
    15  	P256    = "P-256"
    16  	P384    = "P-384"
    17  	P521    = "P-521"
    18  	S256    = "S-256"
    19  	SM2P256 = "SM2-P-256"
    20  )
    21  
    22  func CurveType(curveName string) elliptic.Curve {
    23  	switch curveName {
    24  	case P256:
    25  		return elliptic.P256()
    26  	case P384:
    27  		return elliptic.P384()
    28  	case P521:
    29  		return elliptic.P521()
    30  	case S256:
    31  		return btcecv1.S256()
    32  	case SM2P256:
    33  		return sm2.P256Sm2()
    34  	default:
    35  		logger.Error("unsupported the curve", "curve", curveName)
    36  	}
    37  	return elliptic.P256()
    38  }
    39  
    40  func CurveName(curve elliptic.Curve) string {
    41  	if curve == btcecv1.S256() {
    42  		return S256
    43  	}
    44  	name := curve.Params().Name
    45  	return name
    46  }