#include "ntp_machine.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef DES
#include "ntp_types.h"
#include "ntp_fp.h"
#include "ntp_string.h"
#include "global.h"
#include "des.h"
#include "ntp_stdlib.h"
#define BLOCK_OCTETS 8
#define MAXTPKT 128
int
DESauthencrypt(
u_char *key,
u_int32 *pkt,
int length
)
{
DES_CBC_CTX ctx;
u_int32 tpkt[MAXTPKT];
u_int32 work[2];
int i, j;
work[0] = work[1] = 0;
DES_CBCInit(&ctx, key, (u_char *)work, 1);
DES_CBCUpdate(&ctx, (u_char *)tpkt, (u_char *)pkt,
(u_int)length);
i = length / 4 + 1;
j = i - 3;
pkt[i++] = (u_int32)htonl(tpkt[j++]);
pkt[i] = (u_int32)htonl(tpkt[j]);
return (BLOCK_OCTETS + 4);
}
int
DESauthdecrypt(
u_char *key,
u_int32 *pkt,
int length,
int size
)
{
DES_CBC_CTX ctx;
u_int32 tpkt[MAXTPKT];
u_int32 work[2];
int i, j;
if (size != BLOCK_OCTETS + 4)
return (0);
work[0] = work[1] = 0;
DES_CBCInit (&ctx, key, (u_char *)work, 1);
DES_CBCUpdate (&ctx, (u_char *)tpkt, (u_char *)pkt,
(u_int)length);
i = length / 4 + 1;
j = i - 3;
if ((u_int32)ntohl(pkt[i++]) == tpkt[j++] &&
(u_int32)ntohl(pkt[i]) == tpkt[j])
return (1);
return (0);
}
#else
int authencrypt_bs;
#endif