- Functions requiring File System functions can now be disables by undefining POLARSSL_FS_IO
diff --git a/library/bignum.c b/library/bignum.c
index a2b132d..8f29324 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -407,6 +407,7 @@
return( ret );
}
+#if defined(POLARSSL_FS_IO)
/*
* Read X from an opened file
*/
@@ -468,6 +469,7 @@
return( ret );
}
+#endif /* POLARSSL_FS_IO */
/*
* Import X from unsigned binary data, big endian
diff --git a/library/md.c b/library/md.c
index dcdf7c9..cb720bb 100644
--- a/library/md.c
+++ b/library/md.c
@@ -225,7 +225,14 @@
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 )
diff --git a/library/md2.c b/library/md2.c
index 4daea58..de64d70 100644
--- a/library/md2.c
+++ b/library/md2.c
@@ -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 @@
memset( &ctx, 0, sizeof( md2_context ) );
}
+#if defined(POLARSSL_FS_IO)
/*
* output = MD2( file contents )
*/
@@ -206,6 +209,7 @@
fclose( f );
return( 0 );
}
+#endif /* POLARSSL_FS_IO */
/*
* MD2 HMAC context setup
diff --git a/library/md4.c b/library/md4.c
index 3694899..2b5fcff 100644
--- a/library/md4.c
+++ b/library/md4.c
@@ -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 @@
memset( &ctx, 0, sizeof( md4_context ) );
}
+#if defined(POLARSSL_FS_IO)
/*
* output = MD4( file contents )
*/
@@ -302,6 +305,7 @@
fclose( f );
return( 0 );
}
+#endif /* POLARSSL_FS_IO */
/*
* MD4 HMAC context setup
diff --git a/library/md5.c b/library/md5.c
index f379992..a7faa8d 100644
--- a/library/md5.c
+++ b/library/md5.c
@@ -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 @@
memset( &ctx, 0, sizeof( md5_context ) );
}
+#if defined(POLARSSL_FS_IO)
/*
* output = MD5( file contents )
*/
@@ -321,6 +324,7 @@
fclose( f );
return( 0 );
}
+#endif /* POLARSSL_FS_IO */
/*
* MD5 HMAC context setup
diff --git a/library/md_wrap.c b/library/md_wrap.c
index bb87c63..64d8bb6 100644
--- a/library/md_wrap.c
+++ b/library/md_wrap.c
@@ -58,6 +58,17 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 )
diff --git a/library/sha1.c b/library/sha1.c
index 5f62583..b65ab24 100644
--- a/library/sha1.c
+++ b/library/sha1.c
@@ -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 @@
memset( &ctx, 0, sizeof( sha1_context ) );
}
+#if defined(POLARSSL_FS_IO)
/*
* output = SHA-1( file contents )
*/
@@ -356,6 +359,7 @@
fclose( f );
return( 0 );
}
+#endif /* POLARSSL_FS_IO */
/*
* SHA-1 HMAC context setup
diff --git a/library/sha2.c b/library/sha2.c
index 64ebc43..385c048 100644
--- a/library/sha2.c
+++ b/library/sha2.c
@@ -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 @@
memset( &ctx, 0, sizeof( sha2_context ) );
}
+#if defined(POLARSSL_FS_IO)
/*
* output = SHA-256( file contents )
*/
@@ -358,6 +361,7 @@
fclose( f );
return( 0 );
}
+#endif /* POLARSSL_FS_IO */
/*
* SHA-256 HMAC context setup
diff --git a/library/sha4.c b/library/sha4.c
index bbb3108..e023237 100644
--- a/library/sha4.c
+++ b/library/sha4.c
@@ -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 @@
memset( &ctx, 0, sizeof( sha4_context ) );
}
+#if defined(POLARSSL_FS_IO)
/*
* output = SHA-512( file contents )
*/
@@ -356,6 +359,7 @@
fclose( f );
return( 0 );
}
+#endif /* POLARSSL_FS_IO */
/*
* SHA-512 HMAC context setup
diff --git a/library/x509parse.c b/library/x509parse.c
index c6a9245..3a67539 100644
--- a/library/x509parse.c
+++ b/library/x509parse.c
@@ -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 @@
return( 0 );
}
+#if defined(POLARSSL_FS_IO)
/*
* Load all data from a file into a given buffer.
*/
@@ -1811,6 +1815,51 @@
}
/*
+ * 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
*/
int x509parse_key( rsa_context *rsa, const unsigned char *key, size_t keylen,
@@ -1936,30 +1985,6 @@
}
/*
- * 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
*/
int x509parse_public_key( rsa_context *rsa, const unsigned char *key, size_t keylen )
@@ -2050,26 +2075,6 @@
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 @@
return( 0 );
}
+#if defined(POLARSSL_FS_IO)
/*
* Load and parse a private RSA key
*/
@@ -2173,6 +2179,7 @@
return( ret );
}
+#endif /* POLARSSL_FS_IO */
#endif /* POLARSSL_DHM_C */
#if defined _MSC_VER && !defined snprintf