Make bin2hex() code consistent with hex2bin()

This commit is contained in:
Frank Denis 2015-02-10 19:34:11 +01:00
parent ae66518567
commit 788d8d0178

View File

@ -108,14 +108,14 @@ sodium_bin2hex(char * const hex, const size_t hex_maxlen,
while (i < bin_len) {
c = bin[i] & 0xf;
b = bin[i] >> 4;
x = (unsigned char) (87 + c + (((c - 10) >> 31) & -39)) << 8 |
(unsigned char) (87 + b + (((b - 10) >> 31) & -39));
x = (unsigned char) (87U + c + (((c - 10U) >> 8) & ~38U)) << 8 |
(unsigned char) (87U + b + (((b - 10U) >> 8) & ~38U));
hex[i * 2U] = (char) x;
x >>= 8;
hex[i * 2U + 1U] = (char) x;
i++;
}
hex[i * 2U] = 0;
hex[i * 2U] = 0U;
return hex;
}