mirror of https://github.com/wolfSSL/wolfssl.git
Merge pull request #4176 from SparkiDev/sp_math_read_bin_max
SP math all: allow reading of bin up to max digit sizepull/4211/head
commit
b5eef78cdb
|
@ -12209,8 +12209,7 @@ int sp_read_unsigned_bin(sp_int* a, const byte* in, word32 inSz)
|
||||||
err = MP_VAL;
|
err = MP_VAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extra digit added to SP_INT_DIGITS to be used in calculations. */
|
if ((err == MP_OKAY) && (inSz > (word32)a->size * SP_WORD_SIZEOF)) {
|
||||||
if ((err == MP_OKAY) && (inSz > ((word32)a->size - 1) * SP_WORD_SIZEOF)) {
|
|
||||||
err = MP_VAL;
|
err = MP_VAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12220,6 +12219,8 @@ int sp_read_unsigned_bin(sp_int* a, const byte* in, word32 inSz)
|
||||||
int j;
|
int j;
|
||||||
int s;
|
int s;
|
||||||
|
|
||||||
|
a->used = (inSz + SP_WORD_SIZEOF - 1) / SP_WORD_SIZEOF;
|
||||||
|
|
||||||
#ifndef WOLFSSL_SP_INT_DIGIT_ALIGN
|
#ifndef WOLFSSL_SP_INT_DIGIT_ALIGN
|
||||||
for (i = inSz-1,j = 0; i > SP_WORD_SIZEOF-1; i -= SP_WORD_SIZEOF,j++) {
|
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));
|
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++;
|
j++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
a->dp[j] = 0;
|
if (i >= 0) {
|
||||||
for (s = 0; i >= 0; i--,s += 8) {
|
a->dp[a->used - 1] = 0;
|
||||||
a->dp[j] |= ((sp_int_digit)in[i]) << s;
|
for (s = 0; i >= 0; i--,s += 8) {
|
||||||
|
a->dp[j] |= ((sp_int_digit)in[i]) << s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
a->used = j + 1;
|
|
||||||
sp_clamp(a);
|
sp_clamp(a);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -12274,7 +12277,6 @@ int sp_read_unsigned_bin(sp_int* a, const byte* in, word32 inSz)
|
||||||
#endif
|
#endif
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
a->dp[j] = 0;
|
|
||||||
|
|
||||||
#if SP_WORD_SIZE >= 16
|
#if SP_WORD_SIZE >= 16
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
|
|
|
@ -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));
|
ret = mp_read_unsigned_bin(a, NULL, sizeof(buffer));
|
||||||
if (ret != MP_VAL)
|
if (ret != MP_VAL)
|
||||||
return -12740;
|
return -12740;
|
||||||
ret = mp_read_unsigned_bin(a, buffer,
|
ret = mp_read_unsigned_bin(a, buffer, SP_INT_DIGITS * SP_WORD_SIZEOF + 1);
|
||||||
(SP_INT_DIGITS - 1) * SP_WORD_SIZEOF + 1);
|
|
||||||
if (ret != MP_VAL)
|
if (ret != MP_VAL)
|
||||||
return -12741;
|
return -12741;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue