Merge pull request #4176 from SparkiDev/sp_math_read_bin_max

SP math all: allow reading of bin up to max digit size
pull/4211/head
JacobBarthelmeh 2021-07-14 16:03:32 +07:00 committed by GitHub
commit b5eef78cdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View File

@ -12209,8 +12209,7 @@ int sp_read_unsigned_bin(sp_int* a, const byte* in, word32 inSz)
err = MP_VAL;
}
/* Extra digit added to SP_INT_DIGITS to be used in calculations. */
if ((err == MP_OKAY) && (inSz > ((word32)a->size - 1) * SP_WORD_SIZEOF)) {
if ((err == MP_OKAY) && (inSz > (word32)a->size * SP_WORD_SIZEOF)) {
err = MP_VAL;
}
@ -12220,6 +12219,8 @@ int sp_read_unsigned_bin(sp_int* a, const byte* in, word32 inSz)
int j;
int s;
a->used = (inSz + SP_WORD_SIZEOF - 1) / SP_WORD_SIZEOF;
#ifndef WOLFSSL_SP_INT_DIGIT_ALIGN
for (i = inSz-1,j = 0; i > SP_WORD_SIZEOF-1; i -= SP_WORD_SIZEOF,j++) {
a->dp[j] = *(sp_int_digit*)(in + i - (SP_WORD_SIZEOF - 1));
@ -12243,11 +12244,13 @@ int sp_read_unsigned_bin(sp_int* a, const byte* in, word32 inSz)
j++;
}
#endif
a->dp[j] = 0;
for (s = 0; i >= 0; i--,s += 8) {
a->dp[j] |= ((sp_int_digit)in[i]) << s;
if (i >= 0) {
a->dp[a->used - 1] = 0;
for (s = 0; i >= 0; i--,s += 8) {
a->dp[j] |= ((sp_int_digit)in[i]) << s;
}
}
a->used = j + 1;
sp_clamp(a);
}
#else
@ -12274,7 +12277,6 @@ int sp_read_unsigned_bin(sp_int* a, const byte* in, word32 inSz)
#endif
j++;
}
a->dp[j] = 0;
#if SP_WORD_SIZE >= 16
if (i >= 0) {

View File

@ -33994,8 +33994,7 @@ static int mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng)
ret = mp_read_unsigned_bin(a, NULL, sizeof(buffer));
if (ret != MP_VAL)
return -12740;
ret = mp_read_unsigned_bin(a, buffer,
(SP_INT_DIGITS - 1) * SP_WORD_SIZEOF + 1);
ret = mp_read_unsigned_bin(a, buffer, SP_INT_DIGITS * SP_WORD_SIZEOF + 1);
if (ret != MP_VAL)
return -12741;