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.
Here is how I am trying to do everything:
Generate the key:
openssl ecparam -genkey -name secp256r1 -noout -out privkeyv1.pem
Generate the "message" to be signed:
echo -n "Hello World" > test.txt
I have tried two methods for signing the message. Both lead to the same, unexpected output.
First method - generate sha256 hash of test file, then sign it:
sha256sum test.txt | cut -f 1 -d " " > hash
Sign with pkutil
openssl pkeyutl -sign -in hash -inkey privkeyv1.pem -out test_sig_meth1
Method 2: Sign with openssl dgst
openssl dgst -sha256 -binary -sign privkeyv1.pem -out test_sig_meth2 test.txt
The issue: Here is the output of xxd -p -c 256 test_sig_meth1
:
3045022000a86fb146d5f8f6c15b962640bc2d1d928f5e0f96a5924e4db2853ec8b66fb002210085431613d0a235db1adabc090cc1062a246a78941972e298423f4b3d081b48c8
And the output of xxd -p -c 256 test_sig_meth2
:
30450220693732cd53d9f2ba3deae213d74cdf69a00e7325a10ddc6a4445ff2b33f95e62022100b6d2561e3afba10f95247ed05f0c59620dc0913f0d798b4148e05c4116b6384e
As you can see, both of these methods generate some bytes at the beginning that look like header bytes (the 30450220
, 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. 4677AD09F2AF49D7445ED5D6AC7253ADC863EC6D5DB6D3CFBF9C6D3E221D0A7BA2561942524F46B590AEE749D827FBF80A961E884E3A7D85EC75FE48ADBC0BD00000000000000000000000
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?
See Question&Answers more detail:
os