ReactOS 0.4.17-dev-1005-g171e1de
hmac_pattern.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

VOID SYMCRYPT_CALL SYMCRYPT_HmacXxxStateCopy (_In_ PCSYMCRYPT_HMAC_XXX_STATE pSrc, _In_opt_ PCSYMCRYPT_HMAC_XXX_EXPANDED_KEY pExpandedKey, _Out_ PSYMCRYPT_HMAC_XXX_STATE pDst)
 
VOID SYMCRYPT_CALL SYMCRYPT_HmacXxxKeyCopy (_In_ PCSYMCRYPT_HMAC_XXX_EXPANDED_KEY pSrc, _Out_ PSYMCRYPT_HMAC_XXX_EXPANDED_KEY pDst)
 
SYMCRYPT_ERROR SYMCRYPT_CALL SYMCRYPT_HmacXxxExpandKey (_Out_ PSYMCRYPT_HMAC_XXX_EXPANDED_KEY pExpandedKey, _In_reads_opt_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
 
SYMCRYPT_NOINLINE VOID SYMCRYPT_CALL SYMCRYPT_HmacXxxInit (_Out_ PSYMCRYPT_HMAC_XXX_STATE pState, _In_ PCSYMCRYPT_HMAC_XXX_EXPANDED_KEY pExpandedKey)
 
VOID SYMCRYPT_CALL SYMCRYPT_HmacXxxAppend (_Inout_ PSYMCRYPT_HMAC_XXX_STATE pState, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData)
 
 C_ASSERT (SYMCRYPT_XXX_RESULT_SIZE==SYMCRYPT_HMAC_XXX_RESULT_SIZE)
 
SYMCRYPT_NOINLINE VOID SYMCRYPT_CALL SYMCRYPT_HmacXxxResult (_Inout_ PSYMCRYPT_HMAC_XXX_STATE pState, _Out_writes_(SYMCRYPT_HMAC_XXX_RESULT_SIZE) PBYTE pbResult)
 
SYMCRYPT_NOINLINE VOID SYMCRYPT_CALL SYMCRYPT_HmacXxx (_In_ PCSYMCRYPT_HMAC_XXX_EXPANDED_KEY pExpandedKey, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData, _Out_writes_(SYMCRYPT_HMAC_XXX_RESULT_SIZE) PBYTE pbResult)
 

Function Documentation

◆ C_ASSERT()

◆ SYMCRYPT_HmacXxx()

SYMCRYPT_NOINLINE VOID SYMCRYPT_CALL SYMCRYPT_HmacXxx ( _In_ PCSYMCRYPT_HMAC_XXX_EXPANDED_KEY  pExpandedKey,
_In_reads_(cbData) PCBYTE  pbData,
SIZE_T  cbData,
_Out_writes_(SYMCRYPT_HMAC_XXX_RESULT_SIZE) PBYTE  pbResult 
)

Definition at line 185 of file hmac_pattern.c.

190{
192
196
197}
static int state
Definition: maze.c:121
#define SYMCRYPT_HmacXxxResult
Definition: sc_lib.h:148
#define SYMCRYPT_HmacXxxAppend
Definition: sc_lib.h:147
#define SYMCRYPT_HmacXxxInit
Definition: sc_lib.h:146
#define SYMCRYPT_HMAC_XXX_STATE
Definition: sc_lib.h:159
static const BYTE pbResult[]
PCBYTE PBYTE SIZE_T cbData
PCBYTE pbData
PCVOID pExpandedKey

◆ SYMCRYPT_HmacXxxAppend()

VOID SYMCRYPT_CALL SYMCRYPT_HmacXxxAppend ( _Inout_ PSYMCRYPT_HMAC_XXX_STATE  pState,
_In_reads_(cbData) PCBYTE  pbData,
SIZE_T  cbData 
)

Definition at line 127 of file hmac_pattern.c.

131{
133}
#define SYMCRYPT_XxxAppend
Definition: sc_lib.h:124
PSYMCRYPT_COMMON_HASH_STATE pState

◆ SYMCRYPT_HmacXxxExpandKey()

SYMCRYPT_ERROR SYMCRYPT_CALL SYMCRYPT_HmacXxxExpandKey ( _Out_ PSYMCRYPT_HMAC_XXX_EXPANDED_KEY  pExpandedKey,
_In_reads_opt_(cbKey) PCBYTE  pbKey,
SIZE_T  cbKey 
)

Definition at line 45 of file hmac_pattern.c.

49{
50 SYMCRYPT_XXX_STATE hashState;
51 SYMCRYPT_ALIGN BYTE iblock[ SYMCRYPT_XXX_INPUT_BLOCK_SIZE ]; // One input block for the hash function
52 SIZE_T tmp;
53
55
56 //
57 // Initialize our hash state and our input block
58 // We wipe the whole block & then copy the key into it. This is often faster
59 // as the compiler can optimize the wipe because it knows the size at compile time.
60 //
61 SYMCRYPT_XxxInit( &hashState );
62 memset( iblock, 0, sizeof( iblock ) );
63
64 if( cbKey <= sizeof( iblock ) )
65 {
66 if( cbKey > 0 )
67 {
68 memcpy( iblock, pbKey, cbKey );
69 }
70 } else {
71 //
72 // We can use the existing MD5 state to hash the long key.
73 // The state is re-initialized by the SymCryptMd5Result() function.
74 //
75 SYMCRYPT_XxxAppend( &hashState, pbKey, cbKey );
76 SYMCRYPT_XxxResult( &hashState, iblock );
77 }
78
79 XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE );
80
81 //
82 // Copy the initial chaining state to both states in the expanded key
83 //
84 pExpandedKey->innerState = hashState.chain;
85 pExpandedKey->outerState = hashState.chain;
86
87 //
88 // Update the state in the expanded key directly
89 //
90 SYMCRYPT_XxxAppendBlocks( &pExpandedKey->innerState, iblock, sizeof( iblock ), &tmp );
91
92 XorByteIntoBuffer( iblock, sizeof( iblock )/8, HMAC_IPAD_BYTE ^ HMAC_OPAD_BYTE );
93
94 SYMCRYPT_XxxAppendBlocks( &pExpandedKey->outerState, iblock, sizeof( iblock ), &tmp );
95
96 SymCryptWipeKnownSize( iblock, sizeof( iblock ) );
97 SymCryptWipeKnownSize( &hashState, sizeof( hashState ) );
98
99 return SYMCRYPT_NO_ERROR;
100}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define SYMCRYPT_XxxInit
Definition: sc_lib.h:123
#define SYMCRYPT_XXX_STATE
Definition: sc_lib.h:116
#define SYMCRYPT_XXX_INPUT_BLOCK_SIZE
Definition: sc_lib.h:151
#define HMAC_IPAD_BYTE
Definition: sc_lib.h:301
#define SYMCRYPT_XxxAppendBlocks
Definition: sc_lib.h:126
#define HMAC_OPAD_BYTE
Definition: sc_lib.h:302
#define SYMCRYPT_XxxResult
Definition: sc_lib.h:125
FORCEINLINE VOID SYMCRYPT_CALL XorByteIntoBuffer(_Inout_updates_(8 *cqBuf) PBYTE pbBuf, SIZE_T cqBuf, BYTE v)
Definition: sc_lib.h:915
#define memset(x, y, z)
Definition: compat.h:39
FORCEINLINE VOID SYMCRYPT_CALL SymCryptWipeKnownSize(_Out_writes_bytes_(cbData) PVOID pbData, SIZE_T cbData)
#define SYMCRYPT_ALIGN
PCBYTE pbKey
PCBYTE SIZE_T cbKey
#define SYMCRYPT_SET_MAGIC(p)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
unsigned char BYTE
Definition: xxhash.c:193

