freebsd-nq/usr.sbin/xntpd/authstuff/authcert.c

96 lines
1.5 KiB
C
Raw Normal View History

1994-09-29 23:04:24 +00:00
/*
1993-12-21 18:36:48 +00:00
* This file, and the certdata file, shamelessly stolen
* from Phil Karn's DES implementation.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define DES
#include "ntp_stdlib.h"
u_char ekeys[128];
u_char dkeys[128];
static void get8 P((U_LONG *));
static void put8 P((U_LONG *));
void
main()
{
1994-09-29 23:04:24 +00:00
U_LONG key[2], plain[2], cipher[2], answer[2], temp;
1993-12-21 18:36:48 +00:00
int i;
int test;
int fail;
1994-09-29 23:04:24 +00:00
for(test = 0; !feof(stdin); test++){
1993-12-21 18:36:48 +00:00
get8(key);
DESauth_subkeys(key, ekeys, dkeys);
printf(" K: "); put8(key);
get8(plain);
printf(" P: "); put8(plain);
get8(answer);
printf(" C: "); put8(answer);
1994-09-29 23:04:24 +00:00
for (i = 0; i < 2; i++)
1993-12-21 18:36:48 +00:00
cipher[i] = htonl(plain[i]);
DESauth_des(cipher, ekeys);
1994-09-29 23:04:24 +00:00
for (i = 0; i < 2; i++) {
temp = ntohl(cipher[i]);
if (temp != answer[i])
1993-12-21 18:36:48 +00:00
break;
1994-09-29 23:04:24 +00:00
}
1993-12-21 18:36:48 +00:00
fail = 0;
1994-09-29 23:04:24 +00:00
if (i != 2) {
1993-12-21 18:36:48 +00:00
printf(" Encrypt FAIL");
fail++;
}
DESauth_des(cipher, dkeys);
1994-09-29 23:04:24 +00:00
for (i = 0; i < 2; i++) {
temp = ntohl(cipher[i]);
if (temp != plain[i])
1993-12-21 18:36:48 +00:00
break;
1994-09-29 23:04:24 +00:00
}
if (i != 2) {
1993-12-21 18:36:48 +00:00
printf(" Decrypt FAIL");
fail++;
}
1994-09-29 23:04:24 +00:00
if (fail == 0)
1993-12-21 18:36:48 +00:00
printf(" OK");
printf("\n");
}
}
static void
get8(lp)
1994-09-29 23:04:24 +00:00
U_LONG *lp;
1993-12-21 18:36:48 +00:00
{
int t;
U_LONG l[2];
int i;
1994-09-29 23:04:24 +00:00
l[0] = l[1] = 0;
for (i = 0; i < 8; i++) {
scanf("%2x", &t);
if (feof(stdin))
1993-12-21 18:36:48 +00:00
exit(0);
1994-09-29 23:04:24 +00:00
l[i / 4] <<= 8;
l[i / 4] |= (U_LONG)(t & 0xff);
1993-12-21 18:36:48 +00:00
}
*lp = l[0];
1994-09-29 23:04:24 +00:00
*(lp + 1) = l[1];
1993-12-21 18:36:48 +00:00
}
static void
put8(lp)
1994-09-29 23:04:24 +00:00
U_LONG *lp;
1993-12-21 18:36:48 +00:00
{
int i;
1995-05-30 03:57:47 +00:00
1994-09-29 23:04:24 +00:00
for(i = 0; i < 2; i++)
printf("%08lx", (u_long)(*lp++));
1993-12-21 18:36:48 +00:00
}