broke keygen, fixing

This commit is contained in:
atul.jha 2021-02-11 12:59:17 +01:00
parent c54f7e0351
commit 8350adac77

View File

@ -191,12 +191,14 @@ DIMASTATUS AsymmKeyGen(KeyDrv_context * KD_ctx)
exit(DIMAINVALIDSTATE); exit(DIMAINVALIDSTATE);
} }
if(DEBUG) printf("Generating ECC asymmetric key pair...\n");
//////ECC implementation //////ECC implementation
if(KD_ctx->PKC_MODE == isECC) if(KD_ctx->PKC_MODE == isECC)
{ {
if(DEBUG) printf("Generating ECC asymmetric key pair\n");
ret = mbedtls_pk_setup(&pkey_ctx,mbedtls_pk_info_from_type((mbedtls_pk_type_t)MBEDTLS_PK_ECKEY)); ret = mbedtls_pk_setup(&pkey_ctx,mbedtls_pk_info_from_type((mbedtls_pk_type_t)MBEDTLS_PK_ECKEY));
if(ret < DIMASUCCESS) if(ret < DIMASUCCESS)
{ {
@ -219,13 +221,11 @@ DIMASTATUS AsymmKeyGen(KeyDrv_context * KD_ctx)
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( pkey_ctx ); mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( pkey_ctx );
if(DEBUG) if(DEBUG)
{ {
printf( "key info : \ncurve: %s\n", mbedtls_ecp_curve_info_from_grp_id( ecp->grp.id )->name ); printf( "curve: %s\n", mbedtls_ecp_curve_info_from_grp_id( ecp->grp.id )->name );
mbedtls_mpi_write_file( "X_Q: ", &ecp->Q.X, 16, NULL ); mbedtls_mpi_write_file( "X_Q: ", &ecp->Q.X, 16, NULL );
mbedtls_mpi_write_file( "Y_Q: ", &ecp->Q.Y, 16, NULL ); mbedtls_mpi_write_file( "Y_Q: ", &ecp->Q.Y, 16, NULL );
mbedtls_mpi_write_file( "D: ", &ecp->d , 16, NULL ); mbedtls_mpi_write_file( "D: ", &ecp->d , 16, NULL );
} }
mbedtls_ecp_keypair_free(ecp);
} }
else else
{ {
@ -241,6 +241,7 @@ DIMASTATUS AsymmKeyGen(KeyDrv_context * KD_ctx)
else if(KD_ctx->PKC_MODE == isRSA) else if(KD_ctx->PKC_MODE == isRSA)
{ {
if(DEBUG) printf("Generating RSA asymmetric key pair\n");
mbedtls_mpi N, P, Q, D, E, DP, DQ, QP; mbedtls_mpi N, P, Q, D, E, DP, DQ, QP;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &N );
mbedtls_mpi_init( &P ); mbedtls_mpi_init( &P );
@ -279,7 +280,6 @@ DIMASTATUS AsymmKeyGen(KeyDrv_context * KD_ctx)
if(DEBUG) if(DEBUG)
{ {
printf("RSA Key pair info :\n");
mbedtls_mpi_write_file( "N: ", &N, 16, NULL ); mbedtls_mpi_write_file( "N: ", &N, 16, NULL );
mbedtls_mpi_write_file( "E: ", &E, 16, NULL ); mbedtls_mpi_write_file( "E: ", &E, 16, NULL );
mbedtls_mpi_write_file( "D: ", &D, 16, NULL ); mbedtls_mpi_write_file( "D: ", &D, 16, NULL );
@ -291,15 +291,6 @@ DIMASTATUS AsymmKeyGen(KeyDrv_context * KD_ctx)
} }
} }
mbedtls_mpi_free(&N);
mbedtls_mpi_free(&P);
mbedtls_mpi_free(&Q);
mbedtls_mpi_free(&D);
mbedtls_mpi_free(&E);
mbedtls_mpi_free(&DP);
mbedtls_mpi_free(&DQ);
mbedtls_mpi_free(&QP);
} }
else else
{ {
@ -315,11 +306,6 @@ DIMASTATUS AsymmKeyGen(KeyDrv_context * KD_ctx)
////////////////////////////TODO/////////////////////////// ////////////////////////////TODO///////////////////////////
//free block //free block
mbedtls_entropy_free(&entropyCtx);
mbedtls_ctr_drbg_free(&drbgCtx);
mbedtls_pk_free(&pkey_ctx);
return DIMASUCCESS; return DIMASUCCESS;
} }
@ -397,7 +383,7 @@ DIMASTATUS WritePrivKey(KeyDrv_context * KD_ctx, mbedtls_pk_context * pkey_ctx)
fwrite( outbuf, 1, len, fp ); fwrite( outbuf, 1, len, fp );
fclose( fp ); fclose( fp );
free(outbuf);
return(DIMASUCCESS); return(DIMASUCCESS);
} }
@ -455,7 +441,7 @@ DIMASTATUS WritePubKey(KeyDrv_context * KD_ctx, mbedtls_pk_context * pkey_ctx)
fwrite( outbuf, 1, len, fp ); fwrite( outbuf, 1, len, fp );
fclose( fp ); fclose( fp );
free(outbuf);
return(DIMASUCCESS); return(DIMASUCCESS);
} }