ReactOS 0.4.17-dev-1005-g171e1de
md4.c File Reference
#include "precomp.h"
#include "hash_pattern.c"
Include dependency graph for md4.c:

Go to the source code of this file.

Macros

#define ALG   MD4
 
#define Alg   Md4
 
#define F(x, y, z)   ((((z) ^ (y)) & (x)) ^ (z))
 
#define G(x, y, z)   ((((x) | (y)) & (z) ) | ((x) & (y)))
 
#define H(x, y, z)   ((x) ^ (y) ^ (z) )
 
#define CROUND(r, Func)
 
#define IROUND(r, Func)
 
#define FROUND(r, Func)
 

Functions

VOID SYMCRYPT_CALL SymCryptMd4Init (_Out_ PSYMCRYPT_MD4_STATE pState)
 
VOID SYMCRYPT_CALL SymCryptMd4Append (_Inout_ PSYMCRYPT_MD4_STATE pState, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData)
 
VOID SYMCRYPT_CALL SymCryptMd4Result (_Inout_ PSYMCRYPT_MD4_STATE pState, _Out_writes_(SYMCRYPT_MD4_RESULT_SIZE) PBYTE pbResult)
 
VOID SYMCRYPT_CALL SymCryptMd4AppendBlocks (_Inout_ PSYMCRYPT_MD4_CHAINING_STATE pChain, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData, _Out_ SIZE_T *pcbRemaining)
 
VOID SYMCRYPT_CALL SymCryptMd4StateExport (_In_ PCSYMCRYPT_MD4_STATE pState, _Out_writes_bytes_(SYMCRYPT_MD4_STATE_EXPORT_SIZE) PBYTE pbBlob)
 
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptMd4StateImport (_Out_ PSYMCRYPT_MD4_STATE pState, _In_reads_bytes_(SYMCRYPT_MD4_STATE_EXPORT_SIZE) PCBYTE pbBlob)
 
VOID SYMCRYPT_CALL SymCryptMd4Selftest (void)
 

Variables

const SYMCRYPT_HASH SymCryptMd4Algorithm_default
 
const PCSYMCRYPT_HASH SymCryptMd4Algorithm = &SymCryptMd4Algorithm_default
 
static const UINT32 md4Const [3]
 
static const int md4Rotate [48]
 
static const int md4MsgIndex [48]
 
static const UINT32 md4InitialState [4]
 
static const BYTE md4KATAnswer [16]
 

Macro Definition Documentation

◆ ALG

#define ALG   MD4

Definition at line 104 of file md4.c.

◆ Alg

#define Alg   Md4

Definition at line 105 of file md4.c.

◆ CROUND

#define CROUND (   r,
  Func 
)
Value:
{ \
ad[r%4] = ROL32( ad[r%4] + Func(ad[(r+3)%4], ad[(r+2)%4], ad[(r+1)%4]) + Wt + md4Const[r/16], md4Rotate[r] ); \
}
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
void(* Func)(int)
static const UINT32 md4Const[3]
Definition: md4.c:52
static const int md4Rotate[48]
Definition: md4.c:62

Definition at line 211 of file md4.c.

◆ F

#define F (   x,
  y,
  z 
)    ((((z) ^ (y)) & (x)) ^ (z))

Definition at line 178 of file md4.c.

◆ FROUND

#define FROUND (   r,
  Func 
)
Value:
{ \
Wt = W[md4MsgIndex[r]];\
CROUND( r, Func ); \
}
static const int md4MsgIndex[48]
Definition: md4.c:84
Definition: polytest.cpp:36

Definition at line 227 of file md4.c.

◆ G

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

Definition at line 179 of file md4.c.

◆ H

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

Definition at line 180 of file md4.c.

◆ IROUND

#define IROUND (   r,
  Func 
)
Value:
{ \
W[r] = Wt; \
CROUND( r, Func ); \
}
#define SYMCRYPT_LOAD_LSBFIRST32(p)
Definition: symcrypt.h:299
PCBYTE pbData

