aboutsummaryrefslogtreecommitdiffstats
path: root/behex_lower.c
blob: cca2ddd45c043aeb3b27d018de9c7f03b8c74187 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* See LICENSE file for copyright and license details. */
#include "common.h"


void
libsha1_behex_lower(char *restrict output, const void *restrict hashsum_, size_t n)
{
#define S(X)\
	X"0", X"1", X"2", X"3", X"4", X"5", X"6", X"7",\
	X"8", X"9", X"a", X"b", X"c", X"d", X"e", X"f"
#if defined(__GNUC__)
	__attribute__((__nonstring__))
#endif
	static const char lut[256][2] = {
		S("0"), S("1"), S("2"), S("3"), S("4"), S("5"), S("6"), S("7"),
		S("8"), S("9"), S("a"), S("b"), S("c"), S("d"), S("e"), S("f")
	};

	const unsigned char *restrict hashsum = hashsum_;
	output[2 * n] = '\0';
	while (n--) {
		output[2 * n + 0] = lut[hashsum[n]][0];
		output[2 * n + 1] = lut[hashsum[n]][1];
	}
}