mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 20:26:19 +08:00
[sm9] fix 32-bit GOARCH issue
This commit is contained in:
parent
1ccbc35f12
commit
eca13ba8c5
@ -36,8 +36,18 @@ func fromBigInt(x *big.Int) (out *gfP) {
|
|||||||
} else {
|
} else {
|
||||||
a = new(big.Int).Neg(x)
|
a = new(big.Int).Neg(x)
|
||||||
}
|
}
|
||||||
for i, v := range a.Bits() {
|
bytes := a.Bytes()
|
||||||
out[i] = uint64(v)
|
if len(bytes) > 32 {
|
||||||
|
panic("sm9: invalid byte length")
|
||||||
|
} else if len(bytes) < 32 {
|
||||||
|
fixedBytes := make([]byte, 32)
|
||||||
|
copy(fixedBytes[32-len(bytes):], bytes)
|
||||||
|
bytes = fixedBytes
|
||||||
|
}
|
||||||
|
for i := 0; i < 4; i++ {
|
||||||
|
start := len(bytes) - 8
|
||||||
|
out[i] = binary.BigEndian.Uint64(bytes[start:])
|
||||||
|
bytes = bytes[:start]
|
||||||
}
|
}
|
||||||
if x.Sign() < 0 {
|
if x.Sign() < 0 {
|
||||||
gfpNeg(out, out)
|
gfpNeg(out, out)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user