title: Golang: Convert byte array to big.Int
body: <p>I'm trying to create an RSA Public Key from a Modulus and Exponent stored in a byte array.  After some experimentation I've got the following:</p>
  
  <pre><code>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 &lt; length; i += 4 {
      block = binary.BigEndian.Uint32(b[i:i+4])
      acc = (acc &lt;&lt; 32) + uint64(block)
    }
  return
  }
  
  func main() {
    fmt.Println(bytes_to_int(data[:128]))
    fmt.Println(bytes_to_int(data[128:]))
  }
  </code></pre>
  
  <p>This appears to work (although I'm not convinced there isn't a better way).  My next step was to convert it to use math/big in order to handle larger numbers.  I can see an Lsh function to do the &lt;&lt; but can't figure out how to recursively add the Uint32(block) to the big.Int.</p>
  
  <p>For reference, the Public Key I'm attempting to import is a Mixmaster Key stored in a keyring (pubring.mix):
  <a href="http://www.mixmin.net/draft-sassaman-mixmaster-XX.html#key-format" rel="noreferrer">http://www.mixmin.net/draft-sassaman-mixmaster-XX.html#key-format</a>
  <a href="http://pinger.mixmin.net/pubring.mix" rel="noreferrer">http://pinger.mixmin.net/pubring.mix</a></p>