mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-27 04:36:19 +08:00
sm2: update document
This commit is contained in:
parent
50a5e49d38
commit
80a264c995
@ -186,6 +186,13 @@ func ExampleVerifyASN1WithSM2() {
|
||||
}
|
||||
```
|
||||
|
||||
### 如何处理不用UID的签名、验签?
|
||||
#### 签名
|
||||
也是使用sm2私钥的`Sign`方法,只是```SignerOpts```传入`nil`或者其它非`SM2SignerOption`即可,那么,你自己负责预先计算杂凑值,当然如何计算杂凑值,由你自己说了算了。
|
||||
|
||||
#### 验签
|
||||
调用`sm2.VerifyASN1`方法,同样,你自己负责预先计算杂凑值,确保杂凑算法和签名时使用的杂凑算法保持一致。
|
||||
|
||||
## 密钥交换协议
|
||||
这里有两个实现,一个是传统实现,位于sm2包中;另外一个参考最新go语言的实现在ecdh包中。在这里不详细介绍使用方法,一般只有tls/tlcp才会用到,普通应用通常不会涉及这一块,感兴趣的话可以参考github.com/Trisia/gotlcp中的应用。
|
||||
|
||||
|
@ -213,7 +213,7 @@ var defaultUID = []byte{0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x31, 0x
|
||||
// CalculateZA ZA = H256(ENTLA || IDA || a || b || xG || yG || xA || yA).
|
||||
// Compliance with GB/T 32918.2-2016 5.5.
|
||||
//
|
||||
// This function will not use default UID even the uid argument is empty.
|
||||
// This function will NOT use default UID even the uid argument is empty.
|
||||
// Reference: GM/T 0009-2023 Chapter 8.1.
|
||||
func CalculateZA(pub *ecdsa.PublicKey, uid []byte) ([]byte, error) {
|
||||
uidLen := len(uid)
|
||||
@ -451,7 +451,7 @@ var ErrInvalidSignature = errors.New("sm2: invalid signature")
|
||||
//
|
||||
// Compliance with GB/T 32918.2-2016 regardless it's SM2 curve or not.
|
||||
// Caller should make sure the hash's correctness, in other words,
|
||||
// the caller must pre-calculate the hash value.
|
||||
// the caller must pre-compute the hash value.
|
||||
func VerifyASN1(pub *ecdsa.PublicKey, hash, sig []byte) bool {
|
||||
switch pub.Curve.Params() {
|
||||
case P256().Params():
|
||||
|
Loading…
x
Reference in New Issue
Block a user