ReactOS 0.4.15-dev-5667-ged97270
implglue.c File Reference
#include <config.h>
#include <wine/library.h>
#include <wincrypt.h>
#include "implglue.h"
Include dependency graph for implglue.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define WIN32_LEAN_AND_MEAN
 

Functions

VOID WINAPI MD4Init (MD4_CTX *ctx)
 
VOID WINAPI MD4Update (MD4_CTX *ctx, const unsigned char *buf, unsigned int len)
 
VOID WINAPI MD4Final (MD4_CTX *ctx)
 
VOID WINAPI MD5Init (MD5_CTX *ctx)
 
VOID WINAPI MD5Update (MD5_CTX *ctx, const unsigned char *buf, unsigned int len)
 
VOID WINAPI MD5Final (MD5_CTX *ctx)
 
VOID WINAPI A_SHAInit (PSHA_CTX Context)
 
VOID WINAPI A_SHAUpdate (PSHA_CTX Context, const unsigned char *Buffer, UINT BufferSize)
 
VOID WINAPI A_SHAFinal (PSHA_CTX Context, PULONG Result)
 
BOOL WINAPI SystemFunction036 (PVOID pbBuffer, ULONG dwLen)
 
BOOL init_hash_impl (ALG_ID aiAlgid, HASH_CONTEXT *pHashContext)
 
BOOL update_hash_impl (ALG_ID aiAlgid, HASH_CONTEXT *pHashContext, const BYTE *pbData, DWORD dwDataLen)
 
BOOL finalize_hash_impl (ALG_ID aiAlgid, HASH_CONTEXT *pHashContext, BYTE *pbHashValue)
 
BOOL duplicate_hash_impl (ALG_ID aiAlgid, const HASH_CONTEXT *pSrcHashContext, HASH_CONTEXT *pDestHashContext)
 
BOOL new_key_impl (ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen)
 
BOOL free_key_impl (ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext)
 
BOOL setup_key_impl (ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD dwEffectiveKeyLen, DWORD dwSaltLen, BYTE *abKeyValue)
 
BOOL duplicate_key_impl (ALG_ID aiAlgid, const KEY_CONTEXT *pSrcKeyContext, KEY_CONTEXT *pDestKeyContext)
 
static void reverse_bytes (BYTE *pbData, DWORD dwLen)
 
BOOL encrypt_block_impl (ALG_ID aiAlgid, DWORD dwKeySpec, KEY_CONTEXT *pKeyContext, const BYTE *in, BYTE *out, DWORD enc)
 
BOOL encrypt_stream_impl (ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, BYTE *stream, DWORD dwLen)
 
BOOL gen_rand_impl (BYTE *pbBuffer, DWORD dwLen)
 
BOOL export_public_key_impl (BYTE *pbDest, const KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD *pdwPubExp)
 
BOOL import_public_key_impl (const BYTE *pbSrc, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD dwPubExp)
 
BOOL export_private_key_impl (BYTE *pbDest, const KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD *pdwPubExp)
 
BOOL import_private_key_impl (const BYTE *pbSrc, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD dwDataLen, DWORD dwPubExp)
 

Macro Definition Documentation

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 25 of file implglue.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 24 of file implglue.c.

Function Documentation

◆ A_SHAFinal()

VOID WINAPI A_SHAFinal ( PSHA_CTX  Context,
PULONG  Result 
)

Definition at line 171 of file sha1.c.

172{
173 INT Pad, Index;
174 UCHAR Buffer[72];
175 ULONG *Count;
176 ULONG BufferContentSize, LengthHi, LengthLo;
177
178 BufferContentSize = Context->Count[1] & 63;
179 if (BufferContentSize >= 56)
180 Pad = 56 + 64 - BufferContentSize;
181 else
182 Pad = 56 - BufferContentSize;
183
184 LengthHi = (Context->Count[0] << 3) | (Context->Count[1] >> (32 - 3));
185 LengthLo = (Context->Count[1] << 3);
186
187 memset(Buffer + 1, 0, Pad - 1);
188 Buffer[0] = 0x80;
189 Count = (ULONG*)(Buffer + Pad);
190 Count[0] = DWORD2BE(LengthHi);
191 Count[1] = DWORD2BE(LengthLo);
193
194 for (Index = 0; Index < 5; Index++)
195 Result[Index] = DWORD2BE(Context->State[Index]);
196
198}
char * Pad(char *Str, char PadChar, ULONG Length)
Definition: cabman.cxx:29
Definition: bufpool.h:45
int Count
Definition: noreturn.cpp:7
VOID NTAPI A_SHAUpdate(PSHA_CTX Context, const unsigned char *Buffer, ULONG BufferSize)
Definition: sha1.c:128
#define DWORD2BE(x)
Definition: sha1.c:26
VOID NTAPI A_SHAInit(PSHA_CTX Context)
Definition: sha1.c:102
#define memset(x, y, z)
Definition: compat.h:39
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by finalize_hash_impl().

◆ A_SHAInit()

VOID WINAPI A_SHAInit ( PSHA_CTX  Context)

Definition at line 102 of file sha1.c.

103{
104 /* SHA1 initialization constants */
105 Context->State[0] = 0x67452301;
106 Context->State[1] = 0xEFCDAB89;
107 Context->State[2] = 0x98BADCFE;
108 Context->State[3] = 0x10325476;
109 Context->State[4] = 0xC3D2E1F0;
110 Context->Count[0] =
111 Context->Count[1] = 0;
112}

Referenced by init_hash_impl().

◆ A_SHAUpdate()

VOID WINAPI A_SHAUpdate ( PSHA_CTX  Context,
const unsigned char Buffer,
UINT  BufferSize 
)

Definition at line 128 of file sha1.c.

