From 529d87ba097764db4a30fda2d99be06dc38fc6cc Mon Sep 17 00:00:00 2001 From: cameronrich Date: Fri, 14 Jan 2011 23:25:33 +0000 Subject: [PATCH] Added Visual Studio 2010 support and fixed some VS compilation issues. Removed code to force blocking mode. git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@196 9a5d90b5-6617-0410-8a86-bb477d3ed2e3 --- config/Config.in | 10 +++++++++- config/makefile.conf | 9 +++++++-- crypto/bigint.c | 3 ++- crypto/crypto_misc.c | 3 ++- ssl/os_port.h | 5 +---- ssl/ssl.h | 8 +++++--- ssl/tls1.c | 9 +++++++++ ssl/tls1_clnt.c | 5 +---- 8 files changed, 36 insertions(+), 16 deletions(-) diff --git a/config/Config.in b/config/Config.in index bc11f69d2..c42bcefb7 100644 --- a/config/Config.in +++ b/config/Config.in @@ -58,7 +58,7 @@ depends on CONFIG_PLATFORM_WIN32 choice prompt "Compiler" depends on CONFIG_PLATFORM_WIN32 - default CONFIG_VISUAL_STUDIO_7_0 + default CONFIG_VISUAL_STUDIO_10_0 config CONFIG_VISUAL_STUDIO_7_0 bool "Visual Studio 7.0 (2003)" @@ -70,6 +70,10 @@ config CONFIG_VISUAL_STUDIO_8_0 help Use Microsoft's Visual Studio 2005 platform. +config CONFIG_VISUAL_STUDIO_10_0 + bool "Visual Studio 10.0 (2010)" + help + Use Microsoft's Visual Studio 2010 platform. endchoice config CONFIG_VISUAL_STUDIO_7_0_BASE @@ -82,6 +86,10 @@ config CONFIG_VISUAL_STUDIO_8_0_BASE depends on CONFIG_VISUAL_STUDIO_8_0 default "c:\\Program Files\\Microsoft Visual Studio 8" +config CONFIG_VISUAL_STUDIO_10_0_BASE + string "Base" + depends on CONFIG_VISUAL_STUDIO_10_0 + default "c:\\Program Files\\Microsoft Visual Studio 10.0" endmenu config CONFIG_EXTRA_CFLAGS_OPTIONS diff --git a/config/makefile.conf b/config/makefile.conf index 9f9db1330..9b2373ccf 100644 --- a/config/makefile.conf +++ b/config/makefile.conf @@ -48,16 +48,21 @@ CONFIG_VISUAL_STUDIO_7_0_BASE_UNIX:=$(shell cygpath -u $(CONFIG_VISUAL_STUDIO_7_ export INCLUDE=$(shell echo "$(CONFIG_VISUAL_STUDIO_7_0_BASE)\vc7\include;$(CONFIG_VISUAL_STUDIO_7_0_BASE)\vc7\platformsdk\include") export LIB=$(shell echo "$(CONFIG_VISUAL_STUDIO_7_0_BASE)\vc7\\platformsdk\lib;$(CONFIG_VISUAL_STUDIO_7_0_BASE)\vc7\lib") PATH:=$(CONFIG_VISUAL_STUDIO_7_0_BASE_UNIX)/vc7/bin:$(CONFIG_VISUAL_STUDIO_7_0_BASE_UNIX)/common7/ide:$(PATH) -else +endif ifdef CONFIG_VISUAL_STUDIO_8_0 CONFIG_VISUAL_STUDIO_8_0_BASE_UNIX:=$(shell cygpath -u $(CONFIG_VISUAL_STUDIO_8_0_BASE)) export INCLUDE=$(shell echo "$(CONFIG_VISUAL_STUDIO_8_0_BASE)\vc\include;$(CONFIG_VISUAL_STUDIO_8_0_BASE)\vc\platformsdk\include") export LIB=$(shell echo "$(CONFIG_VISUAL_STUDIO_8_0_BASE)\vc\platformsdk\lib;$(CONFIG_VISUAL_STUDIO_8_0_BASE)\vc\lib") PATH:=$(CONFIG_VISUAL_STUDIO_8_0_BASE_UNIX)/vc/bin:$(CONFIG_VISUAL_STUDIO_8_0_BASE_UNIX)/common7/ide:$(PATH) +endif +ifdef CONFIG_VISUAL_STUDIO_10_0 +CONFIG_VISUAL_STUDIO_10_0_BASE_UNIX:=$(shell cygpath -u $(CONFIG_VISUAL_STUDIO_10_0_BASE)) +export INCLUDE=$(shell echo "$(CONFIG_VISUAL_STUDIO_10_0_BASE)\vc\include;$(CONFIG_VISUAL_STUDIO_10_0_BASE)\..\Microsoft SDKs\Windows\v7.0A\include") +export LIB=$(shell echo "$(CONFIG_VISUAL_STUDIO_10_0_BASE)\vc\lib;$(CONFIG_VISUAL_STUDIO_10_0_BASE)\..\Microsoft SDKs\Windows\v7.0A\lib") +PATH:=$(CONFIG_VISUAL_STUDIO_10_0_BASE_UNIX)/vc/bin:$(CONFIG_VISUAL_STUDIO_10_0_BASE_UNIX)/common7/ide:$(PATH) stuff: @echo $(INCLUDE) endif -endif CC=cl.exe LD=link.exe diff --git a/crypto/bigint.c b/crypto/bigint.c index 93195c623..80a991b22 100644 --- a/crypto/bigint.c +++ b/crypto/bigint.c @@ -826,6 +826,7 @@ static bigint *regular_multiply(BI_CTX *ctx, bigint *bia, bigint *bib, do { + long_comp tmp; comp carry = 0; int r_index = i; j = 0; @@ -843,7 +844,7 @@ static bigint *regular_multiply(BI_CTX *ctx, bigint *bia, bigint *bib, break; } - long_comp tmp = sr[r_index] + ((long_comp)sa[j])*sb[i] + carry; + tmp = sr[r_index] + ((long_comp)sa[j])*sb[i] + carry; sr[r_index++] = (comp)tmp; /* downsize */ carry = tmp >> COMP_BIT_SIZE; } while (++j < n); diff --git a/crypto/crypto_misc.c b/crypto/crypto_misc.c index 8bca842c1..8e7cbf9c5 100644 --- a/crypto/crypto_misc.c +++ b/crypto/crypto_misc.c @@ -177,11 +177,12 @@ EXP_FUNC void STDCALL get_random(int num_rand_bytes, uint8_t *rand_data) struct timeval tv; MD5_CTX rng_digest_ctx; uint8_t digest[MD5_SIZE]; + uint64_t *ep; int i; /* A proper implementation would use counters etc for entropy */ gettimeofday(&tv, NULL); - uint64_t *ep = (uint64_t *)entropy_pool; + ep = (uint64_t *)entropy_pool; ep[0] ^= ENTROPY_COUNTER1; ep[1] ^= ENTROPY_COUNTER2; diff --git a/ssl/os_port.h b/ssl/os_port.h index 0efd6ae70..af71651a8 100644 --- a/ssl/os_port.h +++ b/ssl/os_port.h @@ -82,8 +82,6 @@ extern "C" { #define SOCKET_READ(A,B,C) recv(A,B,C,0) #define SOCKET_WRITE(A,B,C) send(A,B,C,0) #define SOCKET_CLOSE(A) closesocket(A) -#define SOCKET_BLOCK(A) u_long argp = 0; \ - ioctlsocket(A, FIONBIO, &argp) #define srandom(A) srand(A) #define random() rand() #define getpid() _getpid() @@ -143,6 +141,7 @@ EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size); #include #include #include +#include #include #include #include @@ -153,8 +152,6 @@ EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size); #define SOCKET_READ(A,B,C) read(A,B,C) #define SOCKET_WRITE(A,B,C) write(A,B,C) #define SOCKET_CLOSE(A) if (A >= 0) close(A) -#define SOCKET_BLOCK(A) int fd = fcntl(A, F_GETFL, NULL); \ - fcntl(A, F_SETFL, fd & ~O_NONBLOCK) #define TTY_FLUSH() #endif /* Not Win32 */ diff --git a/ssl/ssl.h b/ssl/ssl.h index 6778837f9..c379e02e7 100644 --- a/ssl/ssl.h +++ b/ssl/ssl.h @@ -197,7 +197,8 @@ extern "C" { * are passed during a handshake. * - SSL_DISPLAY_RSA (full mode build only): Display the RSA key details that * are passed during a handshake. - * + * - SSL_CLIENT_NON_BLOCKING (client only): Use non-blocking version of + * ssl_client_new. * @param num_sessions [in] The number of sessions to be used for session * caching. If this value is 0, then there is no session caching. This option * is not used in skeleton mode. @@ -231,8 +232,9 @@ EXP_FUNC SSL * STDCALL ssl_server_new(SSL_CTX *ssl_ctx, int client_fd); * It is up to the application to establish the initial logical connection * (whether it is a socket, serial connection etc). * - * This is a blocking call - it will finish when the handshake is complete (or - * has failed). + * This is a normall a blocking call - it will finish when the handshake is + * complete (or has failed). To use in non-blocking mode, set + * SSL_CLIENT_NON_BLOCKING in ssl_ctx_new. * @param ssl_ctx [in] The client context. * @param client_fd [in] The client's file descriptor. * @param session_id [in] A 32 byte session id for session resumption. This diff --git a/ssl/tls1.c b/ssl/tls1.c index 6d86d8e77..3060faebd 100755 --- a/ssl/tls1.c +++ b/ssl/tls1.c @@ -287,6 +287,7 @@ EXP_FUNC int STDCALL ssl_read(SSL *ssl, uint8_t **in_data) int ret = basic_read(ssl, in_data); /* check for return code so we can send an alert */ + if (ret < SSL_OK && ret != SSL_CLOSE_NOTIFY) { if (ret != SSL_ERROR_CONN_LOST) @@ -1159,6 +1160,14 @@ int basic_read(SSL *ssl, uint8_t **in_data) read_len = SOCKET_READ(ssl->client_fd, &buf[ssl->bm_read_index], ssl->need_bytes-ssl->got_bytes); + if (ret < 0) +#ifdef WIN32 + if (GetLastError() == WSAEWOULDBLOCK) +#else + if (errno == EAGAIN || errno == EWOULDBLOCK) +#endif + return 0; + /* connection has gone, so die */ if (read_len <= 0) { diff --git a/ssl/tls1_clnt.c b/ssl/tls1_clnt.c index f846ffdc9..676d01c55 100644 --- a/ssl/tls1_clnt.c +++ b/ssl/tls1_clnt.c @@ -50,10 +50,7 @@ static int send_cert_verify(SSL *ssl); EXP_FUNC SSL * STDCALL ssl_client_new(SSL_CTX *ssl_ctx, int client_fd, const uint8_t *session_id, uint8_t sess_id_size) { - SSL *ssl; - - SOCKET_BLOCK(client_fd); /* ensure blocking mode */ - ssl = ssl_new(ssl_ctx, client_fd); + SSL *ssl = ssl_new(ssl_ctx, client_fd); if (session_id && ssl_ctx->num_sessions) {