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

Go to the source code of this file.

Macros

#define ALG   MARVIN32
 
#define Alg   Marvin32
 
#define BLOCK(a, b)
 

Functions

SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptMarvin32ExpandSeed (_Out_ PSYMCRYPT_MARVIN32_EXPANDED_SEED pExpandedSeed, _In_reads_(cbSeed) PCBYTE pbSeed, SIZE_T cbSeed)
 
VOID SYMCRYPT_CALL SymCryptMarvin32SeedCopy (_In_ PCSYMCRYPT_MARVIN32_EXPANDED_SEED pSrc, _Out_ PSYMCRYPT_MARVIN32_EXPANDED_SEED pDst)
 
VOID SYMCRYPT_CALL SymCryptMarvin32StateCopy (_In_ PCSYMCRYPT_MARVIN32_STATE pSrc, _In_opt_ PCSYMCRYPT_MARVIN32_EXPANDED_SEED pExpandedSeed, _Out_ PSYMCRYPT_MARVIN32_STATE pDst)
 
VOID SYMCRYPT_CALL SymCryptMarvin32Init (_Out_ PSYMCRYPT_MARVIN32_STATE pState, _In_ PCSYMCRYPT_MARVIN32_EXPANDED_SEED pExpandedSeed)
 
VOID SYMCRYPT_CALL SymCryptMarvin32Append (_Inout_ PSYMCRYPT_MARVIN32_STATE state, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData)
 
VOID SYMCRYPT_CALL SymCryptMarvin32Result (_Inout_ PSYMCRYPT_MARVIN32_STATE pState, _Out_writes_(SYMCRYPT_MARVIN32_RESULT_SIZE) PBYTE pbResult)
 
VOID SYMCRYPT_CALL SymCryptMarvin32AppendBlocks (_Inout_ PSYMCRYPT_MARVIN32_CHAINING_STATE pChain, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData)
 
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)
 
VOID SYMCRYPT_CALL SymCryptMarvin32Selftest (void)
 

Variables

static const SYMCRYPT_MARVIN32_EXPANDED_SEED SymCryptMarvin32DefaultSeedStruct
 
PCSYMCRYPT_MARVIN32_EXPANDED_SEED const SymCryptMarvin32DefaultSeed = &SymCryptMarvin32DefaultSeedStruct
 
static const int rotate [4]
 
static const BYTE marvin32KATAnswer [8]
 

Macro Definition Documentation

◆ ALG

#define ALG   MARVIN32

◆ Alg

#define Alg   Marvin32

◆ BLOCK

#define BLOCK (   a,
  b 
)
Value:
{\
b ^= a; a = ROL32( a, rotate[0] );\
a += b; b = ROL32( b, rotate[1] );\
b ^= a; a = ROL32( a, rotate[2] );\
a += b; b = ROL32( b, rotate[3] );\
}
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
static const int rotate[4]
Definition: marvin32.c:35

Definition at line 184 of file marvin32.c.

Function Documentation

◆ SymCryptMarvin32()

Definition at line 239 of file marvin32.c.

247{
248 UINT32 tmp;
249
250 UINT32 s0 = pExpandedSeed->s[0];
251 UINT32 s1 = pExpandedSeed->s[1];
252
253 while( cbData > 7 )
254 {
256 BLOCK( s0, s1 );
257 s0 += SYMCRYPT_LOAD_LSBFIRST32( pbData + 4 );
258 BLOCK( s0, s1 );
259 pbData += 8;
260 cbData -= 8;
261 }
262
263 /*
264 switch( cbData )
265 {
266 case 3:
267 buf[2] = pbData[2];
268 case 2:
269 *(UINT16 *) &buf[0] = *(UINT16 *) pbData;
270 break;
271 case 1:
272 buf[0] = pbData[0];
273 case 0:
274 ;
275 }
276
277 buf[ cbData ] = 0x80;
278
279 s0 += LOAD_LSBFIRST32( buf );
280 */
281
282
283 switch( cbData )
284 {
285 default:
286 case 4: s0 += SYMCRYPT_LOAD_LSBFIRST32( pbData ); BLOCK( s0, s1 ); pbData += 4;
287 case 0: tmp = 0x80; break;
288
289 case 5: s0 += SYMCRYPT_LOAD_LSBFIRST32( pbData ); BLOCK( s0, s1 ); pbData += 4;
290 case 1: tmp = 0x8000 | pbData[0]; break;
291
292 case 6: s0 += SYMCRYPT_LOAD_LSBFIRST32( pbData ); BLOCK( s0, s1 ); pbData += 4;
293 case 2: tmp = 0x800000 | SYMCRYPT_LOAD_LSBFIRST16( pbData ); break;
294
295 case 7: s0 += SYMCRYPT_LOAD_LSBFIRST32( pbData ); BLOCK( s0, s1 ); pbData += 4;
296 case 3: tmp = SYMCRYPT_LOAD_LSBFIRST16( pbData ) | (pbData[2] << 16) | 0x80000000; break;
297 }
298 s0 += tmp;
299
300
301 BLOCK( s0, s1 );
302 BLOCK( s0, s1 );
303
306}
#define BLOCK(a, b)
Definition: marvin32.c:184
struct S1 s1
static const BYTE pbResult[]
#define SYMCRYPT_LOAD_LSBFIRST16(p)
Definition: symcrypt.h:298
#define SYMCRYPT_LOAD_LSBFIRST32(p)
Definition: symcrypt.h:299
#define SYMCRYPT_STORE_LSBFIRST32(p, v)
Definition: symcrypt.h:307
PCBYTE PBYTE SIZE_T cbData
PCBYTE pbData
uint32_t UINT32
Definition: typedefs.h:59