129{
130 ULONG BufferContentSize;
131
132 BufferContentSize = Context->Count[1] & 63;
133 Context->Count[1] += BufferSize;
134 if (Context->Count[1] < BufferSize)
135 Context->Count[0]++;
136 Context->Count[0] += (BufferSize >> 29);
137
138 if (BufferContentSize + BufferSize < 64)
139 {
140 memcpy(&Context->Buffer[BufferContentSize], Buffer,
141 BufferSize);
142 }
143 else
144 {
145 while (BufferContentSize + BufferSize >= 64)
146 {
147 memcpy(Context->Buffer + BufferContentSize, Buffer,
148 64 - BufferContentSize);
149 Buffer += 64 - BufferContentSize;
150 BufferSize -= 64 - BufferContentSize;
151 SHA1Transform(Context->State, Context->Buffer);
152 BufferContentSize = 0;
153 }
154 memcpy(Context->Buffer + BufferContentSize, Buffer, BufferSize);
155 }
156}
#define BufferSize
Definition: mmc.h:75
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void SHA1Transform(ULONG State[5], UCHAR Buffer[64])
Definition: sha1.c:42
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by update_hash_impl().

◆ duplicate_hash_impl()

BOOL duplicate_hash_impl ( ALG_ID  aiAlgid,
const HASH_CONTEXT pSrcHashContext,
HASH_CONTEXT pDestHashContext 
)

Definition at line 173 of file implglue.c.

175{
176 *pDestHashContext = *pSrcHashContext;
177
178 return TRUE;
179}
#define TRUE
Definition: types.h:120

Referenced by RSAENH_CPDuplicateHash().

◆ duplicate_key_impl()

BOOL duplicate_key_impl ( ALG_ID  aiAlgid,
const KEY_CONTEXT pSrcKeyContext,
KEY_CONTEXT pDestKeyContext 
)

Definition at line 255 of file implglue.c.

257{
258 switch (aiAlgid)
259 {
260 case CALG_RC4:
261 case CALG_RC2:
262 case CALG_3DES:
263 case CALG_3DES_112:
264 case CALG_DES:
265 case CALG_AES:
266 case CALG_AES_128:
267 case CALG_AES_192:
268 case CALG_AES_256:
269 *pDestKeyContext = *pSrcKeyContext;
270 break;
271 case CALG_RSA_KEYX:
272 case CALG_RSA_SIGN:
273 pDestKeyContext->rsa.type = pSrcKeyContext->rsa.type;
274 mp_init_copy(&pDestKeyContext->rsa.e, &pSrcKeyContext->rsa.e);
275 mp_init_copy(&pDestKeyContext->rsa.d, &pSrcKeyContext->rsa.d);
276 mp_init_copy(&pDestKeyContext->rsa.N, &pSrcKeyContext->rsa.N);
277 mp_init_copy(&pDestKeyContext->rsa.p, &pSrcKeyContext->rsa.p);
278 mp_init_copy(&pDestKeyContext->rsa.q, &pSrcKeyContext->rsa.q);
279 mp_init_copy(&pDestKeyContext->rsa.qP, &pSrcKeyContext->rsa.qP);
280 mp_init_copy(&pDestKeyContext->rsa.dP, &pSrcKeyContext->rsa.dP);
281 mp_init_copy(&pDestKeyContext->rsa.dQ, &pSrcKeyContext->rsa.dQ);
282 break;
283
284 default:
286 return FALSE;
287 }
288
289 return TRUE;
290}
#define FALSE
Definition: types.h:117
#define SetLastError(x)
Definition: compat.h:752
int mp_init_copy(mp_int *a, const mp_int *b)
Definition: mpi.c:2344
mp_int p
Definition: tomcrypt.h:458
mp_int N
Definition: tomcrypt.h:458
mp_int q
Definition: tomcrypt.h:458
mp_int dP
Definition: tomcrypt.h:458
mp_int dQ
Definition: tomcrypt.h:458
mp_int e
Definition: tomcrypt.h:458
mp_int qP
Definition: tomcrypt.h:458
mp_int d
Definition: tomcrypt.h:458
int type
Definition: tomcrypt.h:457
rsa_key rsa
Definition: implglue.h:72
#define CALG_RC2
Definition: wincrypt.h:1829
#define CALG_AES_128
Definition: wincrypt.h:1833
#define CALG_AES_192
Definition: wincrypt.h:1834
#define CALG_RSA_SIGN
Definition: wincrypt.h:1816
#define CALG_RC4
Definition: wincrypt.h:1837
#define CALG_3DES_112
Definition: wincrypt.h:1831
#define CALG_AES
Definition: wincrypt.h:1836
#define CALG_RSA_KEYX
Definition: wincrypt.h:1824
#define CALG_AES_256
Definition: wincrypt.h:1835
#define CALG_3DES
Definition: wincrypt.h:1830
#define CALG_DES
Definition: wincrypt.h:1828
#define NTE_BAD_ALGID
Definition: winerror.h:2876

Referenced by RSAENH_CPDuplicateKey().

◆ encrypt_block_impl()

BOOL encrypt_block_impl ( ALG_ID  aiAlgid,
DWORD  dwKeySpec,
KEY_CONTEXT pKeyContext,
const BYTE in,
BYTE out,
DWORD  enc 
)

Definition at line 303 of file implglue.c.

