|
|
// encrypt.c
// contains all encryption code necessary for MSUAM encryption
#include <string.h>
#include "encrypt.h"
#include "UAMDebug.h"
/*-------------------------------------------------------------------*\
DES defines.
\*-------------------------------------------------------------------*/
unsigned char *IP;
unsigned char *FP;
unsigned char *PC1_C;
unsigned char *PC1_D;
unsigned char *PC2_C;
unsigned char *PC2_D;
unsigned char *SHIFTS;
unsigned char *E;
unsigned char S[8][64];
unsigned char *P;
/*-------------------------------------------------------------------*\
DES structure.
\*-------------------------------------------------------------------*/
typedef struct _desdata {
char header[4];
unsigned char IP[64];
unsigned char FP[64];
unsigned char PC1_C[28];
unsigned char PC1_D[28];
unsigned char SHIFTS[16];
unsigned char PC2_C[24];
unsigned char PC2_D[24];
unsigned char E[48];
unsigned char S[8][64];
unsigned char P[32];
} desdata, *PDesData, **HDesData;
static Handle ghMSUAMDesData = NULL; // static global handle (e.g. this file global only)
// ---------------------------------------------------------------------------
// � SetupUAMEncrypt()
// ---------------------------------------------------------------------------
// Setup the table.
//
// Returns TRUE if the data resource was successfully read into memory, FALSE
// otherwise.
Boolean SetupUAMEncrypt( void )
{
PDesData pdd;
ghMSUAMDesData = GetResource('data', 2);
if (ghMSUAMDesData == NULL)
{
DbgPrint_((DBGBUFF, "Couldn't get 'data' resource"));
return(false);
}
HLock(ghMSUAMDesData);
HNoPurge(ghMSUAMDesData);
pdd = *(HDesData)ghMSUAMDesData;
IP = pdd->IP;
FP = pdd->FP;
PC1_C = pdd->PC1_C;
PC1_D = pdd->PC1_D;
SHIFTS = pdd->SHIFTS;
PC2_C = pdd->PC2_C;
PC2_D = pdd->PC2_D;
E = pdd->E;
BlockMove(pdd->S, S, 8*64);
P = pdd->P;
return(true);
}
// ---------------------------------------------------------------------------
// � CleanupUAMEncrypt()
// ---------------------------------------------------------------------------
void CleanupUAMEncrypt( void )
{
if (ghMSUAMDesData)
{
HUnlock(ghMSUAMDesData);
HPurge(ghMSUAMDesData);
ReleaseResource(ghMSUAMDesData);
}
}
// ---------------------------------------------------------------------------
// � UprCString()
// ---------------------------------------------------------------------------
void UprCString(char* psz)
{
c2pstr(psz);
UpperString(*(Str255 *)psz, true); // really a pstr right now
p2cstr((StringPtr)psz);
}
// ---------------------------------------------------------------------------
// � OneWayFunction()
// ---------------------------------------------------------------------------
// Inputs - P14
// Outputs - P22
//
// Let P14 be the plain text password obtained at logon time, *passed in as a
// zero-terminated string and null padded herein to max length*.
//
// P14 is used to encrypt the standard text, S8, and get P21.
// Encryption of standard text is accomplished with an option (ENCR_STD)
// to CryptIOCTL_2.
//
// P21[0..7] = E(P14[0..6], S8)
// P21[8..15] = E(P14[7..13], S8)
// P21[16..20] = 0
unsigned char *OneWayFunction(unsigned char *pucPwd, unsigned char *pucDest, short scb)
{
SInt16 len = strlen((char *)pucPwd);
Assert_(pucPwd != NULL);
Assert_(pucDest != NULL);
if (len > scb)
{
Assert_(0);
return (pucDest);
}
memset((char *)pucPwd+len, '\0', scb-len);
CryptIOCTL2(ENCR_STD, pucPwd, nil, pucDest);
CryptIOCTL2(ENCR_STD, pucPwd+7, nil, pucDest+8);
memset((char *)pucDest + 16, '\0', 5);
return(pucDest);
}
// ---------------------------------------------------------------------------
// � Encrypt()
// ---------------------------------------------------------------------------
// Inputs - P21 (from OneWayChallenge())
// Outputs - P24
//
// P21 is used to encrypt the challenge, C8 sent by the server, to
// get P24, which is the response sent back to the server.
//
// P24[0..7] = E(P21[0..6], C8)
// P24[8..15] = E(P21[7..13
|