From fa6a620b752fde66be4abbaf10b8f6e54a57ed8e Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Mon, 28 Oct 2013 18:48:30 +0100 Subject: [PATCH] Defines for UEFI environment under MSVC added --- ChangeLog | 1 + include/polarssl/aes.h | 2 +- include/polarssl/bignum.h | 2 +- include/polarssl/blowfish.h | 2 +- include/polarssl/camellia.h | 2 +- include/polarssl/compat-1.2.h | 9 ++++++++- include/polarssl/des.h | 2 +- include/polarssl/gcm.h | 2 +- include/polarssl/md4.h | 2 +- include/polarssl/md5.h | 2 +- include/polarssl/padlock.h | 2 +- include/polarssl/pbkdf2.h | 2 +- include/polarssl/pkcs5.h | 2 +- include/polarssl/sha1.h | 2 +- include/polarssl/sha256.h | 2 +- include/polarssl/xtea.h | 2 +- library/base64.c | 2 +- library/cipher.c | 2 +- library/debug.c | 8 ++++++-- library/entropy_poll.c | 2 +- library/error.c | 2 +- library/md.c | 4 ++-- library/net.c | 36 ++++++++++++++++++++++++----------- library/oid.c | 2 +- library/ssl_ciphersuites.c | 2 +- library/ssl_cli.c | 2 +- library/ssl_tls.c | 2 +- library/timing.c | 9 +++++---- library/x509.c | 10 +++++++--- library/x509_crl.c | 7 ++++--- library/x509_crt.c | 10 +++++++--- library/x509_csr.c | 4 ++-- scripts/data_files/error.fmt | 6 +++++- 33 files changed, 94 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index bcbd7c008..eca895dba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,7 @@ Bugfix * Const correctness * cert_write with selfsign should use issuer_name as subject_name * Fix ECDSA corner case: missing reduction mod N (found by DualTachyon) + * Defines to handle UEFI environment under MSVC = PolarSSL 1.3.1 released on 2013-10-15 Features diff --git a/include/polarssl/aes.h b/include/polarssl/aes.h index 27ba37380..1b93e2a3d 100644 --- a/include/polarssl/aes.h +++ b/include/polarssl/aes.h @@ -31,7 +31,7 @@ #include -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/include/polarssl/bignum.h b/include/polarssl/bignum.h index c4680a7a4..9bed027d9 100644 --- a/include/polarssl/bignum.h +++ b/include/polarssl/bignum.h @@ -32,7 +32,7 @@ #include "config.h" -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include #if (_MSC_VER <= 1200) typedef signed short int16_t; diff --git a/include/polarssl/blowfish.h b/include/polarssl/blowfish.h index f8d79c56f..45b138764 100644 --- a/include/polarssl/blowfish.h +++ b/include/polarssl/blowfish.h @@ -31,7 +31,7 @@ #include -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/include/polarssl/camellia.h b/include/polarssl/camellia.h index 4ce10dc41..c98512f3d 100644 --- a/include/polarssl/camellia.h +++ b/include/polarssl/camellia.h @@ -31,7 +31,7 @@ #include -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/include/polarssl/compat-1.2.h b/include/polarssl/compat-1.2.h index ce4566cf0..3e9c396dc 100644 --- a/include/polarssl/compat-1.2.h +++ b/include/polarssl/compat-1.2.h @@ -32,7 +32,14 @@ // Comment out to disable prototype change warnings #define SHOW_PROTOTYPE_CHANGE_WARNINGS -#if defined _MSC_VER +#if defined(_MSC_VER) && !defined(inline) +#define inline _inline +#else +#if defined(__ARMCC_VERSION) && !defined(inline) +#define inline __inline +#endif /* __ARMCC_VERSION */ + +#if defined(_MSC_VER) // MSVC does not support #warning #undef SHOW_PROTOTYPE_CHANGE_WARNINGS #endif diff --git a/include/polarssl/des.h b/include/polarssl/des.h index 74d5acb12..d29bd1dee 100644 --- a/include/polarssl/des.h +++ b/include/polarssl/des.h @@ -31,7 +31,7 @@ #include -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/include/polarssl/gcm.h b/include/polarssl/gcm.h index 279e84ba5..e4267c645 100644 --- a/include/polarssl/gcm.h +++ b/include/polarssl/gcm.h @@ -29,7 +29,7 @@ #include "cipher.h" -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; typedef UINT64 uint64_t; diff --git a/include/polarssl/md4.h b/include/polarssl/md4.h index a5c9142e9..a1b5d459e 100644 --- a/include/polarssl/md4.h +++ b/include/polarssl/md4.h @@ -31,7 +31,7 @@ #include -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/include/polarssl/md5.h b/include/polarssl/md5.h index 87474a79d..df2a61b8a 100644 --- a/include/polarssl/md5.h +++ b/include/polarssl/md5.h @@ -31,7 +31,7 @@ #include -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/include/polarssl/padlock.h b/include/polarssl/padlock.h index 9df75cc7d..8df93c034 100644 --- a/include/polarssl/padlock.h +++ b/include/polarssl/padlock.h @@ -37,7 +37,7 @@ #define POLARSSL_HAVE_X86 #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef INT32 int32_t; #else diff --git a/include/polarssl/pbkdf2.h b/include/polarssl/pbkdf2.h index e2e61b5f1..5ccb2fa9f 100644 --- a/include/polarssl/pbkdf2.h +++ b/include/polarssl/pbkdf2.h @@ -34,7 +34,7 @@ #include "md.h" -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/include/polarssl/pkcs5.h b/include/polarssl/pkcs5.h index dfff381fb..34e824b73 100644 --- a/include/polarssl/pkcs5.h +++ b/include/polarssl/pkcs5.h @@ -34,7 +34,7 @@ #include "asn1.h" #include "md.h" -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/include/polarssl/sha1.h b/include/polarssl/sha1.h index 1c18f8aab..e1d8e27ca 100644 --- a/include/polarssl/sha1.h +++ b/include/polarssl/sha1.h @@ -31,7 +31,7 @@ #include -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/include/polarssl/sha256.h b/include/polarssl/sha256.h index 7d964b810..89df578e9 100644 --- a/include/polarssl/sha256.h +++ b/include/polarssl/sha256.h @@ -31,7 +31,7 @@ #include -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/include/polarssl/xtea.h b/include/polarssl/xtea.h index 752199317..95854d122 100644 --- a/include/polarssl/xtea.h +++ b/include/polarssl/xtea.h @@ -31,7 +31,7 @@ #include -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/library/base64.c b/library/base64.c index e9527dbde..3b4376dac 100644 --- a/library/base64.c +++ b/library/base64.c @@ -29,7 +29,7 @@ #include "polarssl/base64.h" -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/library/cipher.c b/library/cipher.c index 3ed6830c8..277811a70 100644 --- a/library/cipher.c +++ b/library/cipher.c @@ -44,7 +44,7 @@ #define POLARSSL_CIPHER_MODE_STREAM #endif -#if defined _MSC_VER && !defined strcasecmp +#if defined(_MSC_VER) && !defined strcasecmp #define strcasecmp _stricmp #endif diff --git a/library/debug.c b/library/debug.c index 2497a3be1..fb0ec719c 100644 --- a/library/debug.c +++ b/library/debug.c @@ -32,11 +32,15 @@ #include #include -#if defined _MSC_VER && !defined snprintf +#if defined(EFIX64) || defined(EFI32) +#include +#endif + +#if defined(_MSC_VER) && !defined snprintf #define snprintf _snprintf #endif -#if defined _MSC_VER && !defined vsnprintf +#if defined(_MSC_VER) && !defined vsnprintf #define vsnprintf _vsnprintf #endif diff --git a/library/entropy_poll.c b/library/entropy_poll.c index eec8ec465..badcfac5c 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -38,7 +38,7 @@ #endif #if !defined(POLARSSL_NO_PLATFORM_ENTROPY) -#if defined(_WIN32) +#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #if !defined(_WIN32_WINNT) #define _WIN32_WINNT 0x0400 diff --git a/library/error.c b/library/error.c index d17338a83..3f4bc9337 100644 --- a/library/error.c +++ b/library/error.c @@ -160,7 +160,7 @@ #include -#if defined _MSC_VER && !defined snprintf +#if defined(_MSC_VER) && !defined snprintf #define snprintf _snprintf #endif diff --git a/library/md.c b/library/md.c index 716c01611..073f9322a 100644 --- a/library/md.c +++ b/library/md.c @@ -36,8 +36,8 @@ #include -#if defined _MSC_VER && !defined strcasecmp -#define strcasecmp _stricmp +#if defined(_MSC_VER) && !defined strcasecmp +#define snprintf _stricmp #endif static const int supported_digests[] = { diff --git a/library/net.c b/library/net.c index 2ab12dfcc..be2785d98 100644 --- a/library/net.c +++ b/library/net.c @@ -29,7 +29,8 @@ #include "polarssl/net.h" -#if defined(_WIN32) || defined(_WIN32_WCE) +#if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(EFIX64) && \ + !defined(EFI32) #include #include @@ -64,7 +65,8 @@ static int wsa_init_done = 0; #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || \ defined(__DragonflyBSD__) #include -#elif defined(__APPLE__) || defined(HAVE_MACHINE_ENDIAN_H) +#elif defined(__APPLE__) || defined(HAVE_MACHINE_ENDIAN_H) || \ + defined(EFIX64) || defined(EFI32) #include #elif defined(sun) #include @@ -83,7 +85,7 @@ static int wsa_init_done = 0; #include #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else @@ -120,7 +122,9 @@ int net_connect( int *fd, const char *host, int port ) struct sockaddr_in server_addr; struct hostent *server_host; -#if defined(_WIN32) || defined(_WIN32_WCE) +#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ + !defined(EFI32) + WSADATA wsaData; if( wsa_init_done == 0 ) @@ -131,7 +135,9 @@ int net_connect( int *fd, const char *host, int port ) wsa_init_done = 1; } #else +#if !defined(EFIX64) && !defined(EFI32) signal( SIGPIPE, SIG_IGN ); +#endif #endif if( ( server_host = gethostbyname( host ) ) == NULL ) @@ -165,7 +171,8 @@ int net_bind( int *fd, const char *bind_ip, int port ) int n, c[4]; struct sockaddr_in server_addr; -#if defined(_WIN32) || defined(_WIN32_WCE) +#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ + !defined(EFI32) WSADATA wsaData; if( wsa_init_done == 0 ) @@ -176,7 +183,9 @@ int net_bind( int *fd, const char *bind_ip, int port ) wsa_init_done = 1; } #else +#if !defined(EFIX64) && !defined(EFI32) signal( SIGPIPE, SIG_IGN ); +#endif #endif if( ( *fd = (int) socket( AF_INET, SOCK_STREAM, IPPROTO_IP ) ) < 0 ) @@ -228,7 +237,8 @@ int net_bind( int *fd, const char *bind_ip, int port ) */ static int net_is_blocking( void ) { -#if defined(_WIN32) || defined(_WIN32_WCE) +#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ + !defined(EFI32) return( WSAGetLastError() == WSAEWOULDBLOCK ); #else switch( errno ) @@ -282,7 +292,8 @@ int net_accept( int bind_fd, int *client_fd, void *client_ip ) */ int net_set_block( int fd ) { -#if defined(_WIN32) || defined(_WIN32_WCE) +#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ + !defined(EFI32) u_long n = 0; return( ioctlsocket( fd, FIONBIO, &n ) ); #else @@ -292,7 +303,8 @@ int net_set_block( int fd ) int net_set_nonblock( int fd ) { -#if defined(_WIN32) || defined(_WIN32_WCE) +#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ + !defined(EFI32) u_long n = 1; return( ioctlsocket( fd, FIONBIO, &n ) ); #else @@ -317,7 +329,7 @@ void net_usleep( unsigned long usec ) * Read at most 'len' characters */ int net_recv( void *ctx, unsigned char *buf, size_t len ) -{ +{ int ret = read( *((int *) ctx), buf, len ); if( ret < 0 ) @@ -325,7 +337,8 @@ int net_recv( void *ctx, unsigned char *buf, size_t len ) if( net_is_blocking() != 0 ) return( POLARSSL_ERR_NET_WANT_READ ); -#if defined(_WIN32) || defined(_WIN32_WCE) +#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ + !defined(EFI32) if( WSAGetLastError() == WSAECONNRESET ) return( POLARSSL_ERR_NET_CONN_RESET ); #else @@ -354,7 +367,8 @@ int net_send( void *ctx, const unsigned char *buf, size_t len ) if( net_is_blocking() != 0 ) return( POLARSSL_ERR_NET_WANT_WRITE ); -#if defined(_WIN32) || defined(_WIN32_WCE) +#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \ + !defined(EFI32) if( WSAGetLastError() == WSAECONNRESET ) return( POLARSSL_ERR_NET_CONN_RESET ); #else diff --git a/library/oid.c b/library/oid.c index a4f2c0c2c..6efd51084 100644 --- a/library/oid.c +++ b/library/oid.c @@ -530,7 +530,7 @@ FN_OID_TYPED_FROM_ASN1(oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, oid_pkcs12_pbe_alg) FN_OID_GET_ATTR2(oid_get_pkcs12_pbe_alg, oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, md_type_t, md_alg, cipher_type_t, cipher_alg); #endif /* POLARSSL_PKCS12_C */ -#if defined _MSC_VER && !defined snprintf +#if defined(_MSC_VER) && !defined snprintf #include #if !defined vsnprintf diff --git a/library/ssl_ciphersuites.c b/library/ssl_ciphersuites.c index 1c9f80935..e1a86269c 100644 --- a/library/ssl_ciphersuites.c +++ b/library/ssl_ciphersuites.c @@ -34,7 +34,7 @@ #include -#if defined _MSC_VER && !defined strcasecmp +#if defined(_MSC_VER) && !defined strcasecmp #define strcasecmp _stricmp #endif diff --git a/library/ssl_cli.c b/library/ssl_cli.c index bb2afb262..ad6583ba5 100644 --- a/library/ssl_cli.c +++ b/library/ssl_cli.c @@ -40,7 +40,7 @@ #include #include -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) #include typedef UINT32 uint32_t; #else diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 4d654795c..c86e774ff 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -47,7 +47,7 @@ #include -#if defined _MSC_VER && !defined strcasecmp +#if defined(_MSC_VER) && !defined strcasecmp #define strcasecmp _stricmp #endif diff --git a/library/timing.c b/library/timing.c index 0273d1af8..1b4311cbc 100644 --- a/library/timing.c +++ b/library/timing.c @@ -29,7 +29,7 @@ #include "polarssl/timing.h" -#if defined(_WIN32) +#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #include #include @@ -172,14 +172,15 @@ unsigned long hardclock( void ) } #endif -#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(_MSC_VER) +#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(_MSC_VER) && \ + !defined(EFIX64) && !defined(EFI32) #define POLARSSL_HAVE_HARDCLOCK unsigned long hardclock( void ) { LARGE_INTEGER offset; - + QueryPerformanceCounter( &offset ); return (unsigned long)( offset.QuadPart ); @@ -211,7 +212,7 @@ unsigned long hardclock( void ) volatile int alarmed = 0; -#if defined(_WIN32) +#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) unsigned long get_timer( struct hr_time *val, int reset ) { diff --git a/library/x509.c b/library/x509.c index 677760e6c..27040b93a 100644 --- a/library/x509.c +++ b/library/x509.c @@ -54,12 +54,16 @@ #include #include -#if defined(_WIN32) +#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #include #else #include #endif +#if defined(EFIX64) || defined(EFI32) +#include +#endif + #if defined(POLARSSL_FS_IO) #include #if !defined(_WIN32) @@ -425,7 +429,7 @@ int x509_load_file( const char *path, unsigned char **buf, size_t *n ) } #endif /* POLARSSL_FS_IO */ -#if defined _MSC_VER && !defined snprintf +#if defined(_MSC_VER) && !defined snprintf #include #if !defined vsnprintf @@ -620,7 +624,7 @@ int x509_time_expired( const x509_time *to ) int year, mon, day; int hour, min, sec; -#if defined(_WIN32) +#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) SYSTEMTIME st; GetLocalTime(&st); diff --git a/library/x509_crl.c b/library/x509_crl.c index 00d51bdd8..90ceabd67 100644 --- a/library/x509_crl.c +++ b/library/x509_crl.c @@ -53,13 +53,14 @@ #include #include -#if defined(_WIN32) +#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) + #include #else #include #endif -#if defined(POLARSSL_FS_IO) +#if defined(POLARSSL_FS_IO) || defined(EFIX64) || defined(EFI32) #include #endif @@ -544,7 +545,7 @@ int x509_crl_parse_file( x509_crl *chain, const char *path ) } #endif /* POLARSSL_FS_IO */ -#if defined _MSC_VER && !defined snprintf +#if defined(_MSC_VER) && !defined snprintf #include #if !defined vsnprintf diff --git a/library/x509_crt.c b/library/x509_crt.c index 9eba14d32..9470132ba 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -53,12 +53,16 @@ #include #include -#if defined(_WIN32) +#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #include #else #include #endif +#if defined(EFIX64) || defined(EFI32) +#include +#endif + #if defined(POLARSSL_FS_IO) #include #if !defined(_WIN32) @@ -935,7 +939,7 @@ int x509_crt_parse_file( x509_crt *chain, const char *path ) int x509_crt_parse_path( x509_crt *chain, const char *path ) { int ret = 0; -#if defined(_WIN32) +#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) int w_ret; WCHAR szDir[MAX_PATH]; char filename[MAX_PATH]; @@ -1035,7 +1039,7 @@ int x509_crt_parse_path( x509_crt *chain, const char *path ) } #endif /* POLARSSL_FS_IO */ -#if defined _MSC_VER && !defined snprintf +#if defined(_MSC_VER) && !defined snprintf #include #if !defined vsnprintf diff --git a/library/x509_csr.c b/library/x509_csr.c index 8496f5b98..4dec9b934 100644 --- a/library/x509_csr.c +++ b/library/x509_csr.c @@ -54,7 +54,7 @@ #include #include -#if defined(POLARSSL_FS_IO) +#if defined(POLARSSL_FS_IO) || defined(EFIX64) || defined(EFI32) #include #endif @@ -302,7 +302,7 @@ int x509_csr_parse_file( x509_csr *csr, const char *path ) } #endif /* POLARSSL_FS_IO */ -#if defined _MSC_VER && !defined snprintf +#if defined(_MSC_VER) && !defined snprintf #include #if !defined vsnprintf diff --git a/scripts/data_files/error.fmt b/scripts/data_files/error.fmt index 61f63cf5a..98b5765c3 100644 --- a/scripts/data_files/error.fmt +++ b/scripts/data_files/error.fmt @@ -33,7 +33,11 @@ HEADER_INCLUDED #include -#if defined _MSC_VER && !defined snprintf +#if defined(EFIX64) || defined(EFI32) +#include +#endif + +#if defined(_MSC_VER) && !defined snprintf #define snprintf _snprintf #endif