305{
306 unsigned long inlen, outlen;
307 BYTE *in_reversed = NULL;
308
309 switch (aiAlgid) {
310 case CALG_RC2:
311 if (enc) {
312 rc2_ecb_encrypt(in, out, &pKeyContext->rc2);
313 } else {
314 rc2_ecb_decrypt(in, out, &pKeyContext->rc2);
315 }
316 break;
317
318 case CALG_3DES:
319 case CALG_3DES_112:
320 if (enc) {
321 des3_ecb_encrypt(in, out, &pKeyContext->des3);
322 } else {
323 des3_ecb_decrypt(in, out, &pKeyContext->des3);
324 }
325 break;
326
327 case CALG_DES:
328 if (enc) {
329 des_ecb_encrypt(in, out, &pKeyContext->des);
330 } else {
331 des_ecb_decrypt(in, out, &pKeyContext->des);
332 }
333 break;
334
335 case CALG_AES:
336 case CALG_AES_128:
337 case CALG_AES_192:
338 case CALG_AES_256:
339 if (enc) {
340 aes_ecb_encrypt(in, out, &pKeyContext->aes);
341 } else {
342 aes_ecb_decrypt(in, out, &pKeyContext->aes);
343 }
344 break;
345
346 case CALG_RSA_KEYX:
347 case CALG_RSA_SIGN:
348 case CALG_SSL3_SHAMD5:
349 outlen = inlen = (mp_count_bits(&pKeyContext->rsa.N)+7)/8;
350 if (enc) {
351 if (rsa_exptmod(in, inlen, out, &outlen, dwKeySpec, &pKeyContext->rsa) != CRYPT_OK) {
353 return FALSE;
354 }
355 reverse_bytes(out, outlen);
356 } else {
357 in_reversed = HeapAlloc(GetProcessHeap(), 0, inlen);
358 if (!in_reversed) {
360 return FALSE;
361 }
362 memcpy(in_reversed, in, inlen);
363 reverse_bytes(in_reversed, inlen);
364 if (rsa_exptmod(in_reversed, inlen, out, &outlen, dwKeySpec, &pKeyContext->rsa) != CRYPT_OK) {
365 HeapFree(GetProcessHeap(), 0, in_reversed);
367 return FALSE;
368 }
369 HeapFree(GetProcessHeap(), 0, in_reversed);
370 }
371 break;
372
373 default:
375 return FALSE;
376 }
377
378 return TRUE;
379}
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
void aes_ecb_encrypt(const unsigned char *pt, unsigned char *ct, aes_key *skey)
Definition: aes.c:1064
void aes_ecb_decrypt(const unsigned char *ct, unsigned char *pt, aes_key *skey)
Definition: aes.c:1165
void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const des_key *des)
Definition: des.c:1453
void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const des_key *des)
Definition: des.c:1463
void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const des3_key *des3)
Definition: des.c:1473
void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const des3_key *des3)
Definition: des.c:1485
@ CRYPT_OK
Definition: tomcrypt.h:43
GLuint in
Definition: glext.h:9616
static void reverse_bytes(BYTE *pbData, DWORD dwLen)
Definition: implglue.c:292
int mp_count_bits(const mp_int *a)
Definition: mpi.c:1203
void rc2_ecb_encrypt(const unsigned char *plain, unsigned char *cipher, rc2_key *rc2)
Definition: rc2.c:111
void rc2_ecb_decrypt(const unsigned char *cipher, unsigned char *plain, rc2_key *rc2)
Definition: rc2.c:159
static FILE * out
Definition: regtests2xml.c:44
des3_key des3
Definition: implglue.h:69
aes_key aes
Definition: implglue.h:70
des_key des
Definition: implglue.h:68
rc2_key rc2
Definition: implglue.h:67
int rsa_exptmod(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen, int which, rsa_key *key)
Definition: rsa.c:180
#define CALG_SSL3_SHAMD5
Definition: wincrypt.h:1809
#define NTE_FAIL
Definition: winerror.h:2900
#define NTE_NO_MEMORY
Definition: winerror.h:2882
unsigned char BYTE
Definition: xxhash.c:193

Referenced by crypt_export_simple(), import_symmetric_key(), RSAENH_CPDecrypt(), RSAENH_CPEncrypt(), RSAENH_CPSignHash(), and RSAENH_CPVerifySignature().

◆ encrypt_stream_impl()

BOOL encrypt_stream_impl ( ALG_ID  aiAlgid,
KEY_CONTEXT pKeyContext,
BYTE stream,
DWORD  dwLen 
)

Definition at line 381 of file implglue.c.

382{
383 switch (aiAlgid) {
384 case CALG_RC4:
385 rc4_read(stream, dwLen, &pKeyContext->rc4);
386 break;
387
388 default:
390 return FALSE;
391 }
392
393 return TRUE;
394}
unsigned long rc4_read(unsigned char *buf, unsigned long len, prng_state *prng)
Definition: rc4.c:89
Definition: parse.h:23
prng_state rc4
Definition: implglue.h:71

Referenced by RSAENH_CPDecrypt(), and RSAENH_CPEncrypt().

◆ export_private_key_impl()

BOOL export_private_key_impl ( BYTE pbDest,
const KEY_CONTEXT pKeyContext,
DWORD  dwKeyLen,
DWORD pdwPubExp 
)

Definition at line 438 of file implglue.c.

