我正在学习C,我有ome问题。
首先,我使用库gmp,我需要将mpzt转换为unsigned char数组。
我已经在文档上查找但我找不到任何东西。也许使用mpz_get_str,但我不知道如何。
此外,我必须将2个函数从GoLang转换为C但我遇到了一些麻烦
这是两个GoLang功能:
// paddedAppend appends the src byte slice to dst, returning the new slice.
// If the length of the source is smaller than the passed size, leading zero
// bytes are appended to the dst slice before appending src.
func paddedAppend(size uint, dst, src []byte) []byte {
for i := 0; i < int(size)-len(src); i++ {
dst = append(dst, 0)
}
return append(dst, src...)
}
func isOdd(a *big.Int) bool {
return a.Bit(0) == 1
}
// SerializeUncompressed serializes a public key in a 65-byte uncompressed format.
func SerializeUncompressed(x *big.Int, y *big.Int) []byte {
b := make([]byte, 0, PubKeyBytesLenUncompressed)
b = append(b, pubkeyUncompressed)
b = paddedAppend(32, b, x.Bytes())
return paddedAppend(32, b, y.Bytes())
}
// SerializeCompressed serializes a public key in a 33-byte compressed format.
func SerializeCompressed(x *big.Int, y *big.Int) []byte {
b := make([]byte, 0, PubKeyBytesLenCompressed)
format := pubkeyCompressed
if isOdd(y) {
format |= 0x1
}
b = append(b, format)
return paddedAppend(32, b, x.Bytes())
}
我们将不胜感激! Thanx提前