ReactOS 0.4.17-dev-1190-g4c812f4
implglue.c
Go to the documentation of this file.
1/*
2 * dlls/rsaenh/implglue.c
3 * Glueing the RSAENH specific code to the crypto library
4 *
5 * Copyright (c) 2004, 2005 Michael Jung
6 * Copyright (c) 2007 Vijay Kiran Kamuju
7 *
8 * based on code by Mike McCormack and David Hammerton
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <stdarg.h>
26#include <stdlib.h>
27#include <stdio.h>
28#include "windef.h"
29#include "winbase.h"
30#include "ntsecapi.h"
31#include "wincrypt.h"
32
33#include "implglue.h"
34
35SYMCRYPT_ENVIRONMENT_DEFS( WindowsUsermodeWin8_1nLater );
36
38{
40}
41
43{
45}
46
48{
49}
50
52{
53 return SYMCRYPT_NO_ERROR;
54}
55
57{
58 return RtlGenRandom( buf, size ) ? SYMCRYPT_NO_ERROR : SYMCRYPT_EXTERNAL_FAILURE;
59}
60
62
64{
65 const SYMCRYPT_HASH *algorithms[] =
66 {
74 };
75
76 memset( hash, 0, sizeof(*hash) );
77 if (GET_ALG_CLASS(algid) != ALG_CLASS_HASH) return TRUE;
78 if (GET_ALG_SID(algid) >= ARRAY_SIZE(algorithms)) return TRUE;
79 if (!(hash->desc = algorithms[GET_ALG_SID(algid)])) return TRUE;
81 return TRUE;
82}
83
84static SYMCRYPT_RSAKEY *alloc_rsa_key( DWORD bitlen, BOOL private )
85{
87
88 params.version = 1;
89 params.nBitsOfModulus = bitlen;
90 params.nPrimes = private ? 2 : 0;
91 params.nPubExp = 1;
92 return SymCryptRsakeyAllocate( &params, 0 );
93}
94
96{
97 switch (algid)
98 {
99 case CALG_RSA_KEYX:
100 case CALG_RSA_SIGN:
101 {
102 UINT64 pubexp = 65537;
103
104 ctx->rsa.flags = SYMCRYPT_FLAG_KEY_NO_FIPS;
106 else ctx->rsa.flags |= SYMCRYPT_FLAG_RSAKEY_SIGN;
107
108 if (!(ctx->rsa.key = alloc_rsa_key( keylen * 8, TRUE )))
109 {
111 return FALSE;
112 }
113 if (SymCryptRsakeyGenerate( ctx->rsa.key, &pubexp, 1, ctx->rsa.flags ))
114 {
115 SymCryptRsakeyFree( ctx->rsa.key );
116 ctx->rsa.key = NULL;
118 return FALSE;
119 }
120 break;
121 }
122 default:
124 return FALSE;
125 }
126 return TRUE;
127}
128
130{
131 switch (algid)
132 {
133 case CALG_RSA_KEYX:
134 case CALG_RSA_SIGN:
135 if (ctx->rsa.key)
136 {
137 SymCryptRsakeyFree( ctx->rsa.key );
138 ctx->rsa.key = NULL;
139 }
140 break;
141 default:
142 break;
143 }
144 return TRUE;
145}
146
147BOOL setup_key_impl( ALG_ID algid, KEY_CONTEXT *ctx, DWORD keylen, DWORD effective_keylen, DWORD saltlen,
148 const BYTE *secret )
149{
150 switch (algid)
151 {
152 case CALG_RC4:
153 SymCryptRc4Init( &ctx->rc4, secret, keylen + saltlen );
154 break;
155 case CALG_RC2:
156 SymCryptRc2ExpandKeyEx( &ctx->rc2, secret, keylen + saltlen,
157 effective_keylen ? effective_keylen : keylen << 3 );
158 break;
159 case CALG_3DES:
160 SymCrypt3DesExpandKey( &ctx->des3, secret, 24 );
161 break;
162 case CALG_3DES_112:
163 SymCrypt3DesExpandKey( &ctx->des3, secret, 16 );
164 break;
165 case CALG_DES:
166 SymCryptDesExpandKey( &ctx->des, secret, 8 );
167 break;
168 case CALG_AES:
169 case CALG_AES_128:
170 SymCryptAesExpandKey( &ctx->aes, secret, 16 );
171 break;
172 case CALG_AES_192:
173 SymCryptAesExpandKey( &ctx->aes, secret, 24 );
174 break;
175 case CALG_AES_256:
176 SymCryptAesExpandKey( &ctx->aes, secret, 32 );
177 break;
178 }
179
180 return TRUE;
181}
182
184{
185 switch (algid)
186 {
187 case CALG_RC4:
188 case CALG_RC2:
189 case CALG_3DES:
190 case CALG_3DES_112:
191 case CALG_DES:
192 *dst = *src;
193 break;
194 case CALG_AES:
195 case CALG_AES_128:
196 case CALG_AES_192:
197 case CALG_AES_256:
198 /* SYMCRYPT_AES_EXPANDED_KEY contains pointers into its own RoundKey
199 * array, so it cannot be copied by assignment. */
200 SymCryptAesKeyCopy( &src->aes, &dst->aes );
201 break;
202 case CALG_RSA_KEYX:
203 case CALG_RSA_SIGN:
204 {
205 BYTE *blob;
206 DWORD pubexp, keylen = SymCryptRsakeySizeofModulus( src->rsa.key );
207 BOOLEAN private = SymCryptRsakeyHasPrivateKey( src->rsa.key );
208
209 if (!(dst->rsa.key = alloc_rsa_key( keylen * 8, private )) || !(blob = malloc( keylen * 2 )))
210 {
212 return FALSE;
213 }
214 if (private)
215 {
216 if (!export_private_key_impl( src, blob, &pubexp ) ||
217 !import_private_key_impl( algid, blob, keylen, pubexp, dst ))
218 {
219 free( blob );
220 return FALSE;
221 }
222 }
223 else
224 {
225 if (!export_public_key_impl( src, blob, &pubexp ) ||
226 !import_public_key_impl( algid, blob, keylen, pubexp, dst ))
227 {
228 free( blob );
229 return FALSE;
230 }
231 }
232 dst->rsa.flags = src->rsa.flags;
233 free( blob );
234 break;
235 }
236 default:
238 return FALSE;
239 }
240 return TRUE;
241}
242
244 BYTE *scratch, SIZE_T scratch_size )
245{
246 SYMCRYPT_INT *tmp;
247 UINT32 tmp_size;
248
249 if (src_size > SymCryptRsakeySizeofModulus( key )) return FALSE;
250 if (src_size == SymCryptRsakeySizeofModulus( key ))
251 {
252 tmp_size = SymCryptSizeofIntFromDigits( key->nDigitsOfModulus );
253 SYMCRYPT_ASSERT( scratch_size >= tmp_size );
254 tmp = SymCryptIntCreate( scratch, tmp_size, key->nDigitsOfModulus );
255
256 if (SymCryptIntSetValue( src, src_size, format, tmp )) return FALSE;
257 if (!SymCryptIntIsLessThan( tmp, SymCryptIntFromModulus( key->pmModulus ))) return FALSE;
258 return TRUE;
259 }
260 return FALSE;
261}
262
264 BYTE *out, SYMCRYPT_NUMBER_FORMAT out_format )
265{
268 SIZE_T scratch_size, mod_size = SymCryptSizeofModElementFromModulus( key->pmModulus );
271 BYTE *scratch;
272
273 scratch_size = SymCryptSizeofModElementFromModulus( key->pmModulus ) +
275 SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( key->nDigitsOfModulus ) );
276
277 if (!(scratch = malloc( scratch_size ))) return FALSE;
278 if (!verify_input( key, in, key_size, in_format, scratch, scratch_size ))
279 {
280 free( scratch );
281 return FALSE;
282 }
283
284 result = SymCryptModElementCreate( scratch, mod_size, key->pmModulus );
285
286 SymCryptModElementSetValue( in, key_size, in_format, key->pmModulus, result, scratch + mod_size,
287 scratch_size - mod_size );
288
290 SymCryptIntSetValueUint64( key->au64PubExp[0], exp );
291
293 result, scratch + mod_size, scratch_size - mod_size );
294
295 SymCryptModElementGetValue( key->pmModulus, result, out, key_size, out_format, scratch + mod_size,
296 scratch_size - mod_size );
297 free( scratch );
298 return TRUE;
299}
300
302{
303 switch (algid)
304 {
305 case CALG_RC2:
306 SymCryptRc2Encrypt( &ctx->rc2, in, out );
307 break;
308 case CALG_3DES:
309 case CALG_3DES_112:
310 SymCrypt3DesEncrypt( &ctx->des3, in, out );
311 break;
312 case CALG_DES:
313 SymCryptDesEncrypt( &ctx->des, in, out );
314 break;
315 case CALG_AES:
316 case CALG_AES_128:
317 case CALG_AES_192:
318 case CALG_AES_256:
319 SymCryptAesEncrypt( &ctx->aes, in, out );
320 break;
321 case CALG_RSA_KEYX:
322 case CALG_RSA_SIGN:
323 case CALG_SSL3_SHAMD5:
325 default:
327 return FALSE;
328 }
329 return TRUE;
330}
331
333 BYTE *out, SYMCRYPT_NUMBER_FORMAT out_format )
334{
335 SIZE_T scratch_size, offset = 0, int_size, tmp_size, key_size = SymCryptRsakeySizeofModulus( key );
336 SYMCRYPT_INT *ciphertext, *plaintext, *tmp;
338 BYTE *scratch;
339 UINT32 i, crt_element_total = 0, crt_elements_size[SYMCRYPT_RSAKEY_MAX_NUMOF_PRIMES];
340
341 int_size = SymCryptSizeofIntFromDigits( key->nDigitsOfModulus );
342 tmp_size = SymCryptSizeofIntFromDigits( key->nMaxDigitsOfPrimes );
343
344 for (i = 0; i < key->nPrimes; i++)
345 {
346 crt_elements_size[i] = SYMCRYPT_SIZEOF_MODELEMENT_FROM_BITS( key->nBitsOfPrimes[i] );
347 crt_element_total += crt_elements_size[i];
348 }
349
350 scratch_size = 3 * int_size + tmp_size + crt_element_total +
353 SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( key->nDigitsOfModulus, key->nMaxDigitsOfPrimes ),
354 SYMCRYPT_SCRATCH_BYTES_FOR_CRT_SOLUTION( key->nMaxDigitsOfPrimes ) ) ) );
355
356 if (!(scratch = malloc( scratch_size ))) return FALSE;
357
358 ciphertext = SymCryptIntCreate( scratch, int_size, key->nDigitsOfModulus );
359 offset += int_size;
360
361 plaintext = SymCryptIntCreate( scratch + offset, int_size, key->nDigitsOfModulus );
362 offset += int_size;
363
364 tmp = SymCryptIntCreate( scratch + offset, tmp_size, key->nMaxDigitsOfPrimes );
365 offset += tmp_size;
366
367 for (i = 0; i < key->nPrimes; i++)
368 {
369 crt_elements[i] = SymCryptModElementCreate( scratch + offset, crt_elements_size[i], key->pmPrimes[i] );
370 offset += crt_elements_size[i];
371 }
372
373 SymCryptIntSetValue( in, key_size, in_format, ciphertext );
374
375 for (i = 0; i < key->nPrimes; i++)
376 {
377 SymCryptIntDivMod( ciphertext, SymCryptDivisorFromModulus(key->pmPrimes[i]), NULL, tmp, scratch + offset,
378 scratch_size - offset );
379
380 SymCryptIntToModElement( tmp, key->pmPrimes[i], crt_elements[i], scratch + offset, scratch_size - offset );
381
382 SymCryptModExp( key->pmPrimes[i], crt_elements[i], key->piCrtPrivExps[i], key->nBitsOfPrimes[i], 0,
383 crt_elements[i], scratch + offset, scratch_size - offset );
384 }
385
386 SymCryptCrtSolve( key->nPrimes, (const SYMCRYPT_MODULUS **)key->pmPrimes,
387 (SYMCRYPT_MODELEMENT **)key->peCrtInverses, crt_elements, 0, plaintext, scratch + offset,
388 scratch_size - offset );
389
390 SymCryptIntGetValue( plaintext, out, key_size, out_format );
391 free( scratch );
392 return TRUE;
393}
394
396{
397 switch (algid)
398 {
399 case CALG_RC2:
400 SymCryptRc2Decrypt( &ctx->rc2, in, out );
401 break;
402 case CALG_3DES:
403 case CALG_3DES_112:
404 SymCrypt3DesDecrypt( &ctx->des3, in, out );
405 break;
406 case CALG_DES:
407 SymCryptDesDecrypt( &ctx->des, in, out );
408 break;
409 case CALG_AES:
410 case CALG_AES_128:
411 case CALG_AES_192:
412 case CALG_AES_256:
413 SymCryptAesDecrypt( &ctx->aes, in, out );
414 break;
415 case CALG_RSA_KEYX:
416 case CALG_RSA_SIGN:
417 case CALG_SSL3_SHAMD5:
419 default:
421 return FALSE;
422 }
423 return TRUE;
424}
425
427{
429}
430
432{
434}
435
437{
438 switch (algid)
439 {
440 case CALG_RC4:
442 break;
443 default:
445 return FALSE;
446 }
447 return TRUE;
448}
449
451{
452 BYTE *modulus = dst;
453 SIZE_T modulus_size;
454 UINT64 pubexp64;
455
456 if (!ctx->rsa.key) return FALSE;
457
458 modulus_size = SymCryptRsakeySizeofModulus( ctx->rsa.key );
459
460 if (SymCryptRsakeyGetValue( ctx->rsa.key, modulus, modulus_size, &pubexp64, 1, NULL, NULL, 0,
462 {
464 return FALSE;
465 }
466 *pubexp = pubexp64;
467 return TRUE;
468}
469
471{
472 const BYTE *modulus = src;
473 UINT64 exp64 = pubexp;
474
475 ctx->rsa.flags = SYMCRYPT_FLAG_KEY_NO_FIPS;
478
479 if (!(ctx->rsa.key = alloc_rsa_key( keylen * 8, FALSE )))
480 {
482 return FALSE;
483 }
485 ctx->rsa.flags, ctx->rsa.key ))
486 {
488 return FALSE;
489 }
490 return TRUE;
491}
492
494{
495 BYTE *modulus, *primes[2], *exponents[2], *coefficient, *private_exp;
496 SIZE_T modulus_size, primes_sizes[2];
497 UINT64 pubexp64;
498
499 if (!ctx->rsa.key) return FALSE;
500
501 modulus_size = SymCryptRsakeySizeofModulus( ctx->rsa.key );
502
503 primes_sizes[0] = SymCryptRsakeySizeofPrime( ctx->rsa.key, 0 );
504 primes_sizes[1] = SymCryptRsakeySizeofPrime( ctx->rsa.key, 1 );
505
506 modulus = dst;
507 primes[0] = modulus + modulus_size;
508 primes[1] = modulus + modulus_size + primes_sizes[0];
509
510 if (SymCryptRsakeyGetValue( ctx->rsa.key, modulus, modulus_size, &pubexp64, 1, primes, primes_sizes, 2,
512 {
514 return FALSE;
515 }
516
517 exponents[0] = primes[1] + primes_sizes[1];
518 exponents[1] = exponents[0] + primes_sizes[0];
519 coefficient = exponents[1] + primes_sizes[1];
520 private_exp = coefficient + primes_sizes[0];
521
522 if (SymCryptRsakeyGetCrtValue( ctx->rsa.key, exponents, primes_sizes, 2, coefficient, primes_sizes[0],
524 {
526 return FALSE;
527 }
528
529 *pubexp = pubexp64;
530 return TRUE;
531}
532
534{
535 const BYTE *modulus = src, *primes[2];
536 SIZE_T primes_sizes[2];
537 UINT64 exp64 = pubexp;
538
539 ctx->rsa.flags = SYMCRYPT_FLAG_KEY_NO_FIPS;
542
543 if (!(ctx->rsa.key = alloc_rsa_key( keylen * 8, TRUE )))
544 {
546 return FALSE;
547 }
548
549 primes[0] = modulus + keylen;
550 primes[1] = primes[0] + keylen / 2;
551
552 primes_sizes[0] = keylen / 2;
553 primes_sizes[1] = keylen / 2;
554
555 if (SymCryptRsakeySetValue( modulus, keylen, &exp64, 1, primes, primes_sizes, 2,
556 SYMCRYPT_NUMBER_FORMAT_LSB_FIRST, ctx->rsa.flags, ctx->rsa.key ))
557 {
559 return FALSE;
560 }
561
562 return TRUE;
563}
unsigned char BOOLEAN
Definition: actypes.h:127
COMPILER_DEPENDENT_UINT64 UINT64
Definition: actypes.h:131
#define ARRAY_SIZE(A)
Definition: main.h:20
BYTE private_exp[512/8]
Definition: bcrypt.c:2643
BYTE coefficient[512/16]
Definition: bcrypt.c:2642
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define SetLastError(x)
Definition: compat.h:752
void *CDECL _aligned_malloc(size_t size, size_t alignment)
Definition: heap.c:603
void CDECL _aligned_free(void *memblock)
Definition: heap.c:546
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum src
Definition: glext.h:6340
GLsizeiptr size
Definition: glext.h:5919
GLintptr offset
Definition: glext.h:5920
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint in
Definition: glext.h:9616
GLenum GLenum dst
Definition: glext.h:6340
GLuint64EXT * result
Definition: glext.h:11304
GLenum GLsizei len
Definition: glext.h:6722
GLenum const GLfloat * params
Definition: glext.h:5645
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
BOOL import_public_key_impl(ALG_ID algid, const BYTE *src, DWORD keylen, DWORD pubexp, KEY_CONTEXT *ctx)
Definition: implglue.c:470
BOOL new_key_impl(ALG_ID algid, KEY_CONTEXT *ctx, DWORD keylen)
Definition: implglue.c:95
BOOL sign_hash_impl(KEY_CONTEXT *ctx, const BYTE *in, BYTE *out)
Definition: implglue.c:426
static BOOL verify_input(const SYMCRYPT_RSAKEY *key, const BYTE *src, SIZE_T src_size, SYMCRYPT_NUMBER_FORMAT format, BYTE *scratch, SIZE_T scratch_size)
Definition: implglue.c:243
BOOL setup_key_impl(ALG_ID algid, KEY_CONTEXT *ctx, DWORD keylen, DWORD effective_keylen, DWORD saltlen, const BYTE *secret)
Definition: implglue.c:147
BOOL free_key_impl(ALG_ID algid, KEY_CONTEXT *ctx)
Definition: implglue.c:129
BOOL export_public_key_impl(const KEY_CONTEXT *ctx, BYTE *dst, DWORD *pubexp)
Definition: implglue.c:450
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptRsaSignVerifyPct(const SYMCRYPT_RSAKEY *key)
Definition: implglue.c:51
BOOL duplicate_key_impl(ALG_ID algid, const KEY_CONTEXT *src, KEY_CONTEXT *dst)
Definition: implglue.c:183
BOOL import_private_key_impl(ALG_ID algid, const BYTE *src, DWORD keylen, DWORD pubexp, KEY_CONTEXT *ctx)
Definition: implglue.c:533
void SYMCRYPT_CALL SymCryptCallbackFree(void *ptr)
Definition: implglue.c:42
static BOOL rsa_encrypt(const SYMCRYPT_RSAKEY *key, const BYTE *in, SYMCRYPT_NUMBER_FORMAT in_format, BYTE *out, SYMCRYPT_NUMBER_FORMAT out_format)
Definition: implglue.c:263
UINT32 g_SymCryptFipsSelftestsPerformed
Definition: implglue.c:61
BOOL init_hash_impl(ALG_ID algid, struct hash *hash)
Definition: implglue.c:63
BOOL decrypt_block_impl(ALG_ID algid, KEY_CONTEXT *ctx, const BYTE *in, BYTE *out)
Definition: implglue.c:395
void *SYMCRYPT_CALL SymCryptCallbackAlloc(SIZE_T size)
Definition: implglue.c:37
BOOL encrypt_block_impl(ALG_ID algid, KEY_CONTEXT *ctx, const BYTE *in, BYTE *out)
Definition: implglue.c:301
BOOL export_private_key_impl(const KEY_CONTEXT *ctx, BYTE *dst, DWORD *pubexp)
Definition: implglue.c:493
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptCallbackRandom(BYTE *buf, SIZE_T size)
Definition: implglue.c:56
static BOOL rsa_decrypt(const SYMCRYPT_RSAKEY *key, const BYTE *in, SYMCRYPT_NUMBER_FORMAT in_format, BYTE *out, SYMCRYPT_NUMBER_FORMAT out_format)
Definition: implglue.c:332
BOOL verify_signature_impl(KEY_CONTEXT *ctx, const BYTE *in, BYTE *out)
Definition: implglue.c:431
void SYMCRYPT_CALL SymCryptRsaSelftest(void)
Definition: implglue.c:47
static SYMCRYPT_RSAKEY * alloc_rsa_key(DWORD bitlen, BOOL private)
Definition: implglue.c:84
BOOL encrypt_stream_impl(ALG_ID algid, KEY_CONTEXT *ctx, BYTE *stream, DWORD len)
Definition: implglue.c:436
static PVOID ptr
Definition: dispmode.c:27
DWORD exp
Definition: msg.c:18625
algid
#define RtlGenRandom
Definition: ntsecapi.h:691
#define memset(x, y, z)
Definition: compat.h:39
Definition: image.c:229
SYMCRYPT_HASH_STATE state
Definition: bcrypt_main.c:112
const SYMCRYPT_HASH * desc
Definition: bcrypt_main.c:111
Definition: copy.c:22
Definition: parse.h:23
PSYMCRYPT_RSAKEY SYMCRYPT_CALL SymCryptRsakeyAllocate(_In_ PCSYMCRYPT_RSA_PARAMS pParams, _In_ UINT32 flags)
Definition: rsakey.c:13
#define SYMCRYPT_ASSERT(_x)
Definition: symcrypt.h:10807
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptRsakeySetValue(_In_reads_bytes_(cbModulus) PCBYTE pbModulus, SIZE_T cbModulus, _In_reads_(nPubExp) PCUINT64 pu64PubExp, UINT32 nPubExp, _In_reads_opt_(nPrimes) PCBYTE *ppPrimes, _In_reads_opt_(nPrimes) SIZE_T *pcbPrimes, UINT32 nPrimes, SYMCRYPT_NUMBER_FORMAT numFormat, UINT32 flags, _Inout_ PSYMCRYPT_RSAKEY pkRsakey)
Definition: rsakey.c:1399
UINT32 SYMCRYPT_CALL SymCryptRsakeySizeofPrime(_In_ PCSYMCRYPT_RSAKEY pkRsakey, UINT32 index)
Definition: rsakey.c:289
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptRsakeyGenerate(_Inout_ PSYMCRYPT_RSAKEY pkRsakey, _In_reads_opt_(nPubExp) PCUINT64 pu64PubExp, UINT32 nPubExp, _In_ UINT32 flags)
Definition: rsakey.c:514
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptRsakeyGetValue(_In_ PCSYMCRYPT_RSAKEY pkRsakey, _Out_writes_bytes_(cbModulus) PBYTE pbModulus, SIZE_T cbModulus, _Out_writes_opt_(nPubExp) PUINT64 pu64PubExp, UINT32 nPubExp, _Out_writes_opt_(nPrimes) PBYTE *ppPrimes, _In_reads_opt_(nPrimes) SIZE_T *pcbPrimes, UINT32 nPrimes, SYMCRYPT_NUMBER_FORMAT numFormat, UINT32 flags)
Definition: rsakey.c:1445
VOID SYMCRYPT_CALL SymCryptAesDecrypt(_In_ PCSYMCRYPT_AES_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_AES_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_AES_BLOCK_SIZE) PBYTE pbDst)
Definition: aes-default.c:134
VOID SYMCRYPT_CALL SymCryptDesEncrypt(_In_ PCSYMCRYPT_DES_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_DES_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_DES_BLOCK_SIZE) PBYTE pbDst)
Definition: 3des.c:142
VOID SYMCRYPT_CALL SymCryptRsakeyFree(_Out_ PSYMCRYPT_RSAKEY pkObj)
Definition: rsakey.c:42
VOID SYMCRYPT_CALL SymCryptRc2Decrypt(_In_ PCSYMCRYPT_RC2_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_RC2_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_RC2_BLOCK_SIZE) PBYTE pbDst)
Definition: rc2.c:330
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptDesExpandKey(_Out_ PSYMCRYPT_DES_EXPANDED_KEY pExpandedKey, _In_reads_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
Definition: 3des.c:124
const PCSYMCRYPT_HASH SymCryptSha256Algorithm
Definition: sha256.c:46
VOID SYMCRYPT_CALL SymCryptHashInit(_In_ PCSYMCRYPT_HASH pHash, _Out_writes_bytes_(pHash->stateSize) PVOID pState)
Definition: hash.c:173
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptAesExpandKey(_Out_ PSYMCRYPT_AES_EXPANDED_KEY pExpandedKey, _In_reads_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
Definition: aes-key.c:219
UINT32 SYMCRYPT_CALL SymCryptRsakeySizeofModulus(_In_ PCSYMCRYPT_RSAKEY pkRsakey)
Definition: rsakey.c:264
enum _SYMCRYPT_NUMBER_FORMAT SYMCRYPT_NUMBER_FORMAT
VOID SYMCRYPT_CALL SymCryptRc2Encrypt(_In_ PCSYMCRYPT_RC2_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_RC2_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_RC2_BLOCK_SIZE) PBYTE pbDst)
Definition: rc2.c:234
VOID SYMCRYPT_CALL SymCryptRc4Crypt(_Inout_ PSYMCRYPT_RC4_STATE pState, _In_reads_(cbData) PCBYTE pbSrc, _Out_writes_(cbData) PBYTE pbDst, _In_ SIZE_T cbData)
Definition: rc4.c:82
SYMCRYPT_ERROR SYMCRYPT_CALL SymCrypt3DesExpandKey(_Out_ PSYMCRYPT_3DES_EXPANDED_KEY pExpandedKey, _In_reads_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
Definition: 3des.c:295
const PCSYMCRYPT_HASH SymCryptSha1Algorithm
Definition: sha1.c:29
VOID SYMCRYPT_CALL SymCryptAesEncrypt(_In_ PCSYMCRYPT_AES_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_AES_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_AES_BLOCK_SIZE) PBYTE pbDst)
Definition: aes-default.c:95
const PCSYMCRYPT_HASH SymCryptMd2Algorithm
Definition: md2.c:40
const PCSYMCRYPT_HASH SymCryptMd5Algorithm
Definition: md5.c:43
#define SYMCRYPT_FLAG_RSAKEY_SIGN
Definition: symcrypt.h:7598
#define SYMCRYPT_FLAG_RSAKEY_ENCRYPT
Definition: symcrypt.h:7599
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptRc4Init(_Out_ PSYMCRYPT_RC4_STATE pState, _In_reads_(cbKey) PCBYTE pbKey, _In_ SIZE_T cbKey)
Definition: rc4.c:15
#define SYMCRYPT_FLAG_KEY_NO_FIPS
Definition: symcrypt.h:7579
VOID SYMCRYPT_CALL SymCrypt3DesEncrypt(_In_ PCSYMCRYPT_3DES_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_3DES_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_3DES_BLOCK_SIZE) PBYTE pbDst)
Definition: 3des.c:358
VOID SYMCRYPT_CALL SymCryptDesDecrypt(_In_ PCSYMCRYPT_DES_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_DES_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_DES_BLOCK_SIZE) PBYTE pbDst)
Definition: 3des.c:152
const PCSYMCRYPT_HASH SymCryptSha512Algorithm
Definition: sha512.c:170
const PCSYMCRYPT_HASH SymCryptSha384Algorithm
Definition: sha512.c:169
BOOLEAN SYMCRYPT_CALL SymCryptRsakeyHasPrivateKey(_In_ PCSYMCRYPT_RSAKEY pkRsakey)
Definition: rsakey.c:257
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptRsakeyGetCrtValue(_In_ PCSYMCRYPT_RSAKEY pkRsakey, _Out_writes_opt_(nCrtExponents) PBYTE *ppCrtExponents, _In_reads_(nCrtExponents) SIZE_T *pcbCrtExponents, UINT32 nCrtExponents, _Out_writes_bytes_opt_(cbCrtCoefficient) PBYTE pbCrtCoefficient, SIZE_T cbCrtCoefficient, _Out_writes_bytes_opt_(cbPrivateExponent) PBYTE pbPrivateExponent, SIZE_T cbPrivateExponent, SYMCRYPT_NUMBER_FORMAT numFormat, UINT32 flags)
Definition: rsakey.c:1518
@ SYMCRYPT_NUMBER_FORMAT_MSB_FIRST
Definition: symcrypt.h:7017
@ SYMCRYPT_NUMBER_FORMAT_LSB_FIRST
Definition: symcrypt.h:7016
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptRc2ExpandKeyEx(_Out_ PSYMCRYPT_RC2_EXPANDED_KEY pExpandedKey, _In_reads_(cbKey) PCBYTE pbKey, SIZE_T cbKey, UINT32 effectiveKeySizeInBits)
Definition: rc2.c:129
VOID SYMCRYPT_CALL SymCryptAesKeyCopy(_In_ PCSYMCRYPT_AES_EXPANDED_KEY pSrc, _Out_ PSYMCRYPT_AES_EXPANDED_KEY pDst)
Definition: aes-key.c:240
SYMCRYPT_ERROR
Definition: symcrypt.h:227
const PCSYMCRYPT_HASH SymCryptMd4Algorithm
Definition: md4.c:46
VOID SYMCRYPT_CALL SymCrypt3DesDecrypt(_In_ PCSYMCRYPT_3DES_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_3DES_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_3DES_BLOCK_SIZE) PBYTE pbDst)
Definition: 3des.c:478
#define SYMCRYPT_CALL
#define SYMCRYPT_ENVIRONMENT_DEFS(envName)
struct _SYMCRYPT_HASH SYMCRYPT_HASH
SYMCRYPT_MAGIC_FIELD SYMCRYPT_RSAKEY
#define SYMCRYPT_RSAKEY_MAX_NUMOF_PRIMES
struct _SYMCRYPT_INT SYMCRYPT_INT
#define SYMCRYPT_MAX(_a, _b)
#define SYMCRYPT_ASYM_ALIGN_VALUE
#define SYMCRYPT_ASYM_ALIGN_UP(_p)
struct _SYMCRYPT_MODELEMENT SYMCRYPT_MODELEMENT
struct _SYMCRYPT_MODULUS SYMCRYPT_MODULUS
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptCrtSolve(UINT32 nCoprimes, _In_reads_(nCoprimes) PCSYMCRYPT_MODULUS *ppmCoprimes, _In_reads_(nCoprimes) PCSYMCRYPT_MODELEMENT *ppeCrtInverses, _In_reads_(nCoprimes) PCSYMCRYPT_MODELEMENT *ppeCrtRemainders, UINT32 flags, _Out_ PSYMCRYPT_INT piSolution, _Out_writes_bytes_(cbScratch) PBYTE pbScratch, SIZE_T cbScratch)
Definition: crt.c:123
UINT32 SYMCRYPT_CALL SymCryptIntIsLessThan(_In_ PCSYMCRYPT_INT piSrc1, _In_ PCSYMCRYPT_INT piSrc2)
Definition: a_dispatch.c:442
UINT32 SYMCRYPT_CALL SymCryptSizeofModElementFromModulus(PCSYMCRYPT_MODULUS pmMod)
Definition: a_dispatch.c:658
VOID SYMCRYPT_CALL SymCryptIntToModElement(_In_ PCSYMCRYPT_INT piSrc, _In_ PCSYMCRYPT_MODULUS pmMod, _Out_ PSYMCRYPT_MODELEMENT peDst, _Out_writes_bytes_(cbScratch) PBYTE pbScratch, SIZE_T cbScratch)
Definition: a_dispatch.c:749
#define SYMCRYPT_SIZEOF_INT_FROM_BITS(_bitsize)
VOID SYMCRYPT_CALL SymCryptIntSetValueUint64(UINT64 u64Src, _Out_ PSYMCRYPT_INT piDst)
Definition: a_dispatch.c:239
PSYMCRYPT_DIVISOR SYMCRYPT_CALL SymCryptDivisorFromModulus(_In_ PSYMCRYPT_MODULUS pmSrc)
Definition: a_dispatch.c:703
#define SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD(_nSrcDigits, _nDivisorDigits)
#define SYMCRYPT_SCRATCH_BYTES_FOR_CRT_SOLUTION(_nDigits)
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptModElementSetValue(_In_reads_bytes_(cbSrc) PCBYTE pbSrc, SIZE_T cbSrc, SYMCRYPT_NUMBER_FORMAT format, PCSYMCRYPT_MODULUS pmMod, _Out_ PSYMCRYPT_MODELEMENT peDst, _Out_writes_bytes_(cbScratch) PBYTE pbScratch, SIZE_T cbScratch)
Definition: a_dispatch.c:781
#define SYMCRYPT_SIZEOF_MODELEMENT_FROM_BITS(_bitsize)
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptModElementGetValue(PCSYMCRYPT_MODULUS pmMod, _In_ PCSYMCRYPT_MODELEMENT peSrc, _Out_writes_bytes_(cbDst) PBYTE pbDst, SIZE_T cbDst, SYMCRYPT_NUMBER_FORMAT format, _Out_writes_bytes_(cbScratch) PBYTE pbScratch, SIZE_T cbScratch)
Definition: a_dispatch.c:804
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptIntSetValue(_In_reads_bytes_(cbSrc) PCBYTE pbSrc, SIZE_T cbSrc, SYMCRYPT_NUMBER_FORMAT format, _Out_ PSYMCRYPT_INT piDst)
Definition: a_dispatch.c:248
PSYMCRYPT_MODELEMENT SYMCRYPT_CALL SymCryptModElementCreate(_Out_writes_bytes_(cbBuffer) PBYTE pbBuffer, SIZE_T cbBuffer, _In_ PCSYMCRYPT_MODULUS pmMod)
Definition: a_dispatch.c:665
#define SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(_nDigits)
PSYMCRYPT_INT SYMCRYPT_CALL SymCryptIntFromModulus(_In_ PSYMCRYPT_MODULUS pmSrc)
Definition: a_dispatch.c:720
UINT32 SYMCRYPT_CALL SymCryptIntBitsizeOfValue(_In_ PCSYMCRYPT_INT piSrc)
Definition: a_dispatch.c:223
UINT32 SYMCRYPT_CALL SymCryptSizeofIntFromDigits(UINT32 nDigits)
Definition: a_dispatch.c:134
VOID SYMCRYPT_CALL SymCryptModExp(_In_ PCSYMCRYPT_MODULUS pmMod, _In_ PCSYMCRYPT_MODELEMENT peBase, _In_ PCSYMCRYPT_INT piExp, UINT32 nBitsExp, UINT32 flags, _Out_ PSYMCRYPT_MODELEMENT peDst, _Out_writes_bytes_(cbScratch) PBYTE pbScratch, SIZE_T cbScratch)
Definition: a_dispatch.c:961
VOID SYMCRYPT_CALL SymCryptIntDivMod(_In_ PCSYMCRYPT_INT piSrc, _In_ PCSYMCRYPT_DIVISOR pdDivisor, _Out_opt_ PSYMCRYPT_INT piQuotient, _Out_opt_ PSYMCRYPT_INT piRemainder, _Out_writes_bytes_(cbScratch) PBYTE pbScratch, SIZE_T cbScratch)
Definition: a_dispatch.c:573
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptIntGetValue(_In_ PCSYMCRYPT_INT piSrc, _Out_writes_bytes_(cbDst) PBYTE pbDst, SIZE_T cbDst, SYMCRYPT_NUMBER_FORMAT format)
Definition: a_dispatch.c:259
#define SYMCRYPT_FLAG_DATA_PUBLIC
PSYMCRYPT_INT SYMCRYPT_CALL SymCryptIntCreate(_Out_writes_bytes_(cbBuffer) PBYTE pbBuffer, SIZE_T cbBuffer, UINT32 nDigits)
Definition: a_dispatch.c:141
#define SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP(_nDigits)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t UINT32
Definition: typedefs.h:59
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
#define CALG_RC2
Definition: wincrypt.h:2083
#define CALG_AES_128
Definition: wincrypt.h:2087
#define ALG_SID_MD4
Definition: wincrypt.h:2029
#define CALG_AES_192
Definition: wincrypt.h:2088
#define CALG_RSA_SIGN
Definition: wincrypt.h:2069
#define CALG_RC4
Definition: wincrypt.h:2091
#define ALG_SID_MD2
Definition: wincrypt.h:2028
unsigned int ALG_ID
Definition: wincrypt.h:54
#define ALG_SID_SHA_512
Definition: wincrypt.h:2042
#define GET_ALG_SID(x)
Definition: wincrypt.h:1964
#define CALG_3DES_112
Definition: wincrypt.h:2085
#define CALG_AES
Definition: wincrypt.h:2090
#define ALG_CLASS_HASH
Definition: wincrypt.h:1971
#define CALG_RSA_KEYX
Definition: wincrypt.h:2080
#define CALG_AES_256
Definition: wincrypt.h:2089
#define ALG_SID_SHA_384
Definition: wincrypt.h:2041
#define ALG_SID_MD5
Definition: wincrypt.h:2030
#define CALG_3DES
Definition: wincrypt.h:2084
#define ALG_SID_SHA_256
Definition: wincrypt.h:2040
#define CALG_SSL3_SHAMD5
Definition: wincrypt.h:2062
#define ALG_SID_SHA
Definition: wincrypt.h:2031
#define GET_ALG_CLASS(x)
Definition: wincrypt.h:1962
#define CALG_DES
Definition: wincrypt.h:2082
#define NTE_BAD_ALGID
Definition: winerror.h:4255
#define NTE_FAIL
Definition: winerror.h:4279
unsigned char BYTE
Definition: xxhash.c:193