Comments (4)
不是很理解你的问题,这个包没有定义自己的公钥数据结构啊。感觉你的两个case可以合并成一个:
case *ecdsa.PrivateKey,*sm2.PrivateKey:
from gmsm.
是的,先前依赖的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.
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.
了解,感谢您的答复
from gmsm.
Related Issues (20)
- [go1.10] 支持go1.10版本的编译使用 HOT 1
- 关于各类型加密密钥对支持 HOT 9
- 请问 ecdsa.Sign 和sm2.Sign 的区别 HOT 2
- 关于 smx509 模块裁剪 HOT 9
- HashDrbg并发时panic HOT 3
- [sync sdk] crypto/internal/bigmod: switch to saturated limbs HOT 3
- [sync sdk] crypto/internal/bigmod: optimized short exponentiations
- [sync sdk] crypto/x509: properly apply name constrains to roots and intermediates
- SM2 TLS HOT 2
- CGO sm3 fatal error: invalid pointer found on stack HOT 7
- 关于 软件随机数 HOT 7
- SM9 的实现方式 golang 与 java 差异 HOT 4
- 【feature】是否考虑支持 pem 格式的公私钥输出 HOT 5
- ASN1 SM2密文含扩展部分 HOT 7
- [go1.17][sync] x509: respect GODEBUG changes for allowing SHA1 certificates
- [go1.18] internal/godebug: define more efficient API
- [sync] crypto/x509: remove unused member Raw from certificate
- sm4的ECB模式有吗 HOT 3
- 怎么把java的sm2 密钥 转成 go的密钥格式 HOT 8
- CSR to CRT incompatibility with SM2 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmsm.