Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
KevinGrennanson
Level 1
Level 1
First reply posted First question asked Welcome!

Hi

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?

0 Likes
1 Solution
1 Reply
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins
0 Likes