From 41b9c2b418ab4129b64e44764566f08ba983b451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 28 May 2015 14:56:20 +0200 Subject: [PATCH] Remove individual mdX_file() and shaX_file() --- ChangeLog | 6 +- include/mbedtls/error.h | 7 --- include/mbedtls/md2.h | 12 ---- include/mbedtls/md4.h | 12 ---- include/mbedtls/md5.h | 12 ---- include/mbedtls/ripemd160.h | 14 ----- include/mbedtls/sha1.h | 12 ---- include/mbedtls/sha256.h | 13 ----- include/mbedtls/sha512.h | 13 ----- library/error.c | 65 +--------------------- library/md2.c | 38 ------------- library/md4.c | 38 ------------- library/md5.c | 38 ------------- library/ripemd160.c | 38 ------------- library/sha1.c | 38 ------------- library/sha256.c | 38 ------------- library/sha512.c | 38 ------------- tests/suites/test_suite_mdx.data | 51 ----------------- tests/suites/test_suite_mdx.function | 64 --------------------- tests/suites/test_suite_shax.data | 80 --------------------------- tests/suites/test_suite_shax.function | 80 --------------------------- 21 files changed, 4 insertions(+), 703 deletions(-) diff --git a/ChangeLog b/ChangeLog index 209b1e25f..d4f3da631 100644 --- a/ChangeLog +++ b/ChangeLog @@ -81,9 +81,9 @@ Removals * Removed mbedtls_ecp_group_read_string(). Only named groups are supported. * Removed mbedtls_ecp_sub() and mbedtls_ecp_add(), use mbedtls_ecp_muladd(). - * Removed individual mdX_hmac and shaX_hmac functions (use generic - md_hmac functions from md.h) - * Removed mbedtls_timing_msleep(). Use mbedtls_timing_usleep() or a custom + * Removed individual mdX_hmac, shaX_hmac, mdX_file and shaX_file functions + (use generic functions from md.h) + * Removed mbedtls_timing_msleep(). Use mbedtls_net_usleep() or a custom waiting function. * Removed the PBKDF2 module (use PKCS5). * Removed POLARSSL_ERROR_STRERROR_BC (use mbedtls_strerror()). diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index 3dd90a9b8..924424929 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -65,14 +65,7 @@ * NET 9 0x0042-0x0052 0x0043-0x0043 * ENTROPY 1 0x0058-0x0058 * ASN1 7 0x0060-0x006C - * MD2 1 0x0070-0x0070 - * MD4 1 0x0072-0x0072 - * MD5 1 0x0074-0x0074 - * SHA1 1 0x0076-0x0076 - * SHA256 1 0x0078-0x0078 - * SHA512 1 0x007A-0x007A * PBKDF2 1 0x007C-0x007C - * RIPEMD160 1 0x007E-0x007E * HMAC_DRBG 4 0x0003-0x0009 * CCM 2 0x000D-0x000F * diff --git a/include/mbedtls/md2.h b/include/mbedtls/md2.h index 7c1cfc5c8..8d012666d 100644 --- a/include/mbedtls/md2.h +++ b/include/mbedtls/md2.h @@ -32,8 +32,6 @@ #include -#define MBEDTLS_ERR_MD2_FILE_IO_ERROR -0x0070 /**< Read/write error in file. */ - #if !defined(MBEDTLS_MD2_ALT) // Regular implementation // @@ -113,16 +111,6 @@ extern "C" { */ void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[16] ); -/** - * \brief Output = MD2( file contents ) - * - * \param path input file name - * \param output MD2 checksum result - * - * \return 0 if successful, or MBEDTLS_ERR_MD2_FILE_IO_ERROR - */ -int mbedtls_md2_file( const char *path, unsigned char output[16] ); - /** * \brief Checkup routine * diff --git a/include/mbedtls/md4.h b/include/mbedtls/md4.h index 880c81d21..96dcc447f 100644 --- a/include/mbedtls/md4.h +++ b/include/mbedtls/md4.h @@ -33,8 +33,6 @@ #include #include -#define MBEDTLS_ERR_MD4_FILE_IO_ERROR -0x0072 /**< Read/write error in file. */ - #if !defined(MBEDTLS_MD4_ALT) // Regular implementation // @@ -113,16 +111,6 @@ extern "C" { */ void mbedtls_md4( const unsigned char *input, size_t ilen, unsigned char output[16] ); -/** - * \brief Output = MD4( file contents ) - * - * \param path input file name - * \param output MD4 checksum result - * - * \return 0 if successful, or MBEDTLS_ERR_MD4_FILE_IO_ERROR - */ -int mbedtls_md4_file( const char *path, unsigned char output[16] ); - /** * \brief Checkup routine * diff --git a/include/mbedtls/md5.h b/include/mbedtls/md5.h index 0e2657027..163780a24 100644 --- a/include/mbedtls/md5.h +++ b/include/mbedtls/md5.h @@ -33,8 +33,6 @@ #include #include -#define MBEDTLS_ERR_MD5_FILE_IO_ERROR -0x0074 /**< Read/write error in file. */ - #if !defined(MBEDTLS_MD5_ALT) // Regular implementation // @@ -116,16 +114,6 @@ extern "C" { */ void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] ); -/** - * \brief Output = MD5( file contents ) - * - * \param path input file name - * \param output MD5 checksum result - * - * \return 0 if successful, or MBEDTLS_ERR_MD5_FILE_IO_ERROR - */ -int mbedtls_md5_file( const char *path, unsigned char output[16] ); - /** * \brief Checkup routine * diff --git a/include/mbedtls/ripemd160.h b/include/mbedtls/ripemd160.h index 390584b6c..e66c46a20 100644 --- a/include/mbedtls/ripemd160.h +++ b/include/mbedtls/ripemd160.h @@ -33,8 +33,6 @@ #include #include -#define MBEDTLS_ERR_RIPEMD160_FILE_IO_ERROR -0x007E /**< Read/write error in file. */ - #if !defined(MBEDTLS_RIPEMD160_ALT) // Regular implementation // @@ -118,18 +116,6 @@ extern "C" { void mbedtls_ripemd160( const unsigned char *input, size_t ilen, unsigned char output[20] ); -#if defined(MBEDTLS_FS_IO) -/** - * \brief Output = RIPEMD-160( file contents ) - * - * \param path input file name - * \param output RIPEMD-160 checksum result - * - * \return 0 if successful, or MBEDTLS_ERR_RIPEMD160_FILE_IO_ERROR - */ -int mbedtls_ripemd160_file( const char *path, unsigned char output[20] ); -#endif /* MBEDTLS_FS_IO */ - /** * \brief Checkup routine * diff --git a/include/mbedtls/sha1.h b/include/mbedtls/sha1.h index efaf90772..74fb85578 100644 --- a/include/mbedtls/sha1.h +++ b/include/mbedtls/sha1.h @@ -33,8 +33,6 @@ #include #include -#define MBEDTLS_ERR_SHA1_FILE_IO_ERROR -0x0076 /**< Read/write error in file. */ - #if !defined(MBEDTLS_SHA1_ALT) // Regular implementation // @@ -116,16 +114,6 @@ extern "C" { */ void mbedtls_sha1( const unsigned char *input, size_t ilen, unsigned char output[20] ); -/** - * \brief Output = SHA-1( file contents ) - * - * \param path input file name - * \param output SHA-1 checksum result - * - * \return 0 if successful, or MBEDTLS_ERR_SHA1_FILE_IO_ERROR - */ -int mbedtls_sha1_file( const char *path, unsigned char output[20] ); - /** * \brief Checkup routine * diff --git a/include/mbedtls/sha256.h b/include/mbedtls/sha256.h index e4a991fd3..113c23b02 100644 --- a/include/mbedtls/sha256.h +++ b/include/mbedtls/sha256.h @@ -33,8 +33,6 @@ #include #include -#define MBEDTLS_ERR_SHA256_FILE_IO_ERROR -0x0078 /**< Read/write error in file. */ - #if !defined(MBEDTLS_SHA256_ALT) // Regular implementation // @@ -121,17 +119,6 @@ extern "C" { void mbedtls_sha256( const unsigned char *input, size_t ilen, unsigned char output[32], int is224 ); -/** - * \brief Output = SHA-256( file contents ) - * - * \param path input file name - * \param output SHA-224/256 checksum result - * \param is224 0 = use SHA256, 1 = use SHA224 - * - * \return 0 if successful, or MBEDTLS_ERR_SHA256_FILE_IO_ERROR - */ -int mbedtls_sha256_file( const char *path, unsigned char output[32], int is224 ); - /** * \brief Checkup routine * diff --git a/include/mbedtls/sha512.h b/include/mbedtls/sha512.h index 6c61cc36e..6b09a485f 100644 --- a/include/mbedtls/sha512.h +++ b/include/mbedtls/sha512.h @@ -33,8 +33,6 @@ #include #include -#define MBEDTLS_ERR_SHA512_FILE_IO_ERROR -0x007A /**< Read/write error in file. */ - #if !defined(MBEDTLS_SHA512_ALT) // Regular implementation // @@ -118,17 +116,6 @@ extern "C" { void mbedtls_sha512( const unsigned char *input, size_t ilen, unsigned char output[64], int is384 ); -/** - * \brief Output = SHA-512( file contents ) - * - * \param path input file name - * \param output SHA-384/512 checksum result - * \param is384 0 = use SHA512, 1 = use SHA384 - * - * \return 0 if successful, or MBEDTLS_ERR_SHA512_FILE_IO_ERROR - */ -int mbedtls_sha512_file( const char *path, unsigned char output[64], int is384 ); - /** * \brief Checkup routine * diff --git a/library/error.c b/library/error.c index c9e5e79f6..fdeb12ab8 100644 --- a/library/error.c +++ b/library/error.c @@ -101,18 +101,6 @@ #include "mbedtls/md.h" #endif -#if defined(MBEDTLS_MD2_C) -#include "mbedtls/md2.h" -#endif - -#if defined(MBEDTLS_MD4_C) -#include "mbedtls/md4.h" -#endif - -#if defined(MBEDTLS_MD5_C) -#include "mbedtls/md5.h" -#endif - #if defined(MBEDTLS_NET_C) #include "mbedtls/net.h" #endif @@ -141,26 +129,10 @@ #include "mbedtls/pkcs5.h" #endif -#if defined(MBEDTLS_RIPEMD160_C) -#include "mbedtls/ripemd160.h" -#endif - #if defined(MBEDTLS_RSA_C) #include "mbedtls/rsa.h" #endif -#if defined(MBEDTLS_SHA1_C) -#include "mbedtls/sha1.h" -#endif - -#if defined(MBEDTLS_SHA256_C) -#include "mbedtls/sha256.h" -#endif - -#if defined(MBEDTLS_SHA512_C) -#include "mbedtls/sha512.h" -#endif - #if defined(MBEDTLS_SSL_TLS_C) #include "mbedtls/ssl.h" #endif @@ -293,7 +265,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) #if defined(MBEDTLS_PK_C) if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) ) - mbedtls_snprintf( buf, buflen, "PK - Memory alloation failed" ); + mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" ); if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) ) mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" ); if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) ) @@ -649,21 +621,6 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" ); #endif /* MBEDTLS_HMAC_DRBG_C */ -#if defined(MBEDTLS_MD2_C) - if( use_ret == -(MBEDTLS_ERR_MD2_FILE_IO_ERROR) ) - mbedtls_snprintf( buf, buflen, "MD2 - Read/write error in file" ); -#endif /* MBEDTLS_MD2_C */ - -#if defined(MBEDTLS_MD4_C) - if( use_ret == -(MBEDTLS_ERR_MD4_FILE_IO_ERROR) ) - mbedtls_snprintf( buf, buflen, "MD4 - Read/write error in file" ); -#endif /* MBEDTLS_MD4_C */ - -#if defined(MBEDTLS_MD5_C) - if( use_ret == -(MBEDTLS_ERR_MD5_FILE_IO_ERROR) ) - mbedtls_snprintf( buf, buflen, "MD5 - Read/write error in file" ); -#endif /* MBEDTLS_MD5_C */ - #if defined(MBEDTLS_NET_C) if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) ) mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" ); @@ -699,26 +656,6 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" ); #endif /* MBEDTLS_PADLOCK_C */ -#if defined(MBEDTLS_RIPEMD160_C) - if( use_ret == -(MBEDTLS_ERR_RIPEMD160_FILE_IO_ERROR) ) - mbedtls_snprintf( buf, buflen, "RIPEMD160 - Read/write error in file" ); -#endif /* MBEDTLS_RIPEMD160_C */ - -#if defined(MBEDTLS_SHA1_C) - if( use_ret == -(MBEDTLS_ERR_SHA1_FILE_IO_ERROR) ) - mbedtls_snprintf( buf, buflen, "SHA1 - Read/write error in file" ); -#endif /* MBEDTLS_SHA1_C */ - -#if defined(MBEDTLS_SHA256_C) - if( use_ret == -(MBEDTLS_ERR_SHA256_FILE_IO_ERROR) ) - mbedtls_snprintf( buf, buflen, "SHA256 - Read/write error in file" ); -#endif /* MBEDTLS_SHA256_C */ - -#if defined(MBEDTLS_SHA512_C) - if( use_ret == -(MBEDTLS_ERR_SHA512_FILE_IO_ERROR) ) - mbedtls_snprintf( buf, buflen, "SHA512 - Read/write error in file" ); -#endif /* MBEDTLS_SHA512_C */ - #if defined(MBEDTLS_THREADING_C) if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) ) mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" ); diff --git a/library/md2.c b/library/md2.c index 152635242..5cd024a3d 100644 --- a/library/md2.c +++ b/library/md2.c @@ -38,10 +38,6 @@ #include -#if defined(MBEDTLS_FS_IO) -#include -#endif - #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" @@ -213,40 +209,6 @@ void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[ mbedtls_md2_free( &ctx ); } -#if defined(MBEDTLS_FS_IO) -/* - * output = MD2( file contents ) - */ -int mbedtls_md2_file( const char *path, unsigned char output[16] ) -{ - FILE *f; - size_t n; - mbedtls_md2_context ctx; - unsigned char buf[1024]; - - if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_MD2_FILE_IO_ERROR ); - - mbedtls_md2_init( &ctx ); - mbedtls_md2_starts( &ctx ); - - while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 ) - mbedtls_md2_update( &ctx, buf, n ); - - mbedtls_md2_finish( &ctx, output ); - mbedtls_md2_free( &ctx ); - - if( ferror( f ) != 0 ) - { - fclose( f ); - return( MBEDTLS_ERR_MD2_FILE_IO_ERROR ); - } - - fclose( f ); - return( 0 ); -} -#endif /* MBEDTLS_FS_IO */ - #if defined(MBEDTLS_SELF_TEST) /* diff --git a/library/md4.c b/library/md4.c index 75a671905..90623582a 100644 --- a/library/md4.c +++ b/library/md4.c @@ -38,10 +38,6 @@ #include -#if defined(MBEDTLS_FS_IO) -#include -#endif - #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" @@ -309,40 +305,6 @@ void mbedtls_md4( const unsigned char *input, size_t ilen, unsigned char output[ mbedtls_md4_free( &ctx ); } -#if defined(MBEDTLS_FS_IO) -/* - * output = MD4( file contents ) - */ -int mbedtls_md4_file( const char *path, unsigned char output[16] ) -{ - FILE *f; - size_t n; - mbedtls_md4_context ctx; - unsigned char buf[1024]; - - if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_MD4_FILE_IO_ERROR ); - - mbedtls_md4_init( &ctx ); - mbedtls_md4_starts( &ctx ); - - while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 ) - mbedtls_md4_update( &ctx, buf, n ); - - mbedtls_md4_finish( &ctx, output ); - mbedtls_md4_free( &ctx ); - - if( ferror( f ) != 0 ) - { - fclose( f ); - return( MBEDTLS_ERR_MD4_FILE_IO_ERROR ); - } - - fclose( f ); - return( 0 ); -} -#endif /* MBEDTLS_FS_IO */ - #if defined(MBEDTLS_SELF_TEST) /* diff --git a/library/md5.c b/library/md5.c index 592304eb2..599debc47 100644 --- a/library/md5.c +++ b/library/md5.c @@ -37,10 +37,6 @@ #include -#if defined(MBEDTLS_FS_IO) -#include -#endif - #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" @@ -326,40 +322,6 @@ void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[ mbedtls_md5_free( &ctx ); } -#if defined(MBEDTLS_FS_IO) -/* - * output = MD5( file contents ) - */ -int mbedtls_md5_file( const char *path, unsigned char output[16] ) -{ - FILE *f; - size_t n; - mbedtls_md5_context ctx; - unsigned char buf[1024]; - - if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_MD5_FILE_IO_ERROR ); - - mbedtls_md5_init( &ctx ); - mbedtls_md5_starts( &ctx ); - - while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 ) - mbedtls_md5_update( &ctx, buf, n ); - - mbedtls_md5_finish( &ctx, output ); - mbedtls_md5_free( &ctx ); - - if( ferror( f ) != 0 ) - { - fclose( f ); - return( MBEDTLS_ERR_MD5_FILE_IO_ERROR ); - } - - fclose( f ); - return( 0 ); -} -#endif /* MBEDTLS_FS_IO */ - #if defined(MBEDTLS_SELF_TEST) /* * RFC 1321 test vectors diff --git a/library/ripemd160.c b/library/ripemd160.c index 12c2e20cd..d8a451daf 100644 --- a/library/ripemd160.c +++ b/library/ripemd160.c @@ -38,10 +38,6 @@ #include -#if defined(MBEDTLS_FS_IO) -#include -#endif - #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" @@ -384,40 +380,6 @@ void mbedtls_ripemd160( const unsigned char *input, size_t ilen, mbedtls_ripemd160_free( &ctx ); } -#if defined(MBEDTLS_FS_IO) -/* - * output = RIPEMD-160( file contents ) - */ -int mbedtls_ripemd160_file( const char *path, unsigned char output[20] ) -{ - FILE *f; - size_t n; - mbedtls_ripemd160_context ctx; - unsigned char buf[1024]; - - if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_RIPEMD160_FILE_IO_ERROR ); - - mbedtls_ripemd160_init( &ctx ); - mbedtls_ripemd160_starts( &ctx ); - - while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 ) - mbedtls_ripemd160_update( &ctx, buf, n ); - - mbedtls_ripemd160_finish( &ctx, output ); - mbedtls_ripemd160_free( &ctx ); - - if( ferror( f ) != 0 ) - { - fclose( f ); - return( MBEDTLS_ERR_RIPEMD160_FILE_IO_ERROR ); - } - - fclose( f ); - return( 0 ); -} -#endif /* MBEDTLS_FS_IO */ - #if defined(MBEDTLS_SELF_TEST) /* * Test vectors from the RIPEMD-160 paper and diff --git a/library/sha1.c b/library/sha1.c index 6b34ceaec..9a21bcb2a 100644 --- a/library/sha1.c +++ b/library/sha1.c @@ -37,10 +37,6 @@ #include -#if defined(MBEDTLS_FS_IO) -#include -#endif - #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" @@ -359,40 +355,6 @@ void mbedtls_sha1( const unsigned char *input, size_t ilen, unsigned char output mbedtls_sha1_free( &ctx ); } -#if defined(MBEDTLS_FS_IO) -/* - * output = SHA-1( file contents ) - */ -int mbedtls_sha1_file( const char *path, unsigned char output[20] ) -{ - FILE *f; - size_t n; - mbedtls_sha1_context ctx; - unsigned char buf[1024]; - - if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_SHA1_FILE_IO_ERROR ); - - mbedtls_sha1_init( &ctx ); - mbedtls_sha1_starts( &ctx ); - - while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 ) - mbedtls_sha1_update( &ctx, buf, n ); - - mbedtls_sha1_finish( &ctx, output ); - mbedtls_sha1_free( &ctx ); - - if( ferror( f ) != 0 ) - { - fclose( f ); - return( MBEDTLS_ERR_SHA1_FILE_IO_ERROR ); - } - - fclose( f ); - return( 0 ); -} -#endif /* MBEDTLS_FS_IO */ - #if defined(MBEDTLS_SELF_TEST) /* * FIPS-180-1 test vectors diff --git a/library/sha256.c b/library/sha256.c index 4e0b1f328..cf0b15fad 100644 --- a/library/sha256.c +++ b/library/sha256.c @@ -37,10 +37,6 @@ #include -#if defined(MBEDTLS_FS_IO) -#include -#endif - #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" @@ -331,40 +327,6 @@ void mbedtls_sha256( const unsigned char *input, size_t ilen, mbedtls_sha256_free( &ctx ); } -#if defined(MBEDTLS_FS_IO) -/* - * output = SHA-256( file contents ) - */ -int mbedtls_sha256_file( const char *path, unsigned char output[32], int is224 ) -{ - FILE *f; - size_t n; - mbedtls_sha256_context ctx; - unsigned char buf[1024]; - - if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_SHA256_FILE_IO_ERROR ); - - mbedtls_sha256_init( &ctx ); - mbedtls_sha256_starts( &ctx, is224 ); - - while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 ) - mbedtls_sha256_update( &ctx, buf, n ); - - mbedtls_sha256_finish( &ctx, output ); - mbedtls_sha256_free( &ctx ); - - if( ferror( f ) != 0 ) - { - fclose( f ); - return( MBEDTLS_ERR_SHA256_FILE_IO_ERROR ); - } - - fclose( f ); - return( 0 ); -} -#endif /* MBEDTLS_FS_IO */ - #if defined(MBEDTLS_SELF_TEST) /* * FIPS-180-2 test vectors diff --git a/library/sha512.c b/library/sha512.c index fb872a151..f09b0f7fe 100644 --- a/library/sha512.c +++ b/library/sha512.c @@ -43,10 +43,6 @@ #include -#if defined(MBEDTLS_FS_IO) -#include -#endif - #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" @@ -366,40 +362,6 @@ void mbedtls_sha512( const unsigned char *input, size_t ilen, mbedtls_sha512_free( &ctx ); } -#if defined(MBEDTLS_FS_IO) -/* - * output = SHA-512( file contents ) - */ -int mbedtls_sha512_file( const char *path, unsigned char output[64], int is384 ) -{ - FILE *f; - size_t n; - mbedtls_sha512_context ctx; - unsigned char buf[1024]; - - if( ( f = fopen( path, "rb" ) ) == NULL ) - return( MBEDTLS_ERR_SHA512_FILE_IO_ERROR ); - - mbedtls_sha512_init( &ctx ); - mbedtls_sha512_starts( &ctx, is384 ); - - while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 ) - mbedtls_sha512_update( &ctx, buf, n ); - - mbedtls_sha512_finish( &ctx, output ); - mbedtls_sha512_free( &ctx ); - - if( ferror( f ) != 0 ) - { - fclose( f ); - return( MBEDTLS_ERR_SHA512_FILE_IO_ERROR ); - } - - fclose( f ); - return( 0 ); -} -#endif /* MBEDTLS_FS_IO */ - #if defined(MBEDTLS_SELF_TEST) /* diff --git a/tests/suites/test_suite_mdx.data b/tests/suites/test_suite_mdx.data index 36507b2fc..2d403b410 100644 --- a/tests/suites/test_suite_mdx.data +++ b/tests/suites/test_suite_mdx.data @@ -85,57 +85,6 @@ ripemd160_text:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789": mbedtls_ripemd160 Test vector from paper #8 ripemd160_text:"12345678901234567890123456789012345678901234567890123456789012345678901234567890":"9b752e45573d4b39f4dbd3323cab82bf63326bfb" -MD2 Hash file #1 -mbedtls_md2_file:"data_files/hash_file_1":"b593c098712d2e21628c8986695451a8" - -MD2 Hash file #2 -mbedtls_md2_file:"data_files/hash_file_2":"3c027b7409909a4c4b26bbab69ad9f4f" - -MD2 Hash file #3 -mbedtls_md2_file:"data_files/hash_file_3":"6bb43eb285e81f414083a94cdbe2989d" - -MD2 Hash file #4 -mbedtls_md2_file:"data_files/hash_file_4":"8350e5a3e24c153df2275c9f80692773" - -MD4 Hash file #1 -mbedtls_md4_file:"data_files/hash_file_1":"8d19772c176bd27153b9486715e2c0b9" - -MD4 Hash file #2 -mbedtls_md4_file:"data_files/hash_file_2":"f2ac53b8542882a5a0007c6f84b4d9fd" - -MD4 Hash file #3 -mbedtls_md4_file:"data_files/hash_file_3":"195c15158e2d07881d9a654095ce4a42" - -MD4 Hash file #4 -mbedtls_md4_file:"data_files/hash_file_4":"31d6cfe0d16ae931b73c59d7e0c089c0" - -MD5 Hash file #1 -mbedtls_md5_file:"data_files/hash_file_1":"52bcdc983c9ed64fc148a759b3c7a415" - -MD5 Hash file #2 -mbedtls_md5_file:"data_files/hash_file_2":"d17d466f15891df10542207ae78277f0" - -MD5 Hash file #3 -mbedtls_md5_file:"data_files/hash_file_3":"d945bcc6200ea95d061a2a818167d920" - -MD5 Hash file #4 -mbedtls_md5_file:"data_files/hash_file_4":"d41d8cd98f00b204e9800998ecf8427e" - -RIPEMD160 Hash file #0 (from paper) -mbedtls_ripemd160_file:"data_files/hash_file_5":"52783243c1697bdbe16d37f97f68f08325dc1528" - -RIPEMD160 Hash file #1 -mbedtls_ripemd160_file:"data_files/hash_file_1":"82f1d072f0ec0c2b353703a7b575a04c113af1a6" - -RIPEMD160 Hash file #2 -mbedtls_ripemd160_file:"data_files/hash_file_2":"996fbc8b79206ba7393ebcd246584069b1c08f0f" - -RIPEMD160 Hash file #3 -mbedtls_ripemd160_file:"data_files/hash_file_3":"8653b46d65998fa8c8846efa17937e742533ae48" - -RIPEMD160 Hash file #4 -mbedtls_ripemd160_file:"data_files/hash_file_4":"9c1185a5c5e9fc54612808977ee8f548b2258d31" - MD2 Selftest md2_selftest: diff --git a/tests/suites/test_suite_mdx.function b/tests/suites/test_suite_mdx.function index 3959ffd3e..3d233638b 100644 --- a/tests/suites/test_suite_mdx.function +++ b/tests/suites/test_suite_mdx.function @@ -85,70 +85,6 @@ void ripemd160_text( char *text_src_string, char *hex_hash_string ) } /* END_CASE */ -/* BEGIN_CASE depends_on:MBEDTLS_MD2_C:MBEDTLS_FS_IO */ -void mbedtls_md2_file( char *filename, char *hex_hash_string ) -{ - unsigned char hash_str[33]; - unsigned char output[16]; - - memset( hash_str, 0x00, sizeof hash_str ); - memset( output, 0x00, sizeof output ); - - mbedtls_md2_file( filename, output); - hexify( hash_str, output, sizeof output ); - - TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); -} -/* END_CASE */ - -/* BEGIN_CASE depends_on:MBEDTLS_MD4_C:MBEDTLS_FS_IO */ -void mbedtls_md4_file( char *filename, char *hex_hash_string ) -{ - unsigned char hash_str[33]; - unsigned char output[16]; - - memset( hash_str, 0x00, sizeof hash_str ); - memset( output, 0x00, sizeof output ); - - mbedtls_md4_file( filename, output); - hexify( hash_str, output, sizeof output ); - - TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); -} -/* END_CASE */ - -/* BEGIN_CASE depends_on:MBEDTLS_MD5_C:MBEDTLS_FS_IO */ -void mbedtls_md5_file( char *filename, char *hex_hash_string ) -{ - unsigned char hash_str[33]; - unsigned char output[16]; - - memset( hash_str, 0x00, sizeof hash_str ); - memset( output, 0x00, sizeof output ); - - mbedtls_md5_file( filename, output); - hexify( hash_str, output, sizeof output ); - - TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); -} -/* END_CASE */ - -/* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C:MBEDTLS_FS_IO */ -void mbedtls_ripemd160_file( char *filename, char *hex_hash_string ) -{ - unsigned char hash_str[41]; - unsigned char output[20]; - - memset(hash_str, 0x00, sizeof hash_str ); - memset(output, 0x00, sizeof output ); - - mbedtls_ripemd160_file( filename, output); - hexify( hash_str, output, sizeof output ); - - TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); -} -/* END_CASE */ - /* BEGIN_CASE depends_on:MBEDTLS_MD2_C:MBEDTLS_SELF_TEST */ void md2_selftest() { diff --git a/tests/suites/test_suite_shax.data b/tests/suites/test_suite_shax.data index c5c5acf1c..ea2a18380 100644 --- a/tests/suites/test_suite_shax.data +++ b/tests/suites/test_suite_shax.data @@ -158,86 +158,6 @@ SHA-512 Test Vector NIST CAVS #8 depends_on:MBEDTLS_SHA512_C mbedtls_sha512:"990d1ae71a62d7bda9bfdaa1762a68d296eee72a4cd946f287a898fbabc002ea941fd8d4d991030b4d27a637cce501a834bb95eab1b7889a3e784c7968e67cbf552006b206b68f76d9191327524fcc251aeb56af483d10b4e0c6c5e599ee8c0fe4faeca8293844a8547c6a9a90d093f2526873a19ad4a5e776794c68c742fb834793d2dfcb7fea46c63af4b70fd11cb6e41834e72ee40edb067b292a794990c288d5007e73f349fb383af6a756b8301ad6e5e0aa8cd614399bb3a452376b1575afa6bdaeaafc286cb064bb91edef97c632b6c1113d107fa93a0905098a105043c2f05397f702514439a08a9e5ddc196100721d45c8fc17d2ed659376f8a00bd5cb9a0860e26d8a29d8d6aaf52de97e9346033d6db501a35dbbaf97c20b830cd2d18c2532f3a59cc497ee64c0e57d8d060e5069b28d86edf1adcf59144b221ce3ddaef134b3124fbc7dd000240eff0f5f5f41e83cd7f5bb37c9ae21953fe302b0f6e8b68fa91c6ab99265c64b2fd9cd4942be04321bb5d6d71932376c6f2f88e02422ba6a5e2cb765df93fd5dd0728c6abdaf03bce22e0678a544e2c3636f741b6f4447ee58a8fc656b43ef817932176adbfc2e04b2c812c273cd6cbfa4098f0be036a34221fa02643f5ee2e0b38135f2a18ecd2f16ebc45f8eb31b8ab967a1567ee016904188910861ca1fa205c7adaa194b286893ffe2f4fbe0384c2aef72a4522aeafd3ebc71f9db71eeeef86c48394a1c86d5b36c352cc33a0a2c800bc99e62fd65b3a2fd69e0b53996ec13d8ce483ce9319efd9a85acefabdb5342226febb83fd1daf4b24265f50c61c6de74077ef89b6fecf9f29a1f871af1e9f89b2d345cda7499bd45c42fa5d195a1e1a6ba84851889e730da3b2b916e96152ae0c92154b49719841db7e7cc707ba8a5d7b101eb4ac7b629bb327817910fff61580b59aab78182d1a2e33473d05b00b170b29e331870826cfe45af206aa7d0246bbd8566ca7cfb2d3c10bfa1db7dd48dd786036469ce7282093d78b5e1a5b0fc81a54c8ed4ceac1e5305305e78284ac276f5d7862727aff246e17addde50c670028d572cbfc0be2e4f8b2eb28fa68ad7b4c6c2a239c460441bfb5ea049f23b08563b4e47729a59e5986a61a6093dbd54f8c36ebe87edae01f251cb060ad1364ce677d7e8d5a4a4ca966a7241cc360bc2acb280e5f9e9c1b032ad6a180a35e0c5180b9d16d026c865b252098cc1d99ba7375ca31c7702c0d943d5e3dd2f6861fa55bd46d94b67ed3e52eccd8dd06d968e01897d6de97ed3058d91dd":"8e4bc6f8b8c60fe4d68c61d9b159c8693c3151c46749af58da228442d927f23359bd6ccd6c2ec8fa3f00a86cecbfa728e1ad60b821ed22fcd309ba91a4138bc9" -SHA1 Hash file #1 -depends_on:MBEDTLS_SHA1_C -mbedtls_sha1_file:"data_files/hash_file_1":"d21c965b1e768bd7a6aa6869f5f821901d255f9f" - -SHA1 Hash file #2 -depends_on:MBEDTLS_SHA1_C -mbedtls_sha1_file:"data_files/hash_file_2":"353f34271f2aef49d23a8913d4a6bd82b2cecdc6" - -SHA1 Hash file #3 -depends_on:MBEDTLS_SHA1_C -mbedtls_sha1_file:"data_files/hash_file_3":"93640ed592076328096270c756db2fba9c486b35" - -SHA1 Hash file #4 -depends_on:MBEDTLS_SHA1_C -mbedtls_sha1_file:"data_files/hash_file_4":"da39a3ee5e6b4b0d3255bfef95601890afd80709" - -SHA-224 Hash file #1 -depends_on:MBEDTLS_SHA256_C -sha224_file:"data_files/hash_file_1":"8606da018870f0c16834a21bc3385704cb1683b9dbab04c5ddb90a48" - -SHA-224 Hash file #2 -depends_on:MBEDTLS_SHA256_C -sha224_file:"data_files/hash_file_2":"733b2ab97b6f63f2e29b9a2089756d81e14c93fe4cc9615c0d5e8a03" - -SHA-224 Hash file #3 -depends_on:MBEDTLS_SHA256_C -sha224_file:"data_files/hash_file_3":"e1df95867580e2cc2100e9565bf9c2e42c24fe5250c19efe33d1c4fe" - -SHA-224 Hash file #4 -depends_on:MBEDTLS_SHA256_C -sha224_file:"data_files/hash_file_4":"d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f" - -SHA-256 Hash file #1 -depends_on:MBEDTLS_SHA256_C -mbedtls_sha256_file:"data_files/hash_file_1":"975d0c620d3936886f8a3665e585a3e84aa0501f4225bf53029710242823e391" - -SHA-256 Hash file #2 -depends_on:MBEDTLS_SHA256_C -mbedtls_sha256_file:"data_files/hash_file_2":"11fcbf1baa36ca45745f10cc5467aee86f066f80ba2c46806d876bf783022ad2" - -SHA-256 Hash file #3 -depends_on:MBEDTLS_SHA256_C -mbedtls_sha256_file:"data_files/hash_file_3":"9ae4b369f9f4f03b86505b46a5469542e00aaff7cf7417a71af6d6d0aba3b70c" - -SHA-256 Hash file #4 -depends_on:MBEDTLS_SHA256_C -mbedtls_sha256_file:"data_files/hash_file_4":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - -SHA-384 Hash file #1 -depends_on:MBEDTLS_SHA512_C -sha384_file:"data_files/hash_file_1":"e0a3e6259d6378001b54ef82f5dd087009c5fad86d8db226a9fe1d14ecbe33a6fc916e3a4b16f5f286424de15d5a8e0e" - -SHA-384 Hash file #2 -depends_on:MBEDTLS_SHA512_C -sha384_file:"data_files/hash_file_2":"eff727afc8495c92e2f370f97a317f93c3350324b0646b0f0e264708b3c97d3d332d3c5390e1e47130f5c92f1ef4b9cf" - -SHA-384 Hash file #3 -depends_on:MBEDTLS_SHA512_C -sha384_file:"data_files/hash_file_3":"6fc10ebda96a1ccf61777cac72f6034f92533d42052a4bf9f9d929c672973c71e5aeb1213268043c21527ac0f7f349c4" - -SHA-384 Hash file #4 -depends_on:MBEDTLS_SHA512_C -sha384_file:"data_files/hash_file_4":"38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b" - -SHA-512 Hash file #1 -depends_on:MBEDTLS_SHA512_C -mbedtls_sha512_file:"data_files/hash_file_1":"d8207a2e1ff2b424f2c4163fe1b723c9bd42e464061eb411e8df730bcd24a7ab3956a6f3ff044a52eb2d262f9e4ca6b524092b544ab78f14d6f9c4cc8ddf335a" - -SHA-512 Hash file #2 -depends_on:MBEDTLS_SHA512_C -mbedtls_sha512_file:"data_files/hash_file_2":"ecbb7f0ed8a702b49f16ad3088bcc06ea93451912a7187db15f64d93517b09630b039293aed418d4a00695777b758b1f381548c2fd7b92ce5ed996b32c8734e7" - -SHA-512 Hash file #3 -depends_on:MBEDTLS_SHA512_C -mbedtls_sha512_file:"data_files/hash_file_3":"7ccc9b2da71ffde9966c3ce44d7f20945fccf33b1fade4da152b021f1afcc7293382944aa6c09eac67af25f22026758e2bf6bed86ae2a43592677ee50f8eea41" - -SHA-512 Hash file #4 -depends_on:MBEDTLS_SHA512_C -mbedtls_sha512_file:"data_files/hash_file_4":"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" - SHA-1 Selftest depends_on:MBEDTLS_SELF_TEST:MBEDTLS_SHA1_C sha1_selftest: diff --git a/tests/suites/test_suite_shax.function b/tests/suites/test_suite_shax.function index 8368a2c93..ec326fcc9 100644 --- a/tests/suites/test_suite_shax.function +++ b/tests/suites/test_suite_shax.function @@ -109,86 +109,6 @@ void mbedtls_sha512(char *hex_src_string, char *hex_hash_string ) } /* END_CASE */ -/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_FS_IO */ -void mbedtls_sha1_file( char *filename, char *hex_hash_string ) -{ - unsigned char hash_str[41]; - unsigned char output[21]; - - memset(hash_str, 0x00, 41); - memset(output, 0x00, 21); - - mbedtls_sha1_file( filename, output); - hexify( hash_str, output, 20 ); - - TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); -} -/* END_CASE */ - -/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_FS_IO */ -void sha224_file( char *filename, char *hex_hash_string ) -{ - unsigned char hash_str[57]; - unsigned char output[29]; - - memset(hash_str, 0x00, 57); - memset(output, 0x00, 29); - - mbedtls_sha256_file( filename, output, 1); - hexify( hash_str, output, 28 ); - - TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); -} -/* END_CASE */ - -/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_FS_IO */ -void mbedtls_sha256_file( char *filename, char *hex_hash_string ) -{ - unsigned char hash_str[65]; - unsigned char output[33]; - - memset(hash_str, 0x00, 65); - memset(output, 0x00, 33); - - mbedtls_sha256_file( filename, output, 0); - hexify( hash_str, output, 32 ); - - TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); -} -/* END_CASE */ - -/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_FS_IO */ -void sha384_file( char *filename, char *hex_hash_string ) -{ - unsigned char hash_str[97]; - unsigned char output[49]; - - memset(hash_str, 0x00, 97); - memset(output, 0x00, 49); - - mbedtls_sha512_file( filename, output, 1); - hexify( hash_str, output, 48 ); - - TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); -} -/* END_CASE */ - -/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_FS_IO */ -void mbedtls_sha512_file( char *filename, char *hex_hash_string ) -{ - unsigned char hash_str[129]; - unsigned char output[65]; - - memset(hash_str, 0x00, 129); - memset(output, 0x00, 65); - - mbedtls_sha512_file( filename, output, 0); - hexify( hash_str, output, 64 ); - - TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); -} -/* END_CASE */ - /* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */ void sha1_selftest() {