diff --git a/trial5/KeyGen.c b/trial5/KeyGen.c index 4e0fffc..ac1a559 100644 --- a/trial5/KeyGen.c +++ b/trial5/KeyGen.c @@ -191,12 +191,14 @@ DIMASTATUS AsymmKeyGen(KeyDrv_context * KD_ctx) exit(DIMAINVALIDSTATE); } - if(DEBUG) printf("Generating ECC asymmetric key pair...\n"); + //////ECC implementation 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)); if(ret < DIMASUCCESS) { @@ -219,13 +221,11 @@ DIMASTATUS AsymmKeyGen(KeyDrv_context * KD_ctx) mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( pkey_ctx ); 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( "Y_Q: ", &ecp->Q.Y, 16, NULL ); mbedtls_mpi_write_file( "D: ", &ecp->d , 16, NULL ); } - - mbedtls_ecp_keypair_free(ecp); } else { @@ -241,6 +241,7 @@ DIMASTATUS AsymmKeyGen(KeyDrv_context * KD_ctx) 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_init( &N ); mbedtls_mpi_init( &P ); @@ -279,7 +280,6 @@ DIMASTATUS AsymmKeyGen(KeyDrv_context * KD_ctx) if(DEBUG) { - printf("RSA Key pair info :\n"); mbedtls_mpi_write_file( "N: ", &N, 16, NULL ); mbedtls_mpi_write_file( "E: ", &E, 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 { @@ -315,11 +306,6 @@ DIMASTATUS AsymmKeyGen(KeyDrv_context * KD_ctx) ////////////////////////////TODO/////////////////////////// //free block - mbedtls_entropy_free(&entropyCtx); - mbedtls_ctr_drbg_free(&drbgCtx); - mbedtls_pk_free(&pkey_ctx); - - return DIMASUCCESS; } @@ -397,7 +383,7 @@ DIMASTATUS WritePrivKey(KeyDrv_context * KD_ctx, mbedtls_pk_context * pkey_ctx) fwrite( outbuf, 1, len, fp ); fclose( fp ); - free(outbuf); + return(DIMASUCCESS); } @@ -455,7 +441,7 @@ DIMASTATUS WritePubKey(KeyDrv_context * KD_ctx, mbedtls_pk_context * pkey_ctx) fwrite( outbuf, 1, len, fp ); fclose( fp ); - free(outbuf); + return(DIMASUCCESS); }