Merge pull request #5983 from SparkiDev/sp_int_read_radix_neg

SP int negative: handle negative character properly with read radix
pull/5993/head
David Garske 2023-01-19 17:51:07 -08:00 committed by GitHub
commit cfe92aa330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -17090,6 +17090,9 @@ static int _sp_read_radix_10(sp_int* a, const char* in)
int sp_read_radix(sp_int* a, const char* in, int radix)
{
int err = MP_OKAY;
#ifdef WOLFSSL_SP_INT_NEGATIVE
int sign = MP_ZPOS;
#endif
if ((a == NULL) || (in == NULL)) {
err = MP_VAL;
@ -17106,7 +17109,7 @@ int sp_read_radix(sp_int* a, const char* in, int radix)
#ifdef WOLFSSL_SP_INT_NEGATIVE
if (*in == '-') {
/* Make number negative if signed string. */
a->sign = MP_NEG;
sign = MP_NEG;
in++;
}
#endif /* WOLFSSL_SP_INT_NEGATIVE */
@ -17129,8 +17132,13 @@ int sp_read_radix(sp_int* a, const char* in, int radix)
#ifdef WOLFSSL_SP_INT_NEGATIVE
/* Ensure not negative when zero. */
if ((err == MP_OKAY) && sp_iszero(a)) {
a->sign = MP_ZPOS;
if (err == MP_OKAY) {
if (sp_iszero(a)) {
a->sign = MP_ZPOS;
}
else {
a->sign = sign;
}
}
#endif
}