440{
441 mp_to_unsigned_bin(&pKeyContext->rsa.N, pbDest);
442 reverse_bytes(pbDest, mp_unsigned_bin_size(&pKeyContext->rsa.N));
443 if (mp_unsigned_bin_size(&pKeyContext->rsa.N) < dwKeyLen)
444 memset(pbDest + mp_unsigned_bin_size(&pKeyContext->rsa.N), 0,
445 dwKeyLen - mp_unsigned_bin_size(&pKeyContext->rsa.N));
446 pbDest += dwKeyLen;
447 mp_to_unsigned_bin(&pKeyContext->rsa.p, pbDest);
448 reverse_bytes(pbDest, mp_unsigned_bin_size(&pKeyContext->rsa.p));
449 if (mp_unsigned_bin_size(&pKeyContext->rsa.p) < (dwKeyLen+1)>>1)
450 memset(pbDest + mp_unsigned_bin_size(&pKeyContext->rsa.p), 0,
451 ((dwKeyLen+1)>>1) - mp_unsigned_bin_size(&pKeyContext->rsa.p));
452 pbDest += (dwKeyLen+1)>>1;
453 mp_to_unsigned_bin(&pKeyContext->rsa.q, pbDest);
454 reverse_bytes(pbDest, mp_unsigned_bin_size(&pKeyContext->rsa.q));
455 if (mp_unsigned_bin_size(&pKeyContext->rsa.q) < (dwKeyLen+1)>>1)
456 memset(pbDest + mp_unsigned_bin_size(&pKeyContext->rsa.q), 0,
457 ((dwKeyLen+1)>>1) - mp_unsigned_bin_size(&pKeyContext->rsa.q));
458 pbDest += (dwKeyLen+1)>>1;
459 mp_to_unsigned_bin(&pKeyContext->rsa.dP, pbDest);
460 reverse_bytes(pbDest, mp_unsigned_bin_size(&pKeyContext->rsa.dP));
461 if (mp_unsigned_bin_size(&pKeyContext->rsa.dP) < (dwKeyLen+1)>>1)
462 memset(pbDest + mp_unsigned_bin_size(&pKeyContext->rsa.dP), 0,
463 ((dwKeyLen+1)>>1) - mp_unsigned_bin_size(&pKeyContext->rsa.dP));
464 pbDest += (dwKeyLen+1)>>1;
465 mp_to_unsigned_bin(&pKeyContext->rsa.dQ, pbDest);
466 reverse_bytes(pbDest, mp_unsigned_bin_size(&pKeyContext->rsa.dQ));
467 if (mp_unsigned_bin_size(&pKeyContext->rsa.dQ) < (dwKeyLen+1)>>1)
468 memset(pbDest + mp_unsigned_bin_size(&pKeyContext->rsa.dQ), 0,
469 ((dwKeyLen+1)>>1) - mp_unsigned_bin_size(&pKeyContext->rsa.dQ));
470 pbDest += (dwKeyLen+1)>>1;
471 mp_to_unsigned_bin(&pKeyContext->rsa.qP, pbDest);
472 reverse_bytes(pbDest, mp_unsigned_bin_size(&pKeyContext->rsa.qP));
473 if (mp_unsigned_bin_size(&pKeyContext->rsa.qP) < (dwKeyLen+1)>>1)
474 memset(pbDest + mp_unsigned_bin_size(&pKeyContext->rsa.qP), 0,
475 ((dwKeyLen+1)>>1) - mp_unsigned_bin_size(&pKeyContext->rsa.qP));
476 pbDest += (dwKeyLen+1)>>1;
477 mp_to_unsigned_bin(&pKeyContext->rsa.d, pbDest);
478 reverse_bytes(pbDest, mp_unsigned_bin_size(&pKeyContext->rsa.d));
479 if (mp_unsigned_bin_size(&pKeyContext->rsa.d) < dwKeyLen)
480 memset(pbDest + mp_unsigned_bin_size(&pKeyContext->rsa.d), 0,
481 dwKeyLen - mp_unsigned_bin_size(&pKeyContext->rsa.d));
482 *pdwPubExp = (DWORD)mp_get_int(&pKeyContext->rsa.e);
483
484 return TRUE;
485}
int mp_to_unsigned_bin(const mp_int *a, unsigned char *b)
Definition: mpi.c:3875
unsigned long mp_get_int(const mp_int *a)
Definition: mpi.c:2320
int mp_unsigned_bin_size(const mp_int *a)
Definition: mpi.c:3899
#define DWORD
Definition: nt_native.h:44

Referenced by crypt_export_private_key().

◆ export_public_key_impl()

BOOL export_public_key_impl ( BYTE pbDest,
const KEY_CONTEXT pKeyContext,
DWORD  dwKeyLen,
DWORD pdwPubExp 
)

Definition at line 401 of file implglue.c.

402{
403 mp_to_unsigned_bin(&pKeyContext->rsa.N, pbDest);
404 reverse_bytes(pbDest, mp_unsigned_bin_size(&pKeyContext->rsa.N));
405 if (mp_unsigned_bin_size(&pKeyContext->rsa.N) < dwKeyLen)
406 memset(pbDest + mp_unsigned_bin_size(&pKeyContext->rsa.N), 0,
407 dwKeyLen - mp_unsigned_bin_size(&pKeyContext->rsa.N));
408 *pdwPubExp = (DWORD)mp_get_int(&pKeyContext->rsa.e);
409 return TRUE;
410}

Referenced by crypt_export_public_key().

◆ finalize_hash_impl()

BOOL finalize_hash_impl ( ALG_ID  aiAlgid,
HASH_CONTEXT pHashContext,
BYTE pbHashValue 
)

Definition at line 131 of file implglue.c.

132{
133 switch (aiAlgid)
134 {
135 case CALG_MD2:
136 md2_done(&pHashContext->md2, pbHashValue);
137 break;
138
139 case CALG_MD4:
140 MD4Final(&pHashContext->md4);
141 memcpy(pbHashValue, pHashContext->md4.digest, 16);
142 break;
143
144 case CALG_MD5:
145 MD5Final(&pHashContext->md5);
146 memcpy(pbHashValue, pHashContext->md5.digest, 16);
147 break;
148
149 case CALG_SHA:
150 A_SHAFinal(&pHashContext->sha, (PULONG)pbHashValue);
151 break;
152
153 case CALG_SHA_256:
154 SHA256_Final(pbHashValue, &pHashContext->sha256);
155 break;
156
157 case CALG_SHA_384:
158 SHA384_Final(pbHashValue, &pHashContext->sha384);
159 break;
160
161 case CALG_SHA_512:
162 SHA512_Final(pbHashValue, &pHashContext->sha512);
163 break;
164
165 default:
167 return FALSE;
168 }
169
170 return TRUE;
171}
VOID WINAPI A_SHAFinal(PSHA_CTX Context, PULONG Result)
Definition: sha1.c:171
VOID WINAPI MD5Final(MD5_CTX *ctx)
Definition: md5.c:113
VOID WINAPI MD4Final(MD4_CTX *ctx)
Definition: md4.c:113
void SHA256_Final(sha2_byte digest[], SHA256_CTX *context)
Definition: sha2.c:507
void SHA384_Final(sha2_byte digest[], SHA384_CTX *context)
Definition: sha2.c:945
void SHA512_Final(sha2_byte digest[], SHA512_CTX *context)
Definition: sha2.c:870
unsigned char digest[16]
Definition: implglue.h:35
unsigned char digest[16]
Definition: implglue.h:44
uint32_t * PULONG
Definition: typedefs.h:59
SHA512_CTX sha512
Definition: implglue.h:63
SHA_CTX sha
Definition: implglue.h:60
md2_state md2
Definition: implglue.h:57
MD5_CTX md5
Definition: implglue.h:59
SHA256_CTX sha256
Definition: implglue.h:61
SHA384_CTX sha384
Definition: implglue.h:62
MD4_CTX md4
Definition: implglue.h:58
int md2_done(md2_state *md2, unsigned char *hash)
Definition: md2.c:125
#define CALG_SHA_384
Definition: wincrypt.h:1814
#define CALG_MD5
Definition: wincrypt.h:1805
#define CALG_SHA_256
Definition: wincrypt.h:1813
#define CALG_MD2
Definition: wincrypt.h:1803
#define CALG_MD4
Definition: wincrypt.h:1804
#define CALG_SHA
Definition: wincrypt.h:1806
#define CALG_SHA_512
Definition: wincrypt.h:1815

