From ddace27b97d48e853874b603da92b67dc1244e3c Mon Sep 17 00:00:00 2001 From: dkulwin Date: Wed, 4 Nov 2015 17:53:57 -0600 Subject: [PATCH] VC2015 doesn't like it when you take a negative of on unsigned value Negative of an unsigned value should just be the two's complement. Add code to change code with negative unsigned values to two's compliment values if compiling under visual studio. --- contrib/win32/win32compat/kerberos.h | 27 ++++++++++++------------ contrib/win32/win32compat/socket.c | 31 +++++++++++++++++++++++++--- fe25519.c | 8 +++++++ openbsd-compat/strtoull.c | 2 +- smult_curve25519_ref.c | 4 ++++ 5 files changed, 55 insertions(+), 17 deletions(-) diff --git a/contrib/win32/win32compat/kerberos.h b/contrib/win32/win32compat/kerberos.h index e8a8a7d..42ebb26 100644 --- a/contrib/win32/win32compat/kerberos.h +++ b/contrib/win32/win32compat/kerberos.h @@ -55,21 +55,22 @@ void UninitMitKerberos(); * needed by ssh client here. */ -#define KFW_CALL OM_uint32 KRB5_CALLCONV -typedef KFW_CALL (*gss_indicate_mechs_ptr)(OM_uint32 *, gss_OID_set *); -typedef KFW_CALL (*gss_release_buffer_ptr)(OM_uint32 *, gss_buffer_t); +typedef OM_uint32 _stdcall KFW_CALL; -typedef KFW_CALL (*gss_display_status_ptr)(OM_uint32 *, OM_uint32, int, +typedef OM_uint32 (KRB5_CALLCONV *gss_indicate_mechs_ptr)(OM_uint32 *, gss_OID_set *); +typedef OM_uint32(KRB5_CALLCONV *gss_release_buffer_ptr)(OM_uint32 *, gss_buffer_t); + +typedef OM_uint32(KRB5_CALLCONV *gss_display_status_ptr)(OM_uint32 *, OM_uint32, int, gss_OID, OM_uint32 *, gss_buffer_t); -typedef KFW_CALL (*gss_delete_sec_context_ptr)(OM_uint32 *, gss_ctx_id_t *, +typedef OM_uint32(KRB5_CALLCONV *gss_delete_sec_context_ptr)(OM_uint32 *, gss_ctx_id_t *, gss_buffer_t); -typedef KFW_CALL (*gss_release_name_ptr)(OM_uint32 *, gss_name_t *); -typedef KFW_CALL (*gss_release_cred_ptr)(OM_uint32 *, gss_cred_id_t *); +typedef OM_uint32(KRB5_CALLCONV *gss_release_name_ptr)(OM_uint32 *, gss_name_t *); +typedef OM_uint32(KRB5_CALLCONV *gss_release_cred_ptr)(OM_uint32 *, gss_cred_id_t *); -typedef KFW_CALL (*gss_init_sec_context_ptr)(OM_uint32 *, gss_cred_id_t, +typedef OM_uint32(KRB5_CALLCONV *gss_init_sec_context_ptr)(OM_uint32 *, gss_cred_id_t, gss_ctx_id_t *, gss_name_t, gss_OID, OM_uint32, OM_uint32, gss_channel_bindings_t, @@ -77,19 +78,19 @@ typedef KFW_CALL (*gss_init_sec_context_ptr)(OM_uint32 *, gss_cred_id_t, gss_buffer_t, OM_uint32 *, OM_uint32 *); -typedef KFW_CALL (*gss_import_name_ptr)(OM_uint32 *, gss_buffer_t, +typedef OM_uint32(KRB5_CALLCONV *gss_import_name_ptr)(OM_uint32 *, gss_buffer_t, gss_OID, gss_name_t *); -typedef OM_uint32 KRB5_CALLCONV (*gss_get_mic_ptr)(OM_uint32 *, gss_ctx_id_t, +typedef OM_uint32 (KRB5_CALLCONV *gss_get_mic_ptr)(OM_uint32 *, gss_ctx_id_t, gss_qop_t, gss_buffer_t, gss_buffer_t); -typedef void KRB5_CALLCONV (*krb5_free_context_ptr)(krb5_context); +typedef void (KRB5_CALLCONV *krb5_free_context_ptr)(krb5_context); -typedef void KRB5_CALLCONV (*krb5_free_principal_ptr)(krb5_context, +typedef void (KRB5_CALLCONV *krb5_free_principal_ptr)(krb5_context, krb5_principal); -typedef krb5_error_code KRB5_CALLCONV (*krb5_cc_destroy_ptr)(krb5_context, +typedef krb5_error_code (KRB5_CALLCONV *krb5_cc_destroy_ptr)(krb5_context, krb5_ccache); #endif diff --git a/contrib/win32/win32compat/socket.c b/contrib/win32/win32compat/socket.c index 28fb8eb..96b96cb 100644 --- a/contrib/win32/win32compat/socket.c +++ b/contrib/win32/win32compat/socket.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "sfds.h" @@ -42,12 +43,19 @@ #undef DEBUG +#ifdef WIN32 #ifdef DEBUG - #define DBG_MSG(FMT, ARGS...) debug3(FMT, ## ARGS) + #define DBG_MSG(FMT, ...) debug3(FMT, ## ARGS) #else - #define DBG_MSG(FMT, ARGS...) + #define DBG_MSG(FMT, ...) +#endif +#else +#ifdef DEBUG +#define DBG_MSG(FMT, ARGS...) debug3(FMT, ## ARGS) +#else +#define DBG_MSG(FMT, ARGS...) +#endif #endif - extern void debug(const char *fmt,...); extern void debug2(const char *fmt,...); extern void debug3(const char *fmt,...); @@ -71,6 +79,12 @@ static fd_set write_sfd_set; #define MSG_WAITALL 0x8 +#ifdef WIN32 +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 +#endif + int PassInputFd = STDIN_FILENO; int PassOutputFd = STDOUT_FILENO; int PassErrorFd = STDERR_FILENO; @@ -463,6 +477,7 @@ int WSHELPopen(const char *pathname, int flags, ...) newsfd = allocate_sfd(newfd); + return newsfd; } @@ -2408,6 +2423,7 @@ int WSHELPread(int sfd, char *dst, unsigned int max) { DBG_MSG("-> WSHELPread(sfd = %d)...\n", sfd); + SOCKET sock; int ret = -1; @@ -2490,6 +2506,7 @@ int WSHELPread(int sfd, char *dst, unsigned int max) { error("read from pipe/console sfd [%d] failed with error code [%d]", sfd, GetLastError()); + } break; @@ -2903,6 +2920,14 @@ void WSHELPinitialize() winsock_initialized = 1; + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT); + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT); + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT); + + DBG_MSG("<- WSHELPinitialize()...\n"); } diff --git a/fe25519.c b/fe25519.c index e54fd15..3d5e023 100644 --- a/fe25519.c +++ b/fe25519.c @@ -89,7 +89,11 @@ void fe25519_freeze(fe25519 *r) m &= equal(r->v[i],255); m &= ge(r->v[0],237); +#ifndef _WIN32 m = -m; +#else + m = (~m + 1u); +#endif r->v[31] -= m&127; for(i=30;i>0;i--) @@ -142,7 +146,11 @@ void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b) { int i; crypto_uint32 mask = b; +#ifndef _WIN32 mask = -mask; +#else + mask = (~mask + 1u); +#endif for(i=0;i<32;i++) r->v[i] ^= mask & (x->v[i] ^ r->v[i]); } diff --git a/openbsd-compat/strtoull.c b/openbsd-compat/strtoull.c index f7c818c..ed8e4c5 100644 --- a/openbsd-compat/strtoull.c +++ b/openbsd-compat/strtoull.c @@ -102,7 +102,7 @@ strtoull(const char *nptr, char **endptr, int base) } } if (neg && any > 0) - acc = -acc; + acc = (~acc + 1u); if (endptr != 0) *endptr = (char *) (any ? s - 1 : nptr); return (acc); diff --git a/smult_curve25519_ref.c b/smult_curve25519_ref.c index 2e69934..ea238d6 100644 --- a/smult_curve25519_ref.c +++ b/smult_curve25519_ref.c @@ -55,7 +55,11 @@ static void freeze(unsigned int a[32]) for (j = 0;j < 32;++j) aorig[j] = a[j]; add(a,a,minusp); +#ifndef _WIN32 negative = -((a[31] >> 7) & 1); +#else + negative = (~((a[31] >> 7) & 1) + 1u); +#endif for (j = 0;j < 32;++j) a[j] ^= negative & (aorig[j] ^ a[j]); }