Giter VIP home page Giter VIP logo

Comments (4)

emmansun avatar emmansun commented on June 7, 2024

不是很理解你的问题,这个包没有定义自己的公钥数据结构啊。感觉你的两个case可以合并成一个:

case *ecdsa.PrivateKey,*sm2.PrivateKey:

from gmsm.

tossp avatar tossp commented on June 7, 2024

是的,先前依赖的tjfoc/gmsm

没有定义自己的公钥数据结构,代码可读性会显得有点怪
比如这个,明明是sm2,单看函数签名却是ecdsa

// FromsPub 公钥 -> []byte
func FromsPub(pub *ecdsa.PublicKey) []byte {
	if pub == nil || pub.X == nil || pub.Y == nil {
		return nil
	}
	return elliptic.Marshal(pub.Curve, pub.X, pub.Y)
}

// ToPub []byte -> 公钥
func ToPub(pub []byte) *ecdsa.PublicKey {
	if len(pub) == 0 {
		return nil
	}
	curve := sm2.P256()
	x, y := elliptic.Unmarshal(curve, pub)
	return &ecdsa.PublicKey{Curve: curve, X: x, Y: y}
}

from gmsm.

emmansun avatar emmansun commented on June 7, 2024

SM2曲线和NIST P-256只是参数不同而已,所以数据结构是一样的,就象NIST P-224 P-256 P-384 P-512,SM2曲线无需扩展此结构也没有SM2曲线特殊的方法需要实现。还有就是考虑SM2-256曲线理论上是和SM2加解密、签名验签算法分开的,其实无需深度绑定。你的ToPub方法,如果加上curve参数,其实是适用所有NIST P系列和SM2 256曲线的。

from gmsm.

tossp avatar tossp commented on June 7, 2024

了解,感谢您的答复

from gmsm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.