diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index b8eb2e339..28ca2f33d 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -950,7 +950,7 @@ static int sp_div(sp_int* a, sp_int* d, sp_int* r, sp_int* rem) } for (i = sa->used - 1; i >= d->used; i--) { if (sa->dp[i] == dt) { - t = (sp_digit)-1; + t = SP_MASK; /* f's */ } else { t = sp_div_word(sa->dp[i], sa->dp[i-1], dt); diff --git a/wolfssl/wolfcrypt/sp_int.h b/wolfssl/wolfcrypt/sp_int.h index db8fd4433..9d3e124cb 100644 --- a/wolfssl/wolfcrypt/sp_int.h +++ b/wolfssl/wolfcrypt/sp_int.h @@ -85,8 +85,6 @@ This library provides single precision (SP) integer math functions. #endif typedef uint128_t sp_int_word; typedef int128_t sp_int_sword; - #else - #error Word size not defined #endif #else #if SP_WORD_SIZE == 32 @@ -106,12 +104,16 @@ This library provides single precision (SP) integer math functions. #endif typedef uint128_t sp_int_word; typedef int128_t sp_int_sword; - #else - #error Word size not defined #endif #endif -#define SP_MASK (sp_digit)(-1) +#if SP_WORD_SIZE == 32 + #define SP_MASK ((sp_digit)0xffffffff) +#elif SP_WORD_SIZE == 64 + #define SP_MASK ((sp_digit)0xffffffffffffffff) +#else + #error Word size not defined +#endif #if defined(WOLFSSL_HAVE_SP_ECC) && defined(WOLFSSL_SP_NONBLOCK)