2018-02-01 05:46 AM
Hi.
I'm using an RSA cryptographic library and I have a big issue with the verification process.ST crypto library for RSA has a 'standard' module, message, key pairs and signatures in its main program.I need to use my own key pairs and module to sing my message, but the program doesn't get these keys. (I check if the keys were wrong or not, and I am sure they are good)If i check the status error, its set to 1004 ( #define AUTHENTICATION_FAILED (int32_t) (1004) /*!< Authentication failed */)
My RSA especification are this :
const uint8_t T1_Modulus[] =
{ 0xAF, 0xEB, 0x5F, 0x07, 0x82, 0xDA, 0xCF, 0x72, 0xEF, 0x8A, 0x63, 0xE9, 0xA8, 0xA7, 0x66, 0xCA, 0x7B, 0xD2, 0xD4, 0xDB, 0xC3, 0xB0, 0x52, 0xCE, 0x57, 0x14, 0xAA, 0x24, 0xF6, 0x25, 0x14, 0x68, 0xEF, 0x36, 0xA5, 0xA6, 0x7E, 0xC6, 0xE8, 0xCF, 0x2F, 0xAB, 0x03, 0x7A, 0x65, 0x2D, 0xCA, 0xCA, 0xE6, 0x34, 0x8A, 0x41, 0x74, 0xFE, 0x2A, 0xE4, 0x4D,};const uint8_t T1_pubExp[] =
{ 0x01, 0x00, 0x01, };const uint8_t T1_privExp[] =
{0x1D, 0x09, 0x2B, 0x51, 0x31, 0x0E, 0xEE, 0x88, 0x98, 0xF2, 0xED, 0x94, 0xC6, 0x6A, 0x82, 0xF3, 0xCE, 0xC6, 0x38, 0xAD, 0xE1, 0x39, 0xBC, 0x21, 0x24, 0x8C, 0x5B, 0x9C, 0xB2, 0x87, 0x65, 0x76, 0xD1, 0x17, 0x73, 0x18, 0x8B, 0xB2, 0x2C, 0x5F, 0x15, 0x6F, 0x48, 0xC6, 0xBE, 0x03, 0xBD, 0xE3, 0x97, 0xF6, 0x2E, 0x0F, 0x37, 0xE3, 0x67, 0x14, 0x3D, };const uint8_t T1_message_1[] =
{0xcd, 0xc8, 0x7d, 0xa2, 0x23, 0xd7, 0x86, };Signature=(program output)
{0x8F, 0xB2, 0xC8, 0x0B, 0xD8, 0x99, 0x7F, 0x0E, 0xD7, 0xBA, 0xC5, 0xF0, 0xD2, 0x18, 0xD6, 0xF8, 0x99, 0x18, 0x2D, 0x7D, 0xC5, 0x0F, 0xF3, 0x98, 0x07, 0x32, 0x71, 0x09, 0xB4, 0xE6, 0x62, 0x39, 0x1A, 0x6D, 0x85, 0x68, 0xB0, 0xFC, 0x9D, 0x01, 0xEB, 0xF1, 0x56, 0xF2, 0x0C, 0xE6, 0x28, 0x9E, 0x9B, 0x26, 0x96, 0x6B, 0x16, 0xB5, 0xEE, 0x37, 0xE4, };The signature is the output of RSA sign function.
The programs say that the verification failed, but that's not possible, because I choose these keys to sign the message, and do the verification later (if the keys are inverse, every time you run the program the verification must be correct).Im using genRSA program(free program) to verify if my keys are inverse or not, and its says they are good.
I tried to change byte order for message and keys, thinking maybe its a structure problem:
{
MSB, ..., ...., ...., LSB,};{
LSB, ..., ...., ...., MSB,};And nothing.
I can't prove with small numbers (to deduce the signature solution by other ways, and reveal tracks about what kind of mistake is out there ) because you need a module bigger than 20 bytes (hash structure for the message).
Resuming, I need to know if the keys and the module need any previous condition to apply for the RSA program for verification and signature, because our keys doesn't work right now. And the following steps to implement our own RSA signature system with my key pairs, message and module operation.(apology in advance for my spelling, English is not my primary language)
Thanks.
2018-02-01 08:00 AM
Hi
alvaro.vidaurreta@ikusi.com
in order to point you to the right forum, can you please let me know with what ST product are you experiencing this issue? (STM32, STM8,...)
2018-02-04 11:51 PM
Hi.
The product is the STM32F10x, the Cryptografyc templates.
2018-02-05 12:29 AM
Can you show us your code? Also why are your keys 456 bits (57 bytes) long? This is non-standard key size - so that might be the reason. You should use RSA-2048 at least.
2018-02-05 12:55 AM
Ok the discussion has already been moved to the STM32 forum, so you'll soon receive help
2018-02-05 03:09 AM
Hi again.
I p
ut a 57 bytes only to check the program and its functionality. Recently I have changed it to 1028 bit long modules and keys, but still doesn't work.(I don't know if the size of the parameters is the real problem, because the 'original size ' for them to the key generation were 1028(128 bytes)). I will attach the original library (with out changes). My unique changes were replaced the module, keys and message to other values. (I didn't change any core functionalities oressentialcode lines,addedprivatefunctions and libraries buttheydon'tinteract with the RSA).I attached the crypto library and my program adapted to that RSA main.
________________ Attachments : en.stm32-cryp-lib.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hy4N&d=%2Fa%2F0X0000000b3Z%2FMIOmjdtw_X7Uor7IHC2uwie43KaPQkjCGjGZeqMN9zs&asPdf=falsePROGRAMA RSA FUNCIONAL.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hy3Z&d=%2Fa%2F0X0000000b3U%2FPbTCrPAkr0kkEiretTPzc_d2KSfQuc_jGc6gsXGJj5Y&asPdf=false2018-02-05 04:07 AM
Sorry, i didn't attach the correct files. This is the program were I only change the module and keys.
In previous program I change these lines :
status = STM32_RSA_Verify_SHA1(&PubKey_st, T1_message_1, sizeof(T1_message_1), Signature);
if (status == SIGNATURE_VALID) { /* Signature has been validated */ (T1_signature_1 changed to Signature) } else { /* Add application traintment in case of hash not success possible values of status: * RSA_ERR_BAD_PARAMETER, RSA_ERR_UNSUPPORTED_HASH, RSA_ERR_BAD_KEY, ERR_DYNAMIC_ALLOCATION_FAILED, * RSA_ERR_MODULUS_TOO_SHORT, SIGNATURE_INVALID, ERR_MEMORY_FAIL */ }I thought that with that correction the validation willbe madeon the generated Signature, and not on the 'standard' one.(butdidn'twork).
Sorry for the confusionmadeby the previousreply.
________________ Attachments : STM32 Cryptographic library package V2.0.6modified.7z.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hy35&d=%2Fa%2F0X0000000b3S%2Fb0x2jhO6vVFu7dQpDN7VPbqIrNpCoPhrbpBxF5xh2bY&asPdf=false2018-02-05 05:09 AM
Can you please make sure that your CRC peripheral's clock is enabled and try again.
2018-02-05 05:14 AM
Well in this version (PROGRAMA RSA FUNCIONAL/Project/STM32F10x_Cryptographic_Templates/main.c) you have the weird 456-bit RSA. Try to use RSA-1024 or RSA-2048.
2018-02-13 03:16 AM
I tried with 128 and 256 byte modulus and keys and still doesn't work.I'musing a J-Link debugger anditworks with the LittleEndiannotation,Idon'tknow if this could be the problem(Idon'tthink so,because ifIrun thestandard program, itworks well, the verification operationsendsthe 1003 status code and its meananOK response)
________________ Attachments : STM32 Cryptographic library package V2.0.6.7z.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hy0L&d=%2Fa%2F0X0000000b38%2FX4uMN3NNkFS7pxrttMPYB62L6j0NDgdHFrr93IyhgwQ&asPdf=false