Definition at line 218 of file md4.c.

Function Documentation

◆ SymCryptMd4Append()

VOID SYMCRYPT_CALL SymCryptMd4Append ( _Inout_ PSYMCRYPT_MD4_STATE  pState,
_In_reads_(cbData) PCBYTE  pbData,
SIZE_T  cbData 
)

Definition at line 139 of file md4.c.

142{
144}
VOID SYMCRYPT_CALL SymCryptHashAppendInternal(_In_ PCSYMCRYPT_HASH pHash, _Inout_ PSYMCRYPT_COMMON_HASH_STATE pState, _In_reads_bytes_(cbData) PCBYTE pbData, SIZE_T cbData)
Definition: hash.c:10
const PCSYMCRYPT_HASH SymCryptMd4Algorithm
Definition: md4.c:46
PCBYTE PBYTE SIZE_T cbData
* PSYMCRYPT_COMMON_HASH_STATE
PSYMCRYPT_COMMON_HASH_STATE pState

◆ SymCryptMd4AppendBlocks()

VOID SYMCRYPT_CALL SymCryptMd4AppendBlocks ( _Inout_ PSYMCRYPT_MD4_CHAINING_STATE  pChain,
_In_reads_(cbData) PCBYTE  pbData,
SIZE_T  cbData,
_Out_ SIZE_T *  pcbRemaining 
)

Definition at line 234 of file md4.c.

239{
240
243 UINT32 Wt;
244
245 ad[0] = pChain->H[0];
246 ad[1] = pChain->H[3];
247 ad[2] = pChain->H[2];
248 ad[3] = pChain->H[1];
249
250 while( cbData >= 64 )
251 {
252 //
253 // initial rounds 1 to 16
254 //
255
256 IROUND( 0, F );
257 IROUND( 1, F );
258 IROUND( 2, F );
259 IROUND( 3, F );
260 IROUND( 4, F );
261 IROUND( 5, F );
262 IROUND( 6, F );
263 IROUND( 7, F );
264 IROUND( 8, F );
265 IROUND( 9, F );
266 IROUND( 10, F );
267 IROUND( 11, F );
268 IROUND( 12, F );
269 IROUND( 13, F );
270 IROUND( 14, F );
271 IROUND( 15, F );
272
273 FROUND( 16, G );
274 FROUND( 17, G );
275 FROUND( 18, G );
276 FROUND( 19, G );
277 FROUND( 20, G );
278 FROUND( 21, G );
279 FROUND( 22, G );
280 FROUND( 23, G );
281 FROUND( 24, G );
282 FROUND( 25, G );
283 FROUND( 26, G );
284 FROUND( 27, G );
285 FROUND( 28, G );
286 FROUND( 29, G );
287 FROUND( 30, G );
288 FROUND( 31, G );
289
290 FROUND( 32, H );
291 FROUND( 33, H );
292 FROUND( 34, H );
293 FROUND( 35, H );
294 FROUND( 36, H );
295 FROUND( 37, H );
296 FROUND( 38, H );
297 FROUND( 39, H );
298 FROUND( 40, H );
299 FROUND( 41, H );
300 FROUND( 42, H );
301 FROUND( 43, H );
302 FROUND( 44, H );
303 FROUND( 45, H );
304 FROUND( 46, H );
305 FROUND( 47, H );
306
307 pChain->H[0] = ad[0] = ad[0] + pChain->H[0];
308 pChain->H[3] = ad[1] = ad[1] + pChain->H[3];
309 pChain->H[2] = ad[2] = ad[2] + pChain->H[2];
310 pChain->H[1] = ad[3] = ad[3] + pChain->H[1];
311
312 pbData += 64;
313 cbData -= 64;
314 }
315
316 *pcbRemaining = cbData;
317 //
318 // Wipe the variables;
319 //
320 SymCryptWipeKnownSize( ad, sizeof( ad ) );
321 SymCryptWipeKnownSize( W, sizeof( W ) );
322 SYMCRYPT_FORCE_WRITE32( &Wt, 0 );
323}
#define FROUND(r, Func)
Definition: md4.c:227
#define F(x, y, z)
Definition: md4.c:178
#define G(x, y, z)
Definition: md4.c:179
#define H(x, y, z)
Definition: md4.c:180
#define IROUND(r, Func)
Definition: md4.c:218
FORCEINLINE VOID SYMCRYPT_CALL SymCryptWipeKnownSize(_Out_writes_bytes_(cbData) PVOID pbData, SIZE_T cbData)
#define SYMCRYPT_FORCE_WRITE32(_p, _v)
Definition: symcrypt.h:423
#define SYMCRYPT_ALIGN
uint32_t UINT32
Definition: typedefs.h:59