Referenced by finalize_hash().

◆ free_key_impl()

BOOL free_key_impl ( ALG_ID  aiAlgid,
KEY_CONTEXT pKeyContext 
)

Definition at line 197 of file implglue.c.

198{
199 switch (aiAlgid)
200 {
201 case CALG_RSA_KEYX:
202 case CALG_RSA_SIGN:
203 rsa_free(&pKeyContext->rsa);
204 }
205
206 return TRUE;
207}
#define rsa_free
Definition: compat-1.3.h:2238

Referenced by destroy_key().

◆ gen_rand_impl()

BOOL gen_rand_impl ( BYTE pbBuffer,
DWORD  dwLen 
)

Definition at line 396 of file implglue.c.

397{
398 return SystemFunction036(pbBuffer, dwLen);
399}
BOOL WINAPI SystemFunction036(PVOID pbBuffer, ULONG dwLen)
Definition: sysfunc.c:602

Referenced by pad_data(), RSAENH_CPGenKey(), and RSAENH_CPGenRandom().

◆ import_private_key_impl()

BOOL import_private_key_impl ( const BYTE pbSrc,
KEY_CONTEXT pKeyContext,
DWORD  dwKeyLen,
DWORD  dwDataLen,
DWORD  dwPubExp 
)

Definition at line 487 of file implglue.c.

489{
490 BYTE *pbTemp, *pbBigNum;
491
492 if (mp_init_multi(&pKeyContext->rsa.e, &pKeyContext->rsa.d, &pKeyContext->rsa.N,
493 &pKeyContext->rsa.dQ,&pKeyContext->rsa.dP,&pKeyContext->rsa.qP,
494 &pKeyContext->rsa.p, &pKeyContext->rsa.q, NULL) != MP_OKAY)
495 {
497 return FALSE;
498 }
499
500 pbTemp = HeapAlloc(GetProcessHeap(), 0, 2*dwKeyLen+5*((dwKeyLen+1)>>1));
501 if (!pbTemp) return FALSE;
502 memcpy(pbTemp, pbSrc, min(dwDataLen, 2*dwKeyLen+5*((dwKeyLen+1)>>1)));
503 pbBigNum = pbTemp;
504
505 pKeyContext->rsa.type = PK_PRIVATE;
506 reverse_bytes(pbBigNum, dwKeyLen);
507 mp_read_unsigned_bin(&pKeyContext->rsa.N, pbBigNum, dwKeyLen);
508 pbBigNum += dwKeyLen;
509 reverse_bytes(pbBigNum, (dwKeyLen+1)>>1);
510 mp_read_unsigned_bin(&pKeyContext->rsa.p, pbBigNum, (dwKeyLen+1)>>1);
511 pbBigNum += (dwKeyLen+1)>>1;
512 reverse_bytes(pbBigNum, (dwKeyLen+1)>>1);
513 mp_read_unsigned_bin(&pKeyContext->rsa.q, pbBigNum, (dwKeyLen+1)>>1);
514 pbBigNum += (dwKeyLen+1)>>1;
515 reverse_bytes(pbBigNum, (dwKeyLen+1)>>1);
516 mp_read_unsigned_bin(&pKeyContext->rsa.dP, pbBigNum, (dwKeyLen+1)>>1);
517 pbBigNum += (dwKeyLen+1)>>1;
518 reverse_bytes(pbBigNum, (dwKeyLen+1)>>1);
519 mp_read_unsigned_bin(&pKeyContext->rsa.dQ, pbBigNum, (dwKeyLen+1)>>1);
520 pbBigNum += (dwKeyLen+1)>>1;
521 reverse_bytes(pbBigNum, (dwKeyLen+1)>>1);
522 mp_read_unsigned_bin(&pKeyContext->rsa.qP, pbBigNum, (dwKeyLen+1)>>1);
523 pbBigNum += (dwKeyLen+1)>>1;
524 /* The size of the private exponent d is inferred from the remaining
525 * data length.
526 */
527 dwKeyLen = min(dwKeyLen, dwDataLen - (pbBigNum - pbTemp));
528 reverse_bytes(pbBigNum, dwKeyLen);
529 mp_read_unsigned_bin(&pKeyContext->rsa.d, pbBigNum, dwKeyLen);
530 mp_set_int(&pKeyContext->rsa.e, dwPubExp);
531
532 HeapFree(GetProcessHeap(), 0, pbTemp);
533 return TRUE;
534}
#define MP_OKAY
Definition: tomcrypt.h:200
#define PK_PRIVATE
Definition: tomcrypt.h:449
#define min(a, b)
Definition: monoChain.cc:55
int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c)
Definition: mpi.c:3502
int mp_set_int(mp_int *a, unsigned long b)
Definition: mpi.c:3687
int mp_init_multi(mp_int *mp,...)
Definition: mpi.c:2354

Referenced by import_private_key().

◆ import_public_key_impl()

BOOL import_public_key_impl ( const BYTE pbSrc,
KEY_CONTEXT pKeyContext,
DWORD  dwKeyLen,
DWORD  dwPubExp 
)

Definition at line 412 of file implglue.c.

