hash: enumerate hash algorithms

Identify the algorithms with an enum instead of string.
This commit is contained in:
Miroslav Lichvar
2020-05-13 12:51:41 +02:00
parent a0d2513be6
commit a8c8f2f309
10 changed files with 119 additions and 60 deletions

32
util.c
View File

@@ -399,7 +399,7 @@ UTI_IPToRefid(const IPAddr *ip)
return ip->addr.in4;
case IPADDR_INET6:
if (MD5_hash < 0)
MD5_hash = HSH_GetHashId("MD5");
MD5_hash = HSH_GetHashId(HSH_MD5);
if (MD5_hash < 0 ||
HSH_Hash(MD5_hash, (const unsigned char *)ip->addr.in6, sizeof (ip->addr.in6),
@@ -927,6 +927,36 @@ UTI_FloatHostToNetwork(double x)
/* ================================================== */
HSH_Algorithm
UTI_HashNameToAlgorithm(const char *name)
{
if (strcmp(name, "MD5") == 0)
return HSH_MD5;
else if (strcmp(name, "SHA1") == 0)
return HSH_SHA1;
else if (strcmp(name, "SHA256") == 0)
return HSH_SHA256;
else if (strcmp(name, "SHA384") == 0)
return HSH_SHA384;
else if (strcmp(name, "SHA512") == 0)
return HSH_SHA512;
else if (strcmp(name, "SHA3-224") == 0)
return HSH_SHA3_224;
else if (strcmp(name, "SHA3-256") == 0)
return HSH_SHA3_256;
else if (strcmp(name, "SHA3-384") == 0)
return HSH_SHA3_384;
else if (strcmp(name, "SHA3-512") == 0)
return HSH_SHA3_512;
else if (strcmp(name, "TIGER") == 0)
return HSH_TIGER;
else if (strcmp(name, "WHIRLPOOL") == 0)
return HSH_WHIRLPOOL;
return HSH_INVALID;
}
/* ================================================== */
int
UTI_FdSetCloexec(int fd)
{