MCPcopy
hub / github.com/tjfoc/gmsm / Decompress

Function Decompress

sm2/utils.go:8–31  ·  view source on GitHub ↗
(a []byte)

Source from the content-addressed store, hash-verified

6)
7
8func Decompress(a []byte) *PublicKey {
9 var aa, xx, xx3 sm2P256FieldElement
10
11 P256Sm2()
12 x := new(big.Int).SetBytes(a[1:])
13 curve := sm2P256
14 sm2P256FromBig(&xx, x)
15 sm2P256Square(&xx3, &xx) // x3 = x ^ 2
16 sm2P256Mul(&xx3, &xx3, &xx) // x3 = x ^ 2 * x
17 sm2P256Mul(&aa, &curve.a, &xx) // a = a * x
18 sm2P256Add(&xx3, &xx3, &aa)
19 sm2P256Add(&xx3, &xx3, &curve.b)
20
21 y2 := sm2P256ToBig(&xx3)
22 y := new(big.Int).ModSqrt(y2, sm2P256.P)
23 if getLastBit(y)!= uint(a[0]) {
24 y.Sub(sm2P256.P, y)
25 }
26 return &PublicKey{
27 Curve: P256Sm2(),
28 X: x,
29 Y: y,
30 }
31}
32
33func Compress(a *PublicKey) []byte {
34 buf := []byte{}

Callers

nothing calls this directly

Calls 7

P256Sm2Function · 0.85
sm2P256FromBigFunction · 0.85
sm2P256SquareFunction · 0.85
sm2P256MulFunction · 0.85
sm2P256AddFunction · 0.85
sm2P256ToBigFunction · 0.85
getLastBitFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…