/********************************************************************
* lindner
* 3.18
* 1995/02/11 06:19:25
* /home/arcwelder/GopherSrc/CVS/gopher+/gopherd/authenticate.c,v
* Exp
*
* Paul Lindner, University of Minnesota CIS.
*
* Copyright 1991, 1992, 1993 by the Regents of the University of Minnesota
* see the file "Copyright" in the distribution for conditions of use.
*********************************************************************
* MODULE: authenticate.c
* Routines to do encryption and decryption, and validate tickets
*********************************************************************
* Revision History:
* authenticate.c,v
* Revision 3.18 1995/02/11 06:19:25 lindner
* allocate proper amount of space for des routines
*
* Revision 3.17 1995/02/07 07:02:23 lindner
* performance fixes
*
* Revision 3.16 1994/10/13 05:17:47 lindner
* Compiler complaint fixes
*
* Revision 3.15 1994/07/22 22:28:01 lindner
* NO_AUTHENTICATION mods
*
* Revision 3.14 1994/07/19 20:23:17 lindner
* Remove unused vars
*
* Revision 3.13 1994/06/29 05:39:01 lindner
* Add AUTH, remove admit1
*
* Revision 3.12 1994/02/20 16:51:57 lindner
* Don't compile authentication stuff unless needed
*
* Revision 3.11 1993/11/02 05:55:48 lindner
* Fix for interactive unix
*
* Revision 3.10 1993/09/18 03:28:05 lindner
* Fix for Abort() fcn declaration
*
* Revision 3.9 1993/09/11 05:05:08 lindner
* compiler warning fix
*
* Revision 3.8 1993/07/29 20:12:18 lindner
* Removed dead variables
*
* Revision 3.7 1993/07/27 05:27:39 lindner
* Mondo Debug overhaul from Mitra
*
* Revision 3.6 1993/07/07 19:34:17 lindner
* renamed encrypt() to UMNDESencrypt()
*
* Revision 3.5 1993/04/10 06:07:17 lindner
* none
*
* Revision 3.4 1993/04/09 16:51:54 lindner
* Little mods for combined public gopher and admit1 gopher.
*
* Revision 3.3 1993/04/07 05:16:57 lindner
* Unhid changes for Admit1 stuff.
*
* Revision 3.1 1993/03/19 20:02:13 lindner
* DES and ticket routines
*
*
*********************************************************************/
#include "String.h"
#include <stdio.h>
#include "gopherd.h"
#include "command.h"
/* -------------------------------------------------
*
* Sofware DES functions 12 Dec 1986 by Phil Karn, KA9Q;
* large sections from 1977 public-domain program by Jim Gillogly
* Modified by George Gonzalez to not do initial/final permutations
* Further bludgeoned by Farhad Anklesaria for AdmitOne authentication.
*
---------------------------------------------------- */
/*--------------------------------*/
/* Initialize the lookup table for the combined S && P boxes */
void
spinit()
{
char pbox[ 32 ];
short p, i, s, j, t, rowcol;
int val;
for ( p = 1; p <= 32; p++ ) {
for ( i = 0; i <= 31; i++ ) {
if ( p32i[i] == p ) {
pbox[p - 1] = 31 - i;
break;
}
}
}
for ( s = 0; s <= 7; s++ ) {
for ( i = 0; i <= 63; i++ ) {
val = 0;
rowcol = (i & 32) | ((i & 1) ? 16 : 0) | ((i >> 1) & 0xf);
t = si[s][rowcol];
for ( j = 0; j <= 3; j++ ) {
if ( t & ( 8 >> j ) ) {
val |= 1L << pbox[ ( s << 2 ) + j ];
}
}
spbox[s][i] = val;
}
}
}
/*--------------------------------*/
/* Allocate space && initialize DES lookup arrays
* mode == 1: DEA without initial && final permutations for speed
*/
void setdeskey( keynum )
Desnum* keynum;
{
unsigned char key[9];
unsigned char pc1m[56]; /* place to modify pc1 into */
unsigned char pcr[56]; /* place to rotate pc1 into */
register short i, j, k;
/* Do the 16 rounds in reverse order */
for ( i = 0; i <=15; i++ )
pass( 15 - i, work );
mv(work, block );
}
/*--------------------------------*/
short Hx( c )
char c;
{
if ( c >= '0' && c <= '9' ) {
return( c - '0' );
} else {
if ( c >= 'A' && c <= 'F' )
return( c - 'A' + 10 );
else if ( c >= 'a' && c <= 'f' )
return( c - 'a' + 10);
else
return( 0 );
}
}
/*--------------------------------*/
/* Take a character string and convert it into two long ints
*/
void HexToBin( In, Out )
char * In;
Desnum Out[];
{
short i;
int bytes[8];
for (i=0; i < 8; i++)
bytes[i] = (Hx(In[i*2]) * 16 ) + Hx(In[i*2 + 1]);