◆ SYMCRYPT_HmacXxxInit()

SYMCRYPT_NOINLINE VOID SYMCRYPT_CALL SYMCRYPT_HmacXxxInit ( _Out_ PSYMCRYPT_HMAC_XXX_STATE  pState,
_In_ PCSYMCRYPT_HMAC_XXX_EXPANDED_KEY  pExpandedKey 
)

Definition at line 106 of file hmac_pattern.c.

109{
111
113
114 //
115 // We don't call SymCryptXxxInit on the hash sub-state;
116 // instead we directly initialize its fields.
117 //
118 SYMCRYPT_SET_MAGIC( &pState->hash );
119 pState->hash.chain = pExpandedKey->innerState;
121 pState->hash.bytesInBuffer = 0;
122 pState->pKey = pExpandedKey;
123}
#define SET_DATALENGTH(state, len)
Definition: hmacmd5.c:11
#define SYMCRYPT_CHECK_MAGIC(p)

◆ SYMCRYPT_HmacXxxKeyCopy()

Definition at line 36 of file hmac_pattern.c.

37{
39 *pDst = *pSrc;
40 SYMCRYPT_SET_MAGIC( pDst );
41}

◆ SYMCRYPT_HmacXxxResult()

SYMCRYPT_NOINLINE VOID SYMCRYPT_CALL SYMCRYPT_HmacXxxResult ( _Inout_ PSYMCRYPT_HMAC_XXX_STATE  pState,
_Out_writes_(SYMCRYPT_HMAC_XXX_RESULT_SIZE) PBYTE  pbResult 
)

