mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-24 12:36:01 -07:00
Make sodium_bin2hex() slightly faster
This commit is contained in:
parent
814df1e60d
commit
9e64361e66
@ -96,17 +96,22 @@ char *
|
||||
sodium_bin2hex(char * const hex, const size_t hex_maxlen,
|
||||
const unsigned char * const bin, const size_t bin_len)
|
||||
{
|
||||
size_t i = (size_t) 0U;
|
||||
int b;
|
||||
size_t i = (size_t) 0U;
|
||||
unsigned int x;
|
||||
int b;
|
||||
int c;
|
||||
|
||||
if (bin_len >= SIZE_MAX / 2 || hex_maxlen < bin_len * 2U) {
|
||||
abort(); /* LCOV_EXCL_LINE */
|
||||
}
|
||||
while (i < bin_len) {
|
||||
c = bin[i] & 0xf;
|
||||
b = bin[i] >> 4;
|
||||
hex[i * 2U] = (char) (87 + b + (((b - 10) >> 31) & -39));
|
||||
b = bin[i] & 0xf;
|
||||
hex[i * 2U + 1U] = (char) (87 + b + (((b - 10) >> 31) & -39));
|
||||
x = (unsigned char) (87 + c + (((c - 10) >> 31) & -39)) << 8 |
|
||||
(unsigned char) (87 + b + (((b - 10) >> 31) & -39));
|
||||
hex[i * 2U] = (char) x;
|
||||
x >>= 8;
|
||||
hex[i * 2U + 1U] = (char) x;
|
||||
i++;
|
||||
}
|
||||
hex[i * 2U] = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user