diff --git a/programs/pkey/dh_genprime.c b/programs/pkey/dh_genprime.c index 5732f507e..d48773916 100644 --- a/programs/pkey/dh_genprime.c +++ b/programs/pkey/dh_genprime.c @@ -43,22 +43,22 @@ #define GENERATOR "4" #if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \ - !defined(POLARSSL_FS_IO) || !defined(POLARSSL_CTR_DRBG_C) + !defined(POLARSSL_FS_IO) || !defined(POLARSSL_CTR_DRBG_C) || \ + !defined(POLARSSL_GENPRIME) int main( int argc, char *argv[] ) { ((void) argc); ((void) argv); printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or " - "POLARSSL_FS_IO and/or POLARSSL_CTR_DRBG_C not defined.\n"); + "POLARSSL_FS_IO and/or POLARSSL_CTR_DRBG_C and/or " + "POLARSSL_GENPRIME not defined.\n"); return( 0 ); } #else int main( int argc, char *argv[] ) { int ret = 1; - -#if defined(POLARSSL_GENPRIME) mpi G, P, Q; entropy_context entropy; ctr_drbg_context ctr_drbg; @@ -147,9 +147,6 @@ int main( int argc, char *argv[] ) exit: mpi_free( &G ); mpi_free( &P ); mpi_free( &Q ); -#else - printf( "\n ! Prime-number generation is not available.\n\n" ); -#endif #if defined(_WIN32) printf( " Press Enter to exit this program.\n" ); @@ -159,4 +156,4 @@ exit: return( ret ); } #endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_FS_IO && - POLARSSL_CTR_DRBG_C */ + POLARSSL_CTR_DRBG_C && POLARSSL_GENPRIME */ diff --git a/programs/pkey/key_app.c b/programs/pkey/key_app.c index d4c30d22b..b3b235eff 100644 --- a/programs/pkey/key_app.c +++ b/programs/pkey/key_app.c @@ -169,8 +169,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { - polarssl_strerror( ret, buf, sizeof(buf) ); - printf( " failed\n ! pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, buf ); + printf( " failed\n ! pk_parse_keyfile returned -0x%04x\n", -ret ); goto exit; } @@ -223,8 +222,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { - polarssl_strerror( ret, buf, sizeof(buf) ); - printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x - %s\n\n", -ret, buf ); + printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x\n", -ret ); goto exit; } @@ -260,6 +258,11 @@ int main( int argc, char *argv[] ) exit: +#if defined(POLARSSL_ERROR_C) + polarssl_strerror( ret, buf, sizeof(buf) ); + printf( " ! Last error was: %s\n", buf ); +#endif + pk_free( &pk ); #if defined(_WIN32) diff --git a/programs/pkey/pk_decrypt.c b/programs/pkey/pk_decrypt.c index 416bbeccc..8e0d9aa5a 100644 --- a/programs/pkey/pk_decrypt.c +++ b/programs/pkey/pk_decrypt.c @@ -97,9 +97,7 @@ int main( int argc, char *argv[] ) if( ( ret = pk_parse_keyfile( &pk, argv[1], "" ) ) != 0 ) { - polarssl_strerror( ret, (char *) buf, sizeof(buf) ); - printf( " failed\n ! pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, - buf ); + printf( " failed\n ! pk_parse_keyfile returned -0x%04x\n", -ret ); goto exit; } @@ -131,9 +129,7 @@ int main( int argc, char *argv[] ) if( ( ret = pk_decrypt( &pk, buf, i, result, &olen, sizeof(result), ctr_drbg_random, &ctr_drbg ) ) != 0 ) { - polarssl_strerror( ret, (char *) buf, sizeof(buf) ); - printf( " failed\n ! pk_decrypt returned -0x%04x - %s\n\n", -ret, - buf ); + printf( " failed\n ! pk_decrypt returned -0x%04x\n", -ret ); goto exit; } @@ -145,6 +141,11 @@ int main( int argc, char *argv[] ) exit: +#if defined(POLARSSL_ERROR_C) + polarssl_strerror( ret, (char *) buf, sizeof(buf) ); + printf( " ! Last error was: %s\n", buf ); +#endif + #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); fflush( stdout ); getchar(); diff --git a/programs/pkey/pk_encrypt.c b/programs/pkey/pk_encrypt.c index 5d7d1e036..3230eb0ba 100644 --- a/programs/pkey/pk_encrypt.c +++ b/programs/pkey/pk_encrypt.c @@ -84,8 +84,7 @@ int main( int argc, char *argv[] ) (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - polarssl_strerror( ret, (char *) buf, sizeof(buf) ); - printf( " failed\n ! ctr_drbg_init returned -0x%04x - %s\n\n", -ret, buf ); + printf( " failed\n ! ctr_drbg_init returned -0x%04x\n", -ret ); goto exit; } @@ -96,8 +95,7 @@ int main( int argc, char *argv[] ) if( ( ret = pk_parse_public_keyfile( &pk, argv[1] ) ) != 0 ) { - polarssl_strerror( ret, (char *) buf, sizeof(buf) ); - printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x - %s\n\n", -ret, buf ); + printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x\n", -ret ); goto exit; } @@ -119,8 +117,7 @@ int main( int argc, char *argv[] ) buf, &olen, sizeof(buf), ctr_drbg_random, &ctr_drbg ) ) != 0 ) { - polarssl_strerror( ret, (char *) buf, sizeof(buf) ); - printf( " failed\n ! pk_encrypt returned -0x%04x - %s\n\n", -ret, buf ); + printf( " failed\n ! pk_encrypt returned -0x%04x\n", -ret ); goto exit; } @@ -144,6 +141,11 @@ int main( int argc, char *argv[] ) exit: +#if defined(POLARSSL_ERROR_C) + polarssl_strerror( ret, (char *) buf, sizeof(buf) ); + printf( " ! Last error was: %s\n", buf ); +#endif + #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); fflush( stdout ); getchar(); diff --git a/programs/pkey/pk_sign.c b/programs/pkey/pk_sign.c index 61a486887..625a2995c 100644 --- a/programs/pkey/pk_sign.c +++ b/programs/pkey/pk_sign.c @@ -93,8 +93,7 @@ int main( int argc, char *argv[] ) (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - polarssl_strerror( ret, (char *) buf, sizeof(buf) ); - printf( " failed\n ! ctr_drbg_init returned -0x%04x - %s\n\n", -ret, buf ); + printf( " failed\n ! ctr_drbg_init returned -0x%04x\n", -ret ); goto exit; } @@ -126,8 +125,7 @@ int main( int argc, char *argv[] ) if( ( ret = pk_sign( &pk, POLARSSL_MD_SHA1, hash, 0, buf, &olen, ctr_drbg_random, &ctr_drbg ) ) != 0 ) { - polarssl_strerror( ret, (char *) buf, sizeof(buf) ); - printf( " failed\n ! pk_sign returned -0x%04x - %s\n\n", -ret, buf ); + printf( " failed\n ! pk_sign returned -0x%04x\n", -ret ); goto exit; } @@ -156,6 +154,11 @@ int main( int argc, char *argv[] ) exit: pk_free( &pk ); +#if defined(POLARSSL_ERROR_C) + polarssl_strerror( ret, (char *) buf, sizeof(buf) ); + printf( " ! Last error was: %s\n", buf ); +#endif + #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); fflush( stdout ); getchar(); diff --git a/programs/pkey/pk_verify.c b/programs/pkey/pk_verify.c index 68c088700..4e8fc8461 100644 --- a/programs/pkey/pk_verify.c +++ b/programs/pkey/pk_verify.c @@ -84,8 +84,7 @@ int main( int argc, char *argv[] ) if( ( ret = pk_parse_public_keyfile( &pk, argv[1] ) ) != 0 ) { - polarssl_strerror( ret, (char *) buf, sizeof(buf) ); - printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x - %s\n\n", -ret, buf ); + printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x\n", -ret ); goto exit; } @@ -122,8 +121,7 @@ int main( int argc, char *argv[] ) if( ( ret = pk_verify( &pk, POLARSSL_MD_SHA1, hash, 0, buf, i ) ) != 0 ) { - polarssl_strerror( ret, (char *) buf, sizeof(buf) ); - printf( " failed\n ! pk_verify returned -0x%04x - %s\n\n", -ret, buf ); + printf( " failed\n ! pk_verify returned -0x%04x\n", -ret ); goto exit; } @@ -134,6 +132,11 @@ int main( int argc, char *argv[] ) exit: pk_free( &pk ); +#if defined(POLARSSL_ERROR_C) + polarssl_strerror( ret, (char *) buf, sizeof(buf) ); + printf( " ! Last error was: %s\n", buf ); +#endif + #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); fflush( stdout ); getchar();