1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

- Functions requiring File System functions can now be disables by undefining POLARSSL_FS_IO

This commit is contained in:
Paul Bakker
2011-04-25 15:28:35 +00:00
parent 15566e4396
commit 335db3f121
26 changed files with 306 additions and 152 deletions

View File

@ -407,6 +407,7 @@ cleanup:
return( ret );
}
#if defined(POLARSSL_FS_IO)
/*
* Read X from an opened file
*/
@ -468,6 +469,7 @@ cleanup:
return( ret );
}
#endif /* POLARSSL_FS_IO */
/*
* Import X from unsigned binary data, big endian

View File

@ -225,7 +225,14 @@ int md_file( const md_info_t *md_info, const char *path, unsigned char *output )
if( md_info == NULL )
return 3;
#if defined(POLARSSL_FS_IO)
return md_info->file_func( path, output );
#else
((void) path);
((void) output);
return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
#endif
}
int md_hmac_starts( md_context_t *ctx, const unsigned char *key, size_t keylen )

View File

@ -35,7 +35,9 @@
#include "polarssl/md2.h"
#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
#include <stdio.h>
#endif
static const unsigned char PI_SUBST[256] =
{
@ -175,6 +177,7 @@ void md2( const unsigned char *input, size_t ilen, unsigned char output[16] )
memset( &ctx, 0, sizeof( md2_context ) );
}
#if defined(POLARSSL_FS_IO)
/*
* output = MD2( file contents )
*/
@ -206,6 +209,7 @@ int md2_file( const char *path, unsigned char output[16] )
fclose( f );
return( 0 );
}
#endif /* POLARSSL_FS_IO */
/*
* MD2 HMAC context setup

View File

@ -35,7 +35,9 @@
#include "polarssl/md4.h"
#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
#include <stdio.h>
#endif
/*
* 32-bit integer manipulation macros (little endian)
@ -271,6 +273,7 @@ void md4( const unsigned char *input, size_t ilen, unsigned char output[16] )
memset( &ctx, 0, sizeof( md4_context ) );
}
#if defined(POLARSSL_FS_IO)
/*
* output = MD4( file contents )
*/
@ -302,6 +305,7 @@ int md4_file( const char *path, unsigned char output[16] )
fclose( f );
return( 0 );
}
#endif /* POLARSSL_FS_IO */
/*
* MD4 HMAC context setup

View File

@ -34,7 +34,9 @@
#include "polarssl/md5.h"
#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
#include <stdio.h>
#endif
/*
* 32-bit integer manipulation macros (little endian)
@ -290,6 +292,7 @@ void md5( const unsigned char *input, size_t ilen, unsigned char output[16] )
memset( &ctx, 0, sizeof( md5_context ) );
}
#if defined(POLARSSL_FS_IO)
/*
* output = MD5( file contents )
*/
@ -321,6 +324,7 @@ int md5_file( const char *path, unsigned char output[16] )
fclose( f );
return( 0 );
}
#endif /* POLARSSL_FS_IO */
/*
* MD5 HMAC context setup

View File

@ -58,6 +58,17 @@ static void md2_finish_wrap( void *ctx, unsigned char *output )
md2_finish( (md2_context *) ctx, output );
}
int md2_file_wrap( const char *path, unsigned char *output )
{
#if defined(POLARSSL_FS_IO)
return md2_file( path, output );
#else
((void) path);
((void) output);
return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
#endif
}
static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
{
md2_hmac_starts( (md2_context *) ctx, key, keylen );
@ -96,7 +107,7 @@ const md_info_t md2_info = {
md2_update_wrap,
md2_finish_wrap,
md2,
md2_file,
md2_file_wrap,
md2_hmac_starts_wrap,
md2_hmac_update_wrap,
md2_hmac_finish_wrap,
@ -125,6 +136,17 @@ void md4_finish_wrap( void *ctx, unsigned char *output )
md4_finish( (md4_context *) ctx, output );
}
int md4_file_wrap( const char *path, unsigned char *output )
{
#if defined(POLARSSL_FS_IO)
return md4_file( path, output );
#else
((void) path);
((void) output);
return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
#endif
}
void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
{
md4_hmac_starts( (md4_context *) ctx, key, keylen );
@ -163,7 +185,7 @@ const md_info_t md4_info = {
md4_update_wrap,
md4_finish_wrap,
md4,
md4_file,
md4_file_wrap,
md4_hmac_starts_wrap,
md4_hmac_update_wrap,
md4_hmac_finish_wrap,
@ -192,6 +214,17 @@ static void md5_finish_wrap( void *ctx, unsigned char *output )
md5_finish( (md5_context *) ctx, output );
}
int md5_file_wrap( const char *path, unsigned char *output )
{
#if defined(POLARSSL_FS_IO)
return md5_file( path, output );
#else
((void) path);
((void) output);
return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
#endif
}
static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
{
md5_hmac_starts( (md5_context *) ctx, key, keylen );
@ -230,7 +263,7 @@ const md_info_t md5_info = {
md5_update_wrap,
md5_finish_wrap,
md5,
md5_file,
md5_file_wrap,
md5_hmac_starts_wrap,
md5_hmac_update_wrap,
md5_hmac_finish_wrap,
@ -259,6 +292,17 @@ void sha1_finish_wrap( void *ctx, unsigned char *output )
sha1_finish( (sha1_context *) ctx, output );
}
int sha1_file_wrap( const char *path, unsigned char *output )
{
#if defined(POLARSSL_FS_IO)
return sha1_file( path, output );
#else
((void) path);
((void) output);
return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
#endif
}
void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
{
sha1_hmac_starts( (sha1_context *) ctx, key, keylen );
@ -297,7 +341,7 @@ const md_info_t sha1_info = {
sha1_update_wrap,
sha1_finish_wrap,
sha1,
sha1_file,
sha1_file_wrap,
sha1_hmac_starts_wrap,
sha1_hmac_update_wrap,
sha1_hmac_finish_wrap,
@ -337,7 +381,13 @@ void sha224_wrap( const unsigned char *input, size_t ilen,
int sha224_file_wrap( const char *path, unsigned char *output )
{
#if defined(POLARSSL_FS_IO)
return sha2_file( path, output, 1 );
#else
((void) path);
((void) output);
return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
#endif
}
void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
@ -418,7 +468,13 @@ void sha256_wrap( const unsigned char *input, size_t ilen,
int sha256_file_wrap( const char *path, unsigned char *output )
{
#if defined(POLARSSL_FS_IO)
return sha2_file( path, output, 0 );
#else
((void) path);
((void) output);
return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
#endif
}
void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
@ -503,7 +559,13 @@ void sha384_wrap( const unsigned char *input, size_t ilen,
int sha384_file_wrap( const char *path, unsigned char *output )
{
#if defined(POLARSSL_FS_IO)
return sha4_file( path, output, 1 );
#else
((void) path);
((void) output);
return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
#endif
}
void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
@ -584,7 +646,13 @@ void sha512_wrap( const unsigned char *input, size_t ilen,
int sha512_file_wrap( const char *path, unsigned char *output )
{
#if defined(POLARSSL_FS_IO)
return sha4_file( path, output, 0 );
#else
((void) path);
((void) output);
return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
#endif
}
void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )

View File

@ -34,7 +34,9 @@
#include "polarssl/sha1.h"
#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
#include <stdio.h>
#endif
/*
* 32-bit integer manipulation macros (big endian)
@ -325,6 +327,7 @@ void sha1( const unsigned char *input, size_t ilen, unsigned char output[20] )
memset( &ctx, 0, sizeof( sha1_context ) );
}
#if defined(POLARSSL_FS_IO)
/*
* output = SHA-1( file contents )
*/
@ -356,6 +359,7 @@ int sha1_file( const char *path, unsigned char output[20] )
fclose( f );
return( 0 );
}
#endif /* POLARSSL_FS_IO */
/*
* SHA-1 HMAC context setup

View File

@ -34,7 +34,9 @@
#include "polarssl/sha2.h"
#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
#include <stdio.h>
#endif
/*
* 32-bit integer manipulation macros (big endian)
@ -327,6 +329,7 @@ void sha2( const unsigned char *input, size_t ilen,
memset( &ctx, 0, sizeof( sha2_context ) );
}
#if defined(POLARSSL_FS_IO)
/*
* output = SHA-256( file contents )
*/
@ -358,6 +361,7 @@ int sha2_file( const char *path, unsigned char output[32], int is224 )
fclose( f );
return( 0 );
}
#endif /* POLARSSL_FS_IO */
/*
* SHA-256 HMAC context setup

View File

@ -34,7 +34,9 @@
#include "polarssl/sha4.h"
#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
#include <stdio.h>
#endif
/*
* 64-bit integer manipulation macros (big endian)
@ -325,6 +327,7 @@ void sha4( const unsigned char *input, size_t ilen,
memset( &ctx, 0, sizeof( sha4_context ) );
}
#if defined(POLARSSL_FS_IO)
/*
* output = SHA-512( file contents )
*/
@ -356,6 +359,7 @@ int sha4_file( const char *path, unsigned char output[64], int is384 )
fclose( f );
return( 0 );
}
#endif /* POLARSSL_FS_IO */
/*
* SHA-512 HMAC context setup

View File

@ -51,9 +51,12 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#endif
/*
* ASN.1 DER decoding routines
*/
@ -1739,6 +1742,7 @@ int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen )
return( 0 );
}
#if defined(POLARSSL_FS_IO)
/*
* Load all data from a file into a given buffer.
*/
@ -1810,6 +1814,51 @@ int x509parse_crlfile( x509_crl *chain, const char *path )
return( ret );
}
/*
* Load and parse a private RSA key
*/
int x509parse_keyfile( rsa_context *rsa, const char *path, const char *pwd )
{
int ret;
size_t n;
unsigned char *buf;
if ( load_file( path, &buf, &n ) )
return( 1 );
if( pwd == NULL )
ret = x509parse_key( rsa, buf, (int) n, NULL, 0 );
else
ret = x509parse_key( rsa, buf, (int) n,
(unsigned char *) pwd, strlen( pwd ) );
memset( buf, 0, n + 1 );
free( buf );
return( ret );
}
/*
* Load and parse a public RSA key
*/
int x509parse_public_keyfile( rsa_context *rsa, const char *path )
{
int ret;
size_t n;
unsigned char *buf;
if ( load_file( path, &buf, &n ) )
return( 1 );
ret = x509parse_public_key( rsa, buf, (int) n );
memset( buf, 0, n + 1 );
free( buf );
return( ret );
}
#endif /* POLARSSL_FS_IO */
/*
* Parse a private RSA key
*/
@ -1935,30 +1984,6 @@ int x509parse_key( rsa_context *rsa, const unsigned char *key, size_t keylen,
return( 0 );
}
/*
* Load and parse a private RSA key
*/
int x509parse_keyfile( rsa_context *rsa, const char *path, const char *pwd )
{
int ret;
size_t n;
unsigned char *buf;
if ( load_file( path, &buf, &n ) )
return( 1 );
if( pwd == NULL )
ret = x509parse_key( rsa, buf, (int) n, NULL, 0 );
else
ret = x509parse_key( rsa, buf, (int) n,
(unsigned char *) pwd, strlen( pwd ) );
memset( buf, 0, n + 1 );
free( buf );
return( ret );
}
/*
* Parse a public RSA key
*/
@ -2050,26 +2075,6 @@ int x509parse_public_key( rsa_context *rsa, const unsigned char *key, size_t key
return( 0 );
}
/*
* Load and parse a public RSA key
*/
int x509parse_public_keyfile( rsa_context *rsa, const char *path )
{
int ret;
size_t n;
unsigned char *buf;
if ( load_file( path, &buf, &n ) )
return( 1 );
ret = x509parse_public_key( rsa, buf, (int) n );
memset( buf, 0, n + 1 );
free( buf );
return( ret );
}
#if defined(POLARSSL_DHM_C)
/*
* Parse DHM parameters
@ -2154,6 +2159,7 @@ int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen
return( 0 );
}
#if defined(POLARSSL_FS_IO)
/*
* Load and parse a private RSA key
*/
@ -2173,6 +2179,7 @@ int x509parse_dhmfile( dhm_context *dhm, const char *path )
return( ret );
}
#endif /* POLARSSL_FS_IO */
#endif /* POLARSSL_DHM_C */
#if defined _MSC_VER && !defined snprintf