Hey
I was trying to verify a signature generated by this library using openssl on my computer.
It did not work until I finally discovered this issue
Since OpenSSL likes Signatures in the ASN.1 menthod I took the convenient function formatSignature like this:
/*
* Generate a signature NIST-P256
*/
printGreen("Generate Signature ... ");
ret = trustX.calculateSignature(hash, hashLen, eFIRST_DEVICE_PRIKEY_1, formSign, signLen);
Serial.printf("Code: %u\n", ret);
ASSERT(ret);
output_result("Signature", formSign, signLen);
printGreen("Format Signature ... ");
ret = trustX.formatSignature(formSign, signLen, format, formatLen);
ASSERT(ret);
output_result("Signature Formated", format, formatLen);
Theoretically that should be fine, or did I misunderstand something?
As it is this does not work correctly though because the calculate Signature function will already add the 02 20 tags and the 00 for negative values before the r and s numbers. When I then use the formatSignature function they are added again and the rest of the buffer, so 4-6 bytes of the actual signature are discarded. Then verification of course does not work
When I take the data coming out of calculateSignature and add 0x30 and the length infront of it I get the correct ASN.1 format
Either I did not understand how this is supposed to be used or this is definitly a bug, in the first case pls still add this to the docs!
Thanks