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.
This commit is contained in:
dkulwin 2015-11-04 17:53:57 -06:00
parent bf2766ba2d
commit ddace27b97
5 changed files with 55 additions and 17 deletions

View File

@ -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

View File

@ -35,6 +35,7 @@
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <crtdbg.h>
#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");
}

View File

@ -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]);
}

View File

@ -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);

View File

@ -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]);
}