Ensure that all leading zeros are skipped in sp_tohex.

This commit is contained in:
Hayden Roche
2020-12-28 18:03:42 -06:00
parent c482d16029
commit 81f70fba5f

View File

@ -12711,14 +12711,24 @@ int sp_tohex(sp_int* a, char* str)
i = a->used - 1; i = a->used - 1;
#ifndef WC_DISABLE_RADIX_ZERO_PAD #ifndef WC_DISABLE_RADIX_ZERO_PAD
for (j = SP_WORD_SIZE - 8; j >= 0; j -= 8) { for (j = SP_WORD_SIZE - 8; j >= 0; j -= 8) {
if (((a->dp[i] >> j) & 0xff) != 0) if (((a->dp[i] >> j) & 0xff) != 0) {
break; break;
}
else if (j == 0) {
j = SP_WORD_SIZE - 8;
--i;
}
} }
j += 4; j += 4;
#else #else
for (j = SP_WORD_SIZE - 4; j >= 0; j -= 4) { for (j = SP_WORD_SIZE - 4; j >= 0; j -= 4) {
if (((a->dp[i] >> j) & 0xf) != 0) if (((a->dp[i] >> j) & 0xf) != 0) {
break; break;
}
else if (j == 0) {
j = SP_WORD_SIZE - 4;
--i;
}
} }
#endif /* WC_DISABLE_RADIX_ZERO_PAD */ #endif /* WC_DISABLE_RADIX_ZERO_PAD */
for (; j >= 0; j -= 4) { for (; j >= 0; j -= 4) {