freebsd-src/contrib/ntp/libntp/authusekey.c
Cy Schubert a466cc5537 ntp: import ntp-4.2.8p16
Security:       NtpBUg3767, NtpBug3808, NtpBug3807 (CVE-2023-26555)
MFC after:	immediately
2023-06-01 07:04:37 -07:00

35 lines
668 B
C

/*
* authusekey - decode a key from ascii and use it
*/
#include <config.h>
#include <stdio.h>
#include <ctype.h>
#include "ntp_types.h"
#include "ntp_string.h"
#include "ntp_stdlib.h"
/*
* Only used by ntp{q,dc} to set the key/algo/secret triple to use.
* Uses the same decoding scheme ntpd uses for keys in the key file.
*/
int
authusekey(
keyid_t keyno,
int keytype,
const u_char *str
)
{
size_t len;
u_char buf[AUTHPWD_MAXSECLEN];
len = authdecodepw(buf, sizeof(buf), (const char*)str,
AUTHPWD_UNSPEC);
if (len < 1 || len > sizeof(buf))
return 0;
MD5auth_setkey(keyno, keytype, buf, len, NULL);
memset(buf, 0, sizeof(buf));
return 1;
}