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