From 06d5d61302c3e0a59bb36d4521ca799df9c66945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 28 May 2015 16:23:18 +0200 Subject: [PATCH] Adapt programs to generic md_file() --- programs/pkey/pk_sign.c | 41 +++++++++++++++------------------ programs/pkey/pk_verify.c | 36 ++++++++++++++--------------- programs/pkey/rsa_sign.c | 26 +++++++++++---------- programs/pkey/rsa_sign_pss.c | 42 ++++++++++++++++------------------ programs/pkey/rsa_verify.c | 26 +++++++++++---------- programs/pkey/rsa_verify_pss.c | 35 ++++++++++++++-------------- 6 files changed, 102 insertions(+), 104 deletions(-) diff --git a/programs/pkey/pk_sign.c b/programs/pkey/pk_sign.c index be8b5139b..b84d047d8 100644 --- a/programs/pkey/pk_sign.c +++ b/programs/pkey/pk_sign.c @@ -35,38 +35,33 @@ #define mbedtls_snprintf snprintf #endif -#if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_ENTROPY_C) && \ - defined(MBEDTLS_SHA256_C) && \ - defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_FS_IO) && \ - defined(MBEDTLS_CTR_DRBG_C) -#include "mbedtls/error.h" -#include "mbedtls/entropy.h" -#include "mbedtls/ctr_drbg.h" -#include "mbedtls/md.h" -#include "mbedtls/pk.h" -#include "mbedtls/sha1.h" - -#include -#include -#endif - -#if defined _MSC_VER && !defined snprintf -#define snprintf _snprintf -#endif - #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \ - !defined(MBEDTLS_SHA256_C) || \ + !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_MD_C) || \ !defined(MBEDTLS_PK_PARSE_C) || !defined(MBEDTLS_FS_IO) || \ !defined(MBEDTLS_CTR_DRBG_C) int main( void ) { mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C and/or " - "MBEDTLS_SHA256_C and/or " + "MBEDTLS_SHA256_C and/or MBEDLTS_MD_C and/or " "MBEDTLS_PK_PARSE_C and/or MBEDTLS_FS_IO and/or " "MBEDTLS_CTR_DRBG_C not defined.\n"); return( 0 ); } #else + +#include "mbedtls/error.h" +#include "mbedtls/entropy.h" +#include "mbedtls/ctr_drbg.h" +#include "mbedtls/md.h" +#include "mbedtls/pk.h" + +#include +#include + +#if defined _MSC_VER && !defined snprintf +#define snprintf _snprintf +#endif + int main( int argc, char *argv[] ) { FILE *f; @@ -123,7 +118,9 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Generating the SHA-256 signature" ); fflush( stdout ); - if( ( ret = mbedtls_sha1_file( argv[2], hash ) ) != 0 ) + if( ( ret = mbedtls_md_file( + mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ), + argv[2], hash ) ) != 0 ) { mbedtls_printf( " failed\n ! Could not open or read %s\n\n", argv[2] ); goto exit; diff --git a/programs/pkey/pk_verify.c b/programs/pkey/pk_verify.c index 8c69dc37e..a37b66a60 100644 --- a/programs/pkey/pk_verify.c +++ b/programs/pkey/pk_verify.c @@ -35,33 +35,29 @@ #define mbedtls_snprintf snprintf #endif -#if defined(MBEDTLS_BIGNUM_C) && \ - defined(MBEDTLS_SHA256_C) && defined(MBEDTLS_PK_PARSE_C) && \ - defined(MBEDTLS_FS_IO) -#include "mbedtls/error.h" -#include "mbedtls/md.h" -#include "mbedtls/pk.h" -#include "mbedtls/sha1.h" - -#include -#include -#endif - -#if defined _MSC_VER && !defined snprintf -#define snprintf _snprintf -#endif - -#if !defined(MBEDTLS_BIGNUM_C) || \ +#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_MD_C) || \ !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_PK_PARSE_C) || \ !defined(MBEDTLS_FS_IO) int main( void ) { - mbedtls_printf("MBEDTLS_BIGNUM_C and/or " + mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_MD_C and/or " "MBEDTLS_SHA256_C and/or MBEDTLS_PK_PARSE_C and/or " "MBEDTLS_FS_IO not defined.\n"); return( 0 ); } #else + +#include "mbedtls/error.h" +#include "mbedtls/md.h" +#include "mbedtls/pk.h" + +#include +#include + +#if defined _MSC_VER && !defined snprintf +#define snprintf _snprintf +#endif + int main( int argc, char *argv[] ) { FILE *f; @@ -118,7 +114,9 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Verifying the SHA-256 signature" ); fflush( stdout ); - if( ( ret = mbedtls_sha1_file( argv[2], hash ) ) != 0 ) + if( ( ret = mbedtls_md_file( + mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ), + argv[2], hash ) ) != 0 ) { mbedtls_printf( " failed\n ! Could not open or read %s\n\n", argv[2] ); goto exit; diff --git a/programs/pkey/rsa_sign.c b/programs/pkey/rsa_sign.c index 0c441bd4e..e2d39fcbb 100644 --- a/programs/pkey/rsa_sign.c +++ b/programs/pkey/rsa_sign.c @@ -34,24 +34,24 @@ #define mbedtls_printf printf #endif -#if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_RSA_C) && \ - defined(MBEDTLS_SHA256_C) && defined(MBEDTLS_FS_IO) -#include "mbedtls/rsa.h" -#include "mbedtls/sha1.h" - -#include -#include -#endif - #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \ - !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_FS_IO) + !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_MD_C) || \ + !defined(MBEDTLS_FS_IO) int main( void ) { mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_RSA_C and/or " - "MBEDTLS_SHA256_C and/or MBEDTLS_FS_IO not defined.\n"); + "MBEDLTS_MD_C and/or " + "MBEDTLS_SHA256_C and/or MBEDTLS_FS_IO not defined.\n"); return( 0 ); } #else + +#include "mbedtls/rsa.h" +#include "mbedtls/md.h" + +#include +#include + int main( int argc, char *argv[] ) { FILE *f; @@ -119,7 +119,9 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Generating the RSA/SHA-256 signature" ); fflush( stdout ); - if( ( ret = mbedtls_sha1_file( argv[1], hash ) ) != 0 ) + if( ( ret = mbedtls_md_file( + mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ), + argv[1], hash ) ) != 0 ) { mbedtls_printf( " failed\n ! Could not open or read %s\n\n", argv[1] ); goto exit; diff --git a/programs/pkey/rsa_sign_pss.c b/programs/pkey/rsa_sign_pss.c index c8b38f7f3..ff6e4ccd5 100644 --- a/programs/pkey/rsa_sign_pss.c +++ b/programs/pkey/rsa_sign_pss.c @@ -35,38 +35,34 @@ #define mbedtls_snprintf snprintf #endif -#if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_ENTROPY_C) && \ - defined(MBEDTLS_RSA_C) && defined(MBEDTLS_SHA256_C) && \ - defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_FS_IO) && \ - defined(MBEDTLS_CTR_DRBG_C) -#include "mbedtls/entropy.h" -#include "mbedtls/ctr_drbg.h" -#include "mbedtls/md.h" -#include "mbedtls/rsa.h" -#include "mbedtls/sha1.h" -#include "mbedtls/x509.h" - -#include -#include -#endif - -#if defined _MSC_VER && !defined snprintf -#define snprintf _snprintf -#endif - -#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \ +#if !defined(MBEDTLS_MD_C) || !defined(MBEDTLS_ENTROPY_C) || \ !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_SHA256_C) || \ !defined(MBEDTLS_PK_PARSE_C) || !defined(MBEDTLS_FS_IO) || \ !defined(MBEDTLS_CTR_DRBG_C) int main( void ) { - mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C and/or " + mbedtls_printf("MBEDTLS_MD_C and/or MBEDTLS_ENTROPY_C and/or " "MBEDTLS_RSA_C and/or MBEDTLS_SHA256_C and/or " "MBEDTLS_PK_PARSE_C and/or MBEDTLS_FS_IO and/or " "MBEDTLS_CTR_DRBG_C not defined.\n"); return( 0 ); } #else + +#include "mbedtls/entropy.h" +#include "mbedtls/ctr_drbg.h" +#include "mbedtls/md.h" +#include "mbedtls/rsa.h" +#include "mbedtls/md.h" +#include "mbedtls/x509.h" + +#include +#include + +#if defined _MSC_VER && !defined snprintf +#define snprintf _snprintf +#endif + int main( int argc, char *argv[] ) { FILE *f; @@ -133,7 +129,9 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Generating the RSA/SHA-256 signature" ); fflush( stdout ); - if( ( ret = mbedtls_sha1_file( argv[2], hash ) ) != 0 ) + if( ( ret = mbedtls_md_file( + mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ), + argv[2], hash ) ) != 0 ) { mbedtls_printf( " failed\n ! Could not open or read %s\n\n", argv[2] ); goto exit; diff --git a/programs/pkey/rsa_verify.c b/programs/pkey/rsa_verify.c index 3d5d71970..35467ee3e 100644 --- a/programs/pkey/rsa_verify.c +++ b/programs/pkey/rsa_verify.c @@ -33,24 +33,24 @@ #define mbedtls_printf printf #endif -#if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_RSA_C) && \ - defined(MBEDTLS_SHA256_C) && defined(MBEDTLS_FS_IO) -#include "mbedtls/rsa.h" -#include "mbedtls/sha1.h" - -#include -#include -#endif - #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \ - !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_FS_IO) + !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_MD_C) || \ + !defined(MBEDTLS_FS_IO) int main( void ) { mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_RSA_C and/or " - "MBEDTLS_SHA256_C and/or MBEDTLS_FS_IO not defined.\n"); + "MBEDLTS_MD_C and/or " + "MBEDTLS_SHA256_C and/or MBEDTLS_FS_IO not defined.\n"); return( 0 ); } #else + +#include "mbedtls/rsa.h" +#include "mbedtls/md.h" + +#include +#include + int main( int argc, char *argv[] ) { FILE *f; @@ -129,7 +129,9 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Verifying the RSA/SHA-256 signature" ); fflush( stdout ); - if( ( ret = mbedtls_sha1_file( argv[1], hash ) ) != 0 ) + if( ( ret = mbedtls_md_file( + mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ), + argv[1], hash ) ) != 0 ) { mbedtls_printf( " failed\n ! Could not open or read %s\n\n", argv[1] ); goto exit; diff --git a/programs/pkey/rsa_verify_pss.c b/programs/pkey/rsa_verify_pss.c index 0fb733b50..a3c81d42d 100644 --- a/programs/pkey/rsa_verify_pss.c +++ b/programs/pkey/rsa_verify_pss.c @@ -35,34 +35,33 @@ #define mbedtls_snprintf snprintf #endif -#if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_RSA_C) && \ - defined(MBEDTLS_SHA256_C) && defined(MBEDTLS_PK_PARSE_C) && \ - defined(MBEDTLS_FS_IO) +#if !defined(MBEDTLS_MD_C) || !defined(MBEDTLS_ENTROPY_C) || \ + !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_SHA256_C) || \ + !defined(MBEDTLS_PK_PARSE_C) || !defined(MBEDTLS_FS_IO) || \ + !defined(MBEDTLS_CTR_DRBG_C) +int main( void ) +{ + mbedtls_printf("MBEDTLS_MD_C and/or MBEDTLS_ENTROPY_C and/or " + "MBEDTLS_RSA_C and/or MBEDTLS_SHA256_C and/or " + "MBEDTLS_PK_PARSE_C and/or MBEDTLS_FS_IO and/or " + "MBEDTLS_CTR_DRBG_C not defined.\n"); + return( 0 ); +} +#else + #include "mbedtls/md.h" #include "mbedtls/pem.h" #include "mbedtls/pk.h" -#include "mbedtls/sha1.h" +#include "mbedtls/md.h" #include "mbedtls/x509.h" #include #include -#endif #if defined _MSC_VER && !defined snprintf #define snprintf _snprintf #endif -#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \ - !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_PK_PARSE_C) || \ - !defined(MBEDTLS_FS_IO) -int main( void ) -{ - mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_RSA_C and/or " - "MBEDTLS_SHA256_C and/or MBEDTLS_PK_PARSE_C and/or " - "MBEDTLS_FS_IO not defined.\n"); - return( 0 ); -} -#else int main( int argc, char *argv[] ) { FILE *f; @@ -129,7 +128,9 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Verifying the RSA/SHA-256 signature" ); fflush( stdout ); - if( ( ret = mbedtls_sha1_file( argv[2], hash ) ) != 0 ) + if( ( ret = mbedtls_md_file( + mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ), + argv[2], hash ) ) != 0 ) { mbedtls_printf( " failed\n ! Could not open or read %s\n\n", argv[2] ); goto exit;