X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=engines%2Fe_aep.c;h=a9372268cd4a21b78504e655390d6d579953fb82;hp=742b4f9b186dea01a64567568781fa4dec93aecb;hb=cb2182676bdf652070bc272a3896d957763a4324;hpb=e527201f6be3c295358bcc8b6bafec598f02dc97 diff --git a/engines/e_aep.c b/engines/e_aep.c index 742b4f9b18..a9372268cd 100644 --- a/engines/e_aep.c +++ b/engines/e_aep.c @@ -68,6 +68,8 @@ typedef int pid_t; #if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) #define getpid GetThreadID extern int GetThreadID(void); +#elif defined(_WIN32) && !defined(__WATCOMC__) +#define getpid _getpid #endif #include @@ -83,7 +85,6 @@ extern int GetThreadID(void); #ifndef OPENSSL_NO_DH #include #endif -#include #ifndef OPENSSL_NO_HW #ifndef OPENSSL_NO_HW_AEP @@ -867,13 +868,7 @@ static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR phConnection) CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); -#ifdef NETWARE_CLIB - curr_pid = GetThreadID(); -#elif defined(_WIN32) - curr_pid = _getpid(); -#else curr_pid = getpid(); -#endif /*Check if this is the first time this is being called from the current process*/ @@ -1057,13 +1052,10 @@ static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize) /*Cast the ArbBigNum pointer to our BIGNUM struct*/ bn = (BIGNUM*) ArbBigNum; -#ifdef SIXTY_FOUR_BIT_LONG - *BigNumSize = bn->top << 3; -#else - /*Size of the bignum in bytes is equal to the bn->top (no of 32 bit - words) multiplies by 4*/ - *BigNumSize = bn->top << 2; -#endif + *BigNumSize = bn->top*BN_BYTES; + + if (BN_BYTES>sizeof(AEP_U32) && (bn->d[bn->top-1]>>BN_BITS4)==0) + *BigNumSize -= 4; return AEP_R_OK; } @@ -1072,31 +1064,42 @@ static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize, unsigned char* AEP_BigNum) { BIGNUM* bn; - -#ifndef SIXTY_FOUR_BIT_LONG - unsigned char* buf; - int i; -#endif + const union { long one; char little; } is_endian = {1}; + AEP_U32 i,j; /*Cast the ArbBigNum pointer to our BIGNUM struct*/ bn = (BIGNUM*) ArbBigNum; -#ifdef SIXTY_FOUR_BIT_LONG - memcpy(AEP_BigNum, bn->d, BigNumSize); -#else /*Must copy data into a (monotone) least significant byte first format performing endian conversion if necessary*/ - for(i=0;itop;i++) + if (is_endian.little && sizeof(bn->d[0])==BN_BYTES) + memcpy(AEP_BigNum, bn->d, BigNumSize); + else { - buf = (unsigned char*)&bn->d[i]; + BN_ULONG di; - *((AEP_U32*)AEP_BigNum) = (AEP_U32) - ((unsigned) buf[1] << 8 | buf[0]) | - ((unsigned) buf[3] << 8 | buf[2]) << 16; + for (i=0; BigNumSize>=BN_BYTES; i++) + { + di = bn->d[i]; + for (j=0; j>=8; + } + AEP_BigNum += BN_BYTES; + BigNumSize -= BN_BYTES; + } - AEP_BigNum += 4; + if (BigNumSize) + { + di = bn->d[i]; + for (j=0; j>=8; + } + } } -#endif return AEP_R_OK; } @@ -1106,36 +1109,46 @@ static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize, unsigned char* AEP_BigNum) { BIGNUM* bn; -#ifndef SIXTY_FOUR_BIT_LONG - int i; -#endif + const union { long one; char little; } is_endian = {1}; + int i,j,top; bn = (BIGNUM*)ArbBigNum; /*Expand the result bn so that it can hold our big num. Size is in bits*/ - bn_expand(bn, (int)(BigNumSize << 3)); + top = (BigNumSize+BN_BYTES-1)/BN_BYTES; + bn_expand(bn, top); + bn->top = top; + bn->d[top-1] = 0; -#ifdef SIXTY_FOUR_BIT_LONG - bn->top = BigNumSize >> 3; - - if((BigNumSize & 7) != 0) - bn->top++; + if (is_endian.little && sizeof(bn->d[0])==BN_BYTES) + memcpy(bn->d, AEP_BigNum, BigNumSize); + else + { + BN_ULONG di; - memset(bn->d, 0, bn->top << 3); + for (i=0; BigNumSize>=BN_BYTES; i++) + { + for (di=0,j=BN_BYTES; j!=0; ) + { + di <<= 8; + di |= AEP_BigNum[--j]; + } + bn->d[i] = di; + AEP_BigNum += BN_BYTES; + BigNumSize -= BN_BYTES; + } - memcpy(bn->d, AEP_BigNum, BigNumSize); -#else - bn->top = BigNumSize >> 2; - - for(i=0;itop;i++) - { - bn->d[i] = (AEP_U32) - ((unsigned) AEP_BigNum[3] << 8 | AEP_BigNum[2]) << 16 | - ((unsigned) AEP_BigNum[1] << 8 | AEP_BigNum[0]); - AEP_BigNum += 4; + if (BigNumSize) + { + for (di=0,j=BigNumSize; j!=0; ) + { + di <<= 8; + di |= AEP_BigNum[--j]; + } + bn->d[i] = di; + } } -#endif return AEP_R_OK; }