414{
415 BYTE *pbTemp;
416
417 if (mp_init_multi(&pKeyContext->rsa.e, &pKeyContext->rsa.d, &pKeyContext->rsa.N,
418 &pKeyContext->rsa.dQ,&pKeyContext->rsa.dP,&pKeyContext->rsa.qP,
419 &pKeyContext->rsa.p, &pKeyContext->rsa.q, NULL) != MP_OKAY)
420 {
422 return FALSE;
423 }
424
425 pbTemp = HeapAlloc(GetProcessHeap(), 0, dwKeyLen);
426 if (!pbTemp) return FALSE;
427 memcpy(pbTemp, pbSrc, dwKeyLen);
428
429 pKeyContext->rsa.type = PK_PUBLIC;
430 reverse_bytes(pbTemp, dwKeyLen);
431 mp_read_unsigned_bin(&pKeyContext->rsa.N, pbTemp, dwKeyLen);
432 HeapFree(GetProcessHeap(), 0, pbTemp);
433 mp_set_int(&pKeyContext->rsa.e, dwPubExp);
434
435 return TRUE;
436}
#define PK_PUBLIC
Definition: tomcrypt.h:450

Referenced by import_public_key().

◆ init_hash_impl()

BOOL init_hash_impl ( ALG_ID  aiAlgid,
HASH_CONTEXT pHashContext 
)

Definition at line 54 of file implglue.c.

55{
56 switch (aiAlgid)
57 {
58 case CALG_MD2:
59 md2_init(&pHashContext->md2);
60 break;
61
62 case CALG_MD4:
63 MD4Init(&pHashContext->md4);
64 break;
65
66 case CALG_MD5:
67 MD5Init(&pHashContext->md5);
68 break;
69
70 case CALG_SHA:
71 A_SHAInit(&pHashContext->sha);
72 break;
73
74 case CALG_SHA_256:
75 SHA256_Init(&pHashContext->sha256);
76 break;
77
78 case CALG_SHA_384:
79 SHA384_Init(&pHashContext->sha384);
80 break;
81
82 case CALG_SHA_512:
83 SHA512_Init(&pHashContext->sha512);
84 break;
85 }
86
87 return TRUE;
88}
#define md2_init
Definition: compat-1.3.h:2019
VOID WINAPI A_SHAInit(PSHA_CTX Context)
Definition: sha1.c:102
VOID WINAPI MD5Init(MD5_CTX *ctx)
Definition: md5.c:45
VOID WINAPI MD4Init(MD4_CTX *ctx)
Definition: md4.c:45
void SHA384_Init(SHA384_CTX *context)
Definition: sha2.c:932
void SHA256_Init(SHA256_CTX *context)
Definition: sha2.c:275
void SHA512_Init(SHA512_CTX *context)
Definition: sha2.c:603

Referenced by finalize_hash(), and init_hash().

◆ MD4Final()

VOID WINAPI MD4Final ( MD4_CTX ctx)

Definition at line 113 of file md4.c.

114{
115 unsigned int count;
116 unsigned char *p;
117
118 /* Compute number of bytes mod 64 */
119 count = (ctx->i[0] >> 3) & 0x3F;
120
121 /* Set the first char of padding to 0x80. This is safe since there is
122 always at least one byte free */
123 p = ctx->in + count;
124 *p++ = 0x80;
125
126 /* Bytes of padding needed to make 64 bytes */
127 count = 64 - 1 - count;
128
129 /* Pad out to 56 mod 64 */
130 if (count < 8)
131 {
132 /* Two lots of padding: Pad the first block to 64 bytes */
133 memset( p, 0, count );
134 byteReverse( ctx->in, 16 );
135 MD4Transform( ctx->buf, (unsigned int *)ctx->in );
136
137 /* Now fill the next block with 56 bytes */
138 memset( ctx->in, 0, 56 );
139 }
140 else
141 {
142 /* Pad block to 56 bytes */
143 memset( p, 0, count - 8 );
144 }
145
146 byteReverse( ctx->in, 14 );
147
148 /* Append length in bits and transform */
149 ((unsigned int *)ctx->in)[14] = ctx->i[0];
150 ((unsigned int *)ctx->in)[15] = ctx->i[1];
151
152 MD4Transform( ctx->buf, (unsigned int *)ctx->in );
153 byteReverse( (unsigned char *)ctx->buf, 4 );
154 memcpy( ctx->digest, ctx->buf, 16 );
155}
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLfloat GLfloat p
Definition: glext.h:8902
static void MD4Transform(unsigned int buf[4], unsigned int const in[16])
Definition: md4.c:181
#define byteReverse(buf, long)
Definition: util.h:5

Referenced by finalize_hash_impl(), KsecGatherEntropyData(), SystemFunction007(), and SystemFunction010().

◆ MD4Init()

VOID WINAPI MD4Init ( MD4_CTX ctx)

Definition at line 45 of file md4.c.

46{
47 ctx->buf[0] = 0x67452301;
48 ctx->buf[1] = 0xefcdab89;
49 ctx->buf[2] = 0x98badcfe;
50 ctx->buf[3] = 0x10325476;
51
52 ctx->i[0] = ctx->i[1] = 0;
53}

Referenced by init_hash_impl(), KsecGatherEntropyData(), SystemFunction007(), and SystemFunction010().

◆ MD4Update()

VOID WINAPI MD4Update ( MD4_CTX ctx,
const unsigned char buf,
unsigned int  len 
)

Definition at line 59 of file md4.c.

60{
61 register unsigned int t;
62
63 /* Update bitcount */
64 t = ctx->i[0];
65
66 if ((ctx->i[0] = t + (len << 3)) < t)
67 ctx->i[1]++; /* Carry from low to high */
68
69 ctx->i[1] += len >> 29;
70 t = (t >> 3) & 0x3f;
71
72 /* Handle any leading odd-sized chunks */
73 if (t)
74 {
75 unsigned char *p = (unsigned char *)ctx->in + t;
76 t = 64 - t;
77
78 if (len < t)
79 {
80 memcpy( p, buf, len );
81 return;
82 }
83
84 memcpy( p, buf, t );
85 byteReverse( ctx->in, 16 );
86
87 MD4Transform( ctx->buf, (unsigned int *)ctx->in );
88
89 buf += t;
90 len -= t;
91 }
92
93 /* Process data in 64-byte chunks */
94 while (len >= 64)
95 {
96 memcpy( ctx->in, buf, 64 );
97 byteReverse( ctx->in, 16 );
98
99 MD4Transform( ctx->buf, (unsigned int *)ctx->in );
100
101 buf += 64;
102 len -= 64;
103 }
104
105 /* Handle any remaining bytes of data. */
106 memcpy( ctx->in, buf, len );
107}
GLdouble GLdouble t
Definition: gl.h:2047
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
if(dx< 0)
Definition: linetemp.h:194

