154359Sroberto/*
254359Sroberto * authusekey - decode a key from ascii and use it
354359Sroberto */
4290001Sglebius#include <config.h>
554359Sroberto#include <stdio.h>
654359Sroberto#include <ctype.h>
754359Sroberto
854359Sroberto#include "ntp_types.h"
954359Sroberto#include "ntp_string.h"
1054359Sroberto#include "ntp_stdlib.h"
1154359Sroberto
1254359Sroberto/*
1354359Sroberto * Types of ascii representations for keys.  "Standard" means a 64 bit
1454359Sroberto * hex number in NBS format, i.e. with the low order bit of each byte
1554359Sroberto * a parity bit.  "NTP" means a 64 bit key in NTP format, with the
1654359Sroberto * high order bit of each byte a parity bit.  "Ascii" means a 1-to-8
1754359Sroberto * character string whose ascii representation is used as the key.
1854359Sroberto */
1954359Srobertoint
2054359Srobertoauthusekey(
2182498Sroberto	keyid_t keyno,
2254359Sroberto	int keytype,
2354359Sroberto	const u_char *str
2454359Sroberto	)
2554359Sroberto{
26293896Sglebius	size_t	len;
2754359Sroberto
28290001Sglebius	len = strlen((const char *)str);
29290001Sglebius	if (0 == len)
3054359Sroberto		return 0;
3154359Sroberto
32294905Sdelphij	MD5auth_setkey(keyno, keytype, str, len, NULL);
3354359Sroberto	return 1;
3454359Sroberto}
35