Definition at line 140 of file hmac_pattern.c.

143{
145
147
148 //
149 // We have to buffer the inner hash result. We can't put it directly in the
150 // hash state data buffer as the Result() function wipes that buffer before returning.
151 //
152
153 SYMCRYPT_XxxResult( &pState->hash, innerRes );
154
156
158
159 //
160 // We put the data directly in the buffer, rather than call the Append function.
161 //
162 memcpy( &pState->hash.buffer, innerRes, sizeof( innerRes ) );
165
167
168 //
169 // The SymCryptXxxResult already wipes the hash state.
170 // We only need to wipe our own buffer.
171 //
172 // We also set the key pointer to NULL. This is not for security;
173 // it creates a clear error when callers forget to call the Init routine
174 // when re-using a state. Rather than the wrong result, they will get
175 // a NULL pointer exception, and they will fix their code.
176 //
177
178 SymCryptWipe( innerRes, sizeof( innerRes ) );
179 pState->pKey = NULL;
180}
#define NULL
Definition: types.h:112
GLuint buffer
Definition: glext.h:5915
#define SYMCRYPT_XXX_RESULT_SIZE
Definition: sc_lib.h:152
VOID SYMCRYPT_CALL SymCryptWipe(_Out_writes_bytes_(cbData) PVOID pbData, SIZE_T cbData)
Definition: libmain.c:137
SYMCRYPT_MD5_CHAINING_STATE outerState
SIZE_T bytesInBuffer
PCSYMCRYPT_HMAC_MD5_EXPANDED_KEY pKey
struct sock * chain
Definition: tcpcore.h:1
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList

◆ SYMCRYPT_HmacXxxStateCopy()

Definition at line 12 of file hmac_pattern.c.

16{
18
19 SYMCRYPT_XxxStateCopy( &pSrc->hash, &pDst->hash );
20
21 if( pExpandedKey != NULL )
22 {
24 pDst->pKey = pExpandedKey;
25 }
26 else
27 {
28 SYMCRYPT_CHECK_MAGIC( pSrc->pKey );
29 pDst->pKey = pSrc->pKey;
30 }
31 SYMCRYPT_SET_MAGIC( pDst );
32}
#define SYMCRYPT_XxxStateCopy
Definition: sc_lib.h:122