◆ SymCryptMd4Init()

VOID SYMCRYPT_CALL SymCryptMd4Init ( _Out_ PSYMCRYPT_MD4_STATE  pState)

Definition at line 117 of file md4.c.

118{
120
121 pState->dataLengthL = 0;
122 pState->dataLengthH = 0;
123 pState->bytesInBuffer = 0;
124
125 memcpy( &pState->chain.H[0], &md4InitialState[0], sizeof( md4InitialState ) );
126
127 //
128 // There is no need to initialize the buffer part of the state as that will be
129 // filled before it is used.
130 //
131}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static const UINT32 md4InitialState[4]
Definition: md4.c:93
#define SYMCRYPT_SET_MAGIC(p)

Referenced by SymCryptMd4Result().

◆ SymCryptMd4Result()

Definition at line 152 of file md4.c.

155{
157
158 //
159 // Write the output in the correct byte order
160 //
161 SymCryptUint32ToLsbFirst( &pState->chain.H[0], pbResult, 4 );
162
163 //
164 // Wipe & re-initialize
165 // We have to wipe the whole state as the initialization might be optimized away.
166 //
167 SymCryptWipeKnownSize( pState, sizeof( *pState ));
169 }
FORCEINLINE VOID SYMCRYPT_CALL SymCryptUint32ToLsbFirst(_In_reads_(cuData) PCUINT32 puData, _Out_writes_(4 *cuData) PBYTE pbResult, SIZE_T cuData)
Definition: sc_lib.h:471
VOID SYMCRYPT_CALL SymCryptHashCommonPaddingMd4Style(_In_ PCSYMCRYPT_HASH pHash, _Inout_ PSYMCRYPT_COMMON_HASH_STATE pState)
Definition: hash.c:85
VOID SYMCRYPT_CALL SymCryptMd4Init(_Out_ PSYMCRYPT_MD4_STATE pState)
Definition: md4.c:117
static const BYTE pbResult[]

◆ SymCryptMd4Selftest()

VOID SYMCRYPT_CALL SymCryptMd4Selftest ( void  )

Definition at line 414 of file md4.c.

415{
417
419
420 SymCryptInjectError( result, sizeof( result ) );
421
422 if( memcmp( result, md4KATAnswer, sizeof( result ) ) != 0 ) {
423 SymCryptFatal( 'MD4t' );
424 }
425}
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
GLuint64EXT * result
Definition: glext.h:11304
VOID SYMCRYPT_CALL SymCryptInjectError(PBYTE pbData, SIZE_T cbData)
const BYTE SymCryptTestMsg3[3]
Definition: selftest.c:8
static const BYTE md4KATAnswer[16]
Definition: md4.c:407
_Analysis_noreturn_ VOID SYMCRYPT_CALL SymCryptFatal(UINT32 fatalCode)
VOID SYMCRYPT_CALL SymCryptMd4(_In_reads_(cbData) PCBYTE pbData, SIZE_T cbData, _Out_writes_(SYMCRYPT_MD4_RESULT_SIZE) PBYTE pbResult)
#define SYMCRYPT_MD4_RESULT_SIZE
Definition: symcrypt.h:954
unsigned char BYTE
Definition: xxhash.c:193

