Fixes for 16bit processors

pull/2713/head
Martin Akman 2020-01-31 23:05:56 +10:00
parent 3d233d624c
commit 14dc5fe2e3
4 changed files with 28 additions and 19 deletions

View File

@ -6122,6 +6122,14 @@ static WC_INLINE int GetTime(int* value, const byte* date, int* idx)
int ExtractDate(const unsigned char* date, unsigned char format,
struct tm* certTime, int* idx)
{
/* Extract the time from the struct tm - 16bit processors store as uint8_t */
int tm_year = certTime->tm_year;
int tm_mon = certTime->tm_mon;
int tm_mday = certTime->tm_mday;
int tm_hour = certTime->tm_hour;
int tm_min = certTime->tm_min;
int tm_sec = certTime->tm_sec;
XMEMSET(certTime, 0, sizeof(struct tm));
if (format == ASN_UTC_TIME) {
@ -6136,14 +6144,15 @@ int ExtractDate(const unsigned char* date, unsigned char format,
}
/* adjust tm_year, tm_mon */
if (GetTime(&certTime->tm_year, date, idx) != 0) return 0;
certTime->tm_year -= 1900;
if (GetTime(&certTime->tm_mon , date, idx) != 0) return 0;
certTime->tm_mon -= 1;
if (GetTime(&certTime->tm_mday, date, idx) != 0) return 0;
if (GetTime(&certTime->tm_hour, date, idx) != 0) return 0;
if (GetTime(&certTime->tm_min , date, idx) != 0) return 0;
if (GetTime(&certTime->tm_sec , date, idx) != 0) return 0;
tm_year -= 1900;
tm_mon -= 1;
if (GetTime(&tm_year, date, idx) != 0) return 0;
if (GetTime(&tm_mon , date, idx) != 0) return 0;
if (GetTime(&tm_mday, date, idx) != 0) return 0;
if (GetTime(&tm_hour, date, idx) != 0) return 0;
if (GetTime(&tm_min , date, idx) != 0) return 0;
if (GetTime(&tm_sec , date, idx) != 0) return 0;
return 1;
}

View File

@ -1994,7 +1994,7 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y,
calls/ifs) */
#ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
if (((P->used * 2 + 1) < (int)MP_WARRAY) &&
P->used < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
P->used < (1L << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
redux = fast_mp_montgomery_reduce;
} else
#endif
@ -2244,7 +2244,7 @@ int mp_exptmod_base_2(mp_int * X, mp_int * P, mp_int * Y)
calls/ifs) */
#ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
if (((P->used * 2 + 1) < (int)MP_WARRAY) &&
P->used < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
P->used < (1L << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
redux = fast_mp_montgomery_reduce;
} else
#endif
@ -2604,7 +2604,7 @@ int mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
digs = n->used * 2 + 1;
if ((digs < (int)MP_WARRAY) &&
n->used <
(1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
(1L << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
return fast_mp_montgomery_reduce (x, n, rho);
}
@ -3043,7 +3043,7 @@ int mp_mul (mp_int * a, mp_int * b, mp_int * c)
#ifdef BN_FAST_S_MP_MUL_DIGS_C
if ((digs < (int)MP_WARRAY) &&
MIN(a->used, b->used) <=
(1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
(1L << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
res = fast_s_mp_mul_digs (a, b, c, digs);
} else
#endif
@ -3506,7 +3506,7 @@ int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
/* can we use the fast multiplier? */
if ((digs < (int)MP_WARRAY) &&
MIN (a->used, b->used) <
(1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
(1L << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
return fast_s_mp_mul_digs (a, b, c, digs);
}
@ -4014,7 +4014,7 @@ int s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
#ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
if (((a->used + b->used + 1) < (int)MP_WARRAY)
&& MIN (a->used, b->used) <
(1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
(1L << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
return fast_s_mp_mul_high_digs (a, b, c, digs);
}
#endif

View File

@ -2469,7 +2469,7 @@ struct DhKey;
typedef int (*CallbackDhAgree)(WOLFSSL* ssl, struct DhKey* key,
const unsigned char* priv, unsigned int privSz,
const unsigned char* otherPubKeyDer, unsigned int otherPubKeySz,
unsigned char* out, unsigned int* outlen,
unsigned char* out, word32* outlen,
void* ctx);
WOLFSSL_API void wolfSSL_CTX_SetDhAgreeCb(WOLFSSL_CTX*, CallbackDhAgree);
WOLFSSL_API void wolfSSL_SetDhAgreeCtx(WOLFSSL* ssl, void *ctx);
@ -2523,7 +2523,7 @@ WOLFSSL_API void* wolfSSL_GetX25519SharedSecretCtx(WOLFSSL* ssl);
#ifndef NO_RSA
typedef int (*CallbackRsaSign)(WOLFSSL* ssl,
const unsigned char* in, unsigned int inSz,
unsigned char* out, unsigned int* outSz,
unsigned char* out, word32* outSz,
const unsigned char* keyDer, unsigned int keySz,
void* ctx);
WOLFSSL_API void wolfSSL_CTX_SetRsaSignCb(WOLFSSL_CTX*, CallbackRsaSign);
@ -2568,7 +2568,7 @@ WOLFSSL_API void* wolfSSL_GetRsaPssVerifyCtx(WOLFSSL* ssl);
/* RSA Public Encrypt cb */
typedef int (*CallbackRsaEnc)(WOLFSSL* ssl,
const unsigned char* in, unsigned int inSz,
unsigned char* out, unsigned int* outSz,
unsigned char* out, word32* outSz,
const unsigned char* keyDer, unsigned int keySz,
void* ctx);
WOLFSSL_API void wolfSSL_CTX_SetRsaEncCb(WOLFSSL_CTX*, CallbackRsaEnc);

View File

@ -323,9 +323,9 @@
#else
/* just use plain C stdlib stuff if desired */
#include <stdlib.h>
#define XMALLOC(s, h, t) malloc((s))
#define XMALLOC(s, h, t) malloc((size_t)(s))
#define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
#define XREALLOC(p, n, h, t) realloc((p), (n))
#define XREALLOC(p, n, h, t) realloc((p), (size_t)(n))
#endif
#elif !defined(MICRIUM_MALLOC) && !defined(EBSNET) \
&& !defined(WOLFSSL_SAFERTOS) && !defined(FREESCALE_MQX) \