title: Golang signing with ecdsa and Private Key from a SHA224 digest
body: <p>I need to sign a message for submission to a remote service (over a websocket). To do this, I need to structure a private key based on an integer (my user id) and a passphrase (a base64 encoded string)., hashed using SHA224. I'm using golang, and crypto/ecdsa for this with accompanying packages for byte encoding etc.</p>
  
  <p>Here's the documentation I have: </p>
  
  <blockquote>
    <p>Signatures use an Elliptic Curve Digital Signature Algorithm (ECDSA)
    encoded message containing: user ID, Server Nonce, Client Node and
    Private key. Private keys are generated hashing your user ID and your
    password with SHA224.</p>
  </blockquote>
  
  <p>Here's my func:</p>
  
  <pre><code>func NewKey(userId int64, pass string) (prKey ecdsa.PrivateKey) {
      buf := new(bytes.Buffer)
      binary.Write(buf, binary.BigEndian, userId)
      passArr := []byte(pass)
  
      sha := sha256.New224()
      sha.Write(buf.Bytes())
      sha.Write(passArr)
      sum := sha.Sum(nil)
  
      var in int64
      reader := bytes.NewReader(sum)
      err := binary.Read(reader, binary.BigEndian, &amp;in)
  
      if err != nil {
          log.Fatal(err)
      }
  
      prKey.D = big.NewInt(in)
      prKey.PublicKey.Curve = elliptic.P224()
      return prKey
  }
  </code></pre>
  
  <p>My intent with this func is that it:</p>
  
  <ol>
  <li><p>Hashes the userId and pass correctly in a <code>[]byte</code> using SHA224.</p></li>
  <li><p>Reads that into an <code>int64</code> which is then used as the private key</p></li>
  <li><p>Constructs an instance of <code>ecdsa.PrivateKey</code> and corresponding <code>ecdsa.PublicKey</code> correctly</p></li>
  <li><p>Returns said key for use in <code>ecdsa.Sign()</code> function calls</p></li>
  </ol>
  
  <p>I then sign another message which consists of a userId (integer), and two nonces.</p>
  
  <p>Here's how I sign my message:</p>
  
  <pre><code>key := NewKey(userId, pass) // the above func
  msg := sha256.New224().Sum([]byte(userId + srNonce + clNonce))
  r, s, err := ecdsa.Sign(rand.Reader, &amp;key, msg)
  sig := []string{enc(r.String()), enc(s.String())}
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li><p>Is my <code>NewKey</code> func correct?</p></li>
  <li><p>The <code>r</code> and <code>s</code> components are very large - presumably because I'm using <code>int64</code>. Could this be an issue?</p></li>
  <li><p>Is the line <code>sha256.New224().Sum([]byte(userId + pass))</code> "correct" for hasing those two items?</p></li>
  <li><p>How can I create my private key correctly (assuming it's wrong) and subsequently sign the message?</p></li>
  </ol>
  
  <p>I'm very new to ECDSA and have basic crypto knowledge in general.</p>