Referenced by SymCryptKeccakStateExport(), SymCryptKeccakStateImport(), SymCryptMarvin32Selftest(), SymCryptMd2StateExport(), SymCryptMd2StateImport(), SymCryptMd4StateExport(), SymCryptMd4StateImport(), SymCryptMd5StateExport(), SymCryptMd5StateImport(), SymCryptSha1StateExport(), SymCryptSha1StateImport(), SymCryptSha256StateExportCore(), SymCryptSha256StateImportCore(), SymCryptSha512StateExportCore(), and SymCryptSha512StateImportCore().

◆ SymCryptMarvin32Append()

VOID SYMCRYPT_CALL SymCryptMarvin32Append ( _Inout_ PSYMCRYPT_MARVIN32_STATE  state,
_In_reads_(cbData) PCBYTE  pbData,
SIZE_T  cbData 
)

Definition at line 120 of file marvin32.c.

123{
124 UINT32 bytesInBuffer = state->dataLength;
125
127
128 state->dataLength += (UINT32) cbData; // We only keep track of the last 2 bits...
129
130#define ALG MARVIN32
131#define Alg Marvin32
132#include "hash_buffer_pattern.c"
133#undef ALG
134#undef Alg
135
136}
static int state
Definition: maze.c:121
SIZE_T bytesInBuffer
#define SYMCRYPT_CHECK_MAGIC(p)

◆ SymCryptMarvin32AppendBlocks()

VOID SYMCRYPT_CALL SymCryptMarvin32AppendBlocks ( _Inout_ PSYMCRYPT_MARVIN32_CHAINING_STATE  pChain,
_In_reads_(cbData) PCBYTE  pbData,
SIZE_T  cbData 
)

Definition at line 194 of file marvin32.c.

198{
199 UINT32 s0 = pChain->s[0];
200 UINT32 s1 = pChain->s[1];
201
202 SIZE_T bytesInFirstBlock = cbData & 0xc; // 0, 4, 8, or 12
203
204 SYMCRYPT_ASSERT( (cbData & 3) == 0 );
205
206
207 pbData += bytesInFirstBlock;
208 cbData -= bytesInFirstBlock;
209
210 switch( bytesInFirstBlock )
211 {
212 case 0: // This handles the cbData == 0 case too
213 while( cbData > 0 )
214 {
215 pbData += 16;
216 cbData -= 16;
217
218 s0 += SYMCRYPT_LOAD_LSBFIRST32( pbData - 16 );
219 BLOCK( s0, s1 );
220 case 12:
221 s0 += SYMCRYPT_LOAD_LSBFIRST32( pbData - 12 );
222 BLOCK( s0, s1 );
223 case 8:
224 s0 += SYMCRYPT_LOAD_LSBFIRST32( pbData - 8 );
225 BLOCK( s0, s1 );
226 case 4:
227 s0 += SYMCRYPT_LOAD_LSBFIRST32( pbData - 4 );
228 BLOCK( s0, s1 );
229 }
230 }
231
232 pChain->s[0] = s0;
233 pChain->s[1] = s1;
234}
#define SYMCRYPT_ASSERT(_x)
Definition: symcrypt.h:10807
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by SymCryptMarvin32Result().

◆ SymCryptMarvin32ExpandSeed()

SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptMarvin32ExpandSeed ( _Out_ PSYMCRYPT_MARVIN32_EXPANDED_SEED  pExpandedSeed,
_In_reads_(cbSeed) PCBYTE  pbSeed,
SIZE_T  cbSeed 
)

Definition at line 42 of file marvin32.c.

46{
47 SYMCRYPT_ERROR scError = SYMCRYPT_NO_ERROR;
48
50 {
51 scError = SYMCRYPT_WRONG_KEY_SIZE;
52 goto cleanup;
53 }
54 pExpandedSeed->s[0] = SYMCRYPT_LOAD_LSBFIRST32( pbSeed );
55 pExpandedSeed->s[1] = SYMCRYPT_LOAD_LSBFIRST32( pbSeed + 4 );
56
57 SYMCRYPT_SET_MAGIC( pExpandedSeed );
58
60 return scError;
61}
static void cleanup(void)
Definition: main.c:1335
#define SYMCRYPT_MARVIN32_SEED_SIZE
Definition: symcrypt.h:3989
SYMCRYPT_ERROR
Definition: symcrypt.h:227
#define SYMCRYPT_SET_MAGIC(p)
UINT32 cbSeed
PBYTE pbSeed

