xref: /netbsd-src/external/bsd/ntp/dist/libntp/authusekey.c (revision 53b02e147d4ed531c0d2a5ca9b3e8026ba3e99b5)
1 /*	$NetBSD: authusekey.c,v 1.6 2020/05/25 20:47:24 christos Exp $	*/
2 
3 /*
4  * authusekey - decode a key from ascii and use it
5  */
6 #include <config.h>
7 #include <stdio.h>
8 #include <ctype.h>
9 
10 #include "ntp_types.h"
11 #include "ntp_string.h"
12 #include "ntp_stdlib.h"
13 
14 /*
15  * Types of ascii representations for keys.  "Standard" means a 64 bit
16  * hex number in NBS format, i.e. with the low order bit of each byte
17  * a parity bit.  "NTP" means a 64 bit key in NTP format, with the
18  * high order bit of each byte a parity bit.  "Ascii" means a 1-to-8
19  * character string whose ascii representation is used as the key.
20  */
21 int
22 authusekey(
23 	keyid_t keyno,
24 	int keytype,
25 	const u_char *str
26 	)
27 {
28 	size_t	len;
29 
30 	len = strlen((const char *)str);
31 	if (0 == len)
32 		return 0;
33 
34 	MD5auth_setkey(keyno, keytype, str, len, NULL);
35 	return 1;
36 }
37