Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

md4.c File Reference

#include <string.h>

Include dependency graph for md4.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  MD4_CTX

Defines

#define F(x, y, z)   (((x) & (y)) | ((~x) & (z)))
#define FF(a, b, c, d, x, s)   {(a) += F ((b), (c), (d)) + (x); (a) = ROTATE_LEFT ((a), (s));}
#define G(x, y, z)   (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
#define GG(a, b, c, d, x, s)   {(a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; (a) = ROTATE_LEFT ((a), (s));}
#define H(x, y, z)   ((x) ^ (y) ^ (z))
#define HH(a, b, c, d, x, s)   {(a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; (a) = ROTATE_LEFT ((a), (s));}
#define ROTATE_LEFT(x, n)   (((x) << (n)) | ((x) >> (32-(n))))
#define S11   3
#define S12   7
#define S13   11
#define S14   19
#define S21   3
#define S22   5
#define S23   9
#define S24   13
#define S31   3
#define S32   9
#define S33   11
#define S34   15

Typedefs

typedef unsigned char * POINTER
typedef unsigned short int UINT2
typedef unsigned long int UINT4

Functions

unsigned Com_BlockChecksum (void *buffer, int length)
unsigned Com_BlockChecksumKey (void *buffer, int length, int key)
void Com_Memcpy (void *dest, const void *src, const size_t count)
void Com_Memset (void *dest, const int val, const size_t count)
void Decode (UINT4 *, const unsigned char *, unsigned int)
void Encode (unsigned char *, UINT4 *, unsigned int)
void MD4Final (unsigned char[16], MD4_CTX *)
void MD4Init (MD4_CTX *)
void MD4Transform (UINT4[4], const unsigned char[64])
void MD4Update (MD4_CTX *, const unsigned char *, unsigned int)

Variables

unsigned char PADDING [64]


Define Documentation

#define F x,
y,
z   )     (((x) & (y)) | ((~x) & (z)))
 

Definition at line 86 of file md4.c.

Referenced by asdl_defconst(), btot(), CG_DrawAmmoWarning(), CG_DrawDisconnect(), CG_DrawFollow(), CG_DrawFPS(), CG_DrawScores(), CG_DrawSnapshot(), CG_DrawSpectator(), CG_DrawTeamVote(), CG_DrawTimer(), CG_DrawVote(), CG_DrawWarmup(), main(), Pointfile_Draw(), prelabel(), simplify(), and visit().

#define FF a,
b,
c,
d,
x,
 )     {(a) += F ((b), (c), (d)) + (x); (a) = ROTATE_LEFT ((a), (s));}
 

Definition at line 95 of file md4.c.

Referenced by MD4Transform().

#define G x,
y,
z   )     (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
 

Definition at line 87 of file md4.c.

#define GG a,
b,
c,
d,
x,
 )     {(a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; (a) = ROTATE_LEFT ((a), (s));}
 

Definition at line 97 of file md4.c.

Referenced by MD4Transform().

#define H x,
y,
z   )     ((x) ^ (y) ^ (z))
 

Definition at line 88 of file md4.c.

Referenced by main().

#define HH a,
b,
c,
d,
x,
 )     {(a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; (a) = ROTATE_LEFT ((a), (s));}
 

Definition at line 99 of file md4.c.

Referenced by MD4Transform().

#define ROTATE_LEFT x,
n   )     (((x) << (n)) | ((x) >> (32-(n))))
 

Definition at line 91 of file md4.c.

#define S11   3
 

Definition at line 64 of file md4.c.

Referenced by MD4Transform().

#define S12   7
 

Definition at line 65 of file md4.c.

Referenced by MD4Transform().

#define S13   11
 

Definition at line 66 of file md4.c.

Referenced by MD4Transform().

#define S14   19
 

Definition at line 67 of file md4.c.

Referenced by MD4Transform().

#define S21   3
 

Definition at line 68 of file md4.c.

Referenced by MD4Transform().

#define S22   5
 

Definition at line 69 of file md4.c.

Referenced by MD4Transform().

#define S23   9
 

Definition at line 70 of file md4.c.

Referenced by MD4Transform().

#define S24   13
 

Definition at line 71 of file md4.c.

Referenced by MD4Transform().

#define S31   3
 

Definition at line 72 of file md4.c.

Referenced by MD4Transform().

#define S32   9
 

Definition at line 73 of file md4.c.

Referenced by MD4Transform().

#define S33   11
 

Definition at line 74 of file md4.c.

Referenced by MD4Transform().

#define S34   15
 

