ReactOS 0.4.17-dev-1005-g171e1de
kmac_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_Xxx (_In_ PCSYMCRYPT_XXX_EXPANDED_KEY pExpandedKey, _In_reads_bytes_(cbInput) PCBYTE pbInput, SIZE_T cbInput, _Out_writes_bytes_(SYMCRYPT_KMACXXX_RESULT_SIZE) PBYTE pbResult)
 
VOID SYMCRYPT_CALL SYMCRYPT_XxxEx (_In_ PCSYMCRYPT_XXX_EXPANDED_KEY pExpandedKey, _In_reads_bytes_(cbInput) PCBYTE pbInput, SIZE_T cbInput, _Out_writes_bytes_(cbResult) PBYTE pbResult, SIZE_T cbResult)
 
SYMCRYPT_ERROR SYMCRYPT_CALL SYMCRYPT_XxxExpandKey (_Out_ PSYMCRYPT_XXX_EXPANDED_KEY pExpandedKey, _In_reads_bytes_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
 
SYMCRYPT_ERROR SYMCRYPT_CALL SYMCRYPT_XxxExpandKeyEx (_Out_ PSYMCRYPT_XXX_EXPANDED_KEY pExpandedKey, _In_reads_bytes_(cbKey) PCBYTE pbKey, SIZE_T cbKey, _In_reads_bytes_(cbCustomizationString) PCBYTE pbCustomizationString, SIZE_T cbCustomizationString)
 
VOID SYMCRYPT_CALL SYMCRYPT_XxxInit (_Out_ PSYMCRYPT_XXX_STATE pState, _In_ PCSYMCRYPT_XXX_EXPANDED_KEY pExpandedKey)
 
VOID SYMCRYPT_CALL SYMCRYPT_XxxAppend (_Inout_ PSYMCRYPT_XXX_STATE pState, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData)
 
VOID SYMCRYPT_CALL SYMCRYPT_XxxExtract (_Inout_ PSYMCRYPT_XXX_STATE pState, _Out_writes_(cbOutput) PBYTE pbOutput, SIZE_T cbOutput, BOOLEAN bWipe)
 
VOID SYMCRYPT_CALL SYMCRYPT_XxxResult (_Inout_ PSYMCRYPT_XXX_STATE pState, _Out_writes_(SYMCRYPT_KMACXXX_RESULT_SIZE) PBYTE pbOutput)
 
VOID SYMCRYPT_CALL SYMCRYPT_XxxResultEx (_Inout_ PSYMCRYPT_XXX_STATE pState, _Out_writes_(cbOutput) PBYTE pbOutput, SIZE_T cbOutput)
 
VOID SYMCRYPT_CALL SYMCRYPT_XxxKeyCopy (_In_ PCSYMCRYPT_XXX_EXPANDED_KEY pSrc, _Out_ PSYMCRYPT_XXX_EXPANDED_KEY pDst)
 
VOID SYMCRYPT_CALL SYMCRYPT_XxxStateCopy (_In_ const SYMCRYPT_XXX_STATE *pSrc, _Out_ SYMCRYPT_XXX_STATE *pDst)
 

Function Documentation

◆ SYMCRYPT_Xxx()

VOID SYMCRYPT_CALL SYMCRYPT_Xxx ( _In_ PCSYMCRYPT_XXX_EXPANDED_KEY  pExpandedKey,
_In_reads_bytes_(cbInput) PCBYTE  pbInput,
SIZE_T  cbInput,
_Out_writes_bytes_(SYMCRYPT_KMACXXX_RESULT_SIZE) PBYTE  pbResult 
)

Definition at line 23 of file kmac_pattern.c.

28{
30
32 SYMCRYPT_XxxAppend(&state, pbInput, cbInput);
34}
static int state
Definition: maze.c:121
#define SYMCRYPT_XxxInit
Definition: sc_lib.h:123
#define SYMCRYPT_XxxAppend
Definition: sc_lib.h:124
#define SYMCRYPT_XXX_STATE
Definition: sc_lib.h:116
#define SYMCRYPT_XxxResult
Definition: sc_lib.h:125
static const BYTE pbResult[]
PCVOID pExpandedKey

◆ SYMCRYPT_XxxAppend()

VOID SYMCRYPT_CALL SYMCRYPT_XxxAppend ( _Inout_ PSYMCRYPT_XXX_STATE  pState,
_In_reads_(cbData) PCBYTE  pbData,
SIZE_T  cbData 
)

Definition at line 122 of file kmac_pattern.c.

126{
127 SYMCRYPT_ASSERT(!pState->ks.squeezeMode);
129}
VOID SYMCRYPT_CALL SymCryptKeccakAppend(_Inout_ PSYMCRYPT_KECCAK_STATE pState, _In_reads_(cbData) PCBYTE pbData, SIZE_T cbData)
Definition: sha3.c:285
#define SYMCRYPT_ASSERT(_x)
Definition: symcrypt.h:10807
PCBYTE PBYTE SIZE_T cbData
PSYMCRYPT_COMMON_HASH_STATE pState
PCBYTE pbData

◆ SYMCRYPT_XxxEx()

VOID SYMCRYPT_CALL SYMCRYPT_XxxEx ( _In_ PCSYMCRYPT_XXX_EXPANDED_KEY  pExpandedKey,
_In_reads_bytes_(cbInput) PCBYTE  pbInput,
SIZE_T  cbInput,
_Out_writes_bytes_(cbResult) PBYTE  pbResult,
SIZE_T  cbResult 
)

Definition at line 41 of file kmac_pattern.c.

47{
49
51 SYMCRYPT_XxxAppend(&state, pbInput, cbInput);
53}
#define SYMCRYPT_XxxResultEx
Definition: sc_lib.h:139

◆ SYMCRYPT_XxxExpandKey()

SYMCRYPT_ERROR SYMCRYPT_CALL SYMCRYPT_XxxExpandKey ( _Out_ PSYMCRYPT_XXX_EXPANDED_KEY  pExpandedKey,
_In_reads_bytes_(cbKey) PCBYTE  pbKey,
SIZE_T  cbKey 
)

Definition at line 61 of file kmac_pattern.c.

65{
67}
#define NULL
Definition: types.h:112
#define SYMCRYPT_XxxExpandKeyEx
Definition: sc_lib.h:137
PCBYTE pbKey
PCBYTE SIZE_T cbKey

◆ SYMCRYPT_XxxExpandKeyEx()

SYMCRYPT_ERROR SYMCRYPT_CALL SYMCRYPT_XxxExpandKeyEx ( _Out_ PSYMCRYPT_XXX_EXPANDED_KEY  pExpandedKey,
_In_reads_bytes_(cbKey) PCBYTE  pbKey,
SIZE_T  cbKey,
_In_reads_bytes_(cbCustomizationString) PCBYTE  pbCustomizationString,
SIZE_T  cbCustomizationString 
)

Definition at line 74 of file kmac_pattern.c.

80{
81 static const BYTE nameString[] = { 0x4b, 0x4d, 0x41, 0x43 }; // "KMAC"
82
84
85 SYMCRYPT_CSHAKEXXX_INIT( (SYMCRYPT_CSHAKEXXX_STATE*)pExpandedKey, nameString, sizeof(nameString), pbCustomizationString, cbCustomizationString);
86
88
89 // byte_pad( encode_string( K ) )
90 SymCryptKeccakAppendEncodeTimes8(pks, pks->inputBlockSize / 8, TRUE);
92
93 if (pks->stateIndex != 0)
94 {
96 }
97
98 return SYMCRYPT_NO_ERROR;
99}
#define TRUE
Definition: types.h:120
#define C_ASSERT(e)
Definition: intsafe.h:73
#define SYMCRYPT_CSHAKEXXX_INIT
Definition: kmac.c:73
#define SYMCRYPT_CSHAKEXXX_STATE
Definition: kmac.c:74
VOID SYMCRYPT_CALL SymCryptKeccakAppendEncodeTimes8(_Inout_ SYMCRYPT_KECCAK_STATE *pState, UINT64 uValue, BOOLEAN bLeftEncode)
Definition: shake.c:310
VOID SYMCRYPT_CALL SymCryptKeccakZeroAppendBlock(_Inout_ PSYMCRYPT_KECCAK_STATE pState)
Definition: sha3.c:273
VOID SYMCRYPT_CALL SymCryptKeccakAppendEncodedString(_Inout_ PSYMCRYPT_KECCAK_STATE pState, _In_reads_(cbString) PCBYTE pbString, SIZE_T cbString)
Definition: shake.c:330
#define SYMCRYPT_XXX_EXPANDED_KEY
Definition: sc_lib.h:131
SYMCRYPT_KECCAK_STATE
unsigned char BYTE
Definition: xxhash.c:193

◆ SYMCRYPT_XxxExtract()

VOID SYMCRYPT_CALL SYMCRYPT_XxxExtract ( _Inout_ PSYMCRYPT_XXX_STATE  pState,
_Out_writes_(cbOutput) PBYTE  pbOutput,
SIZE_T  cbOutput,
BOOLEAN  bWipe 
)

Definition at line 136 of file kmac_pattern.c.

141{
142 // This function uses KMAC in XOF mode.
143 //
144 // If this is the first time Extract is being called, append right_encode(0)
145 // to indicate that we're in XOF mode. This padding will be applied only once
146 // as SymCryptKeccakExtract will transition the state to squeeze mode.
147 if (!pState->ks.squeezeMode)
148 {
150 }
151
152 SymCryptKeccakExtract(&pState->ks, pbOutput, cbOutput, bWipe);
153}
#define FALSE
Definition: types.h:117
VOID SYMCRYPT_CALL SymCryptKeccakExtract(_Inout_ PSYMCRYPT_KECCAK_STATE pState, _Out_writes_(cbResult) PBYTE pbResult, SIZE_T cbResult, BOOLEAN bWipe)
Definition: sha3.c:411

◆ SYMCRYPT_XxxInit()

VOID SYMCRYPT_CALL SYMCRYPT_XxxInit ( _Out_ PSYMCRYPT_XXX_STATE  pState,
_In_ PCSYMCRYPT_XXX_EXPANDED_KEY  pExpandedKey 
)

Definition at line 106 of file kmac_pattern.c.

109{
110 C_ASSERT(sizeof(*pState) == sizeof(*pExpandedKey));
111
113 memcpy(pState, pExpandedKey, sizeof(*pState));
115}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define SYMCRYPT_SET_MAGIC(p)
#define SYMCRYPT_CHECK_MAGIC(p)

◆ SYMCRYPT_XxxKeyCopy()

Definition at line 201 of file kmac_pattern.c.

202{
204 *pDst = *pSrc;
205 SYMCRYPT_SET_MAGIC(pDst);
206}

◆ SYMCRYPT_XxxResult()

Definition at line 160 of file kmac_pattern.c.

163{
165}
#define SYMCRYPT_KMACXXX_RESULT_SIZE
Definition: kmac.c:75

◆ SYMCRYPT_XxxResultEx()

VOID SYMCRYPT_CALL SYMCRYPT_XxxResultEx ( _Inout_ PSYMCRYPT_XXX_STATE  pState,
_Out_writes_(cbOutput) PBYTE  pbOutput,
SIZE_T  cbOutput 
)

Definition at line 173 of file kmac_pattern.c.

177{
178 // Result and ResultEx functions are used to extract data only once.
179 // KMAC requires the output length to be encoded and appended to the
180 // end of the input before the state switches to squeeze mode.
181 //
182 // If Result or ResultEx is called after an Extract call with bWipe=FALSE,
183 // this means KMAC was used in XOF mode and length padding has already been
184 // applied. In this case, Result and ResultEx functions extract data one last
185 // time in XOF mode and wipe the state afterwards.
186
187 if (!pState->ks.squeezeMode)
188 {
189 // Append right_encode(L)
191 }
192
193 SymCryptKeccakExtract(&pState->ks, pbOutput, cbOutput, TRUE);
194}

◆ SYMCRYPT_XxxStateCopy()

VOID SYMCRYPT_CALL SYMCRYPT_XxxStateCopy ( _In_ const SYMCRYPT_XXX_STATE *  pSrc,
_Out_ SYMCRYPT_XXX_STATE *  pDst 
)

Definition at line 213 of file kmac_pattern.c.

214{
216 *pDst = *pSrc;
217 SYMCRYPT_SET_MAGIC(pDst);
218}