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

Go to the source code of this file.

Functions

SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptPbkdf2Derive (_In_ PCSYMCRYPT_PBKDF2_EXPANDED_KEY pExpandedKey, _In_reads_opt_(cbSalt) PCBYTE pbSalt, SIZE_T cbSalt, UINT64 iterationCnt, _Out_writes_(cbResult) PBYTE pbResult, SIZE_T cbResult)
 
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptPbkdf2ExpandKey (_Out_ PSYMCRYPT_PBKDF2_EXPANDED_KEY pExpandedKey, _In_ PCSYMCRYPT_MAC macAlgorithm, _In_reads_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
 
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptPbkdf2 (PCSYMCRYPT_MAC macAlgorithm, _In_reads_(cbKey) PCBYTE pbKey, SIZE_T cbKey, _In_reads_opt_(cbSalt) PCBYTE pbSalt, SIZE_T cbSalt, UINT64 iterationCnt, _Out_writes_(cbResult) PBYTE pbResult, SIZE_T cbResult)
 

Function Documentation

◆ SymCryptPbkdf2()

SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptPbkdf2 ( PCSYMCRYPT_MAC  macAlgorithm,
_In_reads_(cbKey) PCBYTE  pbKey,
SIZE_T  cbKey,
_In_reads_opt_(cbSalt) PCBYTE  pbSalt,
SIZE_T  cbSalt,
UINT64  iterationCnt,
_Out_writes_(cbResult) PBYTE  pbResult,
SIZE_T  cbResult 
)

Definition at line 89 of file pbkdf2.c.

98{
100 SYMCRYPT_ERROR scError = SYMCRYPT_NO_ERROR;
101
103 if( scError != SYMCRYPT_NO_ERROR )
104 {
105 goto cleanup;
106 }
107
108 scError = SymCryptPbkdf2Derive( &key, pbSalt, cbSalt, iterationCnt, pbResult, cbResult );
109 if( scError != SYMCRYPT_NO_ERROR )
110 {
111 goto cleanup;
112 }
113
114cleanup:
115
116 SymCryptWipeKnownSize( &key, sizeof( key ) );
117
118 return scError;
119
120}
static void cleanup(void)
Definition: main.c:1335
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptPbkdf2ExpandKey(_Out_ PSYMCRYPT_PBKDF2_EXPANDED_KEY pExpandedKey, _In_ PCSYMCRYPT_MAC macAlgorithm, _In_reads_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
Definition: pbkdf2.c:75
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptPbkdf2Derive(_In_ PCSYMCRYPT_PBKDF2_EXPANDED_KEY pExpandedKey, _In_reads_opt_(cbSalt) PCBYTE pbSalt, SIZE_T cbSalt, UINT64 iterationCnt, _Out_writes_(cbResult) PBYTE pbResult, SIZE_T cbResult)
Definition: pbkdf2.c:16
static const BYTE pbResult[]
Definition: copy.c:22
FORCEINLINE VOID SYMCRYPT_CALL SymCryptWipeKnownSize(_Out_writes_bytes_(cbData) PVOID pbData, SIZE_T cbData)
SYMCRYPT_ERROR
Definition: symcrypt.h:227
PCBYTE pbKey
PCBYTE SIZE_T cbKey
PCSYMCRYPT_MAC macAlgorithm

Referenced by SymCryptPbkdf2_HmacSha1SelfTest(), and SymCryptPbkdf2_HmacSha256SelfTest().

◆ SymCryptPbkdf2Derive()

SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptPbkdf2Derive ( _In_ PCSYMCRYPT_PBKDF2_EXPANDED_KEY  pExpandedKey,
_In_reads_opt_(cbSalt) PCBYTE  pbSalt,
SIZE_T  cbSalt,
UINT64  iterationCnt,
_Out_writes_(cbResult) PBYTE  pbResult,
SIZE_T  cbResult 
)

Definition at line 16 of file pbkdf2.c.

23{
24 SYMCRYPT_MAC_STATE macState;
25 UINT32 iBlock;
27 SIZE_T blockSize = pExpandedKey->macAlg->resultSize;
31
33 blockSize <= SYMCRYPT_MAC_MAX_RESULT_SIZE &&
34 cbResult > 0 );
35
36 if (iterationCnt == 0)
37 {
38 return SYMCRYPT_WRONG_ITERATION_COUNT;
39 }
40
41 iBlock = 0;
42 while( cbResult > 0 )
43 {
44 iBlock += 1;
45 SYMCRYPT_STORE_MSBFIRST32( &rbBlockResult[0], iBlock ); // use result buf as temp
46
47 pExpandedKey->macAlg->initFunc ( &macState, &pExpandedKey->macKey);
48 pExpandedKey->macAlg->appendFunc( &macState, pbSalt, cbSalt);
49 pExpandedKey->macAlg->appendFunc( &macState, &rbBlockResult[0], 4 ); // block count encoded in 4 bytes
50 pExpandedKey->macAlg->resultFunc( &macState, rbWorkBuffer);
51
52#pragma warning(suppress: 22105)
53 memcpy( rbBlockResult, rbWorkBuffer, blockSize );
54 for( iterations = 1; iterations < iterationCnt; iterations++ )
55 {
56 pExpandedKey->macAlg->initFunc ( &macState, &pExpandedKey->macKey );
57 pExpandedKey->macAlg->appendFunc( &macState, rbWorkBuffer, blockSize );
58 pExpandedKey->macAlg->resultFunc( &macState, rbWorkBuffer );
59 SymCryptXorBytes( &rbWorkBuffer[0], &rbBlockResult[0], &rbBlockResult[0], blockSize );
60 }
61
62 bytes = SYMCRYPT_MIN( cbResult, blockSize );
63 memcpy( pbResult, rbBlockResult, bytes );
64 pbResult += bytes;
65 cbResult -= bytes;
66 }
67
68 SymCryptWipeKnownSize( &rbWorkBuffer[0], sizeof( rbWorkBuffer ) );
69 SymCryptWipeKnownSize( &rbBlockResult[0], sizeof( rbBlockResult ) );
70 return SYMCRYPT_NO_ERROR;
71}
COMPILER_DEPENDENT_UINT64 UINT64
Definition: actypes.h:131
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
ULONGLONG iterations
Definition: bcrypt.c:539
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define SYMCRYPT_ASSERT(_x)
Definition: symcrypt.h:10807
VOID SYMCRYPT_CALL SymCryptXorBytes(_In_reads_(cbBytes) PCBYTE pbSrc1, _In_reads_(cbBytes) PCBYTE pbSrc2, _Out_writes_(cbBytes) PBYTE pbResult, SIZE_T cbBytes)
Definition: libmain.c:236
#define SYMCRYPT_STORE_MSBFIRST32(p, v)
Definition: symcrypt.h:311
#define SYMCRYPT_ALIGN
#define SYMCRYPT_MIN(_a, _b)
#define SYMCRYPT_MAC_MAX_RESULT_SIZE
PCVOID pExpandedKey
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t UINT32
Definition: typedefs.h:59
unsigned char BYTE
Definition: xxhash.c:193

Referenced by SymCryptPbkdf2().

◆ SymCryptPbkdf2ExpandKey()

SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptPbkdf2ExpandKey ( _Out_ PSYMCRYPT_PBKDF2_EXPANDED_KEY  pExpandedKey,
_In_ PCSYMCRYPT_MAC  macAlgorithm,
_In_reads_(cbKey) PCBYTE  pbKey,
SIZE_T  cbKey 
)

Definition at line 75 of file pbkdf2.c.

80{
82
83 pExpandedKey->macAlg = macAlgorithm;
85}
PSYMCRYPT_MAC_EXPAND_KEY expandKeyFunc

Referenced by SymCryptPbkdf2().