◆ SymCryptMarvin32Init()

VOID SYMCRYPT_CALL SymCryptMarvin32Init ( _Out_ PSYMCRYPT_MARVIN32_STATE  pState,
_In_ PCSYMCRYPT_MARVIN32_EXPANDED_SEED  pExpandedSeed 
)

Definition at line 101 of file marvin32.c.

103{
104 pState->chain = *pExpandedSeed;
105 pState->dataLength = 0;
106 pState->pSeed = pExpandedSeed;
107
108 *(UINT32 *) &pState->buffer[4] = 0; // wipe the last 4 bytes of the buffer.
109
111}
PSYMCRYPT_COMMON_HASH_STATE pState

◆ SymCryptMarvin32Result()

Definition at line 144 of file marvin32.c.

147{
148 SIZE_T bytesInBuffer = ( pState->dataLength) & 0x3;
149
151
152 //
153 // Wipe four bytes in the buffer.
154 // Doing this first ensures that this write is aligned when the input was of
155 // length 0 mod 4.
156 // The buffer is 8 bytes long, so we never overwrite anything else.
157 //
158 *(UINT32 *) &pState->buffer[bytesInBuffer] = 0;
159
160 //
161 // The buffer is never completely full, so we can always put the first
162 // padding byte in.
163 //
164 pState->buffer[bytesInBuffer++] = 0x80;
165
166 //
167 // Process the final block
168 //
169 SymCryptMarvin32AppendBlocks( &pState->chain, pState->buffer, 8 );
170
172 SYMCRYPT_STORE_LSBFIRST32( pbResult + 4, pState->chain.s[1] );
173
174 //
175 // Wipe only those things that we need to wipe.
176 //
177
178 *(UINT32 *) &pState->buffer[0] = 0;
179 pState->dataLength = 0;
180
181 pState->chain = *pState->pSeed;
182}
VOID SYMCRYPT_CALL SymCryptMarvin32AppendBlocks(_Inout_ PSYMCRYPT_MARVIN32_CHAINING_STATE pChain, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData)
Definition: marvin32.c:194

◆ SymCryptMarvin32SeedCopy()

Definition at line 65 of file marvin32.c.

67{
69 *pDst = *pSrc;
70 SYMCRYPT_SET_MAGIC( pDst );
71}

◆ SymCryptMarvin32Selftest()

VOID SYMCRYPT_CALL SymCryptMarvin32Selftest ( void  )

Definition at line 320 of file marvin32.c.

321{
323
325
326 SymCryptInjectError( res, sizeof( res ) );
327 if( memcmp( res, marvin32KATAnswer, sizeof( res ) ) != 0 )
328 {
329 SymCryptFatal( 'marv' );
330 }
331}
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
GLuint res
Definition: glext.h:9613
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
static const BYTE marvin32KATAnswer[8]
Definition: marvin32.c:314
PCSYMCRYPT_MARVIN32_EXPANDED_SEED const SymCryptMarvin32DefaultSeed
Definition: marvin32.c:29
VOID SYMCRYPT_CALL SymCryptInjectError(PBYTE pbData, SIZE_T cbData)
const BYTE SymCryptTestMsg3[3]
Definition: selftest.c:8
_Analysis_noreturn_ VOID SYMCRYPT_CALL SymCryptFatal(UINT32 fatalCode)
#define SYMCRYPT_MARVIN32_RESULT_SIZE
Definition: symcrypt.h:3988
unsigned char BYTE
Definition: xxhash.c:193

◆ SymCryptMarvin32StateCopy()

Definition at line 76 of file marvin32.c.

80{
82 *pDst = *pSrc;
83
84 if( pExpandedSeed == NULL )
85 {
86 SYMCRYPT_CHECK_MAGIC( pSrc->pSeed );
87 pDst->pSeed = pSrc->pSeed;
88 }
89 else
90 {
91 SYMCRYPT_CHECK_MAGIC( pExpandedSeed );
92 pDst->pSeed = pExpandedSeed;
93 }
94
95 SYMCRYPT_SET_MAGIC( pDst );
96}
#define NULL
Definition: types.h:112

Variable Documentation

◆ marvin32KATAnswer

const BYTE marvin32KATAnswer[8]
static
Initial value:
= {
0xbf, 0x69, 0x27, 0x49, 0x39, 0x43, 0xc7, 0x22,
}

Definition at line 314 of file marvin32.c.

Referenced by SymCryptMarvin32Selftest().

◆ rotate

◆ SymCryptMarvin32DefaultSeed

◆ SymCryptMarvin32DefaultSeedStruct

const SYMCRYPT_MARVIN32_EXPANDED_SEED SymCryptMarvin32DefaultSeedStruct
static
Initial value:
= {
{0xcd0893b7, 0xd53cd9ce},
}

Definition at line 22 of file marvin32.c.