Definition at line 75 of file md4.c.

Referenced by MD4Transform().


Typedef Documentation

typedef unsigned char* POINTER
 

Definition at line 9 of file md4.c.

Referenced by asgncode(), compose(), constant(), dclr(), dclr1(), do_type(), emittype(), eqtype(), hasproto(), MD4Final(), MD4Transform(), MD4Update(), outtype(), postfix(), primary(), prtype(), ptr(), tracevalue(), ttob(), typestring(), typeuid(), and vtoa().

typedef unsigned short int UINT2
 

Definition at line 12 of file md4.c.

typedef unsigned long int UINT4
 

Definition at line 15 of file md4.c.

Referenced by MD4Transform().


Function Documentation

unsigned Com_BlockChecksum void *  buffer,
int  length
 

Definition at line 270 of file md4.c.

References buffer, length(), MD4Final(), MD4Init(), and MD4Update().

Referenced by CM_LoadMap(), and CM_LumpChecksum().

00271 {
00272     int         digest[4];
00273     unsigned    val;
00274     MD4_CTX     ctx;
00275 
00276     MD4Init (&ctx);
00277     MD4Update (&ctx, (unsigned char *)buffer, length);
00278     MD4Final ( (unsigned char *)digest, &ctx);
00279     
00280     val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3];
00281 
00282     return val;
00283 }

Here is the call graph for this function:

unsigned Com_BlockChecksumKey void *  buffer,
int  length,
int  key
 

Definition at line 285 of file md4.c.

References buffer, length(), MD4Final(), MD4Init(), and MD4Update().

Referenced by FS_LoadZipFile().

00286 {
00287     int         digest[4];
00288     unsigned    val;
00289     MD4_CTX     ctx;
00290 
00291     MD4Init (&ctx);
00292     MD4Update (&ctx, (unsigned char *)&key, 4);
00293     MD4Update (&ctx, (unsigned char *)buffer, length);
00294     MD4Final ( (unsigned char *)digest, &ctx);
00295     
00296     val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3];
00297 
00298     return val;
00299 }

Here is the call graph for this function:

void Com_Memcpy void *  dest,
const void *  src,
const size_t  count
 

GAS syntax equivalents of the MSVC asm memory calls in common.c

The following changes have been made to the asm: 1. Registers are loaded by the inline asm arguments when possible 2. Labels have been changed to local label format (0,1,etc.) to allow inlining

HISTORY: AH - Created on 08 Dec 2000

Definition at line 235 of file be_aas_bspc.c.

References count, memcpy(), and src.

Referenced by AAS_EntityCollision(), AAS_EntityInfo(), AAS_LoadBSPFile(), AAS_OptimizeArea(), AAS_OptimizeFace(), AAS_ReachabilityFromNum(), AAS_ShowBoundingBox(), AAS_ShowReachableAreas(), AddWindingToConvexHull(), BotGetSecondGoal(), BotGetTopGoal(), BotGetWeaponInfo(), BotImport_DebugPolygonCreate(), BotImport_DebugPolygonShow(), BotNextConsoleMessage(), BotPushGoal(), BotReplaceReplySynonyms(), BotReplyChat(), Cbuf_AddText(), Cbuf_Execute(), Cbuf_InsertText(), CL_CgameSystemCalls(), CL_ConfigstringModified(), CL_GetSnapshot(), CL_ParseGamestate(), CL_UISystemCalls(), CLUI_GetCDKey(), CLUI_SetCDKey(), CM_PatchCollideFromGrid(), CMod_LoadEntityString(), CMod_LoadShaders(), CMod_LoadVisibility(), Com_EventLoop(), ComputeColors(), Con_CheckResize(), CopyWinding(), EA_GetInput(), Field_CompleteCommand(), Field_VariableSizeDraw(), FS_FOpenFileRead(), FS_SortFileList(), GeneratePermanentShader(), GeneticParentsAndChildSelection(), Huff_Compress(), Huff_Decompress(), InvertErrorTable(), LAN_RemoveServer(), LoadBMP(), LoadPCX(), LoadScriptMemory(), LoadWeaponConfig(), MD4Update(), MSG_Copy(), NET_GetLoopPacket(), NET_SendLoopPacket(), Netchan_Process(), Netchan_Transmit(), PC_CheckTokenType(), PC_CopyToken(), PC_ReadSourceToken(), PC_ReadToken(), PS_CheckTokenType(), PS_ReadPrimitive(), PS_ReadToken(), PS_UnreadToken(), R_AddMarkFragments(), R_ChopPolyBehindPlane(), R_CreateSurfaceGridMesh(), R_LoadLightGrid(), R_LoadMD3(), R_LoadMD4(), R_LoadShaders(), R_LoadVisibility(), R_MipMap2(), R_MovePatchSurfacesToHunk(), RE_AddPolyToScene(), RE_RegisterFont(), RE_RenderScene(), RemoveColinearPoints(), RoQInterrupt(), SCR_DrawSmallStringExt(), SCR_DrawStringExt(), StringReplaceWords(), SV_GameSystemCalls(), unzReOpen(), Upload32(), VM_Compile(), VM_Create(), and VM_Restart().

