ReactOS 0.4.15-dev-5667-ged97270
implglue.h File Reference
#include "tomcrypt.h"
#include "sha2.h"
Include dependency graph for implglue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tagMD4_CTX
 
struct  tagMD5_CTX
 
struct  tagSHA_CTX
 
union  tagHASH_CONTEXT
 
union  tagKEY_CONTEXT
 

Typedefs

typedef struct tagMD4_CTX MD4_CTX
 
typedef struct tagMD5_CTX MD5_CTX
 
typedef struct tagSHA_CTX SHA_CTX
 
typedef struct tagSHA_CTXPSHA_CTX
 
typedef union tagHASH_CONTEXT HASH_CONTEXT
 
typedef union tagKEY_CONTEXT KEY_CONTEXT
 

Functions

BOOL init_hash_impl (ALG_ID aiAlgid, HASH_CONTEXT *pHashContext) DECLSPEC_HIDDEN
 
BOOL update_hash_impl (ALG_ID aiAlgid, HASH_CONTEXT *pHashContext, const BYTE *pbData, DWORD dwDataLen) DECLSPEC_HIDDEN
 
BOOL finalize_hash_impl (ALG_ID aiAlgid, HASH_CONTEXT *pHashContext, BYTE *pbHashValue) DECLSPEC_HIDDEN
 
BOOL duplicate_hash_impl (ALG_ID aiAlgid, const HASH_CONTEXT *pSrcHashContext, HASH_CONTEXT *pDestHashContext) DECLSPEC_HIDDEN
 
BOOL new_key_impl (ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen) DECLSPEC_HIDDEN
 
BOOL free_key_impl (ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext) DECLSPEC_HIDDEN
 
BOOL setup_key_impl (ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD dwEffectiveKeyLen, DWORD dwSaltLen, BYTE *abKeyValue) DECLSPEC_HIDDEN
 
BOOL duplicate_key_impl (ALG_ID aiAlgid, const KEY_CONTEXT *pSrcKeyContext, KEY_CONTEXT *pDestKeyContext) DECLSPEC_HIDDEN
 
BOOL encrypt_block_impl (ALG_ID aiAlgid, DWORD dwKeySpec, KEY_CONTEXT *pKeyContext, const BYTE *pbIn, BYTE *pbOut, DWORD enc) DECLSPEC_HIDDEN
 
BOOL encrypt_stream_impl (ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, BYTE *pbInOut, DWORD dwLen) DECLSPEC_HIDDEN
 
BOOL export_public_key_impl (BYTE *pbDest, const KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD *pdwPubExp) DECLSPEC_HIDDEN
 
BOOL import_public_key_impl (const BYTE *pbSrc, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD dwPubExp) DECLSPEC_HIDDEN
 
BOOL export_private_key_impl (BYTE *pbDest, const KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD *pdwPubExp) DECLSPEC_HIDDEN
 
BOOL import_private_key_impl (const BYTE *pbSrc, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD dwDataLen, DWORD dwPubExp) DECLSPEC_HIDDEN
 
BOOL gen_rand_impl (BYTE *pbBuffer, DWORD dwLen) DECLSPEC_HIDDEN
 

Typedef Documentation

◆ HASH_CONTEXT

◆ KEY_CONTEXT

typedef union tagKEY_CONTEXT KEY_CONTEXT

◆ MD4_CTX

◆ MD5_CTX

◆ PSHA_CTX

◆ SHA_CTX

Function Documentation

◆ 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 pbIn,
BYTE pbOut,
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
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
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 pbInOut,
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
#define memset(x, y, z)
Definition: compat.h:39

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().

◆ 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().

◆ 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().

◆ 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
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201

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