diff --git a/wolfcrypt/src/integer.c b/wolfcrypt/src/integer.c index ddaad3f59..a6f1a5793 100644 --- a/wolfcrypt/src/integer.c +++ b/wolfcrypt/src/integer.c @@ -3918,14 +3918,15 @@ int mp_set_int (mp_int * a, unsigned long b) mp_zero (a); /* set chunk bits at a time */ - for (x = 0; x < (int)(sizeof(long) * 8) / MP_SET_CHUNK_BITS; x++) { + for (x = 0; x < (int)(sizeof(b) * 8) / MP_SET_CHUNK_BITS; x++) { /* shift the number up chunk bits */ if ((res = mp_mul_2d (a, MP_SET_CHUNK_BITS, a)) != MP_OKAY) { return res; } /* OR in the top bits of the source */ - a->dp[0] |= (b >> (32 - MP_SET_CHUNK_BITS)) & ((1 << MP_SET_CHUNK_BITS) - 1); + a->dp[0] |= (b >> ((sizeof(b) * 8) - MP_SET_CHUNK_BITS)) & + ((1 << MP_SET_CHUNK_BITS) - 1); /* shift the source up to the next chunk bits */ b <<= MP_SET_CHUNK_BITS; diff --git a/wolfcrypt/src/tfm.c b/wolfcrypt/src/tfm.c index 68738b36b..c857ec795 100644 --- a/wolfcrypt/src/tfm.c +++ b/wolfcrypt/src/tfm.c @@ -1980,11 +1980,12 @@ void fp_set_int(fp_int *a, unsigned long b) fp_zero (a); /* set chunk bits at a time */ - for (x = 0; x < (int)(sizeof(long) * 8) / MP_SET_CHUNK_BITS; x++) { + for (x = 0; x < (int)(sizeof(b) * 8) / MP_SET_CHUNK_BITS; x++) { fp_mul_2d (a, MP_SET_CHUNK_BITS, a); /* OR in the top bits of the source */ - a->dp[0] |= (b >> (32 - MP_SET_CHUNK_BITS)) & ((1 << MP_SET_CHUNK_BITS) - 1); + a->dp[0] |= (b >> ((sizeof(b) * 8) - MP_SET_CHUNK_BITS)) & + ((1 << MP_SET_CHUNK_BITS) - 1); /* shift the source up to the next chunk bits */ b <<= MP_SET_CHUNK_BITS;