Referenced by KsecGatherEntropyData(), SystemFunction007(), SystemFunction010(), and update_hash_impl().

◆ MD5Final()

VOID WINAPI MD5Final ( MD5_CTX ctx)

Definition at line 113 of file md5.c.

114{
115 unsigned int count;
116 unsigned char *p;
117
118 /* Compute number of bytes mod 64 */
119 count = (ctx->i[0] >> 3) & 0x3F;
120
121 /* Set the first char of padding to 0x80. This is safe since there is
122 always at least one byte free */
123 p = ctx->in + count;
124 *p++ = 0x80;
125
126 /* Bytes of padding needed to make 64 bytes */
127 count = 64 - 1 - count;
128
129 /* Pad out to 56 mod 64 */
130 if (count < 8)
131 {
132 /* Two lots of padding: Pad the first block to 64 bytes */
133 memset( p, 0, count );
134 byteReverse( ctx->in, 16 );
135 MD5Transform( ctx->buf, (unsigned int *)ctx->in );
136
137 /* Now fill the next block with 56 bytes */
138 memset( ctx->in, 0, 56 );
139 }
140 else
141 {
142 /* Pad block to 56 bytes */
143 memset( p, 0, count - 8 );
144 }
145
146 byteReverse( ctx->in, 14 );
147
148 /* Append length in bits and transform */
149 ((unsigned int *)ctx->in)[14] = ctx->i[0];
150 ((unsigned int *)ctx->in)[15] = ctx->i[1];
151
152 MD5Transform( ctx->buf, (unsigned int *)ctx->in );
153 byteReverse( (unsigned char *)ctx->buf, 4 );
154 memcpy( ctx->digest, ctx->buf, 16 );
155}
static void MD5Transform(unsigned int buf[4], const unsigned int in[16])
Definition: md5.c:174

Referenced by finalize_hash_impl().

◆ MD5Init()

VOID WINAPI MD5Init ( MD5_CTX ctx)

Definition at line 45 of file md5.c.

46{
47 ctx->buf[0] = 0x67452301;
48 ctx->buf[1] = 0xefcdab89;
49 ctx->buf[2] = 0x98badcfe;
50 ctx->buf[3] = 0x10325476;
51
52 ctx->i[0] = ctx->i[1] = 0;
53}

Referenced by init_hash_impl().

◆ MD5Update()

VOID WINAPI MD5Update ( MD5_CTX ctx,
const unsigned char buf,
unsigned int  len 
)

Definition at line 59 of file md5.c.

60{
61 register unsigned int t;
62
63 /* Update bitcount */
64 t = ctx->i[0];
65
66 if ((ctx->i[0] = t + (len << 3)) < t)
67 ctx->i[1]++; /* Carry from low to high */
68
69 ctx->i[1] += len >> 29;
70 t = (t >> 3) & 0x3f;
71
72 /* Handle any leading odd-sized chunks */
73 if (t)
74 {
75 unsigned char *p = (unsigned char *)ctx->in + t;
76 t = 64 - t;
77
78 if (len < t)
79 {
80 memcpy( p, buf, len );
81 return;
82 }
83
84 memcpy( p, buf, t );
85 byteReverse( ctx->in, 16 );
86
87 MD5Transform( ctx->buf, (unsigned int *)ctx->in );
88
89 buf += t;
90 len -= t;
91 }
92
93 /* Process data in 64-byte chunks */
94 while (len >= 64)
95 {
96 memcpy( ctx->in, buf, 64 );
97 byteReverse( ctx->in, 16 );
98
99 MD5Transform( ctx->buf, (unsigned int *)ctx->in );
100
101 buf += 64;
102 len -= 64;
103 }
104
105 /* Handle any remaining bytes of data. */
106 memcpy( ctx->in, buf, len );
107}

Referenced by update_hash_impl().

◆ new_key_impl()

BOOL new_key_impl ( ALG_ID  aiAlgid,
KEY_CONTEXT pKeyContext,
DWORD  dwKeyLen 
)

Definition at line 181 of file implglue.c.

182{
183 switch (aiAlgid)
184 {
185 case CALG_RSA_KEYX:
186 case CALG_RSA_SIGN:
187 if (rsa_make_key((int)dwKeyLen, 65537, &pKeyContext->rsa) != CRYPT_OK) {
189 return FALSE;
190 }
191 return TRUE;
192 }
193
194 return TRUE;
195}
int rsa_make_key(int size, long e, rsa_key *key)
Definition: rsa.c:87

Referenced by RSAENH_CPGenKey().

◆ reverse_bytes()

static void reverse_bytes ( BYTE pbData,
DWORD  dwLen 
)
inlinestatic

Definition at line 292 of file implglue.c.

292 {
293 BYTE swap;
294 DWORD i;
295
296 for (i=0; i<dwLen/2; i++) {
297 swap = pbData[i];
298 pbData[i] = pbData[dwLen-i-1];
299 pbData[dwLen-i-1] = swap;
300 }
301}
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define swap(a, b)
Definition: qsort.c:63
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201

Referenced by encrypt_block_impl(), export_private_key_impl(), export_public_key_impl(), import_private_key_impl(), and import_public_key_impl().

◆ setup_key_impl()

BOOL setup_key_impl ( ALG_ID  aiAlgid,
KEY_CONTEXT pKeyContext,
DWORD  dwKeyLen,
DWORD  dwEffectiveKeyLen,
DWORD  dwSaltLen,
BYTE abKeyValue 
)

Definition at line 209 of file implglue.c.

