title: OpenSSL ECDSA signatures longer than expected
body: <p>I am attempting to generate "raw", unencoded ECDSA signatures for use with a cryptographic chip. The goal is to sign something on the host pc, then send it to the chip to be validated. However, I am running into a little problem. My understanding is that the ECDSA signature should be 64 bytes (for secp256v1). And, when I use the chip to generate a signature, it is indeed 64 bytes in length. However, when I use openssl, the signature is 71 bytes in length. The beginning of the signature seems to be some kind of prefix, but I can't find any data about what that is. </p>
  
  <p>Here is how I am trying to do everything:</p>
  
  <p>Generate the key:</p>
  
  <pre><code>openssl ecparam -genkey -name secp256r1 -noout -out privkeyv1.pem
  </code></pre>
  
  <p>Generate the "message" to be signed:</p>
  
  <pre><code>echo -n "Hello World" &gt; test.txt
  </code></pre>
  
  <p>I have tried two methods for signing the message. Both lead to the same, unexpected output. </p>
  
  <p>First method - generate sha256 hash of test file, then sign it:</p>
  
  <pre><code>sha256sum test.txt | cut -f 1 -d " " &gt; hash
  </code></pre>
  
  <p>Sign with pkutil</p>
  
  <pre><code>openssl pkeyutl -sign -in hash -inkey privkeyv1.pem -out test_sig_meth1
  </code></pre>
  
  <p>Method 2: Sign with openssl dgst</p>
  
  <p><code>openssl dgst -sha256 -binary -sign privkeyv1.pem  -out test_sig_meth2 test.txt</code>
  The issue: Here is the output of <code>xxd -p -c 256 test_sig_meth1</code>:
  <code>3045022000a86fb146d5f8f6c15b962640bc2d1d928f5e0f96a5924e4db2853ec8b66fb002210085431613d0a235db1adabc090cc1062a246a78941972e298423f4b3d081b48c8</code></p>
  
  <p>And the output of <code>xxd -p -c 256 test_sig_meth2</code>:
  <code>30450220693732cd53d9f2ba3deae213d74cdf69a00e7325a10ddc6a4445ff2b33f95e62022100b6d2561e3afba10f95247ed05f0c59620dc0913f0d798b4148e05c4116b6384e</code></p>
  
  <p>As you can see, both of these methods generate some bytes at the beginning that look like header bytes (the <code>30450220</code>, maybe longer), but I am not sure what they are for or how to remove them. For reference, here is a a signature of the same method generated on the crypto chip. If you remove the null byte padding at the end, it's 64 bytes.  <code>4677AD09F2AF49D7445ED5D6AC7253ADC863EC6D5DB6D3CFBF9C6D3E221D0A7BA2561942524F46B590AEE749D827FBF80A961E884E3A7D85EC75FE48ADBC0BD00000000000000000000000</code></p>
  
  <p>The question: How can I use openssl to generate a 64 byte raw (unencoded, with no header) ECDSA signature I can use with this scheme? </p>