Merge pull request #35 from boling-wang/master
accept nil uid when calling sm2 sign/verify
chenxu authored 4 years ago
GitHub committed 4 years ago
140 | 140 |
// fmt.Printf("--> Content Type: %s", info.ContentType)
|
141 | 141 |
switch {
|
142 | 142 |
case info.ContentType.Equal(oidSignedData):
|
|
143 |
return parseSignedData(info.Content.Bytes)
|
143 | 144 |
case info.ContentType.Equal(oidSMSignedData):
|
144 | 145 |
return parseSignedData(info.Content.Bytes)
|
145 | 146 |
case info.ContentType.Equal(oidEnvelopedData):
|
351 | 351 |
|
352 | 352 |
// ZA = H256(ENTLA || IDA || a || b || xG || yG || xA || yA)
|
353 | 353 |
func ZA(pub *PublicKey, uid []byte) ([]byte, error) {
|
354 | |
if len(uid) <= 0 {
|
355 | |
uid = default_uid
|
356 | |
}
|
357 | 354 |
za := sm3.New()
|
358 | 355 |
uidLen := len(uid)
|
359 | 356 |
if uidLen >= 8192 {
|
|
362 | 359 |
Entla := uint16(8 * uidLen)
|
363 | 360 |
za.Write([]byte{byte((Entla >> 8) & 0xFF)})
|
364 | 361 |
za.Write([]byte{byte(Entla & 0xFF)})
|
365 | |
za.Write(uid)
|
|
362 |
if uidLen > 0 {
|
|
363 |
za.Write(uid)
|
|
364 |
}
|
366 | 365 |
za.Write(sm2P256ToBig(&sm2P256.a).Bytes())
|
367 | 366 |
za.Write(sm2P256.B.Bytes())
|
368 | 367 |
za.Write(sm2P256.Gx.Bytes())
|