211{
212 switch (aiAlgid)
213 {
214 case CALG_RC4:
215 rc4_start(&pKeyContext->rc4);
216 rc4_add_entropy(abKeyValue, dwKeyLen + dwSaltLen, &pKeyContext->rc4);
217 rc4_ready(&pKeyContext->rc4);
218 break;
219
220 case CALG_RC2:
221 rc2_setup(abKeyValue, dwKeyLen + dwSaltLen, dwEffectiveKeyLen ?
222 dwEffectiveKeyLen : dwKeyLen << 3, 0, &pKeyContext->rc2);
223 break;
224
225 case CALG_3DES:
226 des3_setup(abKeyValue, 24, 0, &pKeyContext->des3);
227 break;
228
229 case CALG_3DES_112:
230 memcpy(abKeyValue+16, abKeyValue, 8);
231 des3_setup(abKeyValue, 24, 0, &pKeyContext->des3);
232 break;
233
234 case CALG_DES:
235 des_setup(abKeyValue, 8, 0, &pKeyContext->des);
236 break;
237
238 case CALG_AES:
239 case CALG_AES_128:
240 aes_setup(abKeyValue, 16, 0, &pKeyContext->aes);
241 break;
242
243 case CALG_AES_192:
244 aes_setup(abKeyValue, 24, 0, &pKeyContext->aes);
245 break;
246
247 case CALG_AES_256:
248 aes_setup(abKeyValue, 32, 0, &pKeyContext->aes);
249 break;
250 }
251
252 return TRUE;
253}
int aes_setup(const unsigned char *key, int keylen, int rounds, aes_key *skey)
Definition: aes.c:937
int des_setup(const unsigned char *key, int keylen, int num_rounds, des_key *des)
Definition: des.c:1416
int des3_setup(const unsigned char *key, int keylen, int num_rounds, des3_key *des3)
Definition: des.c:1432
int rc4_ready(prng_state *prng)
Definition: rc4.c:61
int rc4_start(prng_state *prng)
Definition: rc4.c:33
int rc4_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng)
Definition: rc4.c:41
int rc2_setup(const unsigned char *key, int keylen, int bits, int rounds, rc2_key *rc2)
Definition: rc2.c:53

Referenced by setup_key().

◆ SystemFunction036()

BOOL WINAPI SystemFunction036 ( PVOID  pbBuffer,
ULONG  dwLen 
)

Definition at line 602 of file sysfunc.c.

603{
606 // This function will output numbers based on the tick count. //
607 // It will NOT OUTPUT CRYPTOGRAPHIC-SAFE RANDOM NUMBERS !!! //
609
610 DWORD dwSeed;
612 ULONG uPseudoRandom;
614 static ULONG uCounter = 17;
615
616 if(!pbBuffer || !dwLen)
617 {
618 /* This function always returns TRUE, even if invalid parameters were passed. (verified under WinXP SP2) */
619 return TRUE;
620 }
621
622 /* Get the first seed from the performance counter */
624 dwSeed = time.LowPart ^ time.HighPart ^ RtlUlongByteSwap(uCounter++);
625
626 /* We will access the buffer bytewise */
627 pBuffer = (PBYTE)pbBuffer;
628
629 do
630 {
631 /* Use the pseudo random number generator RtlRandom, which outputs a 4-byte value and a new seed */
632 uPseudoRandom = RtlRandom(&dwSeed);
633
634 do
635 {
636 /* Get each byte from the pseudo random number and store it in the buffer */
637 *pBuffer = (BYTE)(uPseudoRandom >> 8 * (dwLen % 3) & 0xFF);
638 ++pBuffer;
639 } while(--dwLen % 3);
640 } while(dwLen);
641
642 return TRUE;
643}
#define RtlUlongByteSwap(_x)
Definition: compat.h:815
BOOL WINAPI QueryPerformanceCounter(OUT PLARGE_INTEGER lpPerformanceCount)
Definition: perfcnt.c:23
__u16 time
Definition: mkdosfs.c:8
NTSYSAPI ULONG NTAPI RtlRandom(_Inout_ PULONG Seed)
BYTE * PBYTE
Definition: pedump.c:66
PVOID pBuffer

Referenced by gen_rand_impl().

◆ update_hash_impl()

BOOL update_hash_impl ( ALG_ID  aiAlgid,
HASH_CONTEXT pHashContext,
const BYTE pbData,
DWORD  dwDataLen 
)

Definition at line 90 of file implglue.c.

92{
93 switch (aiAlgid)
94 {
95 case CALG_MD2:
96 md2_process(&pHashContext->md2, pbData, dwDataLen);
97 break;
98
99 case CALG_MD4:
100 MD4Update(&pHashContext->md4, pbData, dwDataLen);
101 break;
102
103 case CALG_MD5:
104 MD5Update(&pHashContext->md5, pbData, dwDataLen);
105 break;
106
107 case CALG_SHA:
108 A_SHAUpdate(&pHashContext->sha, pbData, dwDataLen);
109 break;
110
111 case CALG_SHA_256:
112 SHA256_Update(&pHashContext->sha256, pbData, dwDataLen);
113 break;
114
115 case CALG_SHA_384:
116 SHA384_Update(&pHashContext->sha384, pbData, dwDataLen);
117 break;
118
119 case CALG_SHA_512:
120 SHA512_Update(&pHashContext->sha512, pbData, dwDataLen);
121 break;
122
123 default:
125 return FALSE;
126 }
127
128 return TRUE;
129}
#define md2_process
Definition: compat-1.3.h:2020
VOID WINAPI MD5Update(MD5_CTX *ctx, const unsigned char *buf, unsigned int len)
Definition: md5.c:59
VOID WINAPI MD4Update(MD4_CTX *ctx, const unsigned char *buf, unsigned int len)
Definition: md4.c:59
VOID WINAPI A_SHAUpdate(PSHA_CTX Context, const unsigned char *Buffer, UINT BufferSize)
Definition: sha1.c:128
void SHA384_Update(SHA384_CTX *context, const sha2_byte *data, size_t len)
Definition: sha2.c:941
void SHA256_Update(SHA256_CTX *context, const sha2_byte *data, size_t len)
Definition: sha2.c:459
void SHA512_Update(SHA512_CTX *context, const sha2_byte *data, size_t len)
Definition: sha2.c:781

Referenced by finalize_hash(), init_hash(), and update_hash().