I try to use the ECC508 Chip on the MKR1000 to sign information I want to send to a webserver.
I think that is the simplest way to assure the integrity of the submitted information.
I was able to lock the chip and generate a new private/public key pair and export the PEMof the public key using Sandeep Mistrys example LINK
It produces a PEM using a prime256v1 curve. Which is great because it is supported by openssl.
I then wanted to use Sandeeps signing example to sign the information. LINK
But I'm don't realy get it. And hope someone here already found a way to use it or has a hint for me to do it otherwise.
- Why can I only sign 64 byte chunks?
- From my understanding signing needs also hashing (e.g. SHA256 which is also implemented in hardware), but it produces 32 bytes from any input.
- What is needed to get the signed data verified by e.g., openssl on the server side?
I tried to firstly reproduce signatures with open ssl to compare the output to what I get from the ECCX08 signature code. So i generated a new key pair using openssl for the same curve.
I took the example input (0x00, 0x01 ... 0x3e, 0x3f), put it into a text file and turned it into a binary file using:
$ xxd -r -p input.txt input.bin
$ hexdump -C input.bin
00000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |................|
00000010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f |................|
00000020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f | !"#$%&'()*+,-./|
00000030 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f |0123456789:;<=>?|
00000040
Then i used openssl dgst to sign and verify it:
$ openssl dgst -sha256 -sign prime256v1.key -out sign.sign input.bin
$ openssl dgst -sha256 -verify prime256v1.pubkey.pem -signature sign.sign input.bin
Verified OK
But its output is 70 byte instead of 64 byte or even 32 byte, which I don't understand. Because I only get 64 Bits out of the ECCX08 sign command.
I also tried to sign and verify by openssel pkeyutl:
$ openssl pkeyutl -sign -in input.bin -inkey prime256v1.key -out sign2.sign
$ openssl pkeyutl -verify -in input.bin -pubin -inkey prime256v1.pubkey.pem -sigfile sign2.sign
Signature Verified Successfully
Also this gets an output of 70 Byte. sign.sign and sign2.sign are different by the way. And the openssl dgst command can't verify openssl pkeyutl commands output and vice versa.
But for sure both can't verify what comes out of the sign example from ECCX08.h
I also thought about hasing the input in the Arduino first. But the output of the hash would be 32 Byte with SHA256 and not 64 Byte, so what to feed into the sign function of ECCX08.h. It says it needs an input of exactly 64 Byte and the output is also expected to be exactly 64 Byte.
So having no further documentation beside the code comments in the examples of ECCX08.h and found no tutorial or post in the forums, I hope someone here can show me some direction.