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

10
keys.c
View File

@@ -201,6 +201,7 @@ KEY_Reload(void)
FILE *in;
char line[2048], *key_file, *key_value;
const char *key_type;
HSH_Algorithm hash_algorithm;
int hash_id;
Key key;
@@ -238,10 +239,15 @@ KEY_Reload(void)
continue;
}
hash_id = HSH_GetHashId(key_type);
cmac_key_length = CMC_GetKeyLength(key_type);
hash_algorithm = UTI_HashNameToAlgorithm(key_type);
if (hash_id >= 0) {
if (hash_algorithm != 0) {
hash_id = HSH_GetHashId(hash_algorithm);
if (hash_id < 0) {
LOG(LOGS_WARN, "Unsupported %s in key %"PRIu32, "hash function", key.id);
continue;
}
key.class = NTP_MAC;
key.data.ntp_mac.value = MallocArray(unsigned char, key_length);
memcpy(key.data.ntp_mac.value, key_value, key_length);