00235                                                                   {
00236     memcpy(dest, src, count);
00237 }

Here is the call graph for this function:

void Com_Memset void *  dest,
const int  val,
const size_t  count
 

Definition at line 226 of file be_aas_bspc.c.

References count, and memset().

Referenced by AAS_AlternativeRouteGoals(), AAS_AreaEntityCollision(), AAS_BestReachableFromJumpPadArea(), AAS_CheckAreaForPossiblePortals(), AAS_ClientMovementPrediction(), AAS_ConnectedAreas(), AAS_DumpBSPData(), AAS_EntityInfo(), AAS_FreeReachability(), AAS_NearestHideArea(), AAS_Reachability_EqualFloorHeight(), AAS_Reachability_JumpPad(), AAS_ReachabilityFromNum(), AAS_Shutdown(), AAS_TraceClientBBox(), AAS_UpdateAreaRoutingCache(), AAS_WriteAASFile(), AllocLevelItem(), AllocWinding(), BotChooseLTGItem(), BotChooseNBGItem(), BotInitialChat(), BotMoveToGoal(), BotPredictVisiblePosition(), BotReplyChat(), BotResetAvoidGoals(), BotResetAvoidReach(), BotResetGoalState(), BotResetMoveState(), BotSetBrushModelTypes(), BotSetChatName(), CIN_PlayCinematic(), CL_CgameSystemCalls(), CL_ClearState(), CL_ConfigstringModified(), CL_CreateCmd(), CL_Disconnect(), CL_GetServerCommand(), CL_LocalServers_f(), CL_MapLoading(), CL_ParseGamestate(), CL_ParseSnapshot(), CL_Ping_f(), CL_Record_f(), CL_ServerStatus_f(), CL_Shutdown(), CL_ShutdownRef(), CL_UISystemCalls(), CL_WritePacket(), CM_ClearMap(), CM_LoadMap(), CM_PatchCollideFromGrid(), CM_Trace(), CM_WriteAreaBits(), CMod_LoadVisibility(), CollapseMultitexture(), Com_AppendCDKey(), Com_ReadCDKey(), ComputeColors(), ComputeTexCoords(), CreateInternalShaders(), Cvar_Restart_f(), DrawSkyBox(), FinishShader(), FS_FCloseFile(), FS_GetModList(), GetBotLibAPI(), GetClearedHunkMemory(), GetClearedMemory(), GetRefAPI(), GetWavinfo(), Huff_Compress(), Huff_Decompress(), Huff_Init(), Hunk_Alloc(), IN_ShutdownMIDI(), Info_Print(), LibVarAlloc(), LoadItemConfig(), LoadScriptFile(), LoadScriptMemory(), LoadSourceFile(), LoadSourceMemory(), LoadWeaponConfig(), MD4Final(), MD4Transform(), MSG_Init(), MSG_InitOOB(), MSG_ReadDeltaEntity(), MSG_ReadDeltaPlayerstate(), MSG_WriteDeltaPlayerstate(), NET_GetLoopPacket(), NET_StringToAdr(), Netchan_Setup(), PC_AddBuiltinDefines(), PC_DefineFromString(), PC_Directive_define(), PC_Directive_include(), PS_CreatePunctuationTable(), PS_ReadToken(), R_ClearFlares(), R_CreateBuiltinImages(), R_CreateDefaultImage(), R_CreateSurfaceGridMesh(), R_DeleteTextures(), R_FindShader(), R_Init(), R_InitImages(), R_InitShaders(), R_LevelShot(), R_LightForPoint(), R_LoadVisibility(), R_PerformanceCounters(), R_PlaneForSurface(), R_RotateForViewer(), RB_ShadowTessEnd(), RB_TakeScreenshot(), RE_LoadWorldMap(), RE_RegisterFont(), RE_RegisterShaderFromImage(), RE_RenderScene(), ResetScript(), S_BeginRegistration(), S_ChannelSetup(), S_ClearSoundBuffer(), S_FindName(), S_Init(), S_PaintChannels(), ScanAndLoadShaderFiles(), Snd_Memset(), SV_AuthorizeIpPacket(), SV_BuildClientSnapshot(), SV_ChangeMaxClients(), SV_ClearServer(), SV_ClearWorld(), SV_ClipToEntity(), SV_DirectConnect(), SV_GameSystemCalls(), SV_SendClientGameState(), SV_Shutdown(), SV_Trace(), SV_UserMove(), VertexLightingCollapse(), VM_Clear(), VM_Compile(), VM_Free(), VM_Init(), VM_Restart(), Z_Free(), and Z_Malloc().

