0

I am trying to generate a RSA 1024 bit key pair with an infineon XMC4500 f100k1024. At the moment, I generate the key pair externally with openssl. Then, to sign and verify data, I use the mbedtls package with no problem. Generating this RSA key pair with this package I had no success.

I tried to use the functions available on mbedtls to generate a key pair ( mbedtls_ctr_drbg_seed and mbedtls_rsa_gen_key), however, during one of the functions (on mbedtls_rsa_gen_key, when finding a Q prime I guess), the program ends up on a hard fault situation.

#define KEY_SIZE 1024
#define EXPONENT 65537

void create_rsa_keys() {
    uint8_t error_found = 0;
mbedtls_rsa_context rsa;
mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
    const char *pers = "rsa_genkey";
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
    mbedtls_ctr_drbg_init( &ctr_drbg );
    mbedtls_entropy_init( &entropy );

error_found = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
        (const unsigned char *) pers, strlen( pers ));
   if( error_found != 0 ){
      error_found = 100;
  }

    error_found = mbedtls_rsa_gen_key( &rsa, mbedtls_ctr_drbg_random, &ctr_drbg, KEY_SIZE,
        EXPONENT );

    if( error_found != 0 ){
      error_found = 100;
    }

    error_found = 1;


 }

Can you tell if I am doing something wrong? There are any more packages that can be used to create RSA keys on a microcontroller unit?

EDIT: The error occurs on the line where I call the function mbedtls_rsa_gen_key. The KEY_SIZE is 1024 and the EXPONENT is 65537.

Best Regards, Ricardo

  • If I don't know the error, I cannot use another expression rather than "hard fault situation". However, I know the function where the program crashes. Regarding the parameters I used, I already edited the post. Thank you – Ricardo Goncalves May 13 '19 at 11:36
  • 3
    In my experience your problem might be with the configuration of the library. Please check if you have all the config options set right in the header. Another thing is that it is a time consuming operation so try checking if it's not some watchdog responsible. – Michal Gluchowski May 13 '19 at 15:09
  • Yes, that is one of the problems. Now that I set up correctly the Defines in the header I cannot compile the code. It says the error is on x809.o file and that # not supported. This has not solved the problem, but now I have more hints to seek it. Thank you – Ricardo Goncalves May 14 '19 at 08:17
  • 1
    You will have dirent includes only if you have MBEDTLS_FS_IO enabled. You might want to disable such system dependencies when using a library on microcontroller. – Michal Gluchowski May 14 '19 at 13:44

0 Answers0