I m learning C an I have ome issues.
First, i m using library gmp and I need to convert a mpzt to an unsigned char array.
I already lookup on documentation but I dont find anything. Maybe using mpz_get_str but I dont known how.
More over I have to convert 2 functions from GoLang to C but I have some trouble
Here is the two GoLang func:
// 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())
}
Every help will be appreciated ! Thanx in advance