Merge pull request #3884 from SparkiDev/tfm_read_bin

TFM read_unsigned_bin: endian may not be defined
This commit is contained in:
toddouska
2021-03-23 14:47:18 -07:00
committed by GitHub

View File

@ -3581,7 +3581,8 @@ int fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
#error Both LITTLE_ENDIAN_ORDER and BIG_ENDIAN_ORDER defined.
#endif
#if (defined(LITTLE_ENDIAN_ORDER) || defined(BIG_ENDIAN_ORDER))
#if (defined(LITTLE_ENDIAN_ORDER) || defined(BIG_ENDIAN_ORDER)) && \
(defined(FP_32BIT) || defined(FP_64BIT))
#ifdef FP_32BIT
/* If we know the endianness of this architecture, and we're using
32-bit fp_digits, we can optimize this */
@ -3589,7 +3590,6 @@ int fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
unsigned char *pd = (unsigned char *)a->dp;
a->used = (c + sizeof(fp_digit) - 1)/sizeof(fp_digit);
/* read the bytes in */
#ifdef BIG_ENDIAN_ORDER
{
/* Use Duff's device to unroll the loop. */
@ -3604,6 +3604,7 @@ int fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
}
}
#else
/* read the bytes in one at a time. */
for (c -= 1; c >= 0; c -= 1) {
pd[c] = *b++;
}
@ -3616,7 +3617,6 @@ int fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
unsigned char *pd = (unsigned char *)a->dp;
a->used = (c + sizeof(fp_digit) - 1)/sizeof(fp_digit);
/* read the bytes in */
#ifdef BIG_ENDIAN_ORDER
{
/* Use Duff's device to unroll the loop. */
@ -3635,6 +3635,7 @@ int fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
}
}
#else
/* read the bytes in one at a time. */
for (c -= 1; c >= 0; c -= 1) {
pd[c] = *b++;
}
@ -3642,7 +3643,7 @@ int fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
}
#endif
#else
/* read the bytes in */
/* read the bytes in one at a time - unknown number of bits in digit */
for (; c > 0; c--) {
int err = fp_mul_2d (a, 8, a);
if (err != FP_OKAY) {