00226                                                                 {
00227     memset(dest, val, count);
00228 }

Here is the call graph for this function:

void Decode UINT4 ,
const unsigned char *  ,
unsigned  int
[static]
 

Definition at line 260 of file md4.c.

References i, input, j, and output.

00261 {
00262 unsigned int i, j;
00263 
00264 for (i = 0, j = 0; j < len; i++, j += 4)
00265     output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
00266 }

void Encode unsigned char *  ,
UINT4 ,
unsigned  int
[static]
 

Definition at line 246 of file md4.c.

References i, input, j, and output.

00247 {
00248     unsigned int i, j;
00249 
00250     for (i = 0, j = 0; j < len; i++, j += 4) {
00251         output[j] = (unsigned char)(input[i] & 0xff);
00252         output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
00253         output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
00254         output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
00255     }
00256 }

void MD4Final unsigned  char[16],
MD4_CTX
 

Definition at line 150 of file md4.c.

References bits, Com_Memset(), MD4_CTX::count, Encode(), MD4Update(), PADDING, POINTER, and MD4_CTX::state.

00151 {
00152     unsigned char bits[8];
00153     unsigned int index, padLen;
00154 
00155     /* Save number of bits */
00156     Encode (bits, context->count, 8);
00157 
00158     /* Pad out to 56 mod 64.*/
00159     index = (unsigned int)((context->count[0] >> 3) & 0x3f);
00160     padLen = (index < 56) ? (56 - index) : (120 - index);
00161     MD4Update (context, PADDING, padLen);
00162 
00163     /* Append length (before padding) */
00164     MD4Update (context, bits, 8);
00165     
00166     /* Store state in digest */
00167     Encode (digest, context->state, 16);
00168 
00169     /* Zeroize sensitive information.*/
00170     Com_Memset ((POINTER)context, 0, sizeof (*context));
00171 }

Here is the call graph for this function:

void MD4Init MD4_CTX  ) 
 

Definition at line 103 of file md4.c.

References MD4_CTX::count, and MD4_CTX::state.

00104 {
00105     context->count[0] = context->count[1] = 0;
00106 
00107 /* Load magic initialization constants.*/
00108 context->state[0] = 0x67452301;
00109 context->state[1] = 0xefcdab89;
00110 context->state[2] = 0x98badcfe;
00111 context->state[3] = 0x10325476;
00112 }

void MD4Transform UINT4  [4],
const unsigned  char[64]
[static]
 

Definition at line 175 of file md4.c.

References a, b, c, Com_Memset(), d, Decode(), FF, GG, HH, POINTER, S11, S12, S13, S14, S21, S22, S23, S24, S31, S32, S33, S34, state, UINT4, and x.

