home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
x
/
xntp3.zip
/
authstuff
/
authcert.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-04
|
1KB
|
86 lines
/*
* 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>
u_char ekeys[128];
u_char dkeys[128];
main()
{
u_long key[2], plain[2], cipher[2], answer[2];
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++)
if(ntohl(cipher[i]) != answer[i])
break;
fail = 0;
if(i != 2){
printf(" Encrypt FAIL");
fail++;
}
DESauth_des(cipher, dkeys);
for(i=0;i<2;i++)
if(ntohl(cipher[i]) != plain[i])
break;
if(i != 2){
printf(" Decrypt FAIL");
fail++;
}
if(fail == 0)
printf(" OK");
printf("\n");
}
}
get8(lp)
u_long *lp;
{
int t;
u_long l[2];
int i;
l[0] = l[1] = 0L;
for(i=0;i<8;i++){
scanf("%2x",&t);
if(feof(stdin))
exit(0);
l[i/4] <<= 8;
l[i/4] |= (u_long)(t & 0xff);
}
*lp = l[0];
*(lp+1) = l[1];
}
put8(lp)
u_long *lp;
{
int i;
for(i=0;i<2;i++){
printf("%08x",*lp++);
}
}