I am trying to create an RSA public key from a module and exponent stored in an array of bytes. After some experimentation, I have the following:
func bytes_to_int(b []byte) (acc uint64) {
length := len(b)
if length % 4 != 0 {
extra := (4 - length % 4)
b = append([]byte(strings.Repeat("\000", extra)), b...)
length += extra
}
var block uint32
for i := 0; i < length; i += 4 {
block = binary.BigEndian.Uint32(b[i:i+4])
acc = (acc << 32) + uint64(block)
}
return
}
func main() {
fmt.Println(bytes_to_int(data[:128]))
fmt.Println(bytes_to_int(data[128:]))
}
This seems to work (although I'm not sure there is no better way). The next step was to convert it to using math / large to handle large numbers. I see the Lsh function to execute <<but cannot figure out how to add Uint32 (block) recursively to large.Int.
For reference, the public key I'm trying to import is a Mixmaster Key stored in keyring (pubring.mix):
http://www.mixmin.net/draft-sassaman-mixmaster-XX.html#key-format
http: //pinger.mixmin.net/pubring.mix