00176 {
00177     UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
00178 
00179     Decode (x, block, 64);
00180 
00181 /* Round 1 */
00182 FF (a, b, c, d, x[ 0], S11);                /* 1 */
00183 FF (d, a, b, c, x[ 1], S12);                /* 2 */
00184 FF (c, d, a, b, x[ 2], S13);                /* 3 */
00185 FF (b, c, d, a, x[ 3], S14);                /* 4 */
00186 FF (a, b, c, d, x[ 4], S11);                /* 5 */
00187 FF (d, a, b, c, x[ 5], S12);                /* 6 */
00188 FF (c, d, a, b, x[ 6], S13);                /* 7 */
00189 FF (b, c, d, a, x[ 7], S14);                /* 8 */
00190 FF (a, b, c, d, x[ 8], S11);                /* 9 */
00191 FF (d, a, b, c, x[ 9], S12);                /* 10 */
00192 FF (c, d, a, b, x[10], S13);            /* 11 */
00193 FF (b, c, d, a, x[11], S14);            /* 12 */
00194 FF (a, b, c, d, x[12], S11);            /* 13 */
00195 FF (d, a, b, c, x[13], S12);            /* 14 */
00196 FF (c, d, a, b, x[14], S13);            /* 15 */
00197 FF (b, c, d, a, x[15], S14);            /* 16 */
00198 
00199 /* Round 2 */
00200 GG (a, b, c, d, x[ 0], S21);            /* 17 */
00201 GG (d, a, b, c, x[ 4], S22);            /* 18 */
00202 GG (c, d, a, b, x[ 8], S23);            /* 19 */
00203 GG (b, c, d, a, x[12], S24);            /* 20 */
00204 GG (a, b, c, d, x[ 1], S21);            /* 21 */
00205 GG (d, a, b, c, x[ 5], S22);            /* 22 */
00206 GG (c, d, a, b, x[ 9], S23);            /* 23 */
00207 GG (b, c, d, a, x[13], S24);            /* 24 */
00208 GG (a, b, c, d, x[ 2], S21);            /* 25 */
00209 GG (d, a, b, c, x[ 6], S22);            /* 26 */
00210 GG (c, d, a, b, x[10], S23);            /* 27 */
00211 GG (b, c, d, a, x[14], S24);            /* 28 */
00212 GG (a, b, c, d, x[ 3], S21);            /* 29 */
00213 GG (d, a, b, c, x[ 7], S22);            /* 30 */
00214 GG (c, d, a, b, x[11], S23);            /* 31 */
00215 GG (b, c, d, a, x[15], S24);            /* 32 */
00216 
00217 /* Round 3 */
00218 HH (a, b, c, d, x[ 0], S31);                /* 33 */
00219 HH (d, a, b, c, x[ 8], S32);            /* 34 */
00220 HH (c, d, a, b, x[ 4], S33);            /* 35 */
00221 HH (b, c, d, a, x[12], S34);            /* 36 */
00222 HH (a, b, c, d, x[ 2], S31);            /* 37 */
00223 HH (d, a, b, c, x[10], S32);            /* 38 */
00224 HH (c, d, a, b, x[ 6], S33);            /* 39 */
00225 HH (b, c, d, a, x[14], S34);            /* 40 */
00226 HH (a, b, c, d, x[ 1], S31);            /* 41 */
00227 HH (d, a, b, c, x[ 9], S32);            /* 42 */
00228 HH (c, d, a, b, x[ 5], S33);            /* 43 */
00229 HH (b, c, d, a, x[13], S34);            /* 44 */
00230 HH (a, b, c, d, x[ 3], S31);            /* 45 */
00231 HH (d, a, b, c, x[11], S32);            /* 46 */
00232 HH (c, d, a, b, x[ 7], S33);            /* 47 */
00233 HH (b, c, d, a, x[15], S34);            /* 48 */
00234 
00235 state[0] += a;
00236 state[1] += b;
00237 state[2] += c;
00238 state[3] += d;
00239 
00240     /* Zeroize sensitive information.*/
00241     Com_Memset ((POINTER)x, 0, sizeof (x));
00242 }

Here is the call graph for this function:

void MD4Update MD4_CTX ,
const unsigned char *  ,
unsigned  int
 

Definition at line 115 of file md4.c.

References MD4_CTX::buffer, Com_Memcpy(), MD4_CTX::count, i, input, MD4Transform(), POINTER, and MD4_CTX::state.

00116 {
00117     unsigned int i, index, partLen;
00118 
00119     /* Compute number of bytes mod 64 */
00120     index = (unsigned int)((context->count[0] >> 3) & 0x3F);
00121 
00122     /* Update number of bits */
00123     if ((context->count[0] += ((UINT4)inputLen << 3))< ((UINT4)inputLen << 3))
00124         context->count[1]++;
00125 
00126     context->count[1] += ((UINT4)inputLen >> 29);
00127 
00128     partLen = 64 - index;
00129 
00130     /* Transform as many times as possible.*/
00131     if (inputLen >= partLen)
00132     {
00133         Com_Memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen);
00134         MD4Transform (context->state, context->buffer);
00135 
00136         for (i = partLen; i + 63 < inputLen; i += 64)
00137             MD4Transform (context->state, &input[i]);
00138 
00139         index = 0;
00140     }
00141     else
00142         i = 0;
00143 
00144     /* Buffer remaining input */
00145     Com_Memcpy ((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i);
00146 }

Here is the call graph for this function:


Variable Documentation

unsigned char PADDING[64] [static]
 

Initial value:

 {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}

Definition at line 81 of file md4.c.

Referenced by MD4Final().


Generated on Thu Aug 25 14:43:27 2005 for Quake III Arena by  doxygen 1.3.9.1