◆ SymCryptMd4StateExport()

Definition at line 327 of file md4.c.

330{
331 SYMCRYPT_ALIGN SYMCRYPT_MD4_STATE_EXPORT_BLOB blob; // local copy to have proper alignment.
333
335
336 SymCryptWipeKnownSize( &blob, sizeof( blob ) ); // wipe to avoid any data leakage
337
338 blob.header.magic = SYMCRYPT_BLOB_MAGIC;
340 blob.header.type = SymCryptBlobTypeMd4State;
341
342 //
343 // Copy the relevant data. Buffer will be 0-padded.
344 //
345
346 SymCryptUint32ToLsbFirst( &pState->chain.H[0], &blob.chain[0], 4 );
347 blob.dataLength = pState->dataLengthL;
348 memcpy( &blob.buffer[0], &pState->buffer[0], blob.dataLength & 0x3f );
349
350 SYMCRYPT_ASSERT( (PCBYTE) &blob + sizeof( blob ) - sizeof( SYMCRYPT_BLOB_TRAILER ) == (PCBYTE) &blob.trailer );
351 SymCryptMarvin32( SymCryptMarvin32DefaultSeed, (PCBYTE) &blob, sizeof( blob ) - sizeof( SYMCRYPT_BLOB_TRAILER ), &blob.trailer.checksum[0] );
352
353 memcpy( pbBlob, &blob, sizeof( blob ) );
354
355//cleanup:
356 SymCryptWipeKnownSize( &blob, sizeof( blob ) );
357 return;
358}
#define C_ASSERT(e)
Definition: intsafe.h:73
#define SYMCRYPT_BLOB_MAGIC
Definition: sc_lib.h:1077
@ SymCryptBlobTypeMd4State
Definition: sc_lib.h:1062
Definition: image.c:229
#define SYMCRYPT_ASSERT(_x)
Definition: symcrypt.h:10807
VOID SYMCRYPT_CALL SymCryptMarvin32(_In_ PCSYMCRYPT_MARVIN32_EXPANDED_SEED pExpandedSeed, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData, _Out_writes_(SYMCRYPT_MARVIN32_RESULT_SIZE) PBYTE pbResult)
Definition: marvin32.c:239
PCSYMCRYPT_MARVIN32_EXPANDED_SEED const SymCryptMarvin32DefaultSeed
Definition: marvin32.c:29
#define SYMCRYPT_MD4_STATE_EXPORT_SIZE
const BYTE * PCBYTE
#define SYMCRYPT_CHECK_MAGIC(p)

◆ SymCryptMd4StateImport()

Definition at line 362 of file md4.c.

365{
366 SYMCRYPT_ERROR scError = SYMCRYPT_NO_ERROR;
367 SYMCRYPT_ALIGN SYMCRYPT_MD4_STATE_EXPORT_BLOB blob; // local copy to have proper alignment.
368 BYTE checksum[8];
369
371 memcpy( &blob, pbBlob, sizeof( blob ) );
372
373 if( blob.header.magic != SYMCRYPT_BLOB_MAGIC ||
374 blob.header.size != SYMCRYPT_MD4_STATE_EXPORT_SIZE ||
375 blob.header.type != SymCryptBlobTypeMd4State )
376 {
377 scError = SYMCRYPT_INVALID_BLOB;
378 goto cleanup;
379 }
380
382 if( memcmp( checksum, &blob.trailer.checksum[0], 8 ) != 0 )
383 {
384 scError = SYMCRYPT_INVALID_BLOB;
385 goto cleanup;
386 }
387
388 SymCryptLsbFirstToUint32( &blob.chain[0], &pState->chain.H[0], 4 );
389 pState->dataLengthL = blob.dataLength;
390 pState->dataLengthH = 0;
391 pState->bytesInBuffer = blob.dataLength & 0x3f;
392 memcpy( &pState->buffer[0], &blob.buffer[0], pState->bytesInBuffer );
393
395
396cleanup:
397 SymCryptWipeKnownSize( &blob, sizeof(blob) );
398 return scError;
399}
static cab_ULONG checksum(const cab_UBYTE *data, cab_UWORD bytes, cab_ULONG csum)
Definition: fdi.c:353
static void cleanup(void)
Definition: main.c:1335
FORCEINLINE VOID SYMCRYPT_CALL SymCryptLsbFirstToUint32(_In_reads_(4 *cuResult) PCBYTE pbData, _Out_writes_(cuResult) PUINT32 puResult, SIZE_T cuResult)
Definition: sc_lib.h:487
SYMCRYPT_ERROR
Definition: symcrypt.h:227

Variable Documentation

◆ md4Const

const UINT32 md4Const[3]
static
Initial value:
= {
0x00000000UL,
0x5A827999UL,
0x6ED9EBA1UL,
}

Definition at line 52 of file md4.c.

◆ md4InitialState

const UINT32 md4InitialState[4]
static
Initial value:
= {
0x67452301UL,
0xefcdab89UL,
0x98badcfeUL,
0x10325476UL,
}

Definition at line 93 of file md4.c.

Referenced by SymCryptMd4Init().

◆ md4KATAnswer

const BYTE md4KATAnswer[16]
static
Initial value:
= {
0xa4, 0x48, 0x01, 0x7a, 0xaf, 0x21, 0xd8, 0x52,
0x5f, 0xc1, 0x0a, 0xe8, 0x7a, 0xa6, 0x72, 0x9d,
}

Definition at line 407 of file md4.c.

Referenced by SymCryptMd4Selftest().

◆ md4MsgIndex

const int md4MsgIndex[48]
static
Initial value:
= {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15,
0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15,
}

Definition at line 84 of file md4.c.

◆ md4Rotate

const int md4Rotate[48]
static
Initial value:
= {
3, 7, 11, 19,
3, 7, 11, 19,
3, 7, 11, 19,
3, 7, 11, 19,
3, 5, 9, 13,
3, 5, 9, 13,
3, 5, 9, 13,
3, 5, 9, 13,
3, 9, 11, 15,
3, 9, 11, 15,
3, 9, 11, 15,
3, 9, 11, 15,
}

Definition at line 62 of file md4.c.

◆ SymCryptMd4Algorithm

Definition at line 46 of file md4.c.

Referenced by init_hash_impl(), SymCryptMd4Append(), and SymCryptMd4Result().

◆ SymCryptMd4Algorithm_default

const SYMCRYPT_HASH SymCryptMd4Algorithm_default
Initial value:
= {
sizeof( SYMCRYPT_MD4_STATE ),
}
VOID SYMCRYPT_CALL SymCryptMd4Result(_Inout_ PSYMCRYPT_MD4_STATE pState, _Out_writes_(SYMCRYPT_MD4_RESULT_SIZE) PBYTE pbResult)
Definition: md4.c:152
VOID SYMCRYPT_CALL SymCryptMd4AppendBlocks(_Inout_ PSYMCRYPT_MD4_CHAINING_STATE pChain, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData, _Out_ SIZE_T *pcbRemaining)
Definition: md4.c:234
VOID SYMCRYPT_CALL SymCryptMd4Append(_Inout_ PSYMCRYPT_MD4_STATE pState, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData)
Definition: md4.c:139
VOID SYMCRYPT_CALL SymCryptMd4StateCopy(_In_ PCSYMCRYPT_MD4_STATE pSrc, _Out_ PSYMCRYPT_MD4_STATE pDst)
#define SYMCRYPT_MD4_INPUT_BLOCK_SIZE
Definition: symcrypt.h:955
#define SYMCRYPT_FIELD_SIZE(type, field)
SYMCRYPT_MD4_STATE
#define SYMCRYPT_FIELD_OFFSET(type, field)
struct sock * chain
Definition: tcpcore.h:1

Definition at line 33 of file md4.c.