Hi
I've written a simple sketch for generating an RSA key pair:
#include <Arduino.h>
#include <mbedtls/pk.h>
#include <mbedtls/entropy.h>
#include <mbedtls/ctr_drbg.h>
#include "mbedtls/bignum.h"
#include "mbedtls/rsa.h"
#define KEY_SIZE 2048
#define EXPONENT 65537
void ard_land_setup() {
Serial.begin(115200);
}
void ard_land_loop() {
mbedtls_pk_context pk;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_mpi N, P, Q, D, E, DP, DQ, QP;
//const char *pers = "rsa_genkey";
mbedtls_ctr_drbg_init( &ctr_drbg ); mbedtls_pk_init( &pk );
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &DP );
mbedtls_mpi_init( &DQ ); mbedtls_mpi_init( &QP );
Serial.print( "Seeding the random number generator..");
mbedtls_entropy_init( &entropy );
Serial.printf( "Generating the RSA key [ %d-bit ]..", KEY_SIZE );
mbedtls_rsa_gen_key( mbedtls_pk_rsa( pk ), mbedtls_ctr_drbg_random, &ctr_drbg, KEY_SIZE, EXPONENT);
Serial.printf( " ok\n . Checking public/private key validity...");
mbedtls_rsa_check_pubkey(mbedtls_pk_rsa( pk ));
Serial.print( "Writing public key to string in PEM format).." );
unsigned char pubKeyPem[5000];
memset(pubKeyPem, 0, sizeof(pubKeyPem));
mbedtls_pk_write_pubkey_pem(&pk, pubKeyPem, sizeof(pubKeyPem));
Serial.printf("Public key:%s", (char*)pubKeyPem);
delay(5000);
}
And the following boot loop is arising:
Seeding the random number generator..Generating the RSA key [ 2048-bit ]..Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x400d9825 PS : 0x00060630 A0 : 0x800d9918 A1 : 0x3ffb5300
0x400d9825: mbedtls_mpi_grow at /home/speffle/esp/esp-idf/components/mbedtls/mbedtls/library/bignum.c:157
A2 : 0x00000014 A3 : 0x00000001 A4 : 0x00000000 A5 : 0x3f40307c
A6 : 0x00000000 A7 : 0x0000000d A8 : 0x00002710 A9 : 0x3ffb5280
A10 : 0x00000001 A11 : 0x00000000 A12 : 0x3ffb90e4 A13 : 0x00000000
A14 : 0x00000000 A15 : 0x3ffb5130 SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000018 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff
Backtrace:0x400d9822:0x3ffb5300 0x400d9915:0x3ffb5320 0x400db5e7:0x3ffb5340 0x400d4314:0x3ffb53a0 0x400d4251:0x3ffb6a80 0x400ec6c0:0x3ffb6aa0 0x40086bf5:0x3ffb6ac0
0x400d9822: mbedtls_mpi_grow at /home/speffle/esp/esp-idf/components/mbedtls/mbedtls/library/bignum.c:154
0x400d9915: mbedtls_mpi_lset at /home/speffle/esp/esp-idf/components/mbedtls/mbedtls/library/bignum.c:365
0x400db5e7: mbedtls_rsa_gen_key at /home/speffle/esp/esp-idf/components/mbedtls/mbedtls/library/rsa.c:593
0x400d4314: ard_land_loop at /home/speffle/crypto/november-2020/DHM/build/../main/ard_land.cpp:36
0x400d4251: app_main at /home/speffle/crypto/november-2020/DHM/build/../main/app_main.c:31 (discriminator 1)
0x400ec6c0: main_task at /home/speffle/esp/esp-idf/components/freertos/xtensa/port.c:537 (discriminator 2)
0x40086bf5: vPortTaskWrapper at /home/speffle/esp/esp-idf/components/freertos/xtensa/port.c:170
ELF file SHA256: e4d71735fccb29dc
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4
load:0x3fff0034,len:6944
ho 0 tail 12 room 4
load:0x40078000,len:14328
ho 0 tail 12 room 4
load:0x40080400,len:3660
0x40080400: _init at ??:?
How do I remedy this issue please?
Thank you
RSA Key Generation triggers Guru Meditation Error: Core 0 panic'ed (LoadProhibited).
Who is online
Users browsing this forum: No registered users and 44 guests