mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 17:35:06 -05:00
util: move authentication and password decoding functions to keys
This doesn't need to be included in chronyc.
This commit is contained in:
51
util.c
51
util.c
@@ -967,57 +967,6 @@ UTI_FdSetCloexec(int fd)
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
UTI_GenerateNTPAuth(int hash_id, const unsigned char *key, int key_len,
|
||||
const unsigned char *data, int data_len, unsigned char *auth, int auth_len)
|
||||
{
|
||||
return HSH_Hash(hash_id, key, key_len, data, data_len, auth, auth_len);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
UTI_CheckNTPAuth(int hash_id, const unsigned char *key, int key_len,
|
||||
const unsigned char *data, int data_len, const unsigned char *auth, int auth_len)
|
||||
{
|
||||
unsigned char buf[MAX_HASH_LENGTH];
|
||||
|
||||
return UTI_GenerateNTPAuth(hash_id, key, key_len, data, data_len,
|
||||
buf, sizeof (buf)) == auth_len && !memcmp(buf, auth, auth_len);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
UTI_DecodePasswordFromText(char *key)
|
||||
{
|
||||
int i, j, len = strlen(key);
|
||||
char buf[3], *p;
|
||||
|
||||
if (!strncmp(key, "ASCII:", 6)) {
|
||||
memmove(key, key + 6, len - 6);
|
||||
return len - 6;
|
||||
} else if (!strncmp(key, "HEX:", 4)) {
|
||||
if ((len - 4) % 2)
|
||||
return 0;
|
||||
|
||||
for (i = 0, j = 4; j + 1 < len; i++, j += 2) {
|
||||
buf[0] = key[j], buf[1] = key[j + 1], buf[2] = '\0';
|
||||
key[i] = strtol(buf, &p, 16);
|
||||
|
||||
if (p != buf + 2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return i;
|
||||
} else {
|
||||
/* assume ASCII */
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
UTI_SetQuitSignalsHandler(void (*handler)(int))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user