1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
/*
* This file, and the certdata file, shamelessly stolen
* from Phil Karn's DES implementation.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#ifndef DES
# define DES
#endif
#include "ntp_stdlib.h"
u_char ekeys[128];
u_char dkeys[128];
static void get8 P((u_int32 *));
static void put8 P((u_int32 *));
void
main()
{
u_int32 key[2], plain[2], cipher[2], answer[2], temp;
int i;
int test;
int fail;
for(test = 0; !feof(stdin); test++){
get8(key);
DESauth_subkeys(key, ekeys, dkeys);
printf(" K: "); put8(key);
get8(plain);
printf(" P: "); put8(plain);
get8(answer);
printf(" C: "); put8(answer);
for (i = 0; i < 2; i++)
cipher[i] = htonl(plain[i]);
DESauth_des(cipher, ekeys);
for (i = 0; i < 2; i++) {
temp = ntohl(cipher[i]);
if (temp != answer[i])
break;
}
fail = 0;
if (i != 2) {
printf(" Encrypt FAIL");
fail++;
}
DESauth_des(cipher, dkeys);
for (i = 0; i < 2; i++) {
temp = ntohl(cipher[i]);
if (temp != plain[i])
break;
}
if (i != 2) {
printf(" Decrypt FAIL");
fail++;
}
if (fail == 0)
printf(" OK");
printf("\n");
}
}
static void
get8(lp)
u_int32 *lp;
{
int t;
u_int32 l[2];
int i;
l[0] = l[1] = 0;
for (i = 0; i < 8; i++) {
scanf("%2x", &t);
if (feof(stdin))
exit(0);
l[i / 4] <<= 8;
l[i / 4] |= (u_int32)(t & 0xff);
}
*lp = l[0];
*(lp + 1) = l[1];
}
static void
put8(lp)
u_int32 *lp;
{
int i;
for(i = 0; i < 2; i++)
printf("%08lx", (u_long)(*lp++));
}
|