ReactOS 0.4.17-dev-1190-g4c812f4
bcrypt.c
Go to the documentation of this file.
1/*
2 * Unit test for bcrypt functions
3 *
4 * Copyright 2014 Bruno Jesus
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <stdio.h>
22#include <ntstatus.h>
23#define WIN32_NO_STATUS
24#include <windows.h>
25#include <bcrypt.h>
26#include <ncrypt.h>
27#include <wincrypt.h>
28
29#include "wine/test.h"
30
31static NTSTATUS (WINAPI *pBCryptHash)(BCRYPT_ALG_HANDLE, UCHAR *, ULONG, UCHAR *, ULONG, UCHAR *, ULONG);
32
33static void test_BCryptGenRandom(void)
34{
36 UCHAR buffer[256];
37
38 ret = BCryptGenRandom(NULL, NULL, 0, 0);
39 ok(ret == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %#lx\n", ret);
41 ok(ret == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %#lx\n", ret);
42 ret = BCryptGenRandom(NULL, buffer, sizeof(buffer), 0);
43 ok(ret == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %#lx\n", ret);
45 ok(ret == STATUS_SUCCESS, "Expected success, got %#lx\n", ret);
48 ok(ret == STATUS_SUCCESS, "Expected success, got %#lx\n", ret);
50 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %#lx\n", ret);
51
52 /* Zero sized buffer should work too */
54 ok(ret == STATUS_SUCCESS, "Expected success, got %#lx\n", ret);
55
56 /* Test random number generation - It's impossible for a sane RNG to return 8 zeros */
57 memset(buffer, 0, 16);
59 ok(ret == STATUS_SUCCESS, "Expected success, got %#lx\n", ret);
60 ok(memcmp(buffer, buffer + 8, 8), "Expected a random number, got 0\n");
61
62 /* Test pseudo handle, which was introduced at the same time as BCryptHash */
63 if (pBCryptHash)
64 {
66 ok(ret == STATUS_SUCCESS, "Expected success, got %#lx\n", ret);
67
69 ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
70 }
71 else win_skip("BCryptGenRandom pseudo handles are not available\n");
72
73}
74
76{
77 HKEY hkey = NULL;
80 DWORD value, count[2] = {sizeof(value), sizeof(value)};
82
84 L"System\\CurrentControlSet\\Control\\Lsa\\FIPSAlgorithmPolicy", &hkey) == ERROR_SUCCESS &&
85 RegQueryValueExW(hkey, L"Enabled", NULL, NULL, (void *)&value, &count[0]) == ERROR_SUCCESS)
86 {
87 expected = !!value;
88 }
89 else if (RegOpenKeyW(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Lsa", &hkey) == ERROR_SUCCESS &&
90 RegQueryValueExW(hkey, L"FIPSAlgorithmPolicy", NULL, NULL, (void *)&value, &count[0]) == ERROR_SUCCESS)
91 {
92 expected = !!value;
93 }
94 else
95 {
98 ok(0, "Neither XP or Vista key is present\n");
99 }
100 RegCloseKey(hkey);
101
103 ok(ret == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %#lx\n", ret);
104 ok(enabled == expected, "expected result %d, got %d\n", expected, enabled);
105
107 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %#lx\n", ret);
108}
109
110static void format_hash(const UCHAR *bytes, ULONG size, char *buf)
111{
112 ULONG i;
113 buf[0] = '\0';
114 for (i = 0; i < size; i++)
115 {
116 sprintf(buf + i * 2, "%02x", bytes[i]);
117 }
118 return;
119}
120
121#define test_object_length(a) _test_object_length(__LINE__,a)
122static void _test_object_length(unsigned line, void *handle)
123{
125 ULONG len, size;
126
127 len = size = 0xdeadbeef;
129 ok_(__FILE__,line)(status == STATUS_INVALID_HANDLE, "BCryptGetProperty failed: %#lx\n", status);
130
131 len = size = 0xdeadbeef;
132 status = BCryptGetProperty(handle, NULL, (UCHAR *)&len, sizeof(len), &size, 0);
133 ok_(__FILE__,line)(status == STATUS_INVALID_PARAMETER, "BCryptGetProperty failed: %#lx\n", status);
134
135 len = size = 0xdeadbeef;
137 ok_(__FILE__,line)(status == STATUS_INVALID_PARAMETER, "BCryptGetProperty failed: %#lx\n", status);
138
139 len = size = 0xdeadbeef;
141 ok_(__FILE__,line)(status == STATUS_SUCCESS, "BCryptGetProperty failed: %#lx\n", status);
142 ok_(__FILE__,line)(size == sizeof(len), "got %lu\n", size);
143
144 len = size = 0xdeadbeef;
146 ok_(__FILE__,line)(status == STATUS_BUFFER_TOO_SMALL, "BCryptGetProperty failed: %#lx\n", status);
147 ok_(__FILE__,line)(len == 0xdeadbeef, "got %lu\n", len);
148 ok_(__FILE__,line)(size == sizeof(len), "got %lu\n", size);
149
150 len = size = 0xdeadbeef;
152 ok_(__FILE__,line)(status == STATUS_SUCCESS, "BCryptGetProperty failed: %#lx\n", status);
153 ok_(__FILE__,line)(len != 0xdeadbeef, "len not set\n");
154 ok_(__FILE__,line)(size == sizeof(len), "got %lu\n", size);
155}
156
157#define test_hash_length(a,b) _test_hash_length(__LINE__,a,b)
158static void _test_hash_length(unsigned line, void *handle, ULONG exlen)
159{
160 ULONG len = 0xdeadbeef, size = 0xdeadbeef;
162
164 ok_(__FILE__,line)(status == STATUS_SUCCESS, "BCryptGetProperty failed: %#lx\n", status);
165 ok_(__FILE__,line)(size == sizeof(len), "got %lu\n", size);
166 ok_(__FILE__,line)(len == exlen, "len = %lu, expected %lu\n", len, exlen);
167}
168
169#define test_hash_block_length(a,b) _test_hash_block_length(__LINE__,a,b)
170static void _test_hash_block_length(unsigned line, void *handle, ULONG exlen)
171{
172 ULONG len = 0xdeadbeef, size = 0xdeadbeef;
174
176 ok_(__FILE__,line)(status == STATUS_SUCCESS, "BCryptGetProperty failed: %#lx\n", status);
177 ok_(__FILE__,line)(size == sizeof(len), "got %lu\n", size);
178 ok_(__FILE__,line)(len == exlen, "len = %lu, expected %lu\n", len, exlen);
179}
180
181#define test_alg_name(a,b) _test_alg_name(__LINE__,a,b)
182static void _test_alg_name(unsigned line, void *handle, const WCHAR *exname)
183{
184 ULONG size = 0xdeadbeef;
185 UCHAR buf[256];
186 const WCHAR *name = (const WCHAR*)buf;
188
190 ok_(__FILE__,line)(status == STATUS_SUCCESS, "BCryptGetProperty failed: %#lx\n", status);
191 ok_(__FILE__,line)(size == (lstrlenW(exname) + 1) * sizeof(WCHAR), "got %lu\n", size);
192 ok_(__FILE__,line)(!lstrcmpW(name, exname), "alg name = %s, expected %s\n", wine_dbgstr_w(name),
193 wine_dbgstr_w(exname));
194}
195
197{
198 const WCHAR *alg;
199 unsigned hash_size;
200 unsigned block_size;
201 const char *hash;
202 const char *hash2;
203 const char *hmac_hash;
204 const char *hmac_hash2;
205};
206
207static void test_hash(const struct hash_test *test)
208{
211 UCHAR buf[512], buf_hmac[1024], hash_buf[128], hmac_hash[128];
212 char str[512];
214 ULONG len;
215
216 alg = NULL;
218 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
219 ok(alg != NULL, "alg not set\n");
220
222 test_hash_length(alg, test->hash_size);
223 test_hash_block_length(alg, test->block_size);
224 test_alg_name(alg, test->alg);
225
226 hash = NULL;
227 len = sizeof(buf);
228 ret = BCryptCreateHash(alg, &hash, buf, len, NULL, 0, 0);
229 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
230 ok(hash != NULL, "hash not set\n");
231
232 ret = BCryptHashData(hash, NULL, 0, 0);
233 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
234
235 ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
236 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
237
238 test_hash_length(hash, test->hash_size);
239 test_alg_name(hash, test->alg);
240
241 memset(hash_buf, 0, sizeof(hash_buf));
242 ret = BCryptFinishHash(hash, hash_buf, test->hash_size, 0);
243 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
244 format_hash( hash_buf, test->hash_size, str );
245 ok(!strcmp(str, test->hash), "got %s\n", str);
246
248 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
249
250 hash = NULL;
251 len = sizeof(buf);
253 ok(ret == STATUS_SUCCESS || broken(ret == STATUS_INVALID_PARAMETER) /* < win8 */, "got %#lx\n", ret);
254 if (ret == STATUS_SUCCESS)
255 {
256 ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
257 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
258
259 memset(hash_buf, 0, sizeof(hash_buf));
260 ret = BCryptFinishHash(hash, hash_buf, test->hash_size, 0);
261 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
262 format_hash( hash_buf, test->hash_size, str );
263 ok(!strcmp(str, test->hash), "got %s\n", str);
264
265 /* reuse it */
266 ret = BCryptHashData(hash, (UCHAR *)"tset", sizeof("tset"), 0);
267 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
268
269 memset(hash_buf, 0, sizeof(hash_buf));
270 ret = BCryptFinishHash(hash, hash_buf, test->hash_size, 0);
271 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
272 format_hash( hash_buf, test->hash_size, str );
273 ok(!strcmp(str, test->hash2), "got %s\n", str);
274
276 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
277 }
278
280 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
281
282 alg = NULL;
284 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
285 ok(alg != NULL, "alg not set\n");
286
287 hash = NULL;
288 len = sizeof(buf_hmac);
289 ret = BCryptCreateHash(alg, &hash, buf_hmac, len, (UCHAR *)"key", sizeof("key"), 0);
290 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
291 ok(hash != NULL, "hash not set\n");
292
293 ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
294 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
295
296 test_hash_length(hash, test->hash_size);
297 test_alg_name(hash, test->alg);
298
299 memset(hmac_hash, 0, sizeof(hmac_hash));
300 ret = BCryptFinishHash(hash, hmac_hash, test->hash_size, 0);
301 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
302 format_hash( hmac_hash, test->hash_size, str );
303 ok(!strcmp(str, test->hmac_hash), "got %s\n", str);
304
306 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
307
308 hash = NULL;
309 len = sizeof(buf_hmac);
310 ret = BCryptCreateHash(alg, &hash, buf_hmac, len, (UCHAR *)"key", sizeof("key"), BCRYPT_HASH_REUSABLE_FLAG);
311 ok(ret == STATUS_SUCCESS || broken(ret == STATUS_INVALID_PARAMETER) /* < win8 */, "got %#lx\n", ret);
312 if (ret == STATUS_SUCCESS)
313 {
314 ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
315 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
316
317 memset(hmac_hash, 0, sizeof(hmac_hash));
318 ret = BCryptFinishHash(hash, hmac_hash, test->hash_size, 0);
319 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
320 format_hash( hmac_hash, test->hash_size, str );
321 ok(!strcmp(str, test->hmac_hash), "got %s\n", str);
322
323 /* reuse it */
324 ret = BCryptHashData(hash, (UCHAR *)"tset", sizeof("tset"), 0);
325 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
326
327 memset(hmac_hash, 0, sizeof(hmac_hash));
328 ret = BCryptFinishHash(hash, hmac_hash, test->hash_size, 0);
329 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
330 format_hash( hmac_hash, test->hash_size, str );
331 ok(!strcmp(str, test->hmac_hash2), "got %s\n", str);
332
334 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
335 }
336
338 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
339
341 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
342
344 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
345
346 if (pBCryptHash)
347 {
348 ret = pBCryptHash(BCRYPT_SHA1_ALG_HANDLE, NULL, 0, NULL, 0, hash_buf, 20);
349 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
350 ret = pBCryptHash(BCRYPT_SHA1_ALG_HANDLE, NULL, 0, (UCHAR *)"test", sizeof("test"), NULL, 20);
351 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
352 ret = pBCryptHash(BCRYPT_SHA1_ALG_HANDLE, NULL, 0, (UCHAR *)"test", sizeof("test"), hash_buf, 21);
353 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
354 ret = pBCryptHash(BCRYPT_SHA1_ALG_HANDLE, NULL, 0, (UCHAR *)"test", sizeof("test"), hash_buf, 20);
355 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
356
358 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
359 ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
360 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
361 ret = BCryptFinishHash(hash, hash_buf, 21, 0);
362 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
363 ret = BCryptFinishHash(hash, hash_buf, 20, 0);
364 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
366 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
367 }
368}
369
370static void test_hashes(void)
371{
372 static const struct hash_test tests[] =
373 {
374 { L"SHA1", 20, 64,
375 "961fa64958818f767707072755d7018dcd278e94",
376 "9314f62ff64197143c91fc86de37e9ae776a3fb8",
377 "2472cf65d0e090618d769d3e46f0d9446cf212da",
378 "b2d2ba8cfd714d474cf0d9622cc5d15e1f53d53f",
379 },
380 { L"SHA256", 32, 64,
381 "ceb73749c899693706ede1e30c9929b3fd5dd926163831c2fb8bd41e6efb1126",
382 "ea0938c118a7b15954f41b85195f2b42aec3a9429c63f593cfa65c137ffaa986",
383 "34c1aa473a4468a91d06e7cdbc75bc4f93b830ccfc2a47ffd74e8e6ed29e4c72",
384 "55feb7052060bd99e33f36eb0982c7f4856eb6a84fbefe19a1afd9faafc3af6f",
385 },
386 { L"SHA384", 48, 128,
387 "62b21e90c9022b101671ba1f808f8631a8149f0f12904055839a35c1ca78ae53"
388 "63eed1e743a692d70e0504b0cfd12ef9",
389 "724db7c0bbc51ef1ac3fc793083fc54c0e5c423faec9b11378c01c236b19aaaf"
390 "a45177ad055feaf003968cc40ece44c7",
391 "4b3e6d6ff2da121790ab7e7b9247583e3a7eed2db5bd4dabc680303b1608f37d"
392 "fdc836d96a704c03283bc05b4f6c5eb8",
393 "03e1818e5c165a0e54619e513acb06c393e1a6cb0ddbb4036b5f29617b334642"
394 "e6e0be8b214d8508595b17a8c4b4e7db",
395 },
396 { L"SHA512", 64, 128,
397 "d55ced17163bf5386f2cd9ff21d6fd7fe576a915065c24744d09cfae4ec84ee1"
398 "ef6ef11bfbc5acce3639bab725b50a1fe2c204f8c820d6d7db0df0ecbc49c5ca",
399 "7752d707b54d2b00e7d1c09120d189475b0fd2e31ebb988cf0a01fc8492ddc0b"
400 "3ca9c9ca61d9d7d1fb65ca7665e87f043c1d5bc9f786f8345e951c2d91ac594f",
401 "415fb6b10018ca03b38a1b1399c42ac0be5e8aceddb9a73103f5e543bf2d888f"
402 "2eecf91373941f9315dd730a77937fa92444450fbece86f409d9cb5ec48c6513",
403 "1487bcecba46ae677622fa499e4cb2f0fdf92f6f3427cba76382d537a06e49c3"
404 "3e70a2fc1fc730092bf21128c3704cc6387f6dfbf7e2f9f315bbb894505a1205",
405 },
406 { L"MD2", 16, 16,
407 "1bb33606ba908912a84221109d29cd7e",
408 "b9a6ad9323b17e2d0cd389dddd6ef78a",
409 "7f05b0638d77f4a27f3a9c4d353cd648",
410 "05980873e6bfdd05dd7b30078de7e42a",
411 },
412 { L"MD4", 16, 64,
413 "74b5db93c0b41e36ca7074338fc0b637",
414 "a14a9ff2059a8c28f47b01e6bc48a1bf",
415 "bc2e8ac4d8248ed21b8d26227a30ea3a",
416 "b609db0eb4b8669db74f2c20099701e4",
417 },
418 { L"MD5", 16, 64,
419 "e2a3e68d23ce348b8f68b3079de3d4c9",
420 "bcdd7ca574342aa9db0e212348eacb16",
421 "7bda029b93fa8d817fcc9e13d6bdf092",
422 "dd636ab8e9592c5088e57c37d44c5bb3",
423 }
424 };
425 unsigned i;
426
427 for(i = 0; i < ARRAY_SIZE(tests); i++)
429}
430
431static void test_BcryptHash(void)
432{
433 static const char expected[] =
434 "e2a3e68d23ce348b8f68b3079de3d4c9";
435 static const char expected_hmac[] =
436 "7bda029b93fa8d817fcc9e13d6bdf092";
438 UCHAR md5[16], md5_hmac[16];
439 char str[65];
441
442 if (!pBCryptHash) /* < Win10 */
443 {
444 win_skip("BCryptHash is not available\n");
445 return;
446 }
447
448 alg = NULL;
450 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
451 ok(alg != NULL, "alg not set\n");
452
454 test_alg_name(alg, L"MD5");
455
456 memset(md5, 0, sizeof(md5));
457 ret = pBCryptHash(alg, NULL, 0, (UCHAR *)"test", sizeof("test"), md5, sizeof(md5));
458 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
459 format_hash( md5, sizeof(md5), str );
460 ok(!strcmp(str, expected), "got %s\n", str);
461
462 /* With a secret but without BCRYPT_ALG_HANDLE_HMAC_FLAG */
463 ret = pBCryptHash(alg, (UCHAR *)"key", sizeof("key"), (UCHAR *)"test", sizeof("test"), md5, sizeof(md5));
464 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
465
467 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
468
469 alg = NULL;
470 memset(md5_hmac, 0, sizeof(md5_hmac));
472 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
473 ok(alg != NULL, "alg not set\n");
474
475 ret = pBCryptHash(alg, (UCHAR *)"key", sizeof("key"), (UCHAR *)"test", sizeof("test"), md5_hmac, sizeof(md5_hmac));
476 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
477 format_hash( md5_hmac, sizeof(md5_hmac), str );
478 ok(!strcmp(str, expected_hmac), "got %s\n", str);
479
481 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
482
483 if (pBCryptHash)
484 {
485 memset(md5, 0, sizeof(md5));
486 ret = pBCryptHash(BCRYPT_MD5_ALG_HANDLE, NULL, 0, (UCHAR *)"test", sizeof("test"), md5, sizeof(md5));
487 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
488 format_hash( md5, sizeof(md5), str );
489 ok(!strcmp(str, expected), "got %s\n", str);
490 }
491}
492
493/* test vectors from RFC 6070 */
494static UCHAR password[] = "password";
495static UCHAR salt[] = "salt";
496static UCHAR long_password[] = "passwordPASSWORDpassword";
497static UCHAR long_salt[] = "saltSALTsaltSALTsaltSALTsaltSALTsalt";
498static UCHAR password_NUL[] = "pass\0word";
499static UCHAR salt_NUL[] = "sa\0lt";
500
501static UCHAR dk1[] = "0c60c80f961f0e71f3a9b524af6012062fe037a6";
502static UCHAR dk2[] = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";
503static UCHAR dk3[] = "4b007901b765489abead49d926f721d065a429c1";
504static UCHAR dk4[] = "364dd6bc200ec7d197f1b85f4a61769010717124";
505static UCHAR dk5[] = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038";
506static UCHAR dk6[] = "56fa6aa75548099dcc37d7f03425e0c3";
507static UCHAR dk7[] = "8754c32c64b0f524fc50c00f788135de";
508
509static const struct
510{
516 UCHAR *salt;
517 const UCHAR *dk;
518} rfc6070[] =
519{
520 { 8, 4, 1, 20, password, salt, dk1 },
521 { 8, 4, 2, 20, password, salt, dk2 },
522 { 8, 4, 4096, 20, password, salt, dk3 },
523 { 8, 4, 1000000, 20, password, salt, dk4 },
524 { 24, 36, 4096, 25, long_password, long_salt, dk5 },
525 { 9, 5, 4096, 16, password_NUL, salt_NUL, dk6 },
526 { 8, 0, 1, 16, password, NULL, dk7 }
528
530{
532 UCHAR buf[25];
533 char str[51];
535 ULONG i;
536
537 alg = NULL;
540 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
541 ok(alg != NULL, "alg not set\n");
542
544 test_alg_name(alg, L"SHA1");
545
547 0, buf, rfc6070[0].dk_len, 0);
548 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
549
550 for (i = 0; i < ARRAY_SIZE(rfc6070); i++)
551 {
552 memset(buf, 0, sizeof(buf));
555 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
557 ok(!memcmp(str, rfc6070[i].dk, rfc6070[i].dk_len), "got %s\n", str);
558 }
559
561 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
562
563 if (pBCryptHash)
564 {
566 rfc6070[0].salt_len, 1, buf, rfc6070[0].dk_len, 0);
567 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
568 }
569}
570
571static void test_rng(void)
572{
574 ULONG size, len;
575 UCHAR buf[16];
577
578 alg = NULL;
580 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
581 ok(alg != NULL, "alg not set\n");
582
583 len = size = 0xdeadbeef;
585 ok(ret == STATUS_NOT_SUPPORTED, "got %#lx\n", ret);
586
587 len = size = 0xdeadbeef;
589 ok(ret == STATUS_NOT_SUPPORTED, "got %#lx\n", ret);
590
591 test_alg_name(alg, L"RNG");
592
593 memset(buf, 0, 16);
594 ret = BCryptGenRandom(alg, buf, 8, 0);
595 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
596 ok(memcmp(buf, buf + 8, 8), "got zeroes\n");
597
599 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
600}
601
602static void test_aes(void)
603{
604 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
606 ULONG size, len;
607 UCHAR mode[64];
609
610 alg = NULL;
612 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
613 ok(alg != NULL, "alg not set\n");
614
615 len = size = 0;
617 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
618 ok(len, "expected non-zero len\n");
619 ok(size == sizeof(len), "got %lu\n", size);
620
621 len = size = 0;
623 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
624 ok(len == 16, "got %lu\n", len);
625 ok(size == sizeof(len), "got %lu\n", size);
626
627 size = 0;
629 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
630 ok(size == 64, "got %lu\n", size);
631
632 size = 0;
634 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
635 ok(size == 64, "got %lu\n", size);
636
637 size = 0;
638 memset(mode, 0, sizeof(mode));
640 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
641 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CBC), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
642 ok(size == 64, "got %lu\n", size);
643
644 size = 0;
645 memset(&key_lengths, 0, sizeof(key_lengths));
646 ret = BCryptGetProperty(alg, BCRYPT_KEY_LENGTHS, (UCHAR*)&key_lengths, sizeof(key_lengths), &size, 0);
647 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
648 ok(size == sizeof(key_lengths), "got %lu\n", size);
649 ok(key_lengths.dwMinLength == 128, "Expected 128, got %lu\n", key_lengths.dwMinLength);
650 ok(key_lengths.dwMaxLength == 256, "Expected 256, got %lu\n", key_lengths.dwMaxLength);
651 ok(key_lengths.dwIncrement == 64, "Expected 64, got %lu\n", key_lengths.dwIncrement);
652
654 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
655
656 size = 0;
657 memset(mode, 0, sizeof(mode));
659 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
660 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_GCM), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
661 ok(size == 64, "got %lu\n", size);
662
664 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
665
666 size = 0;
667 memset(mode, 0, sizeof(mode));
669 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
670 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CFB), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
671 ok(size == 64, "got %lu\n", size);
672
673 len = size = 0;
675 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
676 ok(len == 1, "got %lu\n", len);
677
678 len = 16;
680 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
681
682 test_alg_name(alg, L"AES");
683
685 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
686
687 if (pBCryptHash)
688 {
690 ok(ret == STATUS_ACCESS_DENIED, "got %#lx\n", ret);
691
692 size = 0;
693 memset(mode, 0, sizeof(mode));
695 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
696 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CBC), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
697 ok(size == 64, "got %lu\n", size);
698 }
699
700 alg = NULL;
702 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
703 ok(alg != NULL, "alg not set\n");
704
706 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
707}
708
709static void test_3des(void)
710{
711 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
713 ULONG size, len;
714 UCHAR mode[64];
716
717 alg = NULL;
719 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
720 ok(alg != NULL, "alg not set\n");
721
722 len = size = 0;
724 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
725 ok(len, "expected non-zero len\n");
726 ok(size == sizeof(len), "got %lu\n", size);
727
728 len = size = 0;
730 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
731 ok(len == 8, "got %lu\n", len);
732 ok(size == sizeof(len), "got %lu\n", size);
733
734 size = 0;
736 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
737 ok(size == 64, "got %lu\n", size);
738
739 size = 0;
741 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
742 ok(size == 64, "got %lu\n", size);
743
744 size = 0;
745 memset(mode, 0, sizeof(mode));
747 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
748 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CBC), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
749 ok(size == 64, "got %lu\n", size);
750
751 size = 0;
752 memset(&key_lengths, 0, sizeof(key_lengths));
753 ret = BCryptGetProperty(alg, BCRYPT_KEY_LENGTHS, (UCHAR*)&key_lengths, sizeof(key_lengths), &size, 0);
754 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
755 ok(size == sizeof(key_lengths), "got %lu\n", size);
756 ok(key_lengths.dwMinLength == 192, "Expected 192, got %lu\n", key_lengths.dwMinLength);
757 ok(key_lengths.dwMaxLength == 192, "Expected 192, got %lu\n", key_lengths.dwMaxLength);
758 ok(key_lengths.dwIncrement == 0, "Expected 0, got %lu\n", key_lengths.dwIncrement);
759
762 ok(ret == STATUS_NOT_SUPPORTED, "got %#lx\n", ret);
763
764 test_alg_name(alg, L"3DES");
765
767 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
768}
769
771{
772 static UCHAR secret[] =
773 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
774 static UCHAR iv[] =
775 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
776 static UCHAR data[] =
777 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
778 static UCHAR expected[] =
779 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79};
780 static UCHAR expected2[] =
781 {0xb5,0x8a,0x10,0x64,0xd8,0xac,0xa9,0x9b,0xd9,0xb0,0x40,0x5b,0x85,0x45,0xf5,0xbb};
782 static UCHAR expected3[] =
783 {0xe3,0x7c,0xd3,0x63,0xdd,0x7c,0x87,0xa0,0x9a,0xff,0x0e,0x3e,0x60,0xe0,0x9c,0x82};
786 UCHAR *buf, ciphertext[16], plaintext[16], ivbuf[16], mode[64];
787 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
788 ULONG size, len, len2, i;
790 DWORD keylen;
791
793 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
794
795 len = size = 0xdeadbeef;
796 ret = BCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
797 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
798 len2 = len;
799
800 key = (void *)0xdeadbeef;
802 ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
803 ok(key == (void *)0xdeadbeef, "got %p\n", key);
804
805 key = NULL;
806 buf = calloc(1, len);
807
808 key = (BCRYPT_KEY_HANDLE)0xdeadbeef;
810 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
811 ok(key == (HANDLE)0xdeadbeef, "got unexpected key %p.\n", key);
812
813 key = (BCRYPT_KEY_HANDLE)0xdeadbeef;
814 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret) + 1, 0);
815 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
816 ok(key == (HANDLE)0xdeadbeef, "got unexpected key %p.\n", key);
817
818 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
819 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
820 ok(key != NULL, "key not set\n");
821
822 keylen = 0;
823 ret = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
824 ok(!ret, "got %#lx\n", ret);
825 ok(size == sizeof(keylen), "got %lu\n", size);
826 ok(keylen == 128, "got %lu\n", keylen);
827
829 sizeof(BCRYPT_CHAIN_MODE_CBC), 0);
830 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
831
833 {
834 keylen = 512;
835 ret = BCryptSetProperty(aes, BCRYPT_KEY_LENGTH, (UCHAR *)&keylen, sizeof(keylen), 0);
836 ok(ret == STATUS_NOT_SUPPORTED, "got %#lx\n", ret);
837 }
838
839 size = 0;
840 memset(mode, 0, sizeof(mode));
842 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
843 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CBC), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
844 ok(size == 64, "got %lu\n", size);
845
847 ok(ret == STATUS_SUCCESS || broken(ret == STATUS_NOT_SUPPORTED) /* < Win 8 */, "got %#lx\n", ret);
848 if (ret == STATUS_SUCCESS)
849 {
850 size = 0;
851 memset(mode, 0, sizeof(mode));
853 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
854 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_ECB), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
855 ok(size == 64, "got %lu\n", size);
856 }
857
859 sizeof(BCRYPT_CHAIN_MODE_CBC), 0);
860 ok(ret == STATUS_SUCCESS || broken(ret == STATUS_NOT_SUPPORTED) /* < Win 8 */, "got %#lx\n", ret);
861
862 size = 0xdeadbeef;
863 ret = BCryptEncrypt(key, NULL, 0, NULL, NULL, 0, NULL, 0, &size, 0);
864 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
865 ok(!size, "got %lu\n", size);
866
867 size = 0;
868 memcpy(ivbuf, iv, sizeof(iv));
869 ret = BCryptEncrypt(key, data, 16, NULL, ivbuf, 16, NULL, 0, &size, 0);
870 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
871 ok(size == 16, "got %lu\n", size);
872 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
873
874 size = 0;
875 memcpy(ivbuf, iv, sizeof(iv));
876 memset(ciphertext, 0, sizeof(ciphertext));
877 ret = BCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
878 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
879 ok(size == 16, "got %lu\n", size);
880 ok(!memcmp(ciphertext, expected, sizeof(expected)), "wrong data\n");
881 for (i = 0; i < 16; i++)
882 ok(ciphertext[i] == expected[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected[i]);
883 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
884
885 size = 0;
886 memset(ciphertext, 0, sizeof(ciphertext));
887 ret = BCryptEncrypt(key, data, 16, NULL, NULL, 0, ciphertext, 16, &size, 0);
888 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
889 ok(size == 16, "got %lu\n", size);
890 ok(!memcmp(ciphertext, expected2, sizeof(expected2)), "wrong data\n");
891
892 size = 0;
893 memcpy(ivbuf, iv, sizeof(iv));
894 ++ivbuf[0];
895 memset(ciphertext, 0, sizeof(ciphertext));
896 ret = BCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
897 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
898 ok(size == 16, "got %lu\n", size);
899 ok(!memcmp(ciphertext, expected3, sizeof(expected3)), "wrong data\n");
900 for (i = 0; i < 16; i++)
901 ok(ciphertext[i] == expected3[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected3[i]);
902 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
903
904 key2 = (void *)0xdeadbeef;
905 ret = BCryptDuplicateKey(NULL, &key2, NULL, 0, 0);
906 ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
907 ok(key2 == (void *)0xdeadbeef, "got %p\n", key2);
908
909 if (0) /* crashes on some Windows versions */
910 {
912 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
913 }
914
915 key2 = (void *)0xdeadbeef;
916 ret = BCryptDuplicateKey(key, &key2, NULL, 0, 0);
917 ok(ret == STATUS_SUCCESS || broken(ret == STATUS_INVALID_PARAMETER), "got %#lx\n", ret);
918
919 if (ret == STATUS_SUCCESS)
920 {
921 size = 0;
922 memcpy(ivbuf, iv, sizeof(iv));
923 memset(ciphertext, 0, sizeof(ciphertext));
924 ret = BCryptEncrypt(key2, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
925 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
926 ok(size == 16, "got %lu\n", size);
927 ok(!memcmp(ciphertext, expected, sizeof(expected)), "wrong data\n");
928 for (i = 0; i < 16; i++)
929 ok(ciphertext[i] == expected[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected[i]);
930 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
931
933 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
934 }
935
936 size = 0xdeadbeef;
937 ret = BCryptDecrypt(key, NULL, 0, NULL, NULL, 0, NULL, 0, &size, 0);
938 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
939 ok(!size, "got %lu\n", size);
940
941 size = 0;
942 memcpy(ivbuf, iv, sizeof(iv));
943 ret = BCryptDecrypt(key, ciphertext, 16, NULL, ivbuf, 16, NULL, 0, &size, 0);
944 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
945 ok(size == 16, "got %lu\n", size);
946
947 size = 0;
948 memcpy(ivbuf, iv, sizeof(iv));
949 memset(plaintext, 0, sizeof(plaintext));
950 ret = BCryptDecrypt(key, ciphertext, 16, NULL, ivbuf, 16, plaintext, 16, &size, 0);
951 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
952 ok(size == 16, "got %lu\n", size);
953 ok(!memcmp(plaintext, data, sizeof(data)), "wrong data\n");
954 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
955
956 memset(mode, 0, sizeof(mode));
958 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
959 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CBC), "wrong mode\n");
960
961 len = 0;
962 size = 0;
964 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
965 ok(len == 16, "got %lu\n", len);
966 ok(size == sizeof(len), "got %lu\n", size);
967
968 size = 0;
969 memset(&key_lengths, 0, sizeof(key_lengths));
970 ret = BCryptGetProperty(aes, BCRYPT_KEY_LENGTHS, (UCHAR*)&key_lengths, sizeof(key_lengths), &size, 0);
971 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
972 ok(size == sizeof(key_lengths), "got %lu\n", size);
973 ok(key_lengths.dwMinLength == 128, "Expected 128, got %lu\n", key_lengths.dwMinLength);
974 ok(key_lengths.dwMaxLength == 256, "Expected 256, got %lu\n", key_lengths.dwMaxLength);
975 ok(key_lengths.dwIncrement == 64, "Expected 64, got %lu\n", key_lengths.dwIncrement);
976
978 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
979
980 if (pBCryptHash)
981 {
983 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
985 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
986 }
987
988 free(buf);
990 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
991}
992
993#define RACE_TEST_COUNT 200
995
996static DWORD WINAPI encrypt_race_thread(void *parameter)
997{
998 static UCHAR nonce[] =
999 {0x11,0x20,0x30,0x40,0x50,0x60,0x10,0x20,0x30,0x40,0x50,0x60};
1000 static UCHAR auth_data[] =
1001 {0x61,0x50,0x40,0x30,0x20,0x10,0x60,0x50,0x40,0x30,0x20,0x10};
1002 static UCHAR data2[] =
1003 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
1004 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
1005 static UCHAR expected4[] =
1006 {0xb2,0x27,0x19,0x09,0xc7,0x89,0xdc,0x52,0x24,0x83,0x3a,0x55,0x34,0x76,0x2c,0xbf,
1007 0x15,0xa1,0xcb,0x40,0x78,0x11,0xba,0xbc,0xa4,0x76,0x69,0x7c,0x75,0x4f,0x11,0xba};
1008 static UCHAR expected_tag3[] =
1009 {0xef,0xee,0x75,0x99,0xb8,0x12,0xe9,0xf0,0xb4,0xcc,0x65,0x11,0x67,0x60,0x2d,0xe6};
1010
1012 BCRYPT_KEY_HANDLE key = parameter;
1013 UCHAR ciphertext[48], tag[16];
1014 unsigned int i, test;
1015 NTSTATUS ret;
1016 ULONG size;
1017
1018 memset(&auth_info, 0, sizeof(auth_info));
1019 auth_info.cbSize = sizeof(auth_info);
1020 auth_info.dwInfoVersion = 1;
1021 auth_info.pbNonce = nonce;
1022 auth_info.cbNonce = sizeof(nonce);
1023 auth_info.pbTag = tag;
1024 auth_info.cbTag = sizeof(tag);
1025 auth_info.pbAuthData = auth_data;
1026 auth_info.cbAuthData = sizeof(auth_data);
1027
1030 ;
1031
1032 for (test = 0; test < RACE_TEST_COUNT; ++test)
1033 {
1034 size = 0;
1035 memset(ciphertext, 0xff, sizeof(ciphertext));
1036 memset(tag, 0xff, sizeof(tag));
1037 ret = BCryptEncrypt(key, data2, 32, &auth_info, NULL, 0, ciphertext, 32, &size, 0);
1038 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1039 ok(size == 32, "got %lu\n", size);
1040 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1041 ok(!memcmp(tag, expected_tag3, sizeof(expected_tag3)), "wrong tag\n");
1042 for (i = 0; i < 32; i++)
1043 ok(ciphertext[i] == expected4[i], "%u: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1044 for (i = 0; i < 16; i++)
1045 ok(tag[i] == expected_tag3[i], "%u: %02x != %02x\n", i, tag[i], expected_tag3[i]);
1046 }
1047
1048 return 0;
1049}
1050
1051static void test_BCryptEncrypt(void)
1052{
1053 static UCHAR nonce[] =
1054 {0x10,0x20,0x30,0x40,0x50,0x60,0x10,0x20,0x30,0x40,0x50,0x60};
1055 static UCHAR auth_data[] =
1056 {0x60,0x50,0x40,0x30,0x20,0x10,0x60,0x50,0x40,0x30,0x20,0x10};
1057 static UCHAR secret[] =
1058 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
1059 static UCHAR secret256[] =
1060 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
1061 0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};
1062 static UCHAR iv[] =
1063 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
1064 static UCHAR data[] =
1065 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10};
1066 static UCHAR data2[] =
1067 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
1068 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
1069 static UCHAR expected[] =
1070 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79};
1071 static UCHAR expected2[] =
1072 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
1073 0x28,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9};
1074 static UCHAR expected3[] =
1075 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
1076 0xb1,0xa2,0x92,0x73,0xbe,0x2c,0x42,0x07,0xa5,0xac,0xe3,0x93,0x39,0x8c,0xb6,0xfb,
1077 0x87,0x5d,0xea,0xa3,0x7e,0x0f,0xde,0xfa,0xd9,0xec,0x6c,0x4e,0x3c,0x76,0x86,0xe4};
1078 static UCHAR expected4[] =
1079 {0xe1,0x82,0xc3,0xc0,0x24,0xfb,0x86,0x85,0xf3,0xf1,0x2b,0x7d,0x09,0xb4,0x73,0x67,
1080 0x86,0x64,0xc3,0xfe,0xa3,0x07,0x61,0xf8,0x16,0xc9,0x78,0x7f,0xe7,0xb1,0xc4,0x94};
1081 static UCHAR expected5[] =
1082 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a};
1083 static UCHAR expected6[] =
1084 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a,
1085 0x84,0x07,0x66,0xb7,0x49,0xc0,0x9b,0x49,0x74,0x28,0x8c,0x10,0xb9,0xc2,0x09,0x70};
1086 static UCHAR expected7[] =
1087 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a,
1088 0x95,0x4f,0x64,0xf2,0xe4,0xe8,0x6e,0x9e,0xee,0x82,0xd2,0x02,0x16,0x68,0x48,0x99,
1089 0x95,0x4f,0x64,0xf2,0xe4,0xe8,0x6e,0x9e,0xee,0x82,0xd2,0x02,0x16,0x68,0x48,0x99};
1090 static UCHAR expected8[] =
1091 {0xb5,0x8a,0x10,0x64,0xd8,0xac,0xa9,0x9b,0xd9,0xb0,0x40,0x5b,0x85,0x45,0xf5,0xbb};
1092 static UCHAR expected9[] =
1093 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a};
1094 static UCHAR expected10[] =
1095 {0x66,0xb8,0xbd,0xe5,0x90,0x6c,0xec,0xdf,0xfa,0x8a,0xb2,0xfd,0x92,0x84,0xeb,0xf0,
1096 0x95,0xc4,0xdf,0xa7,0x7a,0x62,0xe4,0xab,0xd4,0x0e,0x94,0x4e,0xd7,0x6e,0xa1,0x47,
1097 0x29,0x4b,0x37,0xfe,0x28,0x6d,0x5f,0x69,0x46,0x30,0x73,0xc0,0xaa,0x42,0xe4,0x46};
1098 static UCHAR expected11[] =
1099 {0x0a,0x22,0xf7,0x96,0xe1,0xb9,0x3e,0x90,0x32,0xcf,0xf8,0x04,0x83,0x8a,0xdf,0xc3};
1100 static UCHAR expected12[] =
1101 {0xb5,0x9d,0xe7,0x8e,0x0f,0x80,0x16,0xc3,0xf6,0x80,0xad,0xf8,0xac,0xef,0xf9,0x9f};
1102 static UCHAR expected13[] =
1103 {0xc6,0x41,0x37,0xd8,0x6f,0x65,0x64,0x1d,0x2b,0xa0,0xad,0xee,0x67,0xba,0x9b,0x5f};
1104 static UCHAR expected14[] =
1105 {0x0a,0x22,0xf7,0x96,0xe1,0xb9,0x3e,0x90,0x32,0xcf,0xf8,0x04,0x83,0x8a,0xdf,0xc3,
1106 0xa5,0xfa,0x54,0xd7,0x62,0x9d,0x8b,0x11,0x3d,0xd8,0xe2,0x95,0xc2,0x23,0x3f,0x29};
1107 static UCHAR expected15[] =
1108 {0x0a,0x22,0xf7,0x96,0xe1,0xb9,0x3e,0x90,0x32,0xcf,0xf8,0x04,0x83,0x8a,0xdf,0xc3,
1109 0xa5,0xe5,0xcd,0x29,0x48,0x37,0x3f,0x92,0x6f,0x09,0x84,0x5a,0xb8,0x88,0xda,0xfd,
1110 0x65,0x00,0x20,0x9a,0xc6,0xdb,0xfa,0x82,0xdb,0xbc,0xf4,0x70,0x7d,0x88,0x86,0xb5};
1111 static UCHAR expected16[] =
1112 {0x64,0xff,0xc6,0x97,0x14,0x5e,0x21,0xfa,0xe8,0x6e,0xba,0xc1,0x0c,0xb1,0x72,0x64,
1113 0x5d,0xf0,0x22,0x72,0xef,0x39,0xe3,0x2f,0x80,0x3e,0x53,0x00,0xc1,0xcf,0x3f,0xbb,
1114 0xea,0x30,0x01,0x78,0x3b,0xba,0x4d,0xca,0xa0,0x2e,0x83,0x5e,0x0e,0xe2,0x65,0xcb};
1115 static UCHAR expected_tag[] =
1116 {0x89,0xb3,0x92,0x00,0x39,0x20,0x09,0xb4,0x6a,0xd6,0xaf,0xca,0x4b,0x5b,0xfd,0xd0};
1117 static UCHAR expected_tag2[] =
1118 {0x9a,0x92,0x32,0x2c,0x61,0x2a,0xae,0xef,0x66,0x2a,0xfb,0x55,0xe9,0x48,0xdf,0xbd};
1119 static UCHAR expected_tag3[] =
1120 {0x17,0x9d,0xc0,0x7a,0xf0,0xcf,0xaa,0xd5,0x1c,0x11,0xc4,0x4b,0xd6,0xa3,0x3e,0x77};
1121 static UCHAR expected_tag4[] =
1122 {0x4c,0x42,0x83,0x9e,0x8d,0x40,0xf1,0x19,0xd6,0x2b,0x1c,0x66,0x03,0x2b,0x39,0x63};
1123
1125 UCHAR *buf, ciphertext[48], ivbuf[16], tag[16];
1127 ULONG size, len, i, test;
1130 HANDLE hthread;
1131 NTSTATUS ret;
1132
1134 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1135
1136 /******************
1137 * AES - CBC mode *
1138 ******************/
1139
1140 len = 0xdeadbeef;
1141 size = sizeof(len);
1142 ret = BCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
1143 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1144
1145 key = NULL;
1146 buf = calloc(1, len);
1147 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1148 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1149 ok(key != NULL, "key not set\n");
1150
1151 /* input size is a multiple of block size */
1152 size = 0;
1153 memcpy(ivbuf, iv, sizeof(iv));
1154 ret = BCryptEncrypt(key, data, 16, NULL, ivbuf, 16, NULL, 0, &size, 0);
1155 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1156 ok(size == 16, "got %lu\n", size);
1157 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1158
1159 size = 0;
1160 memcpy(ivbuf, iv, sizeof(iv));
1161 memset(ciphertext, 0, sizeof(ciphertext));
1162 ret = BCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
1163 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1164 ok(size == 16, "got %lu\n", size);
1165 ok(!memcmp(ciphertext, expected, sizeof(expected)), "wrong data\n");
1166 for (i = 0; i < 16; i++)
1167 ok(ciphertext[i] == expected[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected[i]);
1168 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
1169
1170 /* NULL initialization vector */
1171 size = 0;
1172 memset(ciphertext, 0, sizeof(ciphertext));
1173 ret = BCryptEncrypt(key, data, 16, NULL, NULL, 0, ciphertext, 16, &size, 0);
1174 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1175 ok(size == 16, "got %lu\n", size);
1176 ok(!memcmp(ciphertext, expected8, sizeof(expected8)), "wrong data\n");
1177
1178 /* all zero initialization vector */
1179 size = 0;
1180 memset(ciphertext, 0, sizeof(ciphertext));
1181 memset(ivbuf, 0, sizeof(ivbuf));
1182 ret = BCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
1183 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1184 ok(size == 16, "got %lu\n", size);
1185 ok(!memcmp(ciphertext, expected9, sizeof(expected9)), "wrong data\n");
1186 for (i = 0; i < 16; i++)
1187 ok(ciphertext[i] == expected9[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected9[i]);
1188 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
1189
1190 /* input size is not a multiple of block size */
1191 size = 0;
1192 memcpy(ivbuf, iv, sizeof(iv));
1193 ret = BCryptEncrypt(key, data, 17, NULL, ivbuf, 16, NULL, 0, &size, 0);
1194 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got %#lx\n", ret);
1195 ok(size == 17, "got %lu\n", size);
1196
1197 /* input size is not a multiple of block size, block padding set */
1198 size = 0;
1199 memcpy(ivbuf, iv, sizeof(iv));
1200 ret = BCryptEncrypt(key, data, 17, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1201 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1202 ok(size == 32, "got %lu\n", size);
1203 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1204
1205 size = 0;
1206 memcpy(ivbuf, iv, sizeof(iv));
1207 memset(ciphertext, 0, sizeof(ciphertext));
1208 ret = BCryptEncrypt(key, data, 17, NULL, ivbuf, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1209 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1210 ok(size == 32, "got %lu\n", size);
1211 ok(!memcmp(ciphertext, expected2, sizeof(expected2)), "wrong data\n");
1212 for (i = 0; i < 32; i++)
1213 ok(ciphertext[i] == expected2[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected2[i]);
1214 ok(!memcmp(ivbuf, ciphertext + 32 - 16, sizeof(iv)), "wrong iv data.\n");
1215
1216 /* input size is a multiple of block size, block padding set */
1217 size = 0;
1218 memcpy(ivbuf, iv, sizeof(iv));
1219 ret = BCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1220 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1221 ok(size == 48, "got %lu\n", size);
1222 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1223
1224 size = 0;
1225 memcpy(ivbuf, iv, sizeof(iv));
1226 memset(ciphertext, 0, sizeof(ciphertext));
1227 ret = BCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1228 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1229 ok(size == 48, "got %lu\n", size);
1230 ok(!memcmp(ciphertext, expected3, sizeof(expected3)), "wrong data\n");
1231 for (i = 0; i < 48; i++)
1232 ok(ciphertext[i] == expected3[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected3[i]);
1233 ok(!memcmp(ivbuf, ciphertext + 48 - 16, sizeof(iv)), "wrong iv data.\n");
1234
1235 /* output size too small */
1236 size = 0;
1237 memcpy(ivbuf, iv, sizeof(iv));
1238 memset(ciphertext, 0, sizeof(ciphertext));
1239 ret = BCryptEncrypt(key, data, 17, NULL, ivbuf, 16, ciphertext, 31, &size, BCRYPT_BLOCK_PADDING);
1240 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1241 ok(size == 32, "got %lu\n", size);
1242
1243 size = 0;
1244 memcpy(ivbuf, iv, sizeof(iv));
1245 memset(ciphertext, 0, sizeof(ciphertext));
1246 ret = BCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1247 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1248 ok(size == 48, "got %lu\n", size);
1249
1251 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1252 free(buf);
1253
1254 /* 256 bit key */
1255 buf = calloc(1, len);
1256
1257 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret256, sizeof(secret256), 0);
1258 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1260 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1261
1262 /* Key generations succeeds if the key size exceeds maximum and uses maximum key length
1263 * from secret. */
1264 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret256, sizeof(secret256) + 1, 0);
1265 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1266
1267 size = 0;
1268 memcpy(ivbuf, iv, sizeof(iv));
1269 ret = BCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1270 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1271 ok(size == 48, "got %lu\n", size);
1272 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1273
1274 size = 0;
1275 memcpy(ivbuf, iv, sizeof(iv));
1276 memset(ciphertext, 0, sizeof(ciphertext));
1277 ret = BCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1278 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1279 ok(size == 48, "got %lu\n", size);
1280 ok(!memcmp(ciphertext, expected10, sizeof(expected10)), "wrong data\n");
1281 for (i = 0; i < 48; i++)
1282 ok(ciphertext[i] == expected10[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected10[i]);
1283 ok(!memcmp(ivbuf, ciphertext + 48 - 16, sizeof(iv)), "wrong iv data.\n");
1284
1286 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1287 free(buf);
1288
1289 /******************
1290 * AES - GCM mode *
1291 ******************/
1292
1293 size = 0;
1295 ok(ret == STATUS_NOT_SUPPORTED, "got %#lx\n", ret);
1296
1298 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1299
1300 size = 0;
1302 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1303 ok(size == sizeof(tag_length), "got %lu\n", size);
1304
1305 size = 0;
1306 memset(&tag_length, 0, sizeof(tag_length));
1307 ret = BCryptGetProperty(aes, BCRYPT_AUTH_TAG_LENGTH, (UCHAR*)&tag_length, sizeof(tag_length), &size, 0);
1308 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1309 ok(size == sizeof(tag_length), "got %lu\n", size);
1310 ok(tag_length.dwMinLength == 12, "Expected 12, got %lu\n", tag_length.dwMinLength);
1311 ok(tag_length.dwMaxLength == 16, "Expected 16, got %lu\n", tag_length.dwMaxLength);
1312 ok(tag_length.dwIncrement == 1, "Expected 1, got %lu\n", tag_length.dwIncrement);
1313
1314 len = 0xdeadbeef;
1315 size = sizeof(len);
1316 ret = BCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
1317 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1318
1319 key = NULL;
1320 buf = calloc(1, len);
1321 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1322 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1323 ok(key != NULL, "key not set\n");
1324
1325 ret = BCryptGetProperty(key, BCRYPT_AUTH_TAG_LENGTH, (UCHAR*)&tag_length, sizeof(tag_length), &size, 0);
1326 ok(ret == STATUS_NOT_SUPPORTED, "got %#lx\n", ret);
1327
1328 memset(&auth_info, 0, sizeof(auth_info));
1329 auth_info.cbSize = sizeof(auth_info);
1330 auth_info.dwInfoVersion = 1;
1331 auth_info.pbNonce = nonce;
1332 auth_info.cbNonce = sizeof(nonce);
1333 auth_info.pbTag = tag;
1334 auth_info.cbTag = sizeof(tag);
1335
1336 /* input size is a multiple of block size */
1337 size = 0;
1338 memcpy(ivbuf, iv, sizeof(iv));
1339 memset(ciphertext, 0xff, sizeof(ciphertext));
1340 memset(tag, 0xff, sizeof(tag));
1341 ret = BCryptEncrypt(key, data2, 32, &auth_info, ivbuf, 16, ciphertext, 32, &size, 0);
1342 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1343 ok(size == 32, "got %lu\n", size);
1344 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1345 ok(!memcmp(tag, expected_tag, sizeof(expected_tag)), "wrong tag\n");
1346 for (i = 0; i < 32; i++)
1347 ok(ciphertext[i] == expected4[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1348 for (i = 0; i < 16; i++)
1349 ok(tag[i] == expected_tag[i], "%lu: %02x != %02x\n", i, tag[i], expected_tag[i]);
1350 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1351
1352 ret = BCryptEncrypt(key, data2, 32, &auth_info, ivbuf, 16, ciphertext, 31, &size, 0);
1353 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1354
1355 /* NULL initialization vector */
1356 size = 0;
1357 memset(ciphertext, 0xff, sizeof(ciphertext));
1358 memset(tag, 0xff, sizeof(tag));
1359 ret = BCryptEncrypt(key, data2, 32, &auth_info, NULL, 0, ciphertext, 32, &size, 0);
1360 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1361 ok(size == 32, "got %lu\n", size);
1362 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1363 ok(!memcmp(tag, expected_tag, sizeof(expected_tag)), "wrong tag\n");
1364 for (i = 0; i < 32; i++)
1365 ok(ciphertext[i] == expected4[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1366 for (i = 0; i < 16; i++)
1367 ok(tag[i] == expected_tag[i], "%lu: %02x != %02x\n", i, tag[i], expected_tag[i]);
1368
1369 /* all zero initialization vector */
1370 size = 0;
1371 memset(ciphertext, 0xff, sizeof(ciphertext));
1372 memset(tag, 0xff, sizeof(tag));
1373 memset(ivbuf, 0, sizeof(ivbuf));
1374 ret = BCryptEncrypt(key, data2, 32, &auth_info, ivbuf, 16, ciphertext, 32, &size, 0);
1375 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1376 ok(size == 32, "got %lu\n", size);
1377 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1378 ok(!memcmp(tag, expected_tag, sizeof(expected_tag)), "wrong tag\n");
1379 for (i = 0; i < 32; i++)
1380 ok(ciphertext[i] == expected4[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1381 for (i = 0; i < 16; i++)
1382 ok(tag[i] == expected_tag[i], "%lu: %02x != %02x\n", i, tag[i], expected_tag[i]);
1383 memset(ciphertext, 0, sizeof(iv));
1384 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
1385
1386 /* input size is not multiple of block size */
1387 size = 0;
1388 memcpy(ivbuf, iv, sizeof(iv));
1389 memset(ciphertext, 0xff, sizeof(ciphertext));
1390 memset(tag, 0xff, sizeof(tag));
1391 ret = BCryptEncrypt(key, data2, 24, &auth_info, ivbuf, 16, ciphertext, 24, &size, 0);
1392 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1393 ok(size == 24, "got %lu\n", size);
1394 ok(!memcmp(ciphertext, expected4, 24), "wrong data\n");
1395 ok(!memcmp(tag, expected_tag2, sizeof(expected_tag2)), "wrong tag\n");
1396 for (i = 0; i < 24; i++)
1397 ok(ciphertext[i] == expected4[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1398 for (i = 0; i < 16; i++)
1399 ok(tag[i] == expected_tag2[i], "%lu: %02x != %02x\n", i, tag[i], expected_tag2[i]);
1400 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1401
1402 /* test with auth data */
1403 auth_info.pbAuthData = auth_data;
1404 auth_info.cbAuthData = sizeof(auth_data);
1405
1406 size = 0;
1407 memcpy(ivbuf, iv, sizeof(iv));
1408 memset(ciphertext, 0xff, sizeof(ciphertext));
1409 memset(tag, 0xff, sizeof(tag));
1410 ret = BCryptEncrypt(key, data2, 32, &auth_info, ivbuf, 16, ciphertext, 32, &size, 0);
1411 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1412 ok(size == 32, "got %lu\n", size);
1413 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1414 ok(!memcmp(tag, expected_tag3, sizeof(expected_tag3)), "wrong tag\n");
1415 for (i = 0; i < 32; i++)
1416 ok(ciphertext[i] == expected4[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1417 for (i = 0; i < 16; i++)
1418 ok(tag[i] == expected_tag3[i], "%lu: %02x != %02x\n", i, tag[i], expected_tag3[i]);
1419 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1420
1421 memset(tag, 0xff, sizeof(tag));
1422 ret = BCryptEncrypt(key, data2, 0, &auth_info, ivbuf, 16, NULL, 0, &size, 0);
1423 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1424 ok(!size, "got %lu\n", size);
1425 for (i = 0; i < 16; i++)
1426 ok(tag[i] == 0xff, "%lu: %02x != %02x\n", i, tag[i], 0xff);
1427
1428 memset(tag, 0xff, sizeof(tag));
1429 ret = BCryptEncrypt(key, NULL, 0, &auth_info, ivbuf, 16, NULL, 0, &size, 0);
1430 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1431 ok(!size, "got %lu\n", size);
1432 ok(!memcmp(tag, expected_tag4, sizeof(expected_tag4)), "wrong tag\n");
1433 for (i = 0; i < 16; i++)
1434 ok(tag[i] == expected_tag4[i], "%lu: %02x != %02x\n", i, tag[i], expected_tag4[i]);
1435
1436 /* test with padding */
1437 memcpy(ivbuf, iv, sizeof(iv));
1438 memset(ciphertext, 0, sizeof(ciphertext));
1439 ret = BCryptEncrypt(key, data2, 32, &auth_info, ivbuf, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1440 todo_wine ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1441
1442 memcpy(ivbuf, iv, sizeof(iv));
1443 memset(ciphertext, 0, sizeof(ciphertext));
1444 ret = BCryptEncrypt(key, data2, 32, &auth_info, ivbuf, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1445 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
1446
1447 /* race test */
1448
1450 hthread = CreateThread(NULL, 0, encrypt_race_thread, key, 0, NULL);
1451
1453 ;
1454
1455 for (test = 0; test < RACE_TEST_COUNT; ++test)
1456 {
1457 size = 0;
1458 memset(ciphertext, 0xff, sizeof(ciphertext));
1459 memset(tag, 0xff, sizeof(tag));
1460 ret = BCryptEncrypt(key, data2, 32, &auth_info, NULL, 0, ciphertext, 32, &size, 0);
1461 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1462 ok(size == 32, "got %lu\n", size);
1463 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1464 ok(!memcmp(tag, expected_tag3, sizeof(expected_tag2)), "wrong tag\n");
1465 for (i = 0; i < 32; i++)
1466 ok(ciphertext[i] == expected4[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1467 for (i = 0; i < 16; i++)
1468 ok(tag[i] == expected_tag3[i], "%lu: %02x != %02x\n", i, tag[i], expected_tag3[i]);
1469 }
1470
1471 WaitForSingleObject(hthread, INFINITE);
1472
1474 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1475 free(buf);
1476
1477 /******************
1478 * AES - ECB mode *
1479 ******************/
1480
1482 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1483
1484 len = 0xdeadbeef;
1485 size = sizeof(len);
1486 ret = BCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
1487 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1488
1489 buf = calloc(1, len);
1490 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1491 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1492
1493 /* initialization vector is not allowed */
1494 size = 0;
1495 memcpy(ivbuf, iv, sizeof(iv));
1496 ret = BCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
1497 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
1498 ok(size == 16, "got %lu\n", size);
1499
1500 /* input size is a multiple of block size */
1501 size = 0;
1502 ret = BCryptEncrypt(key, data, 16, NULL, NULL, 16, NULL, 0, &size, 0);
1503 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1504 ok(size == 16, "got %lu\n", size);
1505
1506 size = 0;
1507 memset(ciphertext, 0, sizeof(ciphertext));
1508 ret = BCryptEncrypt(key, data, 16, NULL, NULL, 16, ciphertext, 16, &size, 0);
1509 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1510 ok(size == 16, "got %lu\n", size);
1511 ok(!memcmp(ciphertext, expected5, sizeof(expected5)), "wrong data\n");
1512 for (i = 0; i < 16; i++)
1513 ok(ciphertext[i] == expected5[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected5[i]);
1514
1515 /* input size is not a multiple of block size */
1516 size = 0;
1517 ret = BCryptEncrypt(key, data, 17, NULL, NULL, 16, NULL, 0, &size, 0);
1518 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got %#lx\n", ret);
1519 ok(size == 17, "got %lu\n", size);
1520
1521 /* input size is not a multiple of block size, block padding set */
1522 size = 0;
1524 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1525 ok(size == 32, "got %lu\n", size);
1526
1527 size = 0;
1528 memset(ciphertext, 0, sizeof(ciphertext));
1529 ret = BCryptEncrypt(key, data, 17, NULL, NULL, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1530 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1531 ok(size == 32, "got %lu\n", size);
1532 ok(!memcmp(ciphertext, expected6, sizeof(expected6)), "wrong data\n");
1533 for (i = 0; i < 32; i++)
1534 ok(ciphertext[i] == expected6[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected6[i]);
1535
1536 /* input size is a multiple of block size, block padding set */
1537 size = 0;
1539 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1540 ok(size == 48, "got %lu\n", size);
1541
1542 size = 0;
1543 memset(ciphertext, 0, sizeof(ciphertext));
1544 ret = BCryptEncrypt(key, data2, 32, NULL, NULL, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1545 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1546 ok(size == 48, "got %lu\n", size);
1547 ok(!memcmp(ciphertext, expected7, sizeof(expected7)), "wrong data\n");
1548 for (i = 0; i < 48; i++)
1549 ok(ciphertext[i] == expected7[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected7[i]);
1550
1551 /* output size too small */
1552 size = 0;
1553 memset(ciphertext, 0, sizeof(ciphertext));
1554 ret = BCryptEncrypt(key, data, 17, NULL, NULL, 16, ciphertext, 31, &size, BCRYPT_BLOCK_PADDING);
1555 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1556 ok(size == 32, "got %lu\n", size);
1557
1558 size = 0;
1559 memset(ciphertext, 0, sizeof(ciphertext));
1560 ret = BCryptEncrypt(key, data2, 32, NULL, NULL, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1561 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1562 ok(size == 48, "got %lu\n", size);
1563
1565 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1566 free(buf);
1567
1568 /******************
1569 * AES - CFB mode *
1570 ******************/
1571
1573 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1574
1575 key = NULL;
1576 buf = calloc(1, len);
1577 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1578 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1579 ok(key != NULL, "key not set\n");
1580
1581 /* input size is a multiple of block size */
1582 size = 0;
1583 memcpy(ivbuf, iv, sizeof(iv));
1584 ret = BCryptEncrypt(key, data, 16, NULL, ivbuf, 16, NULL, 0, &size, 0);
1585 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1586 ok(size == 16, "got %lu\n", size);
1587 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1588
1589 size = 0;
1590 memcpy(ivbuf, iv, sizeof(iv));
1591 memset(ciphertext, 0, sizeof(ciphertext));
1592 ret = BCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
1593 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1594 ok(size == 16, "got %lu\n", size);
1595 ok(!memcmp(ciphertext, expected11, sizeof(expected11)), "wrong data\n");
1596 for (i = 0; i < 16; i++)
1597 ok(ciphertext[i] == expected11[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected11[i]);
1598 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
1599
1600 /* NULL initialization vector */
1601 size = 0;
1602 memset(ciphertext, 0, sizeof(ciphertext));
1603 ret = BCryptEncrypt(key, data, 16, NULL, NULL, 0, ciphertext, 16, &size, 0);
1604 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1605 ok(size == 16, "got %lu\n", size);
1606 ok(!memcmp(ciphertext, expected12, sizeof(expected12)), "wrong data\n");
1607
1608 /* all zero initialization vector */
1609 size = 0;
1610 memset(ciphertext, 0, sizeof(ciphertext));
1611 memset(ivbuf, 0, sizeof(ivbuf));
1612 ret = BCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
1613 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1614 ok(size == 16, "got %lu\n", size);
1615 ok(!memcmp(ciphertext, expected13, sizeof(expected13)), "wrong data\n");
1616 for (i = 0; i < 16; i++)
1617 ok(ciphertext[i] == expected13[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected13[i]);
1618 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
1619
1620 /* input size is not a multiple of block size */
1621 size = 0;
1622 memcpy(ivbuf, iv, sizeof(iv));
1623 ret = BCryptEncrypt(key, data, 17, NULL, ivbuf, 16, NULL, 0, &size, 0);
1624 todo_wine ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1625 ok(size == 17, "got %lu\n", size);
1626
1627 /* input size is not a multiple of block size, block padding set */
1628 size = 0;
1629 memcpy(ivbuf, iv, sizeof(iv));
1630 ret = BCryptEncrypt(key, data, 17, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1631 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1632 ok(size == 32, "got %lu\n", size);
1633 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1634
1635 size = 0;
1636 memcpy(ivbuf, iv, sizeof(iv));
1637 memset(ciphertext, 0, sizeof(ciphertext));
1638 ret = BCryptEncrypt(key, data, 17, NULL, ivbuf, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1639 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1640 ok(size == 32, "got %lu\n", size);
1641 ok(!memcmp(ciphertext, expected14, sizeof(expected14)), "wrong data\n");
1642 for (i = 0; i < 32; i++)
1643 ok(ciphertext[i] == expected14[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected14[i]);
1644 ok(!memcmp(ivbuf, ciphertext + 32 - 16, sizeof(iv)), "wrong iv data.\n");
1645
1646 /* input size is a multiple of block size, block padding set */
1647 size = 0;
1648 memcpy(ivbuf, iv, sizeof(iv));
1649 ret = BCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1650 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1651 ok(size == 48, "got %lu\n", size);
1652
1653 size = 0;
1654 memcpy(ivbuf, iv, sizeof(iv));
1655 memset(ciphertext, 0, sizeof(ciphertext));
1656 ret = BCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1657 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1658 ok(size == 48, "got %lu\n", size);
1659 ok(!memcmp(ciphertext, expected15, sizeof(expected15)), "wrong data\n");
1660 for (i = 0; i < 48; i++)
1661 ok(ciphertext[i] == expected15[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected15[i]);
1662 ok(!memcmp(ivbuf, ciphertext + 48 - 16, sizeof(iv)), "wrong iv data.\n");
1663
1664 /* output size too small */
1665 size = 0;
1666 memcpy(ivbuf, iv, sizeof(iv));
1667 memset(ciphertext, 0, sizeof(ciphertext));
1668 ret = BCryptEncrypt(key, data, 17, NULL, ivbuf, 16, ciphertext, 31, &size, BCRYPT_BLOCK_PADDING);
1669 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1670 ok(size == 32, "got %lu\n", size);
1671 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1672
1673 size = 0;
1674 memcpy(ivbuf, iv, sizeof(iv));
1675 memset(ciphertext, 0, sizeof(ciphertext));
1676 ret = BCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1677 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1678 ok(size == 48, "got %lu\n", size);
1679 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1680
1682 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1683 free(buf);
1684
1685 /* 256 bit key */
1686 buf = calloc(1, len);
1687
1688 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret256, sizeof(secret256), 0);
1689 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1691 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1692
1693 /* Key generations succeeds if the key size exceeds maximum and uses maximum key length
1694 * from secret. */
1695 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret256, sizeof(secret256) + 1, 0);
1696 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1697
1698 size = 0;
1699 memcpy(ivbuf, iv, sizeof(iv));
1700 ret = BCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1701 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1702 ok(size == 48, "got %lu\n", size);
1703 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1704
1705 size = 0;
1706 memcpy(ivbuf, iv, sizeof(iv));
1707 memset(ciphertext, 0, sizeof(ciphertext));
1708 ret = BCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1709 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1710 ok(size == 48, "got %lu\n", size);
1711 ok(!memcmp(ciphertext, expected16, sizeof(expected16)), "wrong data\n");
1712 for (i = 0; i < 48; i++)
1713 ok(ciphertext[i] == expected16[i], "%lu: %02x != %02x\n", i, ciphertext[i], expected16[i]);
1714 ok(!memcmp(ivbuf, ciphertext + 48 - 16, sizeof(iv)), "wrong iv data.\n");
1715
1717 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1718}
1719
1720static void test_BCryptDecrypt(void)
1721{
1722 static UCHAR nonce[] =
1723 {0x10,0x20,0x30,0x40,0x50,0x60,0x10,0x20,0x30,0x40,0x50,0x60};
1724 static UCHAR auth_data[] =
1725 {0x60,0x50,0x40,0x30,0x20,0x10,0x60,0x50,0x40,0x30,0x20,0x10};
1726 static UCHAR secret[] =
1727 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
1728 static UCHAR iv[] =
1729 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
1730 static UCHAR expected[] =
1731 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
1732 static UCHAR expected2[] =
1733 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10};
1734 static UCHAR expected3[] =
1735 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
1736 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
1737 static UCHAR expected4[] =
1738 {0x28,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9,
1739 0x10,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f};
1740 static UCHAR expected5[] =
1741 {0x29,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9,
1742 0x10,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f};
1743 static UCHAR ciphertext[32] =
1744 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
1745 0x28,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9};
1746 static UCHAR ciphertext2[] =
1747 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
1748 0x28,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9};
1749 static UCHAR ciphertext3[] =
1750 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
1751 0xb1,0xa2,0x92,0x73,0xbe,0x2c,0x42,0x07,0xa5,0xac,0xe3,0x93,0x39,0x8c,0xb6,0xfb,
1752 0x87,0x5d,0xea,0xa3,0x7e,0x0f,0xde,0xfa,0xd9,0xec,0x6c,0x4e,0x3c,0x76,0x86,0xe4};
1753 static UCHAR ciphertext4[] =
1754 {0xe1,0x82,0xc3,0xc0,0x24,0xfb,0x86,0x85,0xf3,0xf1,0x2b,0x7d,0x09,0xb4,0x73,0x67,
1755 0x86,0x64,0xc3,0xfe,0xa3,0x07,0x61,0xf8,0x16,0xc9,0x78,0x7f,0xe7,0xb1,0xc4,0x94};
1756 static UCHAR ciphertext5[] =
1757 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a,
1758 0x84,0x07,0x66,0xb7,0x49,0xc0,0x9b,0x49,0x74,0x28,0x8c,0x10,0xb9,0xc2,0x09,0x70};
1759 static UCHAR ciphertext6[] =
1760 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a,
1761 0x95,0x4f,0x64,0xf2,0xe4,0xe8,0x6e,0x9e,0xee,0x82,0xd2,0x02,0x16,0x68,0x48,0x99,
1762 0x95,0x4f,0x64,0xf2,0xe4,0xe8,0x6e,0x9e,0xee,0x82,0xd2,0x02,0x16,0x68,0x48,0x99};
1763 static UCHAR tag[] =
1764 {0x89,0xb3,0x92,0x00,0x39,0x20,0x09,0xb4,0x6a,0xd6,0xaf,0xca,0x4b,0x5b,0xfd,0xd0};
1765 static UCHAR tag2[] =
1766 {0x17,0x9d,0xc0,0x7a,0xf0,0xcf,0xaa,0xd5,0x1c,0x11,0xc4,0x4b,0xd6,0xa3,0x3e,0x77};
1768 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
1772 UCHAR *buf, plaintext[48], ivbuf[16];
1773 ULONG size, len;
1774 NTSTATUS ret;
1775
1777 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1778
1779 size = 0;
1780 memset(&key_lengths, 0, sizeof(key_lengths));
1781 ret = BCryptGetProperty(aes, BCRYPT_KEY_LENGTHS, (UCHAR*)&key_lengths, sizeof(key_lengths), &size, 0);
1782 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1783 ok(size == sizeof(key_lengths), "got %lu\n", size);
1784 ok(key_lengths.dwMinLength == 128, "Expected 128, got %lu\n", key_lengths.dwMinLength);
1785 ok(key_lengths.dwMaxLength == 256, "Expected 256, got %lu\n", key_lengths.dwMaxLength);
1786 ok(key_lengths.dwIncrement == 64, "Expected 64, got %lu\n", key_lengths.dwIncrement);
1787
1788 /******************
1789 * AES - CBC mode *
1790 ******************/
1791
1792 len = 0xdeadbeef;
1793 size = sizeof(len);
1794 ret = BCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
1795 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1796
1797 key = NULL;
1798 buf = calloc(1, len);
1799 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1800 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1801 ok(key != NULL, "key not set\n");
1802
1803 /* input size is a multiple of block size */
1804 size = 0;
1805 memcpy(ivbuf, iv, sizeof(iv));
1806 ret = BCryptDecrypt(key, ciphertext, 32, NULL, ivbuf, 16, NULL, 0, &size, 0);
1807 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1808 ok(size == 32, "got %lu\n", size);
1809 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1810
1811 size = 0;
1812 memcpy(ivbuf, iv, sizeof(iv));
1813 memset(plaintext, 0, sizeof(plaintext));
1814 ret = BCryptDecrypt(key, ciphertext, 32, NULL, ivbuf, 16, plaintext, 32, &size, 0);
1815 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1816 ok(size == 32, "got %lu\n", size);
1817 ok(!memcmp(plaintext, expected, sizeof(expected)), "wrong data\n");
1818 ok(!memcmp(ivbuf, ciphertext + size - sizeof(iv), sizeof(iv)), "wrong iv data.\n");
1819
1820 size = 0;
1821 ++ivbuf[0];
1822 memset(plaintext, 0, sizeof(plaintext));
1823 ret = BCryptDecrypt(key, ciphertext, 32, NULL, ivbuf, 16, plaintext, 32, &size, 0);
1824 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1825 ok(size == 32, "got %lu\n", size);
1826 ok(!memcmp(plaintext, expected5, sizeof(expected)), "wrong data\n");
1827 ok(!memcmp(ivbuf, ciphertext + 32 - 16, sizeof(iv)), "wrong iv data.\n");
1828
1829 size = 0;
1830 memset(plaintext, 0, sizeof(plaintext));
1831 ret = BCryptDecrypt(key, ciphertext, 32, NULL, NULL, 0, plaintext, 32, &size, 0);
1832 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1833 ok(size == 32, "got %lu\n", size);
1834 ok(!memcmp(plaintext, expected4, sizeof(expected4)), "wrong data\n");
1835
1836 /* test with padding smaller than block size */
1837 size = 0;
1838 memcpy(ivbuf, iv, sizeof(iv));
1839 ret = BCryptDecrypt(key, ciphertext2, 32, NULL, ivbuf, 16, NULL, 0, &size, 0);
1840 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1841 ok(size == 32, "got %lu\n", size);
1842 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1843
1844 size = 0;
1845 memcpy(ivbuf, iv, sizeof(iv));
1846 memset(plaintext, 0, sizeof(plaintext));
1847 ret = BCryptDecrypt(key, ciphertext2, 32, NULL, ivbuf, 16, plaintext, 17, &size, BCRYPT_BLOCK_PADDING);
1848 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1849 ok(size == 17, "got %lu\n", size);
1850 ok(!memcmp(plaintext, expected2, sizeof(expected2)), "wrong data\n");
1851 ok(!memcmp(ivbuf, ciphertext2 + 32 - sizeof(iv), sizeof(iv)), "wrong iv data.\n");
1852
1853 size = 0;
1854 memset(plaintext, 0, sizeof(plaintext));
1855 ret = BCryptDecrypt(key, ciphertext2, 32, NULL, ivbuf, 16, plaintext, 17, &size, BCRYPT_BLOCK_PADDING);
1856 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1857 ok(size == 17, "got %lu\n", size);
1858 ok(!memcmp(plaintext, expected4, size), "wrong data\n");
1859 ok(!memcmp(ivbuf, ciphertext2 + 32 - 16, sizeof(iv)), "wrong iv data.\n");
1860
1861 /* test with padding of block size */
1862 size = 0;
1863 memcpy(ivbuf, iv, sizeof(iv));
1864 ret = BCryptDecrypt(key, ciphertext3, 48, NULL, ivbuf, 16, NULL, 0, &size, 0);
1865 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1866 ok(size == 48, "got %lu\n", size);
1867 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1868
1869 size = 0;
1870 memcpy(ivbuf, iv, sizeof(iv));
1871 memset(plaintext, 0, sizeof(plaintext));
1872 ret = BCryptDecrypt(key, ciphertext3, 48, NULL, ivbuf, 16, plaintext, 32, &size, BCRYPT_BLOCK_PADDING);
1873 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1874 ok(size == 32, "got %lu\n", size);
1875 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
1876 ok(!memcmp(ivbuf, ciphertext3 + 48 - 16, sizeof(iv)), "wrong iv data.\n");
1877
1878 /* output size too small */
1879 size = 0;
1880 memcpy(ivbuf, iv, sizeof(iv));
1881 ret = BCryptDecrypt(key, ciphertext, 32, NULL, ivbuf, 16, plaintext, 31, &size, 0);
1882 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1883 ok(size == 32, "got %lu\n", size);
1884
1885 size = 0;
1886 memcpy(ivbuf, iv, sizeof(iv));
1887 ret = BCryptDecrypt(key, ciphertext2, 32, NULL, ivbuf, 16, plaintext, 15, &size, BCRYPT_BLOCK_PADDING);
1888 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1889 ok(size == 32, "got %lu\n", size);
1890
1891 size = 0;
1892 memcpy(ivbuf, iv, sizeof(iv));
1893 ret = BCryptDecrypt(key, ciphertext2, 32, NULL, ivbuf, 16, plaintext, 16, &size, BCRYPT_BLOCK_PADDING);
1894 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1895 ok(size == 17, "got %lu\n", size);
1896
1897 size = 0;
1898 memcpy(ivbuf, iv, sizeof(iv));
1899 ret = BCryptDecrypt(key, ciphertext3, 48, NULL, ivbuf, 16, plaintext, 31, &size, BCRYPT_BLOCK_PADDING);
1900 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1901 ok(size == 48, "got %lu\n", size);
1902
1903 /* input size is not a multiple of block size */
1904 size = 0;
1905 memcpy(ivbuf, iv, sizeof(iv));
1906 ret = BCryptDecrypt(key, ciphertext, 17, NULL, ivbuf, 16, NULL, 0, &size, 0);
1907 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got %#lx\n", ret);
1908 ok(size == 17 || broken(size == 0 /* Win < 7 */), "got %lu\n", size);
1909
1910 /* input size is not a multiple of block size, block padding set */
1911 size = 0;
1912 memcpy(ivbuf, iv, sizeof(iv));
1913 ret = BCryptDecrypt(key, ciphertext, 17, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1914 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got %#lx\n", ret);
1915 ok(size == 17 || broken(size == 0 /* Win < 7 */), "got %lu\n", size);
1916
1918 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1919 free(buf);
1920
1921 /******************
1922 * AES - GCM mode *
1923 ******************/
1924
1926 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1927
1928 key = NULL;
1929 buf = calloc(1, len);
1930 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1931 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1932 ok(key != NULL, "key not set\n");
1933
1934 ret = BCryptGetProperty(key, BCRYPT_AUTH_TAG_LENGTH, (UCHAR*)&tag_lengths, sizeof(tag_lengths), &size, 0);
1935 ok(ret == STATUS_NOT_SUPPORTED, "got %#lx\n", ret);
1936
1937 memset(&auth_info, 0, sizeof(auth_info));
1938 auth_info.cbSize = sizeof(auth_info);
1939 auth_info.dwInfoVersion = 1;
1940 auth_info.pbNonce = nonce;
1941 auth_info.cbNonce = sizeof(nonce);
1942 auth_info.pbTag = tag;
1943 auth_info.cbTag = sizeof(tag);
1944
1945 /* input size is a multiple of block size */
1946 size = 0;
1947 memcpy(ivbuf, iv, sizeof(iv));
1948 memset(plaintext, 0, sizeof(plaintext));
1949 ret = BCryptDecrypt(key, ciphertext4, 32, &auth_info, ivbuf, 16, plaintext, 32, &size, 0);
1950 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1951 ok(size == 32, "got %lu\n", size);
1952 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
1953 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv.\n");
1954
1955 size = 0;
1956 ret = BCryptDecrypt(key, ciphertext4, 32, &auth_info, ivbuf, 16, NULL, 0, &size, 0);
1957 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1958 ok(size == 32, "got %lu\n", size);
1959
1960 size = 0;
1961 ret = BCryptDecrypt(key, ciphertext4, 32, &auth_info, ivbuf, 16, plaintext, 31, &size, 0);
1962 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
1963 ok(size == 32, "got %lu\n", size);
1964
1965 size = 0;
1966 memset(plaintext, 0, sizeof(plaintext));
1967 ret = BCryptDecrypt(key, ciphertext4, 32, &auth_info, NULL, 0, plaintext, 32, &size, 0);
1968 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1969 ok(size == 32, "got %lu\n", size);
1970 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
1971
1972 size = 0;
1973 memcpy(ivbuf, iv, sizeof(iv));
1974 ++ivbuf[0];
1975 memset(plaintext, 0, sizeof(plaintext));
1976 ret = BCryptDecrypt(key, ciphertext4, 32, &auth_info, ivbuf, 16, plaintext, 32, &size, 0);
1977 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1978 ok(size == 32, "got %lu\n", size);
1979 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
1980 ok(!memcmp(ivbuf + 1, iv + 1, sizeof(iv) - 1), "wrong iv data.\n");
1981 ok(ivbuf[0] == iv[0] + 1, "wrong iv data.\n");
1982
1983 /* test with auth data */
1984 auth_info.pbAuthData = auth_data;
1985 auth_info.cbAuthData = sizeof(auth_data);
1986 auth_info.pbTag = tag2;
1987 auth_info.cbTag = sizeof(tag2);
1988
1989 size = 0;
1990 memcpy(ivbuf, iv, sizeof(iv));
1991 memset(plaintext, 0, sizeof(plaintext));
1992 ret = BCryptDecrypt(key, ciphertext4, 32, &auth_info, ivbuf, 16, plaintext, 32, &size, 0);
1993 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
1994 ok(size == 32, "got %lu\n", size);
1995 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
1996 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv.\n");
1997
1998 /* test with wrong tag */
1999 memcpy(ivbuf, iv, sizeof(iv));
2000 auth_info.pbTag = iv; /* wrong tag */
2001 ret = BCryptDecrypt(key, ciphertext4, 32, &auth_info, ivbuf, 16, plaintext, 32, &size, 0);
2002 ok(ret == STATUS_AUTH_TAG_MISMATCH, "got %#lx\n", ret);
2003 ok(size == 32, "got %lu\n", size);
2004 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
2005
2007 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2008 free(buf);
2009
2010 /******************
2011 * AES - ECB mode *
2012 ******************/
2013
2015 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2016
2017 len = 0xdeadbeef;
2018 size = sizeof(len);
2019 ret = BCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
2020 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2021
2022 buf = calloc(1, len);
2023 ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
2024 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2025
2026 /* initialization vector is not allowed */
2027 size = 0;
2028 memcpy(ivbuf, iv, sizeof(iv));
2029 ret = BCryptDecrypt(key, ciphertext5, 32, NULL, ivbuf, 16, plaintext, 32, &size, 0);
2030 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
2031 ok(size == 32, "got %lu\n", size);
2032
2033 /* input size is a multiple of block size */
2034 size = 0;
2035 ret = BCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, NULL, 0, &size, 0);
2036 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2037 ok(size == 32, "got %lu\n", size);
2038
2039 size = 0;
2040 memset(plaintext, 0, sizeof(plaintext));
2041 ret = BCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, plaintext, 32, &size, 0);
2042 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2043 ok(size == 32, "got %lu\n", size);
2044 ok(!memcmp(plaintext, expected, sizeof(expected)), "wrong data\n");
2045
2046 /* test with padding smaller than block size */
2047 size = 0;
2048 ret = BCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, NULL, 0, &size, 0);
2049 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2050 ok(size == 32, "got %lu\n", size);
2051
2052 size = 0;
2053 memset(plaintext, 0, sizeof(plaintext));
2054 ret = BCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, plaintext, 17, &size, BCRYPT_BLOCK_PADDING);
2055 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2056 ok(size == 17, "got %lu\n", size);
2057 ok(!memcmp(plaintext, expected2, sizeof(expected2)), "wrong data\n");
2058
2059 /* test with padding of block size */
2060 size = 0;
2061 ret = BCryptDecrypt(key, ciphertext6, 48, NULL, NULL, 16, NULL, 0, &size, 0);
2062 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2063 ok(size == 48, "got %lu\n", size);
2064
2065 size = 0;
2066 memset(plaintext, 0, sizeof(plaintext));
2067 ret = BCryptDecrypt(key, ciphertext6, 48, NULL, NULL, 16, plaintext, 32, &size, BCRYPT_BLOCK_PADDING);
2068 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2069 ok(size == 32, "got %lu\n", size);
2070 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
2071
2072 /* output size too small */
2073 size = 0;
2074 ret = BCryptDecrypt(key, ciphertext4, 32, NULL, NULL, 16, plaintext, 31, &size, 0);
2075 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
2076 ok(size == 32, "got %lu\n", size);
2077
2078 size = 0;
2079 ret = BCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, plaintext, 15, &size, BCRYPT_BLOCK_PADDING);
2080 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
2081 ok(size == 32, "got %lu\n", size);
2082
2083 size = 0;
2084 ret = BCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, plaintext, 16, &size, BCRYPT_BLOCK_PADDING);
2085 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
2086 ok(size == 17, "got %lu\n", size);
2087
2088 size = 0;
2089 ret = BCryptDecrypt(key, ciphertext6, 48, NULL, NULL, 16, plaintext, 31, &size, BCRYPT_BLOCK_PADDING);
2090 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
2091 ok(size == 48, "got %lu\n", size);
2092
2093 /* input size is not a multiple of block size */
2094 size = 0;
2095 ret = BCryptDecrypt(key, ciphertext4, 17, NULL, NULL, 16, NULL, 0, &size, 0);
2096 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got %#lx\n", ret);
2097 ok(size == 17 || broken(size == 0 /* Win < 7 */), "got %lu\n", size);
2098
2099 /* input size is not a multiple of block size, block padding set */
2100 size = 0;
2101 ret = BCryptDecrypt(key, ciphertext4, 17, NULL, NULL, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
2102 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got %#lx\n", ret);
2103 ok(size == 17 || broken(size == 0 /* Win < 7 */), "got %lu\n", size);
2104
2106 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2107
2108 if (0) {
2110 ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
2111 }
2112 free(buf);
2113
2115 ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
2116
2118 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2119
2121 ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
2122
2124 ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
2125}
2126
2127static void test_key_import_export(void)
2128{
2129 static const UCHAR encrypted_blob[40] = {0x33,0x6e,0x51,0x10,
2130 0x25,0xba,0xdb,0xce,0xcb,0x25,0x00,0x85,0x51,0xc0,0xfa,0x21,
2131 0x66,0xdd,0x6d,0x67,0x46,0x76,0x0f,0x8a,0x44,0xe5,0x65,0x31,
2132 0xcb,0x02,0x52,0x9c,0x69,0x59,0x1a,0xec,0x67,0x27,0x11,0xaa};
2133 UCHAR buffer1[sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + 16];
2134 UCHAR buffer2[sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + 32], *buf;
2135 UCHAR buffer3[32 + 8], buffer4[sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + 32];
2136 BCRYPT_KEY_DATA_BLOB_HEADER *key_data1 = (void*)buffer1;
2137 BCRYPT_KEY_DATA_BLOB_HEADER *key_data2 = (void*)buffer2;
2139 BCRYPT_KEY_HANDLE key, key2, key3;
2140 NTSTATUS ret;
2141 ULONG size;
2142
2144 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2145
2146 key_data1->dwMagic = BCRYPT_KEY_DATA_BLOB_MAGIC;
2147 key_data1->dwVersion = BCRYPT_KEY_DATA_BLOB_VERSION1;
2148 key_data1->cbKeyData = 16;
2149 memset(&key_data1[1], 0x11, 16);
2150
2151 key = NULL;
2152 ret = BCryptImportKey(aes, NULL, BCRYPT_KEY_DATA_BLOB, &key, NULL, 0, buffer1, sizeof(buffer1), 0);
2153 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2154 ok(key != NULL, "key not set\n");
2155
2158 key_data2->cbKeyData = 32;
2159 memset(&key_data2[1], 0x22, 32);
2160 key2 = NULL;
2161 ret = BCryptImportKey(aes, NULL, BCRYPT_KEY_DATA_BLOB, &key2, NULL, 0, buffer2, sizeof(buffer2), 0);
2162 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2163 ok(key2 != NULL, "key not set\n");
2164
2165 size = 0;
2167 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2168 ok(size == sizeof(buffer3), "got %lu\n", size);
2169
2171 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2172 ok(!memcmp(buffer3, encrypted_blob, sizeof(encrypted_blob)), "blobs didn't match\n");
2173
2174 key3 = NULL;
2175 ret = BCryptImportKey(aes, key, BCRYPT_AES_WRAP_KEY_BLOB, &key3, NULL, 0, buffer3, sizeof(buffer3), 0);
2176 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2177 ok(key3 != NULL, "key not set\n");
2178
2179 size = 0;
2180 memset(buffer4, 0xff, sizeof(buffer4));
2181 ret = BCryptExportKey(key3, NULL, BCRYPT_KEY_DATA_BLOB, buffer4, sizeof(buffer4), &size, 0);
2182 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2183 ok(size == sizeof(buffer2), "Got %lu\n", size);
2184 ok(!memcmp(buffer4, buffer2, sizeof(buffer2)), "Expected exported key to match imported key\n");
2185
2186 BCryptDestroyKey(key3);
2188
2189 size = 0;
2190 ret = BCryptExportKey(key, NULL, BCRYPT_KEY_DATA_BLOB, buffer1, 0, &size, 0);
2191 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
2192 ok(size == sizeof(buffer1), "got %lu\n", size);
2193
2194 size = 0;
2195 memset(buffer2, 0xff, sizeof(buffer2));
2196 ret = BCryptExportKey(key, NULL, BCRYPT_KEY_DATA_BLOB, buffer2, sizeof(buffer2), &size, 0);
2197 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2198 ok(size == sizeof(buffer1), "Got %lu\n", size);
2199 ok(!memcmp(buffer1, buffer2, sizeof(buffer1)), "Expected exported key to match imported key\n");
2200
2201 /* opaque blob */
2202 size = 0;
2203 ret = BCryptExportKey(key, NULL, BCRYPT_OPAQUE_KEY_BLOB, buffer2, 0, &size, 0);
2204 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
2205 ok(size > 0, "got zero\n");
2206
2207 buf = malloc(size);
2209 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2210
2212 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2213
2214 key = NULL;
2216 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2217 ok(key != NULL, "key not set\n");
2218
2220 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2221
2222 if (pBCryptHash)
2223 {
2225 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2227 }
2228
2229 free(buf);
2231 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2232}
2233
2235{
2236 /* X */
2237 0x26, 0xff, 0x0e, 0xf9, 0x71, 0x93, 0xf8, 0xed, 0x59, 0xfa, 0x24, 0xec, 0x18, 0x13, 0xfe, 0xf5,
2238 0x0b, 0x4a, 0xb1, 0x27, 0xb7, 0xab, 0x3e, 0x4f, 0xc5, 0x5a, 0x91, 0xa3, 0x6e, 0x21, 0x61, 0x65,
2239 /* Y */
2240 0x62, 0x7b, 0x8b, 0x30, 0x7a, 0x63, 0x4c, 0x1a, 0xf4, 0x54, 0x54, 0xbb, 0x75, 0x59, 0x68, 0x36,
2241 0xfe, 0x49, 0x95, 0x75, 0x9e, 0x20, 0x3e, 0x69, 0x58, 0xb9, 0x7a, 0x84, 0x03, 0x45, 0x5c, 0x10,
2242 /* d */
2243 0xb9, 0xcd, 0xbe, 0xd4, 0x75, 0x5d, 0x05, 0xe5, 0x83, 0x0c, 0xd3, 0x37, 0x34, 0x15, 0xe3, 0x2c,
2244 0xe5, 0x85, 0x15, 0xa9, 0xee, 0xba, 0x94, 0x03, 0x03, 0x0b, 0x86, 0xea, 0x85, 0x40, 0xbd, 0x35,
2245};
2247{
2248 /* X */
2249 0x00, 0x5f, 0xea, 0x1e, 0x01, 0xae, 0x69, 0xc3, 0x88, 0x1c, 0xbf, 0x7f, 0x86, 0x1a, 0x48, 0x20,
2250 0xd3, 0xba, 0xac, 0x9f, 0x1c, 0xc9, 0x99, 0xfa, 0x7d, 0x39, 0xf6, 0xe0, 0xd6, 0x92, 0x97, 0xee,
2251 0xf6, 0xca, 0x65, 0x40, 0x24, 0xa6, 0xf7, 0x97, 0x17, 0x8c, 0xe1, 0x81, 0x6c, 0x10, 0x92, 0xcd,
2252 0x41, 0xbc, 0x1c, 0xde, 0x37, 0x4a, 0x21, 0xb9, 0xbc, 0x46, 0x40, 0xa9, 0x91, 0xd9, 0x61, 0x84,
2253 0x15, 0x33,
2254 /* Y */
2255 0x00, 0x31, 0xde, 0xe9, 0x64, 0x9d, 0xb8, 0x43, 0x3a, 0x93, 0x5d, 0xc8, 0x82, 0xec, 0xe4, 0x7f,
2256 0x83, 0x8d, 0x2c, 0xc7, 0xe8, 0x24, 0x38, 0x5a, 0x81, 0x3d, 0xe6, 0x8d, 0xd4, 0xb1, 0xa0, 0x37,
2257 0x89, 0xae, 0x1f, 0x81, 0x23, 0x22, 0x8f, 0xd1, 0xe0, 0xc4, 0x6a, 0x99, 0xcc, 0xc8, 0xe4, 0xa0,
2258 0x65, 0x42, 0x9e, 0xbd, 0xaf, 0x07, 0x79, 0xe8, 0x88, 0xc2, 0xfe, 0xc0, 0x2d, 0x88, 0xd5, 0x3a,
2259 0xbd, 0xb1,
2260 /* d */
2261 0x00, 0x8b, 0xc5, 0xd5, 0x06, 0x3a, 0x1d, 0xd2, 0xf8, 0x26, 0x8e, 0xa2, 0xd3, 0x69, 0x5a, 0xf9,
2262 0xb6, 0x42, 0x8b, 0x1a, 0x9c, 0x34, 0x04, 0xa6, 0x1d, 0xfc, 0x67, 0xe5, 0x23, 0x71, 0x8e, 0xad,
2263 0x61, 0x45, 0x4f, 0x00, 0x3e, 0x8f, 0x61, 0xa3, 0xfb, 0xb6, 0x7a, 0x98, 0xf8, 0x27, 0x2c, 0x1b,
2264 0xa8, 0xda, 0xb7, 0x78, 0xe9, 0xf5, 0x9d, 0xff, 0x6a, 0x07, 0xb0, 0xe2, 0xae, 0x64, 0x15, 0x03,
2265 0xb3, 0x8a,
2266};
2267static BYTE eccPubkey[] =
2268{
2269 /* X */
2270 0x3b, 0x3c, 0x34, 0xc8, 0x3f, 0x15, 0xea, 0x02, 0x68, 0x46, 0x69, 0xdf, 0x0c, 0xa6, 0xee, 0x7a,
2271 0xd9, 0x82, 0x08, 0x9b, 0x37, 0x53, 0x42, 0xf3, 0x13, 0x63, 0xda, 0x65, 0x79, 0xe8, 0x04, 0x9e,
2272 /* Y */
2273 0x8c, 0x77, 0xc4, 0x33, 0x77, 0xd9, 0x5a, 0x7f, 0x60, 0x7b, 0x98, 0xce, 0xf3, 0x96, 0x56, 0xd6,
2274 0xb5, 0x8d, 0x87, 0x7a, 0x00, 0x2b, 0xf3, 0x70, 0xb3, 0x90, 0x73, 0xa0, 0x56, 0x06, 0x3b, 0x22,
2275};
2276static BYTE certHash[] =
2277{
2278 0x28, 0x19, 0x0f, 0x15, 0x6d, 0x75, 0xcc, 0xcf, 0x62, 0xf1, 0x5e, 0xe6, 0x8a, 0xc3, 0xf0, 0x5d,
2279 0x89, 0x28, 0x2d, 0x48, 0xd8, 0x73, 0x7c, 0x05, 0x05, 0x8e, 0xbc, 0xce, 0x28, 0xb7, 0xba, 0xc9,
2280};
2282{
2283 /* r */
2284 0xd7, 0x29, 0xce, 0x5a, 0xef, 0x74, 0x85, 0xd1, 0x18, 0x5f, 0x6e, 0xf1, 0xba, 0x53, 0xd4, 0xcd,
2285 0xdd, 0xe0, 0x5d, 0xf1, 0x5e, 0x48, 0x51, 0xea, 0x63, 0xc0, 0xe8, 0xe2, 0xf6, 0xfa, 0x4c, 0xaf,
2286 /* s */
2287 0xe3, 0x94, 0x15, 0x3b, 0x6c, 0x71, 0x6e, 0x44, 0x22, 0xcb, 0xa0, 0x88, 0xcd, 0x0a, 0x5a, 0x50,
2288 0x29, 0x7c, 0x5c, 0xd6, 0x6c, 0xd2, 0xe0, 0x7f, 0xcd, 0x02, 0x92, 0x21, 0x4c, 0x2c, 0x92, 0xee,
2289};
2291{
2292 0x01, 0x6b, 0xd6, 0xca, 0xac, 0x28, 0xa8, 0xa9, 0x83, 0x9d, 0xca, 0x13, 0x08, 0xd6, 0xf2, 0x9c,
2293 0x94, 0x6b, 0x28, 0x6b, 0x93, 0x58, 0x3c, 0x65, 0x54, 0xb4, 0xa6, 0xb8, 0x0d, 0x55, 0xed, 0x4e,
2294 0xc9, 0x98, 0x26, 0x96, 0x1a, 0xbb, 0x9f, 0x9e, 0x5c, 0xb1, 0x1e, 0x8b, 0x04, 0x82, 0xe6, 0x32,
2295 0x15, 0x92, 0xcb, 0xfe, 0xe7, 0x53, 0xfc, 0x17, 0xe0, 0xc9, 0x44, 0xf5, 0x1d, 0x37, 0x33, 0x02,
2296 0xbb, 0x75, 0x01, 0x65, 0x84, 0xab, 0x89, 0xb3, 0x69, 0x56, 0xf4, 0x18, 0xb0, 0xdd, 0xfd, 0x69,
2297 0xe6, 0x52, 0x1e, 0x75, 0x4f, 0x98, 0xa8, 0x49, 0x88, 0x84, 0x15, 0x58, 0x23, 0x9f, 0x89, 0x06,
2298 0x73, 0x6b, 0x8c, 0xf9, 0x9a, 0x85, 0x1d, 0xd2, 0xf4, 0x06, 0x65, 0xa5, 0x88, 0x12, 0xa3, 0x4e,
2299 0xcd, 0x99, 0x06, 0x1b, 0xf8, 0x17, 0xe0, 0xeb, 0xb8, 0x7f, 0x6b, 0x89, 0x47, 0xd2, 0x5d, 0x30,
2300 0xf4, 0xf6, 0x5f, 0x83,
2301};
2302
2303static void test_ECDSA(void)
2304{
2305 static UCHAR hash[] =
2306 {0x7e, 0xe3, 0x74, 0xe7, 0xc5, 0x0b, 0x6b, 0x70, 0xdb, 0xab, 0x32, 0x6d, 0x1d, 0x51, 0xd6,
2307 0x74, 0x79, 0x8e, 0x5b, 0x4b};
2308 BYTE buffer[sizeof(BCRYPT_ECCKEY_BLOB) + sizeof(ecc521Privkey)];
2309 BCRYPT_ECCKEY_BLOB *ecckey = (void *)buffer;
2313 DWORD keylen;
2314 ULONG size, strength;
2315 UCHAR sig[64];
2316
2318 ok(!status, "got %#lx\n", status);
2319
2321 memcpy(ecckey + 1, eccPubkey, sizeof(eccPubkey));
2322
2323 ecckey->cbKey = 2;
2324 size = sizeof(BCRYPT_ECCKEY_BLOB) + sizeof(eccPubkey);
2326 ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %#lx\n", status);
2327
2329 ecckey->cbKey = 32;
2331 ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %#lx\n", status);
2332
2334 ecckey->cbKey = 32;
2336 ok(!status, "BCryptImportKeyPair failed: %#lx\n", status);
2338
2339 if (pBCryptHash)
2340 {
2342 size, 0);
2343 ok(!status, "BCryptImportKeyPair failed: %#lx\n", status);
2345 }
2346
2348 ok(!status, "BCryptImportKeyPair failed: %#lx\n", status);
2349
2350 keylen = 0;
2351 status = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
2352 ok(!status, "got %#lx\n", status);
2353 ok(size == sizeof(keylen), "got %lu\n", size);
2354 ok(keylen == 256, "got %lu\n", keylen);
2355
2356 memset(buffer, 0xcc, sizeof(buffer));
2358 ok(!status, "Got unexpected status %#lx\n", status);
2359 ok(ecckey->dwMagic == BCRYPT_ECDSA_PUBLIC_P256_MAGIC, "Got unexpected magic %#lx.\n", ecckey->dwMagic);
2360 ok(ecckey->cbKey == 32, "got %lu\n", ecckey->cbKey);
2361 ok(!memcmp(ecckey + 1, eccPubkey, sizeof(eccPubkey)), "Got unexpected key data.\n");
2362
2364 ok(status == STATUS_INVALID_PARAMETER, "Got unexpected status %#lx\n", status);
2365
2367 ok(status == STATUS_INVALID_SIGNATURE, "Expected STATUS_INVALID_SIGNATURE, got %#lx\n", status);
2368
2370 ok(!status, "BCryptVerifySignature failed: %#lx\n", status);
2372
2374 memcpy(ecckey + 1, eccPrivkey, sizeof(eccPrivkey));
2375
2376 ecckey->cbKey = 2;
2377 size = sizeof(BCRYPT_ECCKEY_BLOB) + sizeof(eccPrivkey);
2379 ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %#lx\n", status);
2380
2382 ecckey->cbKey = 32;
2384 ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %#lx\n", status);
2385
2387 ecckey->cbKey = 32;
2389 ok(!status, "BCryptImportKeyPair failed: %#lx\n", status);
2390
2391 memset( buffer, 0xcc, sizeof(buffer) );
2393 ok(!status, "Got unexpected status %#lx\n", status);
2394 ok(ecckey->dwMagic == BCRYPT_ECDSA_PUBLIC_P256_MAGIC, "got %#lx\n", ecckey->dwMagic);
2395 ok(ecckey->cbKey == 32, "got %lu\n", ecckey->cbKey);
2396 ok(!memcmp(ecckey + 1, eccPrivkey, sizeof(eccPubkey)), "Got unexpected key data.\n");
2397
2398 size = sizeof(BCRYPT_ECCKEY_BLOB) + sizeof(eccPrivkey);
2399 memset( buffer, 0, sizeof(buffer) );
2401 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2402 ecckey = (BCRYPT_ECCKEY_BLOB *)buffer;
2403 ok(ecckey->dwMagic == BCRYPT_ECDSA_PRIVATE_P256_MAGIC, "got %#lx\n", ecckey->dwMagic);
2404 ok(ecckey->cbKey == 32, "got %lu\n", ecckey->cbKey);
2405 ok(size == sizeof(*ecckey) + ecckey->cbKey * 3, "got %lu\n", size);
2406
2409
2410 /* P521 */
2412 ok(!status, "got %#lx\n", status);
2413
2415 ecckey->cbKey = 66;
2416 size = sizeof(BCRYPT_ECCKEY_BLOB) + ecckey->cbKey * 2;
2417 memcpy(ecckey + 1, ecc521Privkey, ecckey->cbKey * 2);
2419 ok(!status, "BCryptImportKeyPair failed: %#lx\n", status);
2420
2421 keylen = 0;
2422 status = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
2423 ok(!status, "got %#lx\n", status);
2424 ok(size == sizeof(keylen), "got %lu\n", size);
2425 ok(keylen == 521, "got %lu\n", keylen);
2426
2427 memset(buffer, 0xcc, sizeof(buffer));
2429 ok(!status, "Got unexpected status %#lx\n", status);
2430 ok(ecckey->dwMagic == BCRYPT_ECDSA_PUBLIC_P521_MAGIC, "Got unexpected magic %#lx.\n", ecckey->dwMagic);
2431 ok(ecckey->cbKey == 66, "got %lu\n", ecckey->cbKey);
2432 ok(!memcmp(ecckey + 1, ecc521Privkey, ecckey->cbKey * 2), "Got unexpected key data.\n");
2433
2436 ok(!status, "BCryptVerifySignature failed: %#lx\n", status);
2437
2438 ++buffer[5];
2440 ok(status == STATUS_INVALID_SIGNATURE, "BCryptVerifySignature failed: %#lx\n", status);
2441
2443
2445 ecckey->cbKey = 66;
2446 memcpy(ecckey + 1, ecc521Privkey, sizeof(ecc521Privkey));
2447 size = sizeof(*ecckey) + sizeof(ecc521Privkey);
2449 ok(!status, "BCryptImportKeyPair failed: %#lx\n", status);
2450
2451 memset( buffer, 0xcc, sizeof(buffer) );
2453 ok(!status, "Got unexpected status %#lx\n", status);
2454 ok(ecckey->dwMagic == BCRYPT_ECDSA_PUBLIC_P521_MAGIC, "got %#lx\n", ecckey->dwMagic);
2455 ok(ecckey->cbKey == 66, "got %lu\n", ecckey->cbKey);
2456 ok(!memcmp(ecckey + 1, ecc521Privkey, ecckey->cbKey * 2), "Got unexpected key data.\n");
2457
2458 size = sizeof(BCRYPT_ECCKEY_BLOB) + sizeof(ecc521Privkey);
2459 memset( buffer, 0xcc, sizeof(buffer) );
2461 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2462 ecckey = (BCRYPT_ECCKEY_BLOB *)buffer;
2463 ok(ecckey->dwMagic == BCRYPT_ECDSA_PRIVATE_P521_MAGIC, "got %#lx\n", ecckey->dwMagic);
2464 ok(ecckey->cbKey == 66, "got %lu\n", ecckey->cbKey);
2465 ok(size == sizeof(*ecckey) + ecckey->cbKey * 3, "got %lu\n", size);
2466 ok(!memcmp(ecckey + 1, ecc521Privkey, ecckey->cbKey * 3), "Got unexpected key data.\n");
2467
2470
2471 /* generic ECDSA provider */
2473 if (status == STATUS_NOT_FOUND)
2474 {
2475 win_skip("generic ECDSA provider not found\n");
2476 return;
2477 }
2478 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2479
2481 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2482
2484 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
2487
2489 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2490
2492 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2493
2494 status = BCryptGenerateKeyPair(alg, &key, 255, 0);
2495 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
2496
2498 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2499
2500 strength = 0;
2501 status = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&strength, sizeof(strength), &size, 0);
2502 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2503 ok(strength == 256, "got %lu\n", strength);
2504
2506 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2509
2511 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2512
2514 ok(status == STATUS_NOT_SUPPORTED, "got %#lx\n", status);
2516
2517 /* Brainpool curve */
2519 ok(!status, "got %#lx\n", status);
2520
2523 ok(!status, "got %#lx\n", status);
2524
2525 status = BCryptGenerateKeyPair(alg, &key, 256, 0);
2526 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2527
2528 strength = 0;
2529 status = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&strength, sizeof(strength), &size, 0);
2530 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2531 ok(strength == 256, "got %lu\n", strength);
2532
2534 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2535
2536 size = 0;
2537 status = BCryptSignHash(key, NULL, hash, sizeof(hash), sig, sizeof(sig), &size, 0);
2538 ok (status == STATUS_SUCCESS, "got %#lx\n", status);
2539 ok (size == 64, "got %lu\n", size);
2540
2541 status = BCryptVerifySignature(key, NULL, hash, sizeof(hash), sig, size, 0);
2542 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
2545}
2546
2548{
2549 0x52, 0x53, 0x41, 0x31, 0x00, 0x08, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
2550 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xad, 0x41, 0x09, 0xa2, 0x56,
2551 0x3a, 0x7b, 0x75, 0x4b, 0x72, 0x9b, 0x28, 0x72, 0x3b, 0xae, 0x9f, 0xd8, 0xa8, 0x25, 0x4a, 0x4c,
2552 0x19, 0xf5, 0xa6, 0xd0, 0x05, 0x1c, 0x59, 0x8f, 0xe3, 0xf3, 0x2d, 0x29, 0x47, 0xf8, 0x80, 0x25,
2553 0x25, 0x21, 0x58, 0xc2, 0xac, 0xa1, 0x9e, 0x93, 0x8e, 0x82, 0x6d, 0xd7, 0xf3, 0xe7, 0x8f, 0x0b,
2554 0xc0, 0x41, 0x85, 0x29, 0x3c, 0xf1, 0x0b, 0x2c, 0x5d, 0x49, 0xed, 0xb4, 0x30, 0x6e, 0x02, 0x15,
2555 0x4b, 0x9a, 0x08, 0x0d, 0xe1, 0x6f, 0xa8, 0xd3, 0x12, 0xab, 0x66, 0x48, 0x4d, 0xd9, 0x28, 0x03,
2556 0x6c, 0x9d, 0x44, 0x7a, 0xed, 0xc9, 0x43, 0x4f, 0x9d, 0x4e, 0x3c, 0x7d, 0x0e, 0xff, 0x07, 0x87,
2557 0xeb, 0xca, 0xca, 0x65, 0x6d, 0xbe, 0xc5, 0x31, 0x8b, 0xcc, 0x7e, 0x0a, 0x71, 0x4a, 0x4d, 0x9d,
2558 0x3d, 0xfd, 0x7a, 0x56, 0x32, 0x8a, 0x6c, 0x6d, 0x9d, 0x2a, 0xd9, 0x8e, 0x68, 0x89, 0x63, 0xc6,
2559 0x4f, 0x24, 0xd1, 0x2a, 0x72, 0x69, 0x08, 0x77, 0xa0, 0x7f, 0xfe, 0xc6, 0x33, 0x8d, 0xb4, 0x7d,
2560 0x73, 0x91, 0x13, 0x9c, 0x47, 0x53, 0x6a, 0x13, 0xdf, 0x19, 0xc7, 0xed, 0x48, 0x81, 0xed, 0xd8,
2561 0x1f, 0x11, 0x11, 0xbb, 0x41, 0x15, 0x5b, 0xa4, 0xf5, 0xc9, 0x2b, 0x48, 0x5e, 0xd8, 0x4b, 0x52,
2562 0x1f, 0xf7, 0x87, 0xf2, 0x68, 0x25, 0x28, 0x79, 0xee, 0x39, 0x41, 0xc9, 0x0e, 0xc8, 0xf9, 0xf2,
2563 0xd8, 0x24, 0x09, 0xb4, 0xd4, 0xb7, 0x90, 0xba, 0x26, 0xe8, 0x1d, 0xb4, 0xd7, 0x09, 0x00, 0xc4,
2564 0xa0, 0xb6, 0x14, 0xe8, 0x4c, 0x29, 0x60, 0x54, 0x2e, 0x01, 0xde, 0x54, 0x66, 0x40, 0x22, 0x50,
2565 0x27, 0xf1, 0xe7, 0x62, 0xa9, 0x00, 0x5a, 0x61, 0x2e, 0xfa, 0xfe, 0x16, 0xd8, 0xe0, 0xe7, 0x66,
2566 0x17, 0xda, 0xb8, 0x0c, 0xa6, 0x04, 0x8d, 0xf8, 0x21, 0x68, 0x39
2567};
2568
2569static UCHAR rsaHash[] =
2570{
2571 0x96, 0x1f, 0xa6, 0x49, 0x58, 0x81, 0x8f, 0x76, 0x77, 0x07, 0x07, 0x27, 0x55, 0xd7, 0x01, 0x8d,
2572 0xcd, 0x27, 0x8e, 0x94
2573};
2574
2576{
2577 0xa8, 0x3a, 0x9d, 0xaf, 0x92, 0x94, 0xa4, 0x4d, 0x34, 0xba, 0x41, 0x0c, 0xc1, 0x23, 0x91, 0xc7,
2578 0x91, 0xa8, 0xf8, 0xfc, 0x94, 0x87, 0x4d, 0x05, 0x85, 0x63, 0xe8, 0x7d, 0xea, 0x7f, 0x6b, 0x8d,
2579 0xbb, 0x9a, 0xd4, 0x46, 0xa6, 0xc0, 0xd6, 0xdc, 0x91, 0xba, 0xd3, 0x1a, 0xbf, 0xf4, 0x52, 0xa0,
2580 0xc7, 0x15, 0x87, 0xe9, 0x1e, 0x60, 0x49, 0x9c, 0xee, 0x5a, 0x9c, 0x6c, 0xbd, 0x7a, 0x3e, 0xc3,
2581 0x48, 0xb3, 0xee, 0xca, 0x68, 0x40, 0x9b, 0xa1, 0x4c, 0x6e, 0x20, 0xd6, 0xca, 0x6c, 0x72, 0xaf,
2582 0x2b, 0x6b, 0x62, 0x7c, 0x78, 0x06, 0x94, 0x4c, 0x02, 0xf3, 0x8d, 0x49, 0xe0, 0x11, 0xc4, 0x9b,
2583 0x62, 0x5b, 0xc2, 0xfd, 0x68, 0xf4, 0x07, 0x15, 0x71, 0x11, 0x4c, 0x35, 0x97, 0x5d, 0xc0, 0xe6,
2584 0x22, 0xc9, 0x8a, 0x7b, 0x96, 0xc9, 0xc3, 0xe4, 0x2b, 0x1e, 0x88, 0x17, 0x4f, 0x98, 0x9b, 0xf3,
2585 0x42, 0x23, 0x0c, 0xa0, 0xfa, 0x19, 0x03, 0x2a, 0xf7, 0x13, 0x2d, 0x27, 0xac, 0x9f, 0xaf, 0x2d,
2586 0xa3, 0xce, 0xf7, 0x63, 0xbb, 0x39, 0x9f, 0x72, 0x80, 0xdd, 0x6c, 0x73, 0x00, 0x85, 0x70, 0xf2,
2587 0xed, 0x50, 0xed, 0xa0, 0x74, 0x42, 0xd7, 0x22, 0x46, 0x24, 0xee, 0x67, 0xdf, 0xb5, 0x45, 0xe8,
2588 0x49, 0xf4, 0x9c, 0xe4, 0x00, 0x83, 0xf2, 0x27, 0x8e, 0xa2, 0xb1, 0xc3, 0xc2, 0x01, 0xd7, 0x59,
2589 0x2e, 0x4d, 0xac, 0x49, 0xa2, 0xc1, 0x8d, 0x88, 0x4b, 0xfe, 0x28, 0xe5, 0xac, 0xa6, 0x85, 0xc4,
2590 0x1f, 0xf8, 0xc5, 0xc5, 0x14, 0x4e, 0xa3, 0xcb, 0x17, 0xb7, 0x64, 0xb3, 0xc2, 0x12, 0xf8, 0xf8,
2591 0x36, 0x99, 0x1c, 0x91, 0x9b, 0xbd, 0xed, 0x55, 0x0f, 0xfd, 0x49, 0x85, 0xbb, 0x32, 0xad, 0x78,
2592 0xc1, 0x74, 0xe6, 0x7c, 0x18, 0x0f, 0x2b, 0x3b, 0xaa, 0xd1, 0x9d, 0x40, 0x71, 0x1d, 0x19, 0x53
2593};
2594
2596{
2597 0x52, 0x53, 0x41, 0x32, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
2598 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xa6, 0x8b, 0x46, 0x26, 0xb5,
2599 0xa9, 0x69, 0x83, 0x94, 0x66, 0xa7, 0xf3, 0x33, 0x95, 0x74, 0xe9, 0xeb, 0xc8, 0xcd, 0xd7, 0x81,
2600 0x9e, 0x45, 0x66, 0xb2, 0x48, 0x8b, 0x1f, 0xfe, 0xb3, 0x62, 0xc4, 0x0d, 0xa2, 0xf9, 0xf3, 0xe2,
2601 0xa6, 0x86, 0xd1, 0x1e, 0x8a, 0xbb, 0x1d, 0xa5, 0xc5, 0xe8, 0xa7, 0x50, 0x37, 0xfd, 0x69, 0x1f,
2602 0x6f, 0x99, 0x99, 0xca, 0x39, 0x13, 0xea, 0x5b, 0x6b, 0xe3, 0x91, 0xc0, 0xd2, 0x2c, 0x0b, 0x21,
2603 0xb1, 0xac, 0xa9, 0xe8, 0xa0, 0x6d, 0xa4, 0x1f, 0x1b, 0x34, 0xcb, 0x88, 0x7f, 0x2e, 0xeb, 0x7d,
2604 0x91, 0x38, 0x48, 0xce, 0x05, 0x73, 0x05, 0xdd, 0x22, 0x94, 0xc3, 0xdd, 0x1c, 0xfd, 0xc5, 0x41,
2605 0x2e, 0x94, 0xf9, 0xed, 0xe5, 0x92, 0x5f, 0x3f, 0x06, 0xf8, 0x49, 0x60, 0xb8, 0x92, 0x52, 0x6a,
2606 0x56, 0x6e, 0xd7, 0x04, 0x1a, 0xb5, 0xb5, 0x1c, 0x31, 0xd1, 0x1b,
2607};
2608
2610{
2611 0x52, 0x53, 0x41, 0x33, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
2612 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xa6, 0x8b, 0x46, 0x26, 0xb5,
2613 0xa9, 0x69, 0x83, 0x94, 0x66, 0xa7, 0xf3, 0x33, 0x95, 0x74, 0xe9, 0xeb, 0xc8, 0xcd, 0xd7, 0x81,
2614 0x9e, 0x45, 0x66, 0xb2, 0x48, 0x8b, 0x1f, 0xfe, 0xb3, 0x62, 0xc4, 0x0d, 0xa2, 0xf9, 0xf3, 0xe2,
2615 0xa6, 0x86, 0xd1, 0x1e, 0x8a, 0xbb, 0x1d, 0xa5, 0xc5, 0xe8, 0xa7, 0x50, 0x37, 0xfd, 0x69, 0x1f,
2616 0x6f, 0x99, 0x99, 0xca, 0x39, 0x13, 0xea, 0x5b, 0x6b, 0xe3, 0x91, 0xc0, 0xd2, 0x2c, 0x0b, 0x21,
2617 0xb1, 0xac, 0xa9, 0xe8, 0xa0, 0x6d, 0xa4, 0x1f, 0x1b, 0x34, 0xcb, 0x88, 0x7f, 0x2e, 0xeb, 0x7d,
2618 0x91, 0x38, 0x48, 0xce, 0x05, 0x73, 0x05, 0xdd, 0x22, 0x94, 0xc3, 0xdd, 0x1c, 0xfd, 0xc5, 0x41,
2619 0x2e, 0x94, 0xf9, 0xed, 0xe5, 0x92, 0x5f, 0x3f, 0x06, 0xf8, 0x49, 0x60, 0xb8, 0x92, 0x52, 0x6a,
2620 0x56, 0x6e, 0xd7, 0x04, 0x1a, 0xb5, 0xb5, 0x1c, 0x31, 0xd1, 0x1b, 0xa3, 0xf3, 0xd1, 0x69, 0x61,
2621 0xab, 0xfe, 0xc1, 0xb6, 0x40, 0x7b, 0x19, 0xbb, 0x2d, 0x59, 0xf5, 0xda, 0x49, 0x32, 0x6f, 0x20,
2622 0x24, 0xd3, 0xb3, 0xec, 0x21, 0xec, 0x0c, 0xc7, 0x5b, 0xf9, 0x1b, 0xba, 0x6e, 0xe9, 0x61, 0xda,
2623 0x55, 0xc6, 0x72, 0xfd, 0x2d, 0x66, 0x3f, 0x3c, 0xcb, 0x49, 0xa9, 0xc5, 0x0d, 0x9b, 0x02, 0x36,
2624 0x7a, 0xee, 0x36, 0x09, 0x55, 0xe4, 0x03, 0xf2, 0xe3, 0xe6, 0x25, 0x14, 0x89, 0x7f, 0x2b, 0xfb,
2625 0x27, 0x0e, 0x8d, 0x37, 0x84, 0xfd, 0xad, 0x10, 0x79, 0x43, 0x4e, 0x38, 0x4a, 0xd4, 0x5e, 0xfa,
2626 0xda, 0x9f, 0x88, 0x21, 0x7c, 0xb4, 0x98, 0xb6, 0x6e, 0x1c, 0x24, 0x09, 0xe5, 0xe7, 0x22, 0x6f,
2627 0xd3, 0x84, 0xc0, 0xdc, 0x36, 0x09, 0xaf, 0x4b, 0x96, 0x8b, 0x5f, 0x47, 0xb3, 0x24, 0x80, 0xb5,
2628 0x64, 0x69, 0xad, 0x83, 0xd5, 0x09, 0xe7, 0xb9, 0xe4, 0x81, 0x6f, 0x1a, 0xe2, 0x6d, 0xf1, 0x5e,
2629 0x2b, 0xb3, 0x7a, 0xd0, 0x77, 0xef, 0x82, 0xcd, 0x55, 0x2e, 0xd5, 0xb1, 0xa7, 0x72, 0xec, 0x02,
2630 0x9d, 0xe2, 0xcc, 0x5a, 0xf1, 0x68, 0x30, 0xe5, 0xbc, 0x8d, 0xad,
2631};
2632
2633static struct
2634{
2637 BYTE modulus[512 / 8];
2638 BYTE prime1[512 / 16];
2639 BYTE prime2[512 / 16];
2640 BYTE exp1[512 / 16];
2641 BYTE exp2[512 / 16];
2644
2646{
2648 { BCRYPT_RSAPRIVATE_MAGIC, 512, 0x10001 },
2649 {
2650 0x91, 0xe3, 0x6b, 0x5b, 0xea, 0x13, 0x39, 0xca, 0x99, 0x99, 0x6f, 0x1f, 0x69, 0xfd, 0x37, 0x50,
2651 0xa7, 0xe8, 0xc5, 0xa5, 0x1d, 0xbb, 0x8a, 0x1e, 0xd1, 0x86, 0xa6, 0xe2, 0xf3, 0xf9, 0xa2, 0x0d,
2652 0xc4, 0x62, 0xb3, 0xfe, 0x1f, 0x8b, 0x48, 0xb2, 0x66, 0x45, 0x9e, 0x81, 0xd7, 0xcd, 0xc8, 0xeb,
2653 0xe9, 0x74, 0x95, 0x33, 0xf3, 0xa7, 0x66, 0x94, 0x83, 0x69, 0xa9, 0xb5, 0x26, 0x46, 0x8b, 0xa6
2654 },
2655 {
2656 0xc3, 0x94, 0x22, 0xdd, 0x05, 0x73, 0x05, 0xce, 0x48, 0x38, 0x91, 0x7d, 0xeb, 0x2e, 0x7f, 0x88,
2657 0xcb, 0x34, 0x1b, 0x1f, 0xa4, 0x6d, 0xa0, 0xe8, 0xa9, 0xac, 0xb1, 0x21, 0x0b, 0x2c, 0xd2, 0xc0
2658 },
2659 {
2660 0x1b, 0xd1, 0x31, 0x1c, 0xb5, 0xb5, 0x1a, 0x04, 0xd7, 0x6e, 0x56, 0x6a, 0x52, 0x92, 0xb8, 0x60,
2661 0x49, 0xf8, 0x06, 0x3f, 0x5f, 0x92, 0xe5, 0xed, 0xf9, 0x94, 0x2e, 0x41, 0xc5, 0xfd, 0x1c, 0xdd
2662 },
2663 {
2664 0x1b, 0xf9, 0x5b, 0xc7, 0x0c, 0xec, 0x21, 0xec, 0xb3, 0xd3, 0x24, 0x20, 0x6f, 0x32, 0x49, 0xda,
2665 0xf5, 0x59, 0x2d, 0xbb, 0x19, 0x7b, 0x40, 0xb6, 0xc1, 0xfe, 0xab, 0x61, 0x69, 0xd1, 0xf3, 0xa3
2666 },
2667 {
2668 0x25, 0xe6, 0xe3, 0xf2, 0x03, 0xe4, 0x55, 0x09, 0x36, 0xee, 0x7a, 0x36, 0x02, 0x9b, 0x0d, 0xc5,
2669 0xa9, 0x49, 0xcb, 0x3c, 0x3f, 0x66, 0x2d, 0xfd, 0x72, 0xc6, 0x55, 0xda, 0x61, 0xe9, 0x6e, 0xba
2670 },
2671 {
2672 0x24, 0x1c, 0x6e, 0xb6, 0x98, 0xb4, 0x7c, 0x21, 0x88, 0x9f, 0xda, 0xfa, 0x5e, 0xd4, 0x4a, 0x38,
2673 0x4e, 0x43, 0x79, 0x10, 0xad, 0xfd, 0x84, 0x37, 0x8d, 0x0e, 0x27, 0xfb, 0x2b, 0x7f, 0x89, 0x14
2674 },
2675 {
2676 0xad, 0x8d, 0xbc, 0xe5, 0x30, 0x68, 0xf1, 0x5a, 0xcc, 0xe2, 0x9d, 0x02, 0xec, 0x72, 0xa7, 0xb1,
2677 0xd5, 0x2e, 0x55, 0xcd, 0x82, 0xef, 0x77, 0xd0, 0x7a, 0xb3, 0x2b, 0x5e, 0xf1, 0x6d, 0xe2, 0x1a,
2678 0x6f, 0x81, 0xe4, 0xb9, 0xe7, 0x09, 0xd5, 0x83, 0xad, 0x69, 0x64, 0xb5, 0x80, 0x24, 0xb3, 0x47,
2679 0x5f, 0x8b, 0x96, 0x4b, 0xaf, 0x09, 0x36, 0xdc, 0xc0, 0x84, 0xd3, 0x6f, 0x22, 0xe7, 0xe5, 0x09
2680 }
2682
2683
2685{
2686 0x52, 0x53, 0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
2687 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2688 0x01, 0x00, 0x01, 0xc7, 0x8f, 0xac, 0x2a, 0xce, 0xbf, 0xc9, 0x6c, 0x7b,
2689 0x85, 0x74, 0x71, 0xbb, 0xff, 0xbb, 0x9b, 0x20, 0x03, 0x79, 0x17, 0x34,
2690 0xe7, 0x26, 0x91, 0x5c, 0x1f, 0x1b, 0x03, 0x3d, 0x46, 0xdf, 0xb6, 0xf2,
2691 0x10, 0x55, 0xf0, 0x39, 0x55, 0x0a, 0xe3, 0x9c, 0x0c, 0x63, 0xc2, 0x14,
2692 0x03, 0x94, 0x51, 0x0d, 0xb4, 0x22, 0x09, 0xf2, 0x5c, 0xb2, 0xd1, 0xc3,
2693 0xac, 0x6f, 0xa8, 0xc4, 0xac, 0xb8, 0xbc, 0x59, 0xe7, 0xed, 0x77, 0x6e,
2694 0xb1, 0x80, 0x58, 0x7d, 0xb2, 0x94, 0x46, 0xe5, 0x00, 0xe2, 0xb7, 0x33,
2695 0x48, 0x7a, 0xd3, 0x78, 0xe9, 0x26, 0x01, 0xc7, 0x00, 0x7b, 0x41, 0x6d,
2696 0x94, 0x3a, 0xe1, 0x50, 0x2b, 0x9f, 0x6b, 0x1c, 0x08, 0xa3, 0xfc, 0x0a,
2697 0x44, 0x81, 0x09, 0x41, 0x80, 0x23, 0x7b, 0xf6, 0x3f, 0xaf, 0x91, 0xa1,
2698 0x87, 0x75, 0x33, 0x15, 0xb8, 0xde, 0x32, 0x30, 0xb4, 0x5e, 0xfd
2699};
2700
2702{
2703 0x4a, 0xc1, 0xfa, 0x4f, 0xe0, 0x3f, 0x36, 0x9a, 0x64, 0xbf, 0x2e, 0x00, 0xb4, 0xb5, 0x40, 0xbe,
2704 0x2d, 0x9a, 0x14, 0xf6, 0x8f, 0xa5, 0xc2, 0xe2, 0x20, 0xaf, 0x21, 0x79, 0xc6, 0x32, 0x7e, 0xea,
2705 0x73, 0x00, 0x01, 0xbb, 0x9a, 0x19, 0x73, 0x41, 0x96, 0xae, 0x88, 0x6e, 0x36, 0x56, 0xe9, 0x9c,
2706 0xac, 0x04, 0x82, 0xa8, 0x00, 0xdb, 0x4e, 0x29, 0x61, 0x7e, 0xaf, 0x64, 0xdb, 0xa2, 0x70, 0x0f,
2707};
2708
2709static void test_rsa_encrypt(void)
2710{
2711 UCHAR input[] = "Hello World!", input_no_padding[64] = { 0 }, encrypted[64], decrypted[64];
2714 NTSTATUS ret;
2715 DWORD encrypted_size, decrypted_size;
2716 UCHAR *encrypted_a = NULL, *encrypted_b = NULL;
2717 BCRYPT_OAEP_PADDING_INFO oaep_pad;
2718
2720 oaep_pad.pbLabel = (UCHAR *)"test";
2721 oaep_pad.cbLabel = 5;
2722
2724 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2725 ret = BCryptGenerateKeyPair(rsa, &key, 512, 0);
2726 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2727
2728 /* Not finalized key */
2729 ret = BCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, NULL, 0, &encrypted_size, 0);
2730 ok(ret == STATUS_INVALID_HANDLE, "got %lx\n", ret);
2732
2733 /* Import a different public key first to make sure a public key from private key improted next
2734 * overrides it. */
2736 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2737
2739 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2740
2741 /* No padding */
2742 memset(input_no_padding, 0, sizeof(input_no_padding));
2743
2744 encrypted_size = 0;
2745 ret = BCryptEncrypt(key, input_no_padding, sizeof(input_no_padding), NULL, NULL, 0, NULL, 0, &encrypted_size, BCRYPT_PAD_NONE);
2746 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2747 ok(encrypted_size == 64, "got size of %ld\n", encrypted_size);
2748
2749 strcpy((char *)input_no_padding, "Hello World");
2750 encrypted_size = 0;
2751 ret = BCryptEncrypt(key, input_no_padding, sizeof(input_no_padding), NULL, NULL, 0, NULL, 0, &encrypted_size, BCRYPT_PAD_NONE);
2752 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2753 ok(encrypted_size == 64, "got size of %ld\n", encrypted_size);
2754
2755 encrypted_a = malloc(encrypted_size);
2756 memset(encrypted_a, 0, encrypted_size);
2757 encrypted_b = malloc(encrypted_size);
2758 memset(encrypted_b, 0xff, encrypted_size);
2759
2760 ret = BCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, encrypted_a, encrypted_size, &encrypted_size, BCRYPT_PAD_NONE);
2761 ok(ret == STATUS_INVALID_PARAMETER, "got %lx\n", ret);
2762
2763 ret = BCryptEncrypt(key, input_no_padding, sizeof(input_no_padding), NULL, NULL, 0, encrypted_a, 12, &encrypted_size, BCRYPT_PAD_NONE);
2764 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %lx\n", ret);
2765 ok(encrypted_size == 64, "got size of %ld\n", encrypted_size);
2766
2767 ret = BCryptEncrypt(key, input_no_padding, sizeof(input_no_padding), NULL, NULL, 0, encrypted_a, encrypted_size, &encrypted_size, BCRYPT_PAD_NONE);
2768 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2769 ok(encrypted_size == 64, "got size of %ld\n", encrypted_size);
2770
2771 ret = BCryptEncrypt(key, input_no_padding, sizeof(input_no_padding), NULL, NULL, 0, encrypted_b, encrypted_size, &encrypted_size, BCRYPT_PAD_NONE);
2772 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2773 ok(!memcmp(encrypted_a, encrypted_b, encrypted_size), "Both outputs should be the same\n");
2774 ok(!memcmp(encrypted_b, rsa_encrypted_no_padding, encrypted_size), "Data mismatch.\n");
2775
2776 decrypted_size = 0;
2777 ret = BCryptDecrypt(key, encrypted_a, encrypted_size, NULL, NULL, 0, NULL, 0, &decrypted_size, BCRYPT_PAD_NONE);
2778 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2779 ok(decrypted_size == sizeof(input_no_padding), "got %lu\n", decrypted_size);
2780
2781 ret = BCryptDecrypt(key, encrypted_a, encrypted_size, NULL, NULL, 0, decrypted, decrypted_size, &decrypted_size, BCRYPT_PAD_NONE);
2782 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2783 ok(decrypted_size == sizeof(input_no_padding), "got %lu\n", decrypted_size);
2784 ok(!memcmp(decrypted, input_no_padding, sizeof(input_no_padding)), "unexpected output\n");
2785
2786 /* PKCS1 Padding */
2787 encrypted_size = 0;
2788 ret = BCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, NULL, 0, &encrypted_size, BCRYPT_PAD_PKCS1);
2789 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2790 ok(encrypted_size == 64, "got size of %ld\n", encrypted_size);
2791
2792 encrypted_a = realloc(encrypted_a, encrypted_size);
2793 memset(encrypted_a, 0, encrypted_size);
2794 encrypted_b = realloc(encrypted_b, encrypted_size);
2795 memset(encrypted_b, 0, encrypted_size);
2796
2797 ret = BCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, encrypted_a, encrypted_size, &encrypted_size, BCRYPT_PAD_PKCS1);
2798 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2799 ok(encrypted_size == 64, "got size of %ld\n", encrypted_size);
2800
2801 ret = BCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, encrypted_b, encrypted_size, &encrypted_size, BCRYPT_PAD_PKCS1);
2802 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2803 ok(encrypted_size == 64, "got size of %ld\n", encrypted_size);
2804 ok(memcmp(encrypted_a, encrypted_b, encrypted_size), "Both outputs are the same\n");
2805
2806 decrypted_size = 0;
2807 ret = BCryptDecrypt(key, encrypted_a, encrypted_size, NULL, NULL, 0, NULL, 0, &decrypted_size, BCRYPT_PAD_PKCS1);
2808 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2809 ok(decrypted_size == sizeof(input), "got size of %ld\n", decrypted_size);
2810
2811 ret = BCryptDecrypt(key, encrypted_a, encrypted_size, NULL, NULL, 0, decrypted, decrypted_size, &decrypted_size, BCRYPT_PAD_PKCS1);
2812 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2813 ok(decrypted_size == sizeof(input), "got size of %ld\n", decrypted_size);
2814 ok(!memcmp(decrypted, input, sizeof(input)), "unexpected output\n");
2815
2817 sizeof(rsaLegacyPrivateBlob), 0);
2818 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2819
2820 ret = BCryptEncrypt(key2, input, sizeof(input), NULL, NULL, 0, encrypted, sizeof(encrypted),
2821 &encrypted_size, BCRYPT_PAD_PKCS1);
2822 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2823 ok(encrypted_size == 64, "got size of %ld\n", encrypted_size);
2824
2825 memset(decrypted, 0, sizeof(decrypted));
2826 ret = BCryptDecrypt(key, encrypted, sizeof(encrypted), NULL, NULL, 0, decrypted, sizeof(decrypted),
2827 &decrypted_size, BCRYPT_PAD_PKCS1);
2828 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2829 ok(decrypted_size == sizeof(input), "got size of %ld\n", decrypted_size);
2830 ok(!memcmp(decrypted, input, sizeof(input)), "unexpected output\n");
2833
2834 /* OAEP Padding */
2835 ret = BCryptGenerateKeyPair(rsa, &key, 640 /* minimum size for sha256 hash */, 0);
2836 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2837
2839 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
2840
2841 encrypted_size = 0;
2842 ret = BCryptEncrypt(key, input, sizeof(input), &oaep_pad, NULL, 0, NULL, 0, &encrypted_size, BCRYPT_PAD_OAEP);
2843 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2844 ok(encrypted_size == 80, "got size of %ld\n", encrypted_size);
2845
2846 encrypted_size = 0;
2847 ret = BCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, NULL, 0, &encrypted_size, BCRYPT_PAD_OAEP);
2848 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2849 ok(encrypted_size == 80, "got size of %ld\n", encrypted_size);
2850
2851 encrypted_a = realloc(encrypted_a, encrypted_size);
2852 memset(encrypted_a, 0, encrypted_size);
2853 encrypted_b = realloc(encrypted_b, encrypted_size);
2854 memset(encrypted_b, 0, encrypted_size);
2855
2856 encrypted_size = 0;
2857 ret = BCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, encrypted_a, 0, &encrypted_size, BCRYPT_PAD_OAEP);
2858 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %lx\n", ret);
2859 ok(encrypted_size == 80, "got size of %ld\n", encrypted_size);
2860
2861 ret = BCryptEncrypt(key, input, sizeof(input), &oaep_pad, NULL, 0, encrypted_a, encrypted_size, &encrypted_size, BCRYPT_PAD_OAEP);
2862 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2863 ok(encrypted_size == 80, "got size of %ld\n", encrypted_size);
2864
2865 ret = BCryptEncrypt(key, input, sizeof(input), &oaep_pad, NULL, 0, encrypted_b, encrypted_size, &encrypted_size, BCRYPT_PAD_OAEP);
2866 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2867 ok(encrypted_size == 80, "got size of %ld\n", encrypted_size);
2868 ok(memcmp(encrypted_a, encrypted_b, encrypted_size), "Both outputs are the same\n");
2869
2870 decrypted_size = 0;
2871 memset(decrypted, 0, sizeof(decrypted));
2872 ret = BCryptDecrypt(key, encrypted_a, encrypted_size, NULL, NULL, 0, NULL, 0, &decrypted_size, BCRYPT_PAD_OAEP);
2873 ok(ret == STATUS_INVALID_PARAMETER, "got %lx\n", ret);
2874
2875 decrypted_size = 0;
2876 memset(decrypted, 0, sizeof(decrypted));
2877 ret = BCryptDecrypt(key, encrypted_a, encrypted_size, &oaep_pad, NULL, 0, NULL, 0, &decrypted_size, BCRYPT_PAD_OAEP);
2878 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2879 ok(decrypted_size == sizeof(input), "got %lu\n", decrypted_size);
2880
2881 ret = BCryptDecrypt(key, encrypted_a, encrypted_size, &oaep_pad, NULL, 0, decrypted, decrypted_size, &decrypted_size, BCRYPT_PAD_OAEP);
2882 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2883 ok(decrypted_size == sizeof(input), "got %lu\n", decrypted_size);
2884 ok(!memcmp(decrypted, input, sizeof(input)), "unexpected output\n");
2885
2886 /* Prove empty label (pbLabel NULL, cbLabel 0) works for OAEP. */
2887 {
2888 BCRYPT_OAEP_PADDING_INFO sha1_empty_label;
2889 UCHAR roundtrip_plain[sizeof(input)];
2890 DWORD roundtrip_size;
2891
2892 sha1_empty_label.pszAlgId = BCRYPT_SHA1_ALGORITHM;
2893 sha1_empty_label.pbLabel = NULL;
2894 sha1_empty_label.cbLabel = 0;
2895
2896 encrypted_size = 0;
2897 ret = BCryptEncrypt(key, input, sizeof(input), &sha1_empty_label, NULL, 0, NULL, 0, &encrypted_size, BCRYPT_PAD_OAEP);
2898 ok(ret == STATUS_SUCCESS, "encrypt with empty label failed: %lx\n", ret);
2899
2900 encrypted_a = realloc(encrypted_a, encrypted_size);
2901 ret = BCryptEncrypt(key, input, sizeof(input), &sha1_empty_label, NULL, 0, encrypted_a, encrypted_size, &encrypted_size, BCRYPT_PAD_OAEP);
2902 ok(ret == STATUS_SUCCESS, "encrypt with empty label failed: %lx\n", ret);
2903
2904 roundtrip_size = 0;
2905 ret = BCryptDecrypt(key, encrypted_a, encrypted_size, &sha1_empty_label, NULL, 0, NULL, 0, &roundtrip_size, BCRYPT_PAD_OAEP);
2906 ok(ret == STATUS_SUCCESS, "decrypt with empty label failed: %lx\n", ret);
2907 ok(roundtrip_size == sizeof(input), "decrypted size %lu, expected %lu\n", roundtrip_size, (unsigned long)sizeof(input));
2908
2909 ret = BCryptDecrypt(key, encrypted_a, encrypted_size, &sha1_empty_label, NULL, 0, roundtrip_plain, roundtrip_size, &roundtrip_size, BCRYPT_PAD_OAEP);
2910 ok(ret == STATUS_SUCCESS, "decrypt failed: %lx\n", ret);
2911 ok(!memcmp(roundtrip_plain, input, sizeof(input)), "roundtrip plaintext mismatch\n");
2912 }
2913
2914 /* OAEP(NULL) behavior observed on native Windows:
2915 * - size query succeeds
2916 * - actual encryption fails with STATUS_INVALID_PARAMETER */
2917 {
2918 UCHAR *encrypted_null = NULL;
2919 DWORD encrypted_null_size = 0;
2920
2921 ret = BCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, NULL, 0, &encrypted_null_size, BCRYPT_PAD_OAEP);
2922 ok(ret == STATUS_SUCCESS, "unexpected OAEP(NULL) size query status %lx\n", ret);
2923
2924 if (ret == STATUS_SUCCESS)
2925 {
2926 encrypted_null = malloc(encrypted_null_size);
2927 ret = BCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, encrypted_null, encrypted_null_size,
2928 &encrypted_null_size, BCRYPT_PAD_OAEP);
2930 "unexpected OAEP(NULL) encrypt status %lx\n", ret);
2931
2932 free(encrypted_null);
2933 }
2934 }
2935
2936 free(encrypted_a);
2937 free(encrypted_b);
2938
2940
2941 if (pBCryptHash)
2942 {
2944 ok(ret == STATUS_SUCCESS, "got %lx\n", ret);
2946 }
2947}
2948
2949/* legacy RSA key with public exponent 1 */
2951{
2952 0x07, 0x02, 0x00, 0x00, 0x00, 0xa4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x02, 0x00, 0x00,
2953 0x01, 0x00, 0x00, 0x00, 0xab, 0xef, 0xfa, 0xc6, 0x7d, 0xe8, 0xde, 0xfb, 0x68, 0x38, 0x09, 0x92,
2954 0xd9, 0x42, 0x7e, 0x6b, 0x89, 0x9e, 0x21, 0xd7, 0x52, 0x1c, 0x99, 0x3c, 0x17, 0x48, 0x4e, 0x3a,
2955 0x44, 0x02, 0xf2, 0xfa, 0x74, 0x57, 0xda, 0xe4, 0xd3, 0xc0, 0x35, 0x67, 0xfa, 0x6e, 0xdf, 0x78,
2956 0x4c, 0x75, 0x35, 0x1c, 0xa0, 0x74, 0x49, 0xe3, 0x20, 0x13, 0x71, 0x35, 0x65, 0xdf, 0x12, 0x20,
2957 0xf5, 0xf5, 0xf5, 0xc1, 0xed, 0x5c, 0x91, 0x36, 0x75, 0xb0, 0xa9, 0x9c, 0x04, 0xdb, 0x0c, 0x8c,
2958 0xbf, 0x99, 0x75, 0x13, 0x7e, 0x87, 0x80, 0x4b, 0x71, 0x94, 0xb8, 0x00, 0xa0, 0x7d, 0xb7, 0x53,
2959 0xdd, 0x20, 0x63, 0xee, 0xf7, 0x83, 0x41, 0xfe, 0x16, 0xa7, 0x6e, 0xdf, 0x21, 0x7d, 0x76, 0xc0,
2960 0x85, 0xd5, 0x65, 0x7f, 0x00, 0x23, 0x57, 0x45, 0x52, 0x02, 0x9d, 0xea, 0x69, 0xac, 0x1f, 0xfd,
2961 0x3f, 0x8c, 0x4a, 0xd0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2962 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2963 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2964 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2965 0x00, 0x00, 0x00, 0x00, 0x64, 0xd5, 0xaa, 0xb1, 0xa6, 0x03, 0x18, 0x92, 0x03, 0xaa, 0x31, 0x2e,
2966 0x48, 0x4b, 0x65, 0x20, 0x99, 0xcd, 0xc6, 0x0c, 0x15, 0x0c, 0xbf, 0x3e, 0xff, 0x78, 0x95, 0x67,
2967 0xb2, 0x74, 0x5b, 0x60, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2968 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2969 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2970 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2971 0x00, 0x00, 0x00, 0x00,
2972};
2973
2974static void test_RSA(void)
2975{
2976 static UCHAR hash[] =
2977 {0x7e,0xe3,0x74,0xe7,0xc5,0x0b,0x6b,0x70,0xdb,0xab,0x32,0x6d,0x1d,0x51,0xd6,0x74,0x79,0x8e,0x5b,0x4b};
2978 static UCHAR hash48[] =
2979 {0x62,0xb2,0x1e,0x90,0xc9,0x02,0x2b,0x10,0x16,0x71,0xba,0x1f,0x80,0x8f,0x86,0x31,0xa8,0x14,0x9f,0x0f,
2980 0x12,0x90,0x40,0x55,0x83,0x9a,0x35,0xc1,0xca,0x78,0xae,0x53,0x1b,0xb3,0x36,0x06,0xba,0x90,0x89,0x12,
2981 0xa8,0x42,0x21,0x10,0x9d,0x29,0xcd,0x7e};
2986 BCRYPT_RSAKEY_BLOB *rsablob;
2987 UCHAR sig[256], sig_pss[256];
2988 ULONG len, size, size2, schemes;
2989 NTSTATUS ret;
2990 BYTE *buf;
2991 DWORD keylen;
2992
2994 ok(!ret, "got %#lx\n", ret);
2995
2996 schemes = size = 0;
2997 ret = BCryptGetProperty(alg, L"PaddingSchemes", (UCHAR *)&schemes, sizeof(schemes), &size, 0);
2998 ok(!ret, "got %#lx\n", ret);
2999 ok(schemes, "schemes not set\n");
3000 ok(size == sizeof(schemes), "got %lu\n", size);
3001
3003 ok(!ret, "BCryptImportKeyPair failed: %#lx\n", ret);
3005
3007 ok(!ret, "BCryptImportKeyPair failed: %#lx\n", ret);
3008
3009 size = keylen = 0;
3010 ret = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
3011 ok(!ret, "got %#lx\n", ret);
3012 ok(size == sizeof(keylen), "got %lu\n", size);
3013 ok(keylen == 2048, "got %lu\n", keylen);
3014
3015 size = len = 0;
3017 ok(!ret, "got %#lx\n", ret);
3018 ok(size == sizeof(len), "got %lu\n", size);
3019 ok(len == 256, "got %lu\n", len);
3020
3023 ok(!ret, "BCryptVerifySignature failed: %#lx\n", ret);
3024
3026 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %#lx\n", ret);
3027
3029 ret = BCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), 0);
3031
3033 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %#lx\n", ret);
3034
3037 ok(ret == STATUS_NOT_SUPPORTED, "Expected STATUS_NOT_SUPPORTED, got %#lx\n", ret);
3038
3039 pad.pszAlgId = NULL;
3041 ok(ret == STATUS_INVALID_SIGNATURE, "Expected STATUS_INVALID_SIGNATURE, got %#lx\n", ret);
3042
3044 ok(!ret, "BCryptDestroyKey failed: %#lx\n", ret);
3045
3046 /* sign/verify with export/import round-trip */
3047 ret = BCryptGenerateKeyPair(alg, &key, 1024, 0);
3048 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3049
3050 keylen = 2048;
3051 ret = BCryptSetProperty(key, BCRYPT_KEY_LENGTH, (UCHAR *)&keylen, 2, 0);
3052 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
3053 ret = BCryptSetProperty(key, BCRYPT_KEY_LENGTH, (UCHAR *)&keylen, sizeof(keylen), 0);
3054 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3055
3057 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3058
3059 keylen = 0;
3060 ret = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
3061 ok(!ret, "got %#lx\n", ret);
3062 ok(size == sizeof(keylen), "got %lu\n", size);
3063 ok(keylen == 2048, "got %lu\n", keylen);
3064
3065 ret = BCryptSetProperty(key, BCRYPT_KEY_LENGTH, (UCHAR *)&keylen, sizeof(keylen), 0);
3066 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3067
3069 memset(sig, 0, sizeof(sig));
3070 len = 0;
3071 ret = BCryptSignHash(key, &pad, hash, 16, sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
3072 ok(!ret, "got %#lx\n", ret);
3073 ok(len == 256, "got %lu\n", len);
3076 ok(!ret, "BCryptVerifySignature failed: %#lx\n", ret);
3077
3079 memset(sig, 0, sizeof(sig));
3080 len = 0;
3081 ret = BCryptSignHash(key, &pad, hash, sizeof(hash), sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
3082 ok(!ret, "got %#lx\n", ret);
3083 ok(len == 256, "got %lu\n", len);
3085 ret = BCryptVerifySignature(key, &pad, hash, sizeof(hash), sig, len, BCRYPT_PAD_PKCS1);
3086 ok(!ret, "BCryptVerifySignature failed: %#lx\n", ret);
3087
3088 pad.pszAlgId = NULL;
3089 memset(sig, 0, sizeof(sig));
3090 len = 0;
3091 ret = BCryptSignHash(key, &pad, hash, sizeof(hash), sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
3092 ok(!ret, "got %#lx\n", ret);
3093 ok(len == 256, "got %lu\n", len);
3094
3096 ret = BCryptVerifySignature(key, &pad, hash, sizeof(hash), sig, len, BCRYPT_PAD_PKCS1);
3097 ok(ret == STATUS_INVALID_SIGNATURE, "BCryptVerifySignature failed: %#lx, len %ld\n", ret, len);
3098
3099 pad.pszAlgId = NULL;
3100 ret = BCryptVerifySignature(key, &pad, hash, sizeof(hash), sig, len, BCRYPT_PAD_PKCS1);
3101 ok(!ret, "BCryptVerifySignature failed: %#lx, len %ld\n", ret, len);
3102
3104 pad_pss.cbSalt = 48;
3105 memset(sig_pss, 0, sizeof(sig_pss));
3106 len = 0;
3107 ret = BCryptSignHash(key, &pad_pss, hash48, sizeof(hash48), sig_pss, sizeof(sig_pss), &len, BCRYPT_PAD_PSS);
3108 ok(!ret, "got %#lx\n", ret);
3109 ok(len == 256, "got %lu\n", len);
3110
3111 /* export private key */
3112 size = 0;
3114 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3115 ok(size, "size not set\n");
3116
3117 buf = malloc(size);
3119 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3120 rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
3121 ok(rsablob->Magic == BCRYPT_RSAPRIVATE_MAGIC, "got %#lx\n", rsablob->Magic);
3122 ok(rsablob->BitLength == 2048, "got %lu\n", rsablob->BitLength);
3123 ok(rsablob->cbPublicExp == 3, "got %lu\n", rsablob->cbPublicExp);
3124 ok(rsablob->cbModulus == 256, "got %lu\n", rsablob->cbModulus);
3125 ok(rsablob->cbPrime1 == 128, "got %lu\n", rsablob->cbPrime1);
3126 ok(rsablob->cbPrime2 == 128, "got %lu\n", rsablob->cbPrime2);
3127 size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus + rsablob->cbPrime1 + rsablob->cbPrime2;
3128 ok(size == size2, "got %lu expected %lu\n", size2, size);
3129 free(buf);
3130
3131 size = 0;
3133 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3134 ok(size, "size not set\n");
3135
3136 buf = malloc(size);
3138 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3139 rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
3140 ok(rsablob->Magic == BCRYPT_RSAFULLPRIVATE_MAGIC, "got %#lx\n", rsablob->Magic);
3141 ok(rsablob->BitLength == 2048, "got %lu\n", rsablob->BitLength);
3142 ok(rsablob->cbPublicExp == 3, "got %lu\n", rsablob->cbPublicExp);
3143 ok(rsablob->cbModulus == 256, "got %lu\n", rsablob->cbModulus);
3144 ok(rsablob->cbPrime1 == 128, "got %lu\n", rsablob->cbPrime1);
3145 ok(rsablob->cbPrime2 == 128, "got %lu\n", rsablob->cbPrime2);
3146 size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus * 2 + rsablob->cbPrime1 * 3 + rsablob->cbPrime2 * 2;
3147 ok(size == size2, "got %lu expected %lu\n", size2, size);
3148 free(buf);
3149
3150 /* import/export public key */
3151 size = 0;
3153 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3154 ok(size, "size not set\n");
3155
3156 buf = malloc(size);
3158 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3159 rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
3160 ok(rsablob->Magic == BCRYPT_RSAPUBLIC_MAGIC, "got %#lx\n", rsablob->Magic);
3161 ok(rsablob->BitLength == 2048, "got %lu\n", rsablob->BitLength);
3162 ok(rsablob->cbPublicExp == 3, "got %lu\n", rsablob->cbPublicExp);
3163 ok(rsablob->cbModulus == 256, "got %lu\n", rsablob->cbModulus);
3164 ok(!rsablob->cbPrime1, "got %lu\n", rsablob->cbPrime1);
3165 ok(!rsablob->cbPrime2, "got %lu\n", rsablob->cbPrime2);
3166 ok(size == sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus, "got %lu\n", size);
3168 ok(!ret, "got %#lx\n", ret);
3169
3172 ok(ret == NTE_BAD_DATA, "got %#lx\n", ret);
3173
3175 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3176 free(buf);
3177
3178 ret = BCryptVerifySignature(key, &pad, hash, sizeof(hash), sig, sizeof(sig), BCRYPT_PAD_PKCS1);
3179 ok(!ret, "got %#lx\n", ret);
3180 ret = BCryptVerifySignature(key, &pad_pss, hash48, sizeof(hash48), sig_pss, sizeof(sig_pss), BCRYPT_PAD_PSS);
3181 ok(!ret, "got %#lx\n", ret);
3183 ok(!ret, "got %#lx\n", ret);
3184
3185 /* import/export private key */
3187 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3188
3190 ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
3191
3192 size = 0;
3193 buf = malloc(sizeof(rsaPrivateBlob));
3195 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3196 ok(size == sizeof(rsaPrivateBlob), "got %lu\n", size);
3197 ok(!memcmp(buf, rsaPrivateBlob, size), "wrong data\n");
3198 free(buf);
3200
3201 /* import/export full private key */
3203 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3204
3205 size = 0;
3206 buf = malloc(sizeof(rsaFullPrivateBlob));
3208 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3209 ok(size == sizeof(rsaFullPrivateBlob), "got %lu\n", size);
3210 ok(!memcmp(buf, rsaFullPrivateBlob, size), "wrong data\n");
3211 free(buf);
3213
3215 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
3216
3218 ok(!ret, "got %#lx\n", ret);
3219}
3220
3221static void test_RSA_SIGN(void)
3222{
3226 BCRYPT_RSAKEY_BLOB *rsablob;
3227 NTSTATUS ret;
3228 ULONG size, size2, len;
3229 BYTE *buf, buf2[sizeof(BCRYPT_RSAKEY_BLOB) + sizeof(rsaPublicBlob)];
3230
3232 ok(!ret, "got %#lx\n", ret);
3233
3235 ok(!ret, "BCryptImportKeyPair failed: %#lx\n", ret);
3236
3237 memset(buf2, 0xcc, sizeof(buf2));
3238 ret = BCryptExportKey(key, NULL, BCRYPT_RSAPUBLIC_BLOB, buf2, sizeof(buf2), &size, 0);
3239 ok(!ret, "got %#lx\n", ret);
3240 rsablob = (BCRYPT_RSAKEY_BLOB *)buf2;
3241 ok(rsablob->Magic == BCRYPT_RSAPUBLIC_MAGIC, "got %#lx\n", rsablob->Magic);
3242 ok(rsablob->BitLength == 2048, "got %lu\n", rsablob->BitLength);
3243 ok(rsablob->cbPublicExp == 3, "got %lu\n", rsablob->cbPublicExp);
3244 ok(rsablob->cbModulus == 256, "got %lu\n", rsablob->cbModulus);
3245 ok(rsablob->cbPrime1 == 0, "got %lu\n", rsablob->cbPrime1);
3246 ok(rsablob->cbPrime2 == 0, "got %lu\n", rsablob->cbPrime2);
3247 size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus + rsablob->cbPrime1 + rsablob->cbPrime2;
3248 ok(size == size2, "got %lu expected %lu\n", size2, size);
3249
3250 ret = BCryptExportKey(key, NULL, BCRYPT_RSAPRIVATE_BLOB, buf2, sizeof(buf2), &size, 0);
3251 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
3252
3253 pad.pszAlgId = NULL;
3255 ok(ret == STATUS_INVALID_SIGNATURE, "BCryptVerifySignature failed: %#lx\n", ret);
3256
3259 ok(!ret, "BCryptVerifySignature failed: %#lx\n", ret);
3260
3262 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %#lx\n", ret);
3263
3265 ret = BCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), 0);
3267
3269 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got %#lx\n", ret);
3270
3273 ok(ret == STATUS_NOT_SUPPORTED, "Expected STATUS_NOT_SUPPORTED, got %#lx\n", ret);
3274
3275 pad.pszAlgId = NULL;
3277 ok(ret == STATUS_INVALID_SIGNATURE, "Expected STATUS_INVALID_SIGNATURE, got %#lx\n", ret);
3278
3280 ok(!ret, "BCryptDestroyKey failed: %#lx\n", ret);
3281
3282 /* export private key */
3283 ret = BCryptGenerateKeyPair(alg, &key, 512, 0);
3284 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3285
3287 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3288
3289 size = len = 0;
3291 ok(!ret, "got %#lx\n", ret);
3292 ok(size == sizeof(len), "got %lu\n", size);
3293 ok(len == 64, "got %lu\n", len);
3294
3295 size = 0;
3297 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3298 ok(size, "size not set\n");
3299
3300 buf = malloc(size);
3302 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3303 rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
3304 ok(rsablob->Magic == BCRYPT_RSAPRIVATE_MAGIC, "got %#lx\n", rsablob->Magic);
3305 ok(rsablob->BitLength == 512, "got %lu\n", rsablob->BitLength);
3306 ok(rsablob->cbPublicExp == 3, "got %lu\n", rsablob->cbPublicExp);
3307 ok(rsablob->cbModulus == 64, "got %lu\n", rsablob->cbModulus);
3308 ok(rsablob->cbPrime1 == 32, "got %lu\n", rsablob->cbPrime1);
3309 ok(rsablob->cbPrime2 == 32, "got %lu\n", rsablob->cbPrime2);
3310 size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus + rsablob->cbPrime1 + rsablob->cbPrime2;
3311 ok(size == size2, "got %lu expected %lu\n", size2, size);
3312 free(buf);
3313
3314 size = 0;
3316 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3317 ok(size, "size not set\n");
3318
3319 buf = malloc(size);
3321 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
3322 rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
3323 ok(rsablob->Magic == BCRYPT_RSAFULLPRIVATE_MAGIC, "got %#lx\n", rsablob->Magic);
3324 ok(rsablob->BitLength == 512, "got %lu\n", rsablob->BitLength);
3325 ok(rsablob->cbPublicExp == 3, "got %lu\n", rsablob->cbPublicExp);
3326 ok(rsablob->cbModulus == 64, "got %lu\n", rsablob->cbModulus);
3327 ok(rsablob->cbPrime1 == 32, "got %lu\n", rsablob->cbPrime1);
3328 ok(rsablob->cbPrime2 == 32, "got %lu\n", rsablob->cbPrime2);
3329 size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus * 2 + rsablob->cbPrime1 * 3 + rsablob->cbPrime2 * 2;
3330 ok(size == size2, "got %lu expected %lu\n", size2, size);
3331 free(buf);
3333
3335 ok(!ret, "BCryptCloseAlgorithmProvider failed: %#lx\n", ret);
3336}
3337
3339{
3340 const WCHAR *alg;
3352};
3353
3354static const UCHAR hash_prepend[][2] = {{0xca, 0xfe}, {0xf0, 0x0d}};
3355
3356static void test_ECDH_alg(const struct ecdh_test *t)
3357{
3358 BCryptBuffer hash_param_buffers[] =
3359 {
3360 {
3361 sizeof(BCRYPT_SHA1_ALGORITHM),
3363 (void *)BCRYPT_SHA1_ALGORITHM,
3364 }
3365 };
3366 BCryptBuffer hash_param_buffers_prepended[] =
3367 {
3368 {
3369 sizeof(BCRYPT_SHA1_ALGORITHM),
3371 (void *)BCRYPT_SHA1_ALGORITHM,
3372 },
3373 {
3374 sizeof(hash_prepend[0]),
3376 (void *)hash_prepend[0],
3377 },
3378 {
3379 sizeof(hash_prepend[1]),
3381 (void *)hash_prepend[1],
3382 }
3383 };
3384
3385 BCryptBufferDesc hash_params =
3386 {
3388 ARRAY_SIZE(hash_param_buffers),
3389 hash_param_buffers,
3390 };
3391 BCryptBufferDesc hash_params_prepended =
3392 {
3394 ARRAY_SIZE(hash_param_buffers_prepended),
3395 hash_param_buffers_prepended,
3396 };
3397 BYTE *buf;
3398 BCRYPT_ECCKEY_BLOB *ecckey;
3400 BCRYPT_KEY_HANDLE key, privkey, pubkey;
3403 ULONG size;
3404
3405 status = BCryptOpenAlgorithmProvider(&alg, t->alg, NULL, 0);
3406 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3407
3408 key = NULL;
3409 status = BCryptGenerateKeyPair(alg, &key, t->bitlen, 0);
3410 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3411 ok(key != NULL, "key not set\n");
3412
3414 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3415
3416 size = 0;
3418 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3419 ok(size, "size not set\n");
3420
3421 buf = malloc(size);
3423 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3424 ecckey = (BCRYPT_ECCKEY_BLOB *)buf;
3425 ok(ecckey->dwMagic == t->public_magic, "got %#lx\n", ecckey->dwMagic);
3426 ok(ecckey->cbKey == (t->bitlen + 7) / 8, "got %lu\n", ecckey->cbKey);
3427 ok(size == sizeof(*ecckey) + ecckey->cbKey * 2, "got %lu\n", size);
3428
3430 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3432
3434 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3435 free(buf);
3436
3437 size = 0;
3439 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3440 ok(size, "size not set\n");
3441
3442 buf = malloc(size);
3444 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3445 ecckey = (BCRYPT_ECCKEY_BLOB *)buf;
3446 ok(ecckey->dwMagic == t->private_magic, "got %#lx\n", ecckey->dwMagic);
3447 ok(ecckey->cbKey == (t->bitlen + 7) / 8, "got %lu\n", ecckey->cbKey);
3448 ok(size == sizeof(*ecckey) + ecckey->cbKey * 3, "got %lu\n", size);
3449
3451 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3452 free(buf);
3454 BCryptDestroyKey(privkey);
3456
3457 status = BCryptImportKeyPair(alg, NULL, BCRYPT_ECCPRIVATE_BLOB, &privkey, t->eccprivkey, t->eccprivkey_len, 0);
3458 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3459
3460 size = 0;
3462 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3463 ok(size, "size not set\n");
3464
3465 buf = malloc(size);
3467 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3468 ok(size == t->eccprivkey_len, "got %lu\n", size);
3469 ok(!memcmp(buf, t->eccprivkey, size), "wrong data\n");
3470 free(buf);
3471
3472 status = BCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &pubkey, t->ecdh_pubkey, t->ecdh_pubkey_len, 0);
3473 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3474
3475 status = BCryptSecretAgreement(privkey, pubkey, &secret, 0);
3476 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3477 if (status != STATUS_SUCCESS) goto derive_end;
3478
3480 if (status == STATUS_NOT_SUPPORTED) /* < win10 */
3481 {
3482 win_skip("BCRYPT_KDF_RAW_SECRET not supported\n");
3483 goto raw_secret_end;
3484 }
3485 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3486 if (status != STATUS_SUCCESS) goto raw_secret_end;
3487
3488 ok(size == (t->bitlen + 7) / 8, "size of secret key incorrect, got %lu, expected 32\n", size);
3489 buf = malloc(size);
3491 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3492 ok(!(memcmp(t->ecdh_secret, buf, size)), "wrong data\n");
3493 free(buf);
3494
3495 /* Raw secret with a BCryptBufferDesc, which is ignored */
3496 status = BCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, &hash_params_prepended, NULL, 0, &size, 0);
3497 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3498
3499 ok(size == (t->bitlen + 7) / 8, "size of secret key incorrect, got %lu, expected 32\n", size);
3500 buf = malloc(size);
3501 status = BCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, &hash_params_prepended, buf, size, &size, 0);
3502 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3503 ok(!(memcmp(t->ecdh_secret, buf, size)), "wrong data\n");
3504 free(buf);
3505
3506raw_secret_end:
3507 status = BCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, NULL, 0, &size, 0);
3508 ok (status == STATUS_SUCCESS, "got %#lx\n", status);
3509 if (status != STATUS_SUCCESS) goto derive_end;
3510
3511 ok (size == 20, "got %lu\n", size);
3512 buf = malloc(size);
3513 status = BCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, buf, size, &size, 0);
3514 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3515 ok(!(memcmp(t->hashed_secret, buf, size)), "wrong data\n");
3516 free(buf);
3517
3518 status = BCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params_prepended, NULL, 0, &size, 0);
3519 ok (status == STATUS_SUCCESS, "got %#lx\n", status);
3520
3521 ok (size == 20, "got %lu\n", size);
3522 buf = malloc(size);
3523 status = BCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params_prepended, buf, size, &size, 0);
3524 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3525 ok(!(memcmp(t->hashed_secret_prepended, buf, size)), "wrong data\n");
3526 free(buf);
3527
3528 /* ulVersion is not verified */
3529 hash_params.ulVersion = 0xdeadbeef;
3530 status = BCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, NULL, 0, &size, 0);
3531 ok (status == STATUS_SUCCESS, "got %#lx\n", status);
3532
3533 hash_params.ulVersion = BCRYPTBUFFER_VERSION;
3534 hash_param_buffers[0].pvBuffer = (void*) L"INVALID";
3535 hash_param_buffers[0].cbBuffer = sizeof(L"INVALID");
3536
3537 status = BCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, NULL, 0, &size, 0);
3538 ok (status == STATUS_NOT_SUPPORTED || broken (status == STATUS_NOT_FOUND) /* < win8 */, "got %#lx\n", status);
3539
3540 hash_param_buffers[0].pvBuffer = (void*) BCRYPT_RNG_ALGORITHM;
3541 hash_param_buffers[0].cbBuffer = sizeof(BCRYPT_RNG_ALGORITHM);
3542 status = BCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, NULL, 0, &size, 0);
3543 ok (status == STATUS_NOT_SUPPORTED, "got %#lx\n", status);
3544
3545derive_end:
3548 BCryptDestroyKey(privkey);
3550}
3551
3552static void test_ECDH(void)
3553{
3554 static BYTE ecc256privkey[] =
3555 {
3556 0x45, 0x43, 0x4b, 0x32, 0x20, 0x00, 0x00, 0x00,
3557 0xfb, 0xbd, 0x3d, 0x20, 0x1b, 0x6d, 0x66, 0xb3, 0x7c, 0x9f, 0x89, 0xf3, 0xe4, 0x41, 0x16, 0xa5,
3558 0x68, 0x52, 0x77, 0xac, 0xab, 0x55, 0xb2, 0x6c, 0xb0, 0x23, 0x55, 0xcb, 0x96, 0x14, 0xfd, 0x0b,
3559 0x1c, 0xef, 0xdf, 0x07, 0x6d, 0x31, 0xaf, 0x39, 0xce, 0x8c, 0x8f, 0x9d, 0x75, 0xd0, 0x7b, 0xea,
3560 0x81, 0xdc, 0x40, 0x21, 0x1f, 0x58, 0x22, 0x5f, 0x72, 0x55, 0xfc, 0x58, 0x8a, 0xeb, 0x88, 0x5d,
3561 0x02, 0x09, 0x90, 0xd2, 0xe3, 0x36, 0xac, 0xfe, 0x83, 0x13, 0x6c, 0x88, 0x1a, 0xab, 0x9b, 0xdd,
3562 0xaa, 0x8a, 0xee, 0x69, 0x9a, 0x6a, 0x62, 0x86, 0x6a, 0x13, 0x69, 0x88, 0xb7, 0xd5, 0xa3, 0xcd
3563 };
3564 static BYTE ecdh256_pubkey[] =
3565 {
3566 0x45, 0x43, 0x4b, 0x31, 0x20, 0x00, 0x00, 0x00,
3567 0x07, 0x61, 0x9d, 0x49, 0x63, 0x6b, 0x96, 0x94, 0xd1, 0x8f, 0xd1, 0x48, 0xcc, 0xcf, 0x72, 0x4d,
3568 0xff, 0x43, 0xf4, 0x97, 0x0f, 0xa3, 0x8a, 0x72, 0xe9, 0xe0, 0xba, 0x87, 0x6d, 0xc3, 0x62, 0x15,
3569 0xae, 0x65, 0xdd, 0x31, 0x51, 0xfc, 0x3b, 0xc9, 0x59, 0xa1, 0x0a, 0x92, 0x17, 0x2b, 0x64, 0x55,
3570 0x03, 0x3e, 0x62, 0x1d, 0xac, 0x3e, 0x37, 0x40, 0x6a, 0x4c, 0xb6, 0x21, 0x3f, 0x73, 0x5c, 0xf5
3571 };
3572 static BYTE ecdh256_secret[] =
3573 {
3574 0x48, 0xb0, 0x11, 0xdb, 0x69, 0x4e, 0xb4, 0xf4, 0xf5, 0x3e, 0xe1, 0x9b, 0xca, 0x00, 0x04, 0xc8,
3575 0x9b, 0x69, 0xaf, 0xd1, 0xaf, 0x1f, 0xc2, 0xd7, 0x83, 0x0a, 0xb7, 0xf8, 0x4f, 0x24, 0x32, 0x8e,
3576 };
3577 static BYTE hashed256_secret[] =
3578 {
3579 0x1b, 0xe7, 0xbf, 0x0f, 0x65, 0x1e, 0xd0, 0x07, 0xf9, 0xf4, 0x77, 0x48, 0x48, 0x39, 0xd0, 0xf8,
3580 0xf3, 0xce, 0xfc, 0x89
3581 };
3582 static BYTE hashed256_secret_prepended[] =
3583 {
3584 0x10, 0x99, 0x5f, 0x01, 0xef, 0xa8, 0x18, 0x82, 0xd2, 0x62, 0x37, 0xab, 0xe0, 0x7c, 0x62, 0xc7,
3585 0x50, 0x7f, 0xa6, 0xa0,
3586 };
3587
3588 static BYTE ecc384privkey[] =
3589 {
3590 0x45, 0x43, 0x4b, 0x34, 0x30, 0x00, 0x00, 0x00,
3591 0xc9, 0xcb, 0x38, 0x54, 0xa1, 0xe2, 0xb6, 0x60, 0x13, 0xd9, 0x45, 0x0d, 0x76, 0x90, 0xf9, 0x49,
3592 0x75, 0x81, 0x76, 0xac, 0x43, 0x96, 0xc1, 0x04, 0x04, 0xda, 0x76, 0x72, 0xb1, 0x19, 0x38, 0xbd,
3593 0xaf, 0x96, 0x0c, 0x4e, 0xc3, 0x29, 0x67, 0x91, 0x6c, 0xac, 0xcc, 0x33, 0x51, 0x1f, 0x82, 0xd5,
3594 0x17, 0xbf, 0xa2, 0x94, 0xd7, 0x15, 0x4f, 0x83, 0xe7, 0xa3, 0xb8, 0x6d, 0xd0, 0x7f, 0xbc, 0x8a,
3595 0x30, 0x09, 0x9e, 0x13, 0xaa, 0x2e, 0xf6, 0xde, 0x1c, 0x02, 0x4a, 0x65, 0xf6, 0x72, 0xb3, 0xf0,
3596 0x4f, 0x7f, 0x1a, 0xce, 0x4e, 0x94, 0xc5, 0x98, 0x89, 0x74, 0xad, 0x51, 0x8f, 0x2b, 0x25, 0x17,
3597 0xdc, 0x4a, 0x54, 0x8a, 0x42, 0xda, 0x30, 0x1a, 0xe3, 0x6d, 0x77, 0x4d, 0x3b, 0x33, 0x9a, 0xe3,
3598 0x37, 0xd4, 0x06, 0x5b, 0xb3, 0x3f, 0x73, 0xb9, 0x7e, 0x0b, 0x37, 0x02, 0x8b, 0xed, 0x08, 0x10,
3599 0x03, 0xf8, 0x69, 0xe3, 0x2a, 0x4f, 0xbb, 0x20, 0x6c, 0x5d, 0x24, 0x09, 0x0d, 0xd9, 0x86, 0x32,
3600 };
3601 static BYTE ecdh384_pubkey[] =
3602 {
3603 0x45, 0x43, 0x4b, 0x33, 0x30, 0x00, 0x00, 0x00,
3604 0xd6, 0xc3, 0xef, 0x4a, 0xbb, 0x4c, 0xa2, 0x27, 0xa1, 0x96, 0x03, 0x3b, 0x0a, 0x83, 0x01, 0xff,
3605 0xeb, 0x9a, 0xf1, 0x06, 0xee, 0x83, 0xce, 0x7c, 0xaa, 0x6b, 0x7c, 0x43, 0x1c, 0x8b, 0x30, 0x82,
3606 0x99, 0x8f, 0xc4, 0x86, 0x0d, 0x19, 0x16, 0xb6, 0xab, 0xd1, 0x9f, 0xeb, 0xf9, 0x31, 0xda, 0xcd,
3607 0xb9, 0xf8, 0xea, 0x87, 0xa1, 0x36, 0xaf, 0x10, 0x98, 0x8f, 0x9b, 0xcc, 0x6c, 0xe3, 0x24, 0xb4,
3608 0x82, 0x37, 0xde, 0x1e, 0x04, 0x53, 0x03, 0xc0, 0x2a, 0x41, 0xe9, 0x50, 0x07, 0x87, 0xb2, 0x60,
3609 0xe6, 0x32, 0x53, 0x4c, 0x8e, 0xa7, 0x80, 0x0f, 0xad, 0x25, 0x3b, 0x01, 0xa4, 0xd6, 0xe3, 0x54,
3610 };
3611 static BYTE ecdh384_secret[] =
3612 {
3613 0x08, 0x8c, 0xd1, 0xfa, 0x57, 0xb6, 0xf9, 0x79, 0x9e, 0x0c, 0x71, 0xc3, 0xcb, 0xa5, 0xb1, 0xfd,
3614 0xde, 0xbc, 0x6d, 0x7c, 0x8a, 0x5b, 0x26, 0xe8, 0x18, 0x80, 0x61, 0x45, 0x6a, 0x38, 0xf9, 0x13,
3615 0x2a, 0x8f, 0x4b, 0xfe, 0x75, 0x02, 0x62, 0xe9, 0xb3, 0x6e, 0xc5, 0x52, 0xc9, 0x82, 0x38, 0x53,
3616 };
3617 static BYTE hashed384_secret[] =
3618 {
3619 0x78, 0xf8, 0x07, 0xab, 0x00, 0x35, 0xaa, 0x8c, 0x22, 0xd0, 0xe7, 0x06, 0xfc, 0x0b, 0x74, 0x41,
3620 0xed, 0xdc, 0x16, 0x6c,
3621 };
3622 static BYTE hashed384_secret_prepended[] =
3623 {
3624 0x3d, 0xe0, 0x30, 0xd9, 0xe2, 0xdc, 0x61, 0xad, 0x26, 0x21, 0xad, 0xa3, 0x3e, 0xaf, 0xd5, 0x8e,
3625 0xb6, 0xbc, 0x5a, 0x51,
3626 };
3627
3628 static BYTE ecc521privkey[] =
3629 {
3630 0x45, 0x43, 0x4b, 0x36, 0x42, 0x00, 0x00, 0x00,
3631 0x01, 0x96, 0xb0, 0x4e, 0x35, 0x6f, 0xbe, 0x00, 0xb6, 0xc3, 0x83, 0x53, 0x92, 0x18, 0xda, 0x86,
3632 0x9e, 0x4b, 0x0f, 0xb2, 0x0b, 0xc3, 0x9f, 0xd8, 0x9c, 0x18, 0x8a, 0x93, 0x5c, 0x91, 0xb2, 0x4f,
3633 0x56, 0x7d, 0x0e, 0xf7, 0xf4, 0xdf, 0x91, 0xc6, 0x74, 0x00, 0xc7, 0xb8, 0x59, 0xeb, 0x55, 0xc0,
3634 0xb5, 0x26, 0x7f, 0x6d, 0x49, 0x53, 0x02, 0x3b, 0x3c, 0xa0, 0x57, 0x1e, 0x1c, 0x7c, 0x5b, 0x08,
3635 0x23, 0x68, 0x01, 0x47, 0x4d, 0x47, 0xcf, 0x05, 0xfe, 0x18, 0x26, 0x81, 0x9d, 0xb4, 0x34, 0xfa,
3636 0x50, 0x7e, 0x03, 0x29, 0xa3, 0x6e, 0x90, 0x9c, 0x27, 0x69, 0x66, 0x2c, 0x70, 0x7b, 0xf9, 0xe7,
3637 0xef, 0xac, 0x27, 0xbf, 0x15, 0x86, 0xf6, 0xff, 0x2d, 0x99, 0x41, 0x9e, 0x36, 0x1f, 0xe9, 0x3a,
3638 0x99, 0x74, 0x54, 0xf3, 0xc3, 0x08, 0xb1, 0x00, 0x28, 0x84, 0x82, 0x84, 0xe3, 0xf4, 0x32, 0xfd,
3639 0x48, 0x67, 0xae, 0x08, 0x01, 0xe2, 0x08, 0x1d, 0xeb, 0x27, 0xc2, 0x98, 0x45, 0x8b, 0x33, 0x20,
3640 0x3b, 0x21, 0x5c, 0x7f, 0x56, 0xbd, 0xa5, 0x99, 0x58, 0xea, 0x19, 0xf8, 0xbc, 0xf1, 0x9e, 0x39,
3641 0x00, 0xb9, 0x2c, 0x2a, 0xb6, 0x19, 0x3a, 0xaf, 0xea, 0x4b, 0xa6, 0x22, 0xb4, 0x35, 0x09, 0x86,
3642 0x2e, 0x67, 0xe0, 0xfe, 0x81, 0x0e, 0x6a, 0x68, 0x6a, 0xb3, 0x32, 0x3b, 0xf8, 0x89, 0x45, 0x72,
3643 0x69, 0xf1, 0xe1, 0x84, 0xd7, 0xed,
3644 };
3645 static BYTE ecdh521_pubkey[] =
3646 {
3647 0x45, 0x43, 0x4b, 0x35, 0x42, 0x00, 0x00, 0x00,
3648 0x00, 0xfd, 0x72, 0xca, 0x31, 0x08, 0x76, 0xd9, 0x08, 0xb7, 0x26, 0x4a, 0x04, 0xbc, 0x73, 0x1a,
3649 0x04, 0xbb, 0x77, 0xf4, 0xe2, 0xfc, 0x3a, 0x88, 0x0a, 0xa8, 0x72, 0x8f, 0xfc, 0xe9, 0xe3, 0x5f,
3650 0x73, 0x05, 0xf1, 0x7f, 0x31, 0xee, 0x15, 0x91, 0x36, 0xe9, 0xeb, 0xed, 0xbe, 0x0e, 0x78, 0xa1,
3651 0x28, 0x4e, 0xc5, 0xcb, 0xba, 0xd8, 0x0c, 0x96, 0x75, 0x44, 0x71, 0x71, 0x00, 0x41, 0x43, 0xdf,
3652 0x27, 0x91, 0x00, 0x81, 0xcc, 0x56, 0x8d, 0x8e, 0x32, 0xae, 0x78, 0xfb, 0x3e, 0x84, 0x7b, 0x3b,
3653 0xf8, 0x8e, 0x7b, 0x27, 0x73, 0xa4, 0x11, 0x61, 0x24, 0x40, 0x9b, 0xbe, 0xd3, 0xc3, 0x0e, 0xbb,
3654 0x26, 0xae, 0x55, 0x58, 0xd1, 0xec, 0x14, 0xd3, 0x13, 0xf2, 0x6b, 0x2b, 0xc3, 0xf9, 0xa4, 0x50,
3655 0x9e, 0xce, 0xfe, 0x18, 0xa0, 0x8b, 0x10, 0x80, 0x68, 0x72, 0x2e, 0x5c, 0xa0, 0xb3, 0x01, 0x6b,
3656 0x43, 0x26, 0xad, 0x58,
3657 };
3658 static BYTE ecdh521_secret[] =
3659 {
3660 0x2d, 0xab, 0x9f, 0x38, 0x14, 0x5d, 0x49, 0x65, 0x06, 0x22, 0x04, 0xf9, 0xb3, 0x25, 0xca, 0xf9,
3661 0xe6, 0xdc, 0xc6, 0xe8, 0xf9, 0x0b, 0xbf, 0x3c, 0x9d, 0xf0, 0x08, 0x95, 0x92, 0xdd, 0x92, 0x8a,
3662 0x95, 0x85, 0xe8, 0x1c, 0x6d, 0x41, 0xb9, 0xe4, 0x7b, 0x7a, 0xa5, 0x68, 0x30, 0x48, 0x8e, 0xc0,
3663 0xbc, 0x2b, 0xc6, 0xe9, 0x75, 0x9c, 0xed, 0xc3, 0xf5, 0x3a, 0xa3, 0xd7, 0x41, 0xec, 0x28, 0x82,
3664 0xef, 0x01,
3665 };
3666 static BYTE hashed521_secret[] =
3667 {
3668 0x72, 0x39, 0x73, 0x5f, 0xc9, 0x26, 0x1f, 0x8e, 0xe3, 0x30, 0x11, 0xe1, 0x4f, 0xc4, 0x65, 0xc0,
3669 0xde, 0xf9, 0xe6, 0x6a,
3670 };
3671 static BYTE hashed521_secret_prepended[] =
3672 {
3673 0x2e, 0x6f, 0x51, 0xc9, 0x15, 0xfb, 0x9f, 0xd0, 0xad, 0x92, 0x43, 0xdb, 0xc8, 0x6b, 0xd9, 0xe6,
3674 0x1a, 0x5f, 0x52, 0xa6,
3675 };
3676
3677 static const struct ecdh_test tests[] =
3678 {
3679 {
3680 BCRYPT_ECDH_P256_ALGORITHM, 256, ecc256privkey, sizeof(ecc256privkey), ecdh256_pubkey, sizeof(ecdh256_pubkey),
3681 ecdh256_secret, sizeof(ecdh256_secret), hashed256_secret, hashed256_secret_prepended,
3683 },
3684 {
3685 BCRYPT_ECDH_P384_ALGORITHM, 384, ecc384privkey, sizeof(ecc384privkey), ecdh384_pubkey, sizeof(ecdh384_pubkey),
3686 ecdh384_secret, sizeof(ecdh384_secret), hashed384_secret, hashed384_secret_prepended,
3688 },
3689 {
3690 BCRYPT_ECDH_P521_ALGORITHM, 521, ecc521privkey, sizeof(ecc521privkey), ecdh521_pubkey, sizeof(ecdh521_pubkey),
3691 ecdh521_secret, sizeof(ecdh521_secret), hashed521_secret, hashed521_secret_prepended,
3693 },
3694 };
3699 ULONG strength, size, i;
3700 UCHAR *buf;
3701
3702 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3703 {
3707 }
3708
3709 /* generic ECDH provider */
3711 if (status == STATUS_NOT_FOUND)
3712 {
3713 win_skip("generic ECDH provider not found\n");
3714 return;
3715 }
3716 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3717
3719 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3720
3722 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
3725
3727 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3728
3730 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3731
3732 status = BCryptGenerateKeyPair(alg, &key, 255, 0);
3733 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
3734
3736 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3737
3738 strength = 0;
3739 status = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&strength, sizeof(strength), &size, 0);
3740 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3741 ok(strength == 256, "got %lu\n", strength);
3742
3744 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3747
3749 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3750
3752 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3753
3754 status = BCryptGenerateKeyPair(alg, &key, 253, 0);
3755 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
3756
3757 status = BCryptGenerateKeyPair(alg, &key, 255, 0);
3758 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3760
3762 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3763
3764 strength = 0;
3765 status = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&strength, sizeof(strength), &size, 0);
3766 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3767 ok(strength == 253, "got %lu\n", strength);
3768
3770 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3771
3772 size = 0;
3774 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3775 ok(size, "size not set\n");
3776
3777 buf = malloc(size);
3779 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3781 ok(blob->dwMagic == BCRYPT_ECDH_PRIVATE_GENERIC_MAGIC, "got %08lx\n", blob->dwMagic);
3782 ok(blob->cbKey == 32, "got %lu\n", blob->cbKey);
3783
3785 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3786
3787 free( buf );
3791
3792 /* Brainpool curve */
3794 ok(!status, "got %#lx\n", status);
3795
3798 ok(!status, "got %#lx\n", status);
3799
3800 status = BCryptGenerateKeyPair(alg, &key, 256, 0);
3801 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3802
3805}
3806
3807static BYTE dh_pubkey[] =
3808{
3809 /* BCRYPT_DH_KEY_BLOB */
3810 0x44, 0x48, 0x50, 0x42, 0x40, 0x00, 0x00, 0x00,
3811 /* p */
3812 0xcf, 0x18, 0xe9, 0xa9, 0xb3, 0x97, 0x59, 0xae, 0x0d, 0xac, 0xf0, 0x99, 0x39, 0xdc, 0xd2, 0xfe,
3813 0x1e, 0xf3, 0xfc, 0x2c, 0x49, 0xdf, 0x76, 0x89, 0xff, 0x13, 0x57, 0xc7, 0xe6, 0xbd, 0xed, 0xa7,
3814 0x42, 0xc0, 0xc3, 0xd7, 0x8e, 0x84, 0xa8, 0xdf, 0xcd, 0x52, 0x50, 0x81, 0x73, 0x8a, 0x33, 0x60,
3815 0xde, 0x6d, 0x56, 0xeb, 0xd5, 0xec, 0x1f, 0x9f, 0x9f, 0xd6, 0x2c, 0xe4, 0x8f, 0xab, 0x58, 0x0b,
3816 /* g */
3817 0x5f, 0xc5, 0x50, 0x9a, 0xde, 0xf6, 0x84, 0x48, 0x39, 0xa9, 0xa7, 0xb1, 0x73, 0x0c, 0x56, 0xd4,
3818 0x28, 0xbb, 0x12, 0x93, 0x51, 0x44, 0x33, 0xdf, 0xa6, 0xe7, 0x7f, 0x0b, 0x3f, 0xe9, 0x41, 0xef,
3819 0x32, 0x80, 0xcd, 0x8e, 0x2b, 0x38, 0x85, 0x49, 0x4d, 0x0c, 0xcc, 0x74, 0x02, 0x07, 0x92, 0xd3,
3820 0xe4, 0x3e, 0x37, 0x84, 0x27, 0x1f, 0xa3, 0xad, 0x94, 0x8c, 0xc1, 0xc2, 0x22, 0x99, 0x36, 0xf0,
3821 /* y */
3822 0x22, 0xaf, 0x98, 0xeb, 0xd9, 0xc4, 0xb5, 0xbd, 0xe1, 0xab, 0x19, 0x1b, 0xe3, 0x36, 0x20, 0xca,
3823 0xff, 0xe8, 0x6c, 0x30, 0x96, 0x3c, 0x90, 0x77, 0x0e, 0xe0, 0x96, 0xae, 0xb1, 0x47, 0xd1, 0x52,
3824 0x2c, 0xc3, 0x65, 0x5e, 0x9b, 0x41, 0x9a, 0xa6, 0xfe, 0xab, 0x54, 0xa0, 0xf0, 0x71, 0xab, 0x6c,
3825 0xd0, 0x0e, 0x01, 0x08, 0x5b, 0x66, 0xe5, 0x62, 0xd2, 0xe5, 0x5d, 0xae, 0x9c, 0x60, 0xb2, 0xc6,
3826};
3827
3829{
3830 /* BCRYPT_DH_KEY_BLOB */
3831 0x44, 0x48, 0x50, 0x56, 0x40, 0x00, 0x00, 0x00,
3832 /* p */
3833 0xcf, 0x18, 0xe9, 0xa9, 0xb3, 0x97, 0x59, 0xae, 0x0d, 0xac, 0xf0, 0x99, 0x39, 0xdc, 0xd2, 0xfe,
3834 0x1e, 0xf3, 0xfc, 0x2c, 0x49, 0xdf, 0x76, 0x89, 0xff, 0x13, 0x57, 0xc7, 0xe6, 0xbd, 0xed, 0xa7,
3835 0x42, 0xc0, 0xc3, 0xd7, 0x8e, 0x84, 0xa8, 0xdf, 0xcd, 0x52, 0x50, 0x81, 0x73, 0x8a, 0x33, 0x60,
3836 0xde, 0x6d, 0x56, 0xeb, 0xd5, 0xec, 0x1f, 0x9f, 0x9f, 0xd6, 0x2c, 0xe4, 0x8f, 0xab, 0x58, 0x0b,
3837 /* g */
3838 0x5f, 0xc5, 0x50, 0x9a, 0xde, 0xf6, 0x84, 0x48, 0x39, 0xa9, 0xa7, 0xb1, 0x73, 0x0c, 0x56, 0xd4,
3839 0x28, 0xbb, 0x12, 0x93, 0x51, 0x44, 0x33, 0xdf, 0xa6, 0xe7, 0x7f, 0x0b, 0x3f, 0xe9, 0x41, 0xef,
3840 0x32, 0x80, 0xcd, 0x8e, 0x2b, 0x38, 0x85, 0x49, 0x4d, 0x0c, 0xcc, 0x74, 0x02, 0x07, 0x92, 0xd3,
3841 0xe4, 0x3e, 0x37, 0x84, 0x27, 0x1f, 0xa3, 0xad, 0x94, 0x8c, 0xc1, 0xc2, 0x22, 0x99, 0x36, 0xf0,
3842 /* y */
3843 0x22, 0xaf, 0x98, 0xeb, 0xd9, 0xc4, 0xb5, 0xbd, 0xe1, 0xab, 0x19, 0x1b, 0xe3, 0x36, 0x20, 0xca,
3844 0xff, 0xe8, 0x6c, 0x30, 0x96, 0x3c, 0x90, 0x77, 0x0e, 0xe0, 0x96, 0xae, 0xb1, 0x47, 0xd1, 0x52,
3845 0x2c, 0xc3, 0x65, 0x5e, 0x9b, 0x41, 0x9a, 0xa6, 0xfe, 0xab, 0x54, 0xa0, 0xf0, 0x71, 0xab, 0x6c,
3846 0xd0, 0x0e, 0x01, 0x08, 0x5b, 0x66, 0xe5, 0x62, 0xd2, 0xe5, 0x5d, 0xae, 0x9c, 0x60, 0xb2, 0xc6,
3847 /* x */
3848 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3849 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3850 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x71, 0x3e, 0x82,
3851 0x8b, 0xea, 0x11, 0x77, 0xc4, 0xb4, 0x62, 0xc7, 0x4d, 0xff, 0x0f, 0x63, 0xd9, 0xe2, 0xda, 0xab,
3852};
3853
3854static BYTE dh_secret[] =
3855{
3856 0x73, 0x84, 0x62, 0xc1, 0x9a, 0x9c, 0xc2, 0x91, 0x9f, 0xc1, 0xc2, 0x94, 0x0c, 0xa8, 0x2f, 0x58,
3857 0xac, 0x50, 0xcd, 0xd5, 0x29, 0x43, 0x41, 0x8e, 0x5d, 0xca, 0x73, 0x55, 0x4d, 0x46, 0x50, 0xe5,
3858 0xb7, 0x34, 0xa9, 0xcb, 0x3a, 0x18, 0x68, 0x99, 0x30, 0xef, 0x58, 0x26, 0xd3, 0x03, 0x61, 0x02,
3859 0x17, 0xb7, 0xba, 0x01, 0xbc, 0xae, 0xdf, 0x3f, 0xb5, 0xb5, 0x4a, 0xb0, 0x08, 0xe5, 0xea, 0xc3,
3860};
3861
3863{
3864 0xa7, 0xfc, 0xff, 0x21, 0xb3, 0xd1, 0x46, 0xb8, 0x21, 0x3d, 0xc6, 0xd4, 0xe3, 0x61, 0x97, 0x5e,
3865 0xb5, 0x0a, 0xfe, 0x8f,
3866};
3867
3869{
3870 0x03, 0x9d, 0x31, 0x52, 0x32, 0xca, 0xfc, 0x12, 0x23, 0x2e, 0x63, 0x0b, 0x7a, 0x1c, 0xaf, 0xee,
3871 0x17, 0xf0, 0x7b, 0xc6,
3872};
3873
3875{
3876 {
3877 sizeof(BCRYPT_SHA1_ALGORITHM),
3879 (void *)BCRYPT_SHA1_ALGORITHM,
3880 }
3881};
3883{
3884 {
3885 sizeof(BCRYPT_SHA1_ALGORITHM),
3887 (void *)BCRYPT_SHA1_ALGORITHM,
3888 },
3889 {
3890 sizeof(hash_prepend[0]),
3892 (void *)hash_prepend[0],
3893 },
3894 {
3895 sizeof(hash_prepend[1]),
3897 (void *)hash_prepend[1],
3898 }
3899};
3900
3902{
3906};
3908{
3912};
3913
3914static void test_DH(void)
3915{
3916 UCHAR hash[20];
3917 BCRYPT_KEY_HANDLE key, pubkey, privkey;
3919 BCRYPT_DH_KEY_BLOB *dhkey;
3921 UCHAR *buf;
3922 ULONG size;
3923
3924 if (!pBCryptHash) /* < Win10 */
3925 {
3926 win_skip("broken DH detected\n");
3927 return;
3928 }
3929
3930 key = NULL;
3932 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3933 ok(key != NULL, "key not set\n");
3934
3936 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3937 if (status != STATUS_SUCCESS)
3938 {
3940 return;
3941 }
3942
3943 size = 0;
3945 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3946 ok(size, "size not set\n");
3947
3948 buf = malloc(size);
3950 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3951 dhkey = (BCRYPT_DH_KEY_BLOB *)buf;
3952 ok(dhkey->dwMagic == BCRYPT_DH_PUBLIC_MAGIC, "got %#lx\n", dhkey->dwMagic);
3953 ok(dhkey->cbKey == 64, "got %lu\n", dhkey->cbKey);
3954 ok(size == sizeof(*dhkey) + dhkey->cbKey * 3, "got %lu\n", size);
3955
3957 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3958 free(buf);
3960
3961 size = 0;
3963 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3964 ok(size == sizeof(*dhkey) + 64 * 4, "size not set\n");
3965
3966 buf = calloc(1, size);
3968 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3969 dhkey = (BCRYPT_DH_KEY_BLOB *)buf;
3970 ok(dhkey->dwMagic == BCRYPT_DH_PRIVATE_MAGIC, "got %#lx\n", dhkey->dwMagic);
3971 ok(dhkey->cbKey == 64, "got %lu\n", dhkey->cbKey);
3972 ok(size == sizeof(*dhkey) + dhkey->cbKey * 4, "got %lu\n", size);
3974
3976 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3977 free(buf);
3978 BCryptDestroyKey(privkey);
3979
3981 sizeof(dh_privkey), 0);
3982 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3983
3984 size = 0;
3986 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3987 ok(size, "size not set\n");
3988
3989 buf = malloc(size);
3991 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3992 ok(size == sizeof(dh_privkey), "got %lu\n", size);
3993 ok(!memcmp(buf, dh_privkey, size), "wrong data\n");
3994 free(buf);
3995
3997 sizeof(dh_pubkey), 0);
3998 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
3999
4000 size = 0;
4002 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4003 ok(size, "size not set\n");
4004
4005 buf = malloc(size);
4007 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4008 ok(size == sizeof(dh_pubkey), "got %lu\n", size);
4009 ok(!memcmp(buf, dh_pubkey, size), "wrong data\n");
4010 free(buf);
4011
4012 status = BCryptSignHash(privkey, NULL, hash, sizeof(hash), NULL, 0, &size, 0);
4013 ok(status == STATUS_NOT_SUPPORTED, "got %#lx\n", status);
4014
4015 status = BCryptEncrypt(privkey, NULL, 0, NULL, NULL, 0, NULL, 0, &size, 0);
4016 ok(status == STATUS_NOT_SUPPORTED, "got %lx\n", status);
4017
4018 status = BCryptSecretAgreement(privkey, pubkey, &secret, 0);
4019 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4021 BCryptDestroyKey(privkey);
4022
4023 size = 0;
4026 {
4027 win_skip("BCRYPT_KDF_RAW_SECRET not supported\n"); /* < win10 */
4029 return;
4030 }
4031 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4032 ok(size == 64, "got %lu\n", size);
4033
4034 buf = calloc(1, size);
4036 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4037 ok(!memcmp(dh_secret, buf, size), "wrong data\n");
4038 free(buf);
4039
4040 /* Raw secret with a BCryptBufferDesc, which is ignored */
4041 size = 0;
4043 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4044 ok(size == 64, "got %lu\n", size);
4045
4046 buf = calloc(1, size);
4048 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4049 ok(!memcmp(dh_secret, buf, size), "wrong data\n");
4050 free(buf);
4051
4052 size = 0;
4054 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4055 ok(size == 20, "got %lu\n", size);
4056
4057 size = 0;
4059 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4060 ok(size == 20, "got %lu\n", size);
4061
4062 buf = calloc(1, size);
4064 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
4065
4067 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4068 ok(!memcmp(dh_hashed_secret, buf, size), "wrong data\n");
4069 ok(size == 20, "got %lu\n", size);
4070
4071 size = 0;
4073 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4074 ok(size == 20, "got %lu\n", size);
4075
4076 buf = calloc(1, size);
4078 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4079 ok(!memcmp(dh_hashed_secret_prepended, buf, size), "wrong data\n");
4080 ok(size == 20, "got %lu\n", size);
4081
4082 memset(buf, 0, 20);
4084 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4085 ok(!memcmp(dh_hashed_secret, buf, size), "wrong data\n");
4086 ok(size == 10, "got %lu\n", size);
4087 free(buf);
4088
4090}
4091
4093{
4096 ULONG buflen;
4097
4098 buffer = NULL;
4100 todo_wine ok( status == STATUS_SUCCESS, "got %#lx\n", status);
4102}
4103
4104static BYTE rsapublic[] =
4105{
4106 0x52, 0x53, 0x41, 0x31, 0x00, 0x08, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
4107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xd5, 0xfe, 0xf6, 0x7a, 0x9a, 0xa1, 0x2d, 0xcf, 0x98,
4108 0x60, 0xca, 0x38, 0x60, 0x0b, 0x74, 0x4c, 0x7e, 0xa1, 0x42, 0x64, 0xad, 0x05, 0xa5, 0x29, 0x25, 0xcb, 0xd5,
4109 0x9c, 0xaf, 0x6f, 0x63, 0x85, 0x6d, 0x5b, 0x59, 0xe5, 0x17, 0x8f, 0xf9, 0x18, 0x90, 0xa7, 0x63, 0xae, 0xe0,
4110 0x3a, 0x62, 0xf7, 0x98, 0x57, 0xe9, 0x91, 0xda, 0xfb, 0xd9, 0x36, 0x45, 0xe4, 0x9e, 0x75, 0xf6, 0x73, 0xc4,
4111 0x99, 0x23, 0x21, 0x1b, 0x3d, 0xe1, 0xe0, 0xa6, 0xa0, 0x4a, 0x50, 0x2a, 0xcb, 0x2a, 0x50, 0xf0, 0x8b, 0x70,
4112 0x9c, 0xe4, 0x1a, 0x14, 0x3b, 0xbe, 0x35, 0xa5, 0x5a, 0x91, 0xa3, 0xa1, 0x82, 0xea, 0x84, 0x4d, 0xe8, 0x62,
4113 0x3b, 0x11, 0xec, 0x61, 0x09, 0x6c, 0xfe, 0xb2, 0xcc, 0x4b, 0xa8, 0xff, 0xaf, 0x73, 0x72, 0x05, 0x4e, 0x7e,
4114 0xe5, 0x73, 0xdf, 0x24, 0xcf, 0x7f, 0x5d, 0xaf, 0x8a, 0xf0, 0xd8, 0xcb, 0x08, 0x1e, 0xf2, 0x36, 0x70, 0x8d,
4115 0x1b, 0x9e, 0xc8, 0x98, 0x60, 0x54, 0xeb, 0x45, 0x34, 0x21, 0x43, 0x4d, 0x42, 0x0a, 0x3a, 0x2d, 0x0f, 0x0e,
4116 0xd6, 0x0d, 0xe4, 0x2e, 0x8c, 0x31, 0x87, 0xa8, 0x09, 0x89, 0x61, 0x16, 0xca, 0x5b, 0xbe, 0x76, 0x69, 0xbb,
4117 0xfd, 0x91, 0x63, 0xd2, 0x66, 0x57, 0x08, 0xef, 0xe2, 0x40, 0x67, 0xd7, 0x7f, 0x50, 0x15, 0x42, 0x33, 0x97,
4118 0x54, 0x73, 0x47, 0xe7, 0x9c, 0x14, 0xa8, 0xb0, 0x3d, 0xc9, 0x23, 0xb0, 0x27, 0x3b, 0xe7, 0xdd, 0x5f, 0xd1,
4119 0x4f, 0x31, 0x10, 0x7d, 0xdd, 0x69, 0x8e, 0xde, 0xa3, 0xe8, 0x92, 0x00, 0xfa, 0xa5, 0xa4, 0x40, 0x51, 0x23,
4120 0x82, 0x84, 0xc7, 0xce, 0x19, 0x61, 0x26, 0xf1, 0xae, 0xf3, 0x90, 0x93, 0x98, 0x56, 0x23, 0x9a, 0xd1, 0xbd,
4121 0xf2, 0xdf, 0xfd, 0x13, 0x9c, 0x30, 0x07, 0xf9, 0x5a, 0x2e, 0x00, 0xc6, 0x1f
4122};
4123
4124static void test_BCryptSignHash(void)
4125{
4126 static UCHAR hash[] =
4127 {0x7e,0xe3,0x74,0xe7,0xc5,0x0b,0x6b,0x70,0xdb,0xab,0x32,0x6d,0x1d,0x51,0xd6,0x74,0x79,0x8e,0x5b,0x4b};
4128 static UCHAR hash_sha256[] =
4129 {0x25,0x2f,0x10,0xc8,0x36,0x10,0xeb,0xca,0x1a,0x05,0x9c,0x0b,0xae,0x82,0x55,0xeb,0xa2,0xf9,0x5b,0xe4,
4130 0xd1,0xd7,0xbC,0xfA,0x89,0xd7,0x24,0x8a,0x82,0xd9,0xf1,0x11};
4134 UCHAR sig[256];
4135 NTSTATUS ret;
4136 ULONG len;
4137
4138 /* RSA */
4140 ok(!ret, "got %#lx\n", ret);
4141
4142 /* public key */
4144 ok(!ret, "got %#lx\n", ret);
4145
4146 len = 0;
4148 ret = BCryptSignHash(key, &pad, NULL, 0, NULL, 0, &len, BCRYPT_PAD_PKCS1);
4149 ok(!ret, "got %#lx\n", ret);
4150 ok(len == 256, "got %lu\n", len);
4151
4152 /* test len return when only output is NULL, as described in BCryptSignHash doc */
4153 ret = BCryptSignHash(key, &pad, hash, sizeof(hash), NULL, 0, &len, BCRYPT_PAD_PKCS1);
4154 ok(!ret, "got %#lx\n", ret);
4155 ok(len == 256, "got %lu\n", len);
4156
4157 len = 0;
4158 ret = BCryptSignHash(key, &pad, hash, sizeof(hash), sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
4159 ok(ret == STATUS_INVALID_PARAMETER || broken(ret == STATUS_INTERNAL_ERROR) /* < win7 */, "got %#lx\n", ret);
4161 ok(!ret, "got %#lx\n", ret);
4162
4163 ret = BCryptGenerateKeyPair(alg, &key, 512, 0);
4164 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4165
4167 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4168
4170 ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
4171
4172 len = 0;
4173 memset(sig, 0, sizeof(sig));
4174
4175 /* inference of padding info on RSA not supported */
4176 ret = BCryptSignHash(key, NULL, hash, sizeof(hash), sig, sizeof(sig), &len, 0);
4177 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
4178
4179 ret = BCryptSignHash(key, &pad, hash, sizeof(hash), sig, 0, &len, BCRYPT_PAD_PKCS1);
4180 ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
4181
4182 ret = BCryptSignHash(key, &pad, hash, sizeof(hash), sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
4183 ok(!ret, "got %#lx\n", ret);
4184 ok(len == 64, "got %lu\n", len);
4185
4186 ret = BCryptVerifySignature(key, &pad, hash, sizeof(hash), sig, len, BCRYPT_PAD_PKCS1);
4187 ok(!ret, "got %#lx\n", ret);
4188
4190 ok(!ret, "got %#lx\n", ret);
4191
4193 ok(!ret, "got %#lx\n", ret);
4194
4195 /* ECDSA */
4197 ok(!ret, "got %#lx\n", ret);
4198
4199 ret = BCryptGenerateKeyPair(alg, &key, 256, 0);
4200 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4201
4203 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4204
4205 memset(sig, 0, sizeof(sig));
4206 len = 0;
4207
4208 /* automatically detects padding info */
4209 ret = BCryptSignHash(key, NULL, hash, sizeof(hash), sig, sizeof(sig), &len, 0);
4210 ok (!ret, "got %#lx\n", ret);
4211 ok (len == 64, "got %lu\n", len);
4212
4213 ret = BCryptVerifySignature(key, NULL, hash, sizeof(hash), sig, len, 0);
4214 ok(!ret, "got %#lx\n", ret);
4215
4216 /* mismatch info (SHA-1 != SHA-256) */
4217 ret = BCryptSignHash(key, &pad, hash_sha256, sizeof(hash_sha256), sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
4218 ok (ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
4219
4221 ok(!ret, "got %#lx\n", ret);
4222
4224 ok(!ret, "got %#lx\n", ret);
4225
4226 /* ECDSA P521 */
4228 ok(!ret, "got %#lx\n", ret);
4229
4230 ret = BCryptGenerateKeyPair(alg, &key, 256, 0);
4231 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
4232 ret = BCryptGenerateKeyPair(alg, &key, 522, 0);
4233 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
4234
4235 ret = BCryptGenerateKeyPair(alg, &key, 521, 0);
4236 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4238 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4239 len = 0;
4240 ret = BCryptSignHash(key, NULL, hash, sizeof(hash), sig, sizeof(sig), &len, 0);
4241 ok (!ret, "got %#lx\n", ret);
4242 ok (len == 132, "got %lu\n", len);
4243
4244 ret = BCryptVerifySignature(key, NULL, hash, sizeof(hash), sig, len, 0);
4245 ok(!ret, "got %#lx\n", ret);
4246
4248 ok(!ret, "got %#lx\n", ret);
4250 ok(!ret, "got %#lx\n", ret);
4251}
4252
4254{
4256 NTSTATUS ret;
4257 ULONG count, op;
4258
4260 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
4261
4263 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
4264
4265 ret = BCryptEnumAlgorithms(0, NULL, &list, 0);
4266 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
4267
4268 ret = BCryptEnumAlgorithms(~0u, &count, &list, 0);
4269 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
4270
4271 count = 0;
4272 list = NULL;
4273 ret = BCryptEnumAlgorithms(0, &count, &list, 0);
4274 ok(!ret, "got %#lx\n", ret);
4275 ok(list != NULL, "NULL list\n");
4276 ok(count, "got %lu\n", count);
4278
4281 count = 0;
4282 list = NULL;
4284 ok(!ret, "got %#lx\n", ret);
4285 ok(list != NULL, "NULL list\n");
4286 ok(count, "got %lu\n", count);
4288}
4289
4290static void test_aes_vector(void)
4291{
4292 static const UCHAR secret[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10};
4293 static const UCHAR expect[] = {0xb0,0xcb,0xf5,0x80,0xd4,0xe3,0x55,0x23,0x6e,0x19,0x5b,0xdb,0xfe,0xe0,0x6c,0xd3};
4294 static const UCHAR expect2[] = {0x06,0x0c,0x81,0xab,0xd4,0x28,0x80,0x42,0xce,0x30,0x56,0x17,0x15,0x00,0x9e,0xc1};
4295 static const UCHAR expect3[] = {0x3e,0x99,0xbf,0x02,0xf5,0xd3,0xb8,0x81,0x91,0x4d,0x93,0xea,0xd4,0x92,0x93,0x46};
4296 static UCHAR iv[16], input[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'};
4297 UCHAR output[16];
4300 UCHAR data[sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + sizeof(secret)];
4302 ULONG size;
4303 NTSTATUS ret;
4304
4306 ok(!ret, "got %#lx\n", ret);
4307
4308 size = sizeof(BCRYPT_CHAIN_MODE_CBC);
4310 ok(!ret, "got %#lx\n", ret);
4311
4314 blob->cbKeyData = sizeof(secret);
4315 memcpy(data + sizeof(*blob), secret, sizeof(secret));
4316 size = sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + sizeof(secret);
4318 ok(!ret, "got %#lx\n", ret);
4319
4320 /* zero initialization vector */
4321 size = 0;
4322 memset(output, 0, sizeof(output));
4323 ret = BCryptEncrypt(key, input, sizeof(input), NULL, iv, sizeof(iv), output, sizeof(output), &size, 0);
4324 ok(!ret, "got %#lx\n", ret);
4325 ok(size == 16, "got %lu\n", size);
4326 ok(!memcmp(output, expect, sizeof(expect)), "wrong cipher text\n");
4327
4328 /* same initialization vector */
4329 size = 0;
4330 memset(output, 0, sizeof(output));
4331 ret = BCryptEncrypt(key, input, sizeof(input), NULL, iv, sizeof(iv), output, sizeof(output), &size, 0);
4332 ok(!ret, "got %#lx\n", ret);
4333 ok(size == 16, "got %lu\n", size);
4334 ok(!memcmp(output, expect2, sizeof(expect2)), "wrong cipher text\n");
4335
4336 /* different initialization vector */
4337 iv[0] = 0x1;
4338 size = 0;
4339 memset(output, 0, sizeof(output));
4340 ret = BCryptEncrypt(key, input, sizeof(input), NULL, iv, sizeof(iv), output, sizeof(output), &size, 0);
4341 ok(!ret, "got %#lx\n", ret);
4342 ok(size == 16, "got %lu\n", size);
4343 ok(!memcmp(output, expect3, sizeof(expect3)), "wrong cipher text\n");
4344
4346 ok(!ret, "got %#lx\n", ret);
4347
4349 ok(!ret, "got %#lx\n", ret);
4350}
4351
4353{
4354 static const UCHAR secret[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10};
4355 static const UCHAR vector[] = {0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};
4356 static const UCHAR expect[] = {0x3e,0xfa,0x1a,0xc8,0x92,0x54,0xe4,0x21,0x1a,0x3d,0xfd,0x42,0x1c,0xc0,0x7d,0x20};
4357 static const UCHAR expect2[] = {0xb0,0xcb,0xf5,0x80,0xd4,0xe3,0x55,0x23,0x6e,0x19,0x5b,0xdb,0xfe,0xe0,0x6c,0xd3};
4358 static UCHAR input[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'};
4359 UCHAR data[sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + sizeof(secret)];
4361 UCHAR output[16], iv[16];
4364 ULONG size;
4365 NTSTATUS ret;
4366
4368 ok(!ret, "got %#lx\n", ret);
4369
4370 size = sizeof(BCRYPT_CHAIN_MODE_CBC);
4372 ok(!ret, "got %#lx\n", ret);
4373
4376 blob->cbKeyData = sizeof(secret);
4377 memcpy(data + sizeof(*blob), secret, sizeof(secret));
4378 size = sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + sizeof(secret);
4380 ok(!ret, "got %#lx\n", ret);
4381
4383 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
4384
4385 /* the initialization vector can be set on the key instead of being passed to BCryptEncrypt() */
4387 ok(!ret, "got %#lx\n", ret);
4388
4389 size = 0;
4390 memset(output, 0, sizeof(output));
4391 ret = BCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, output, sizeof(output), &size, 0);
4392 ok(!ret, "got %#lx\n", ret);
4393 ok(size == 16, "got %lu\n", size);
4394 ok(!memcmp(output, expect, sizeof(expect)), "wrong cipher text\n");
4395
4396 /* setting it again restarts the chain instead of continuing it */
4398 ok(!ret, "got %#lx\n", ret);
4399
4400 size = 0;
4401 memset(output, 0, sizeof(output));
4402 ret = BCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, output, sizeof(output), &size, 0);
4403 ok(!ret, "got %#lx\n", ret);
4404 ok(size == 16, "got %lu\n", size);
4405 ok(!memcmp(output, expect, sizeof(expect)), "wrong cipher text\n");
4406
4407 /* a vector passed to BCryptEncrypt() overrides the one set on the key */
4409 ok(!ret, "got %#lx\n", ret);
4410
4411 size = 0;
4412 memset(iv, 0, sizeof(iv));
4413 memset(output, 0, sizeof(output));
4414 ret = BCryptEncrypt(key, input, sizeof(input), NULL, iv, sizeof(iv), output, sizeof(output), &size, 0);
4415 ok(!ret, "got %#lx\n", ret);
4416 ok(size == 16, "got %lu\n", size);
4417 ok(!memcmp(output, expect2, sizeof(expect2)), "wrong cipher text\n");
4418
4419 /* and the same vector decrypts what it encrypted */
4421 ok(!ret, "got %#lx\n", ret);
4422
4423 size = 0;
4424 memset(output, 0, sizeof(output));
4425 ret = BCryptDecrypt(key, (UCHAR *)expect, sizeof(expect), NULL, NULL, 0, output, sizeof(output), &size, 0);
4426 ok(!ret, "got %#lx\n", ret);
4427 ok(size == 16, "got %lu\n", size);
4428 ok(!memcmp(output, input, sizeof(input)), "wrong plain text\n");
4429
4431 ok(!ret, "got %#lx\n", ret);
4432
4434 ok(!ret, "got %#lx\n", ret);
4435}
4436
4438{
4439 static const UCHAR expect[] =
4440 {0xda,0x39,0xa3,0xee,0x5e,0x6b,0x4b,0x0d,0x32,0x55,0xbf,0xef,0x95,0x60,0x18,0x90,0xaf,0xd8,0x07,0x09};
4441 static const UCHAR expect2[] =
4442 {0x9b,0x03,0x17,0x41,0xf4,0x75,0x11,0xac,0xff,0x22,0xee,0x40,0xbb,0xe8,0xf9,0x74,0x17,0x26,0xb6,0xf2,
4443 0xf8,0xc7,0x88,0x02,0x9a,0xdc,0x0d,0xd7,0x83,0x58,0xea,0x65,0x2e,0x8b,0x85,0xc6,0xdb,0xb7,0xed,0x1c};
4446 UCHAR key[40];
4447 NTSTATUS ret;
4448
4450 ok(!ret, "got %#lx\n", ret);
4451
4452 ret = BCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0);
4453 ok(!ret, "got %#lx\n", ret);
4454
4456 ok(ret == STATUS_INVALID_PARAMETER || ret == STATUS_INVALID_HANDLE /* win7 */, "got %#lx\n", ret);
4457
4459 ok(ret == STATUS_INVALID_PARAMETER || !ret /* win7 */, "got %#lx\n", ret);
4460
4462 ok(!ret, "got %#lx\n", ret);
4463
4464 ret = BCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0);
4465 ok(!ret, "got %#lx\n", ret);
4466
4467 ret = BCryptDeriveKeyCapi(hash, NULL, key, 0, 0);
4468 ok(ret == STATUS_INVALID_PARAMETER || !ret /* win7 */, "got %#lx\n", ret);
4469
4471 ok(!ret, "got %#lx\n", ret);
4472
4473 ret = BCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0);
4474 ok(!ret, "got %#lx\n", ret);
4475
4476 memset(key, 0, sizeof(key));
4477 ret = BCryptDeriveKeyCapi(hash, NULL, key, 41, 0);
4478 ok(ret == STATUS_INVALID_PARAMETER || !ret /* win7 */, "got %#lx\n", ret);
4479 if (!ret)
4480 ok(!memcmp(key, expect, sizeof(expect) - 1), "wrong key data\n");
4481
4483 ok(!ret, "got %#lx\n", ret);
4484
4485 ret = BCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0);
4486 ok(!ret, "got %#lx\n", ret);
4487
4488 memset(key, 0, sizeof(key));
4489 ret = BCryptDeriveKeyCapi(hash, NULL, key, 20, 0);
4490 ok(!ret, "got %#lx\n", ret);
4491 ok(!memcmp(key, expect, sizeof(expect) - 1), "wrong key data\n");
4492
4493 ret = BCryptDeriveKeyCapi(hash, NULL, key, 20, 0);
4494 todo_wine ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
4495
4496 ret = BCryptHashData(hash, NULL, 0, 0);
4497 todo_wine ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
4498
4500 ok(!ret, "got %#lx\n", ret);
4501
4502 ret = BCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0);
4503 ok(!ret, "got %#lx\n", ret);
4504
4505 ret = BCryptHashData(hash, (UCHAR *)"test", 4, 0);
4506 ok(!ret, "got %#lx\n", ret);
4507
4508 /* padding */
4509 memset(key, 0, sizeof(key));
4510 ret = BCryptDeriveKeyCapi(hash, NULL, key, 40, 0);
4511 ok(!ret, "got %#lx\n", ret);
4512 ok(!memcmp(key, expect2, sizeof(expect2) - 1), "wrong key data\n");
4513
4515 ok(!ret, "got %#lx\n", ret);
4516}
4517
4518static UCHAR dsaHash[] =
4519{
4520 0x7e,0xe3,0x74,0xe7,0xc5,0x0b,0x6b,0x70,0xdb,0xab,0x32,0x6d,0x1d,0x51,0xd6,0x74,0x79,0x8e,0x5b,0x4b
4521};
4522
4524{
4525 0x5f,0x95,0x1f,0x08,0x19,0x44,0xa5,0xab,0x28,0x11,0x51,0x68,0x82,0x9b,0xe4,0xc3,0x04,0x1b,0xc9,0xdc,
4526 0x41,0x2a,0x89,0xd4,0x4a,0x8b,0x86,0xaf,0x98,0x2c,0x59,0x0b,0xd2,0x88,0xf6,0xe8,0x29,0x13,0x84,0x49
4527};
4528
4530{
4531 0x44,0x53,0x50,0x42,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x8f,0xd2,0x92,0xbb,0x92,0xb9,0x00,0xc5,0xed,
4532 0x52,0xcc,0x48,0x4a,0x44,0x1d,0xd3,0x74,0xfb,0x75,0xd1,0x7e,0xb6,0x24,0x9b,0x5d,0x57,0x0a,0x8a,0xc4,
4533 0x5d,0xab,0x9c,0x26,0x86,0xc6,0x25,0x16,0x20,0xf9,0xa9,0x71,0xbc,0x1d,0x30,0xc4,0xef,0x8c,0xc4,0xdf,
4534 0x1a,0xaf,0x96,0xdf,0x90,0xd8,0x85,0x9d,0xf9,0x2c,0x86,0x8c,0x91,0x39,0x6c,0x6d,0x11,0x4e,0x53,0x63,
4535 0x2a,0x2b,0x26,0xa7,0xf9,0x76,0x74,0x51,0xbf,0x08,0x87,0x6f,0xe0,0x71,0x91,0x24,0x8a,0xc2,0x84,0x2d,
4536 0x84,0x9c,0x5f,0x94,0xaa,0x38,0x53,0x77,0x84,0xba,0xbc,0xff,0x49,0x3a,0x08,0x0f,0x38,0xb5,0x91,0x5c,
4537 0x06,0x15,0xa4,0x27,0xf4,0xa5,0x59,0xaa,0x1c,0x41,0xa3,0xa0,0xbb,0xf7,0x32,0x86,0xfb,0x94,0x41,0xff,
4538 0xcd,0xed,0x69,0xeb,0xc6,0x5e,0xb6,0xa8,0x15,0x82,0x3b,0x60,0x1e,0x91,0x55,0xd5,0x2c,0xa5,0x74,0x5a,
4539 0x65,0x8f,0xc6,0x56,0xc4,0x3f,0x4e,0xe3,0x3a,0x71,0xb2,0x63,0x66,0xa4,0x0d,0x0d,0xf9,0xdd,0x1e,0x48,
4540 0x81,0xe9,0xbf,0x8f,0xbb,0x85,0x47,0x81,0x68,0x11,0xb5,0x91,0x6b,0xc4,0x05,0xef,0xa3,0xc7,0xbf,0x26,
4541 0x53,0x4f,0xc4,0x10,0xfd,0xfa,0xed,0x61,0x64,0xd6,0x2e,0xad,0x04,0x3e,0x82,0xed,0xb2,0x22,0x76,0xd0,
4542 0x44,0xad,0xc1,0x4c,0xde,0x33,0xa3,0x61,0x55,0xec,0x24,0xe5,0x79,0x45,0xcf,0x94,0x39,0x92,0x9f,0xd8,
4543 0x24,0xce,0x85,0xb9
4544};
4545
4546static UCHAR dssKey[] =
4547{
4548 0x07,0x02,0x00,0x00,0x00,0x22,0x00,0x00,0x44,0x53,0x53,0x32,0x00,0x04,0x00,0x00,0x01,0xd1,0xfc,0x7a,
4549 0x70,0x53,0xb2,0x48,0x70,0x23,0x19,0x1f,0x3c,0xe1,0x26,0x14,0x7e,0x9f,0x0f,0x7f,0x33,0x5e,0x2b,0xf7,
4550 0xca,0x01,0x74,0x8c,0xb4,0xfd,0xf6,0x44,0x95,0x35,0x56,0xaa,0x4d,0x62,0x48,0xe2,0xd1,0xa2,0x7e,0x6e,
4551 0xeb,0xd6,0xcc,0x7c,0xe8,0xfd,0x21,0x9a,0xa2,0xfd,0x7a,0x9d,0x1a,0x38,0x69,0x87,0x39,0x5a,0x91,0xc0,
4552 0x52,0x2b,0x9f,0x2a,0x54,0x78,0x37,0x82,0x9a,0x70,0x57,0xab,0xec,0x93,0x8e,0xac,0x73,0x04,0xe8,0x53,
4553 0x72,0x72,0x32,0xc6,0xcb,0xef,0x47,0x98,0x3c,0x56,0x49,0x62,0xcb,0xbb,0xe7,0x34,0x84,0xa6,0x72,0x3a,
4554 0xbe,0x26,0x46,0x86,0xca,0xcb,0x35,0x62,0x4f,0x19,0x18,0x0b,0xb0,0x78,0xae,0xd5,0x42,0xdf,0x26,0xdb,
4555 0x85,0x63,0x77,0x85,0x01,0x3b,0x32,0xbe,0x5c,0xf8,0x05,0xc8,0xde,0x17,0x7f,0xb9,0x03,0x82,0xfa,0xf1,
4556 0x9e,0x32,0x73,0xfa,0x8d,0xea,0xa3,0x30,0x48,0xe2,0xdf,0x5a,0xcb,0x83,0x3d,0xff,0x56,0xe9,0xc0,0x94,
4557 0xf8,0x6d,0xb3,0xaf,0x4a,0x97,0xb9,0x43,0x0e,0xd4,0x28,0x98,0x57,0x2e,0x3a,0xca,0xde,0x6f,0x45,0x0d,
4558 0xfb,0x58,0xec,0x78,0x34,0x2e,0x46,0x4d,0xfe,0x98,0x02,0xbb,0xef,0x07,0x1a,0x13,0xb6,0xc2,0x2c,0x06,
4559 0xd9,0x0c,0xc4,0xb0,0x4c,0x3a,0xfc,0x01,0x63,0xb5,0x5a,0x5d,0x2d,0x9c,0x47,0x04,0x67,0x51,0xf2,0x52,
4560 0xf5,0x82,0x36,0xeb,0x6e,0x66,0x58,0x4c,0x10,0x2c,0x29,0x72,0x4a,0x6f,0x6b,0x6c,0xe0,0x93,0x31,0x42,
4561 0xf6,0xda,0xfa,0x5b,0x22,0x43,0x9b,0x1a,0x98,0x71,0xe7,0x41,0x74,0xe9,0x12,0xa4,0x1f,0x27,0x0a,0x63,
4562 0x94,0x49,0xd7,0xad,0xa5,0xc4,0x5c,0xc3,0xc9,0x70,0xb3,0x7b,0x16,0xb6,0x1d,0xd4,0x09,0xc4,0x9a,0x46,
4563 0x2d,0x0e,0x75,0x07,0x31,0x7b,0xed,0x45,0xcd,0x99,0x84,0x14,0xf1,0x01,0x00,0x00,0x93,0xd5,0xa3,0xe4,
4564 0x34,0x05,0xeb,0x98,0x3b,0x5f,0x2f,0x11,0xa4,0xa5,0xc4,0xff,0xfb,0x22,0x7c,0x54
4565};
4566
4567static void test_DSA(void)
4568{
4571 BCRYPT_DSA_KEY_BLOB *dsablob;
4572 UCHAR sig[40], schemes;
4573 ULONG len, size;
4574 NTSTATUS ret;
4575 BYTE *buf, buf2[sizeof(BCRYPT_DSA_KEY_BLOB) + sizeof(dsaPublicBlob)];
4576
4578 ok(!ret, "got %#lx\n", ret);
4579
4580 ret = BCryptGetProperty(alg, L"PaddingSchemes", (UCHAR *)&schemes, sizeof(schemes), &size, 0);
4581 ok(ret == STATUS_NOT_SUPPORTED, "got %#lx\n", ret);
4582
4584 ok(!ret, "got %#lx\n", ret);
4586
4588 ok(!ret, "got %#lx\n", ret);
4589
4590 memset(buf2, 0xcc, sizeof(buf2));
4591 ret = BCryptExportKey(key, NULL, BCRYPT_DSA_PUBLIC_BLOB, buf2, sizeof(buf2), &size, 0);
4592 ok(!ret, "got %#lx\n", ret);
4593 dsablob = (BCRYPT_DSA_KEY_BLOB *)buf2;
4594 ok(dsablob->dwMagic == BCRYPT_DSA_PUBLIC_MAGIC, "got %#lx\n", dsablob->dwMagic);
4595 ok(dsablob->cbKey == 64, "got %lu\n", dsablob->cbKey);
4596 ok(size == sizeof(*dsablob) + dsablob->cbKey * 3, "got %lu\n", size);
4597
4598 ret = BCryptExportKey(key, NULL, BCRYPT_DSA_PRIVATE_BLOB, buf2, sizeof(buf2), &size, 0);
4599 ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
4600
4602 ok(!ret, "got %#lx\n", ret);
4603
4605 ok(!ret, "got %#lx\n", ret);
4606
4607 /* sign/verify with export/import round-trip */
4608 ret = BCryptGenerateKeyPair(alg, &key, 512, 0);
4609 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4610
4612 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4613
4614 len = 0;
4615 memset(sig, 0, sizeof(sig));
4616 ret = BCryptSignHash(key, NULL, dsaHash, sizeof(dsaHash), sig, sizeof(sig), &len, 0);
4617 ok(!ret, "got %#lx\n", ret);
4618 ok(len == 40, "got %lu\n", len);
4619
4620 size = 0;
4622 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4623 ok(size, "size not set\n");
4624
4625 buf = calloc(1, size);
4627 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4628 dsablob = (BCRYPT_DSA_KEY_BLOB *)buf;
4629 ok(dsablob->dwMagic == BCRYPT_DSA_PUBLIC_MAGIC, "got %#lx\n", dsablob->dwMagic);
4630 ok(dsablob->cbKey == 64, "got %lu\n", dsablob->cbKey);
4631 ok(size == sizeof(*dsablob) + dsablob->cbKey * 3, "got %lu\n", size);
4632
4634 ok(!ret, "got %#lx\n", ret);
4635
4637 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4638 free(buf);
4639
4640 ret = BCryptVerifySignature(key, NULL, dsaHash, sizeof(dsaHash), sig, len, 0);
4641 ok(!ret, "got %#lx\n", ret);
4643 ok(!ret, "got %#lx\n", ret);
4644
4646 ok(!ret, "got %#lx\n", ret);
4647
4648 size = 0;
4650 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4651 ok(size, "size not set\n");
4652
4653 buf = calloc(1, size);
4655 ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
4656 ok(size == sizeof(dssKey), "got %lu expected %Iu\n", size, sizeof(dssKey));
4657 ok(!memcmp(dssKey, buf, size), "wrong data\n");
4658 free(buf);
4659
4661 ok(!ret, "got %#lx\n", ret);
4662
4664 ok(!ret, "got %#lx\n", ret);
4665}
4666
4667static void test_SecretAgreement(void)
4668{
4669 static BCryptBuffer hash_param_buffers[] =
4670 {
4671 {
4675 }
4676 };
4677 static BCryptBufferDesc hash_params =
4678 {
4680 ARRAY_SIZE(hash_param_buffers),
4681 hash_param_buffers,
4682 };
4683
4684 static const ULONG dh_private_key[] =
4685 {
4686 0xc4caf69c, 0x57b4db27, 0x36f7135f, 0x5ccba686, 0xc37b8819, 0x1d35c9b2, 0xbb07a1cf, 0x0c5d1c1b,
4687 0xc79acb10, 0x31dfdabb, 0x702e02b9, 0x1efab345, 0x262a8074, 0x5edf7698, 0x9b9dc630, 0x13c34b93,
4688 0xacbc928b, 0xb79eed8c, 0x7413dce9, 0xa5521280, 0x88d8e695, 0xa310269f, 0xca7c5719, 0xcd0c775b,
4689 0x9a6e2cf2, 0x9e235c51, 0xf49db62d, 0x28e72424, 0x4a44da5a, 0x3d98268d, 0x8e4d2be3, 0x254e44e6,
4690
4691 0x18a67e55, 0x572e13a1, 0x46f81ca8, 0xc331c9b9, 0xf8fe3dd4, 0x8a889e5a, 0x6c0505fd, 0xbd97a121,
4692 0xed2dbd67, 0xf39efa8e, 0x36f9c287, 0xf6bbfa6c, 0x461e42ad, 0x17dc170e, 0xc002dc2e, 0x4813d9a4,
4693 0x0b6fabb8, 0x6a9e1860, 0xa8a8cbd9, 0xb7ed6b5d, 0xabb34d23, 0xf2fbe1fd, 0x8670df1e, 0xba7fa4e6,
4694 0xf7039712, 0x94448f30, 0xe10c812e, 0x3e311976, 0xcfdd72c4, 0xbdbea98f, 0xc9a540d6, 0x89646d57,
4695
4696 0x7ab63b33, 0x03a1e9b6, 0x947f7a9b, 0x5ae59eeb, 0x1d12eb05, 0x3f425d92, 0xe028c6ba, 0xbf90ddc9,
4697 0xb554f55a, 0x7aeb88b6, 0x4a443a5f, 0xbab35111, 0x82c78a0c, 0x298dd482, 0x02937cb1, 0xc94cdc2e,
4698 0x59b010eb, 0x3bbc0a2b, 0xd845fee0, 0x04c1d0db, 0x0c8c9424, 0x1cafd4b2, 0x9aa7aed9, 0x6a478486,
4699 0xa8841fd7, 0xbfeff40a, 0x8fd7bcc5, 0x3bb28977, 0x2b9a7955, 0xa55cd2e4, 0x1b6ad657, 0x067cdf21,
4700
4701 0x06f36920, 0x63280e1b, 0xf17d930f, 0xa06e74a8, 0x463b3a6f, 0x2a464507, 0x93f8a982, 0x8f620a7d,
4702 0xeda32d11, 0x9706a6d4, 0x33dce588, 0x75a1c446, 0x048ab567, 0xd735aafa, 0x806f7c1c, 0xdcb9651a,
4703 0x26acf3b4, 0x45f91cc9, 0x2a0de6fc, 0xf3c03d0c, 0xf5aee0aa, 0x3eeaaf36, 0x18ccee61, 0x83faa783,
4704 0x4b2b5250, 0xf4ccea22, 0x5ac0714b, 0x3f0b2bc6, 0x481b13ce, 0x12040ea7, 0x66e0bbed, 0x158e1a67,
4705 };
4706 static const ULONG dh_private_key2[] =
4707 {
4708 0xffffffff, 0xffffffff, 0xa2da0fc9, 0x34c26821, 0x8b62c6c4, 0xd11cdc80, 0x084e0229, 0x74cc678a,
4709 0xa6be0b02, 0x229b133b, 0x79084a51, 0xdd04348e, 0xb31995ef, 0x1b433acd, 0x6d0a2b30, 0x37145ff2,
4710 0x6d35e14f, 0x45c2516d, 0x76b585e4, 0xc67e5e62, 0xe9424cf4, 0x6bed37a6, 0xb65cff0b, 0xedb706f4,
4711 0xfb6b38ee, 0xa59f895a, 0x11249fae, 0xe61f4b7c, 0x51662849, 0x8153e6ec, 0xffffffff, 0xffffffff,
4712
4713 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4714 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4715 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4716 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02000000,
4717
4718 0xa0c3c734, 0xc130c92d, 0x5265abf8, 0xff409f17, 0xbcdce187, 0xff64dae3, 0x170560aa, 0xb2423ed8,
4719 0x9ee5a8b9, 0x92548030, 0x02bba1f9, 0x823e39a4, 0x69c438f5, 0xf91016ac, 0x89bfd166, 0x7f996446,
4720 0x86224203, 0x15bf689c, 0x619354a4, 0x0c1d3a1f, 0x11bcf3d2, 0x58aae029, 0x41c69824, 0x3fafc179,
4721 0xa742747c, 0x60658c7a, 0xd3b0bde4, 0x78d3f08b, 0x6cefa061, 0x33752536, 0xe84d4901, 0x48cd73f4,
4722
4723 0x8d449700, 0x1f95120e, 0xceb31745, 0x3663177b, 0xbd9bb2d5, 0x9c23c0d9, 0x814d34f8, 0xbc54edb0,
4724 0xb874659a, 0x3bac8a30, 0xa1f3dd46, 0x1705c900, 0xbc46fefe, 0x7d13875b, 0x3064351a, 0x4bd89a1c,
4725 0x9e938761, 0x931949db, 0x34490719, 0x84fb08ca, 0xa9dd355a, 0x5b3f5061, 0x2ac96663, 0xc594429e,
4726 0xbe58395d, 0x2f7d872a, 0x303d37b3, 0xa3a9b606, 0x735a6732, 0xa095bd95, 0x3d55a7c3, 0x00e54635,
4727 };
4728 static const ULONG dh_peer_key[] =
4729 {
4730 0xffffffff, 0xffffffff, 0xa2da0fc9, 0x34c26821, 0x8b62c6c4, 0xd11cdc80, 0x084e0229, 0x74cc678a,
4731 0xa6be0b02, 0x229b133b, 0x79084a51, 0xdd04348e, 0xb31995ef, 0x1b433acd, 0x6d0a2b30, 0x37145ff2,
4732 0x6d35e14f, 0x45c2516d, 0x76b585e4, 0xc67e5e62, 0xe9424cf4, 0x6bed37a6, 0xb65cff0b, 0xedb706f4,
4733 0xfb6b38ee, 0xa59f895a, 0x11249fae, 0xe61f4b7c, 0x51662849, 0x8153e6ec, 0xffffffff, 0xffffffff,
4734
4735 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4736 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4737 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4738 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02000000,
4739
4740 0x3bf7404b, 0x6284fffe, 0x97c0d565, 0xd830c658, 0xcc21bf39, 0xcae45bb6, 0x019df7df, 0xbf4cd293,
4741 0x6bf1989d, 0x78a81f52, 0xa4ed861c, 0x6bacf493, 0xa3e700d1, 0xd06cc206, 0x411b9727, 0x01e9c9ab,
4742 0x9b7e6efa, 0xf46bb25d, 0xd1027242, 0x6130787c, 0xa7b87d8b, 0xfee41492, 0x50db6213, 0x321199b6,
4743 0x7dace53a, 0xe8b1ec51, 0x2181b113, 0x3b33e3c0, 0x5b3a2d67, 0xbd34f0c1, 0x7037c542, 0x4a8d5540,
4744 };
4745 static const ULONG dh_shared_secret_raw[] =
4746 {
4747 0x375d89b5, 0x35a9c270, 0xfbc5ba82, 0x09eb3069, 0xd50965b0, 0xace510f7, 0x981e8731, 0x80a76115,
4748 0xf386d348, 0xca17b8df, 0x0b0e84ec, 0xf81f756e, 0x5030fa20, 0x03113b71, 0x97b7e879, 0x899b5fae,
4749 0xe6913299, 0x09270076, 0x39bc813a, 0xde3ef070, 0x65ad5b3a, 0x2b7c4ba4, 0x86c98ef9, 0x3236feaf,
4750 0x3e0253f7, 0x0489d2dd, 0x97669a3d, 0x50242fca, 0x5d4aecb1, 0xcf2d805f, 0x2258afff, 0x750e92cd,
4751 };
4752 static const ULONG dh_shared_secret_raw2[] =
4753 {
4754 0x0815f37d, 0x19ee74ab, 0x9f63f123, 0xe1b3f10c, 0xbcc9be83, 0xaddf5b9d, 0x28174e72, 0xf8a33825,
4755 0xfc74e47d, 0x2c950888, 0xf5b776d9, 0xfc712fef, 0x5b213b32, 0x489a9829, 0xfc0a4d1d, 0x6e641d3b,
4756 0x3bb2ff57, 0x63500318, 0x081ee54f, 0xf33a2805, 0xb3759e98, 0xa9a64afe, 0x964b8897, 0x04691bbc,
4757 0x80f4aae1, 0x617405ee, 0xab71724d, 0x6c10c214, 0x6f60b96f, 0xdc777b0b, 0x22f40d4f, 0x8a1c4eb5,
4758 };
4759 static const ULONG dh_shared_secret_sha1[] =
4760 {
4761 0x0babba9c, 0x0bdeacbd, 0x04e36574, 0xdd504dcd, 0x0cd88db0,
4762 };
4763 static const ULONG dh_shared_secret_sha256[] =
4764 {
4765 0x3213db5b, 0x8cc8250b, 0xc829eaab, 0x00933709, 0x68160aa9, 0xfb9f1e20, 0xf92368e6, 0x2b8e18eb,
4766 };
4767 static const struct
4768 {
4769 const WCHAR *alg;
4770 ULONG bitlen;
4771 }
4772 ecdh_algorithms[] =
4773 {
4777 };
4778 static const ULONG length = 1024;
4779 BCRYPT_DH_PARAMETER_HEADER *dh_header;
4780 BCRYPT_DH_KEY_BLOB *dh_key_blob;
4784 UCHAR buffer[2048];
4786 ULONG size, i;
4787
4788 for (i = 0; i < ARRAY_SIZE(ecdh_algorithms); ++i)
4789 {
4790 winetest_push_context("%s", debugstr_w(ecdh_algorithms[i].alg));
4791 status = BCryptOpenAlgorithmProvider(&alg, ecdh_algorithms[i].alg, NULL, 0);
4792 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4793
4794 key = NULL;
4795 status = BCryptGenerateKeyPair(alg, &key, ecdh_algorithms[i].bitlen, 0);
4796 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4797 ok(key != NULL, "key not set\n");
4798
4800 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4801
4803 ok(status == STATUS_INVALID_HANDLE, "got %#lx\n", status);
4804
4806 ok(status == STATUS_INVALID_HANDLE, "got %#lx\n", status);
4807
4809 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
4810
4812 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4813
4814 status = BCryptDeriveKey(NULL, L"HASH", NULL, NULL, 0, &size, 0);
4815 ok(status == STATUS_INVALID_HANDLE, "got %#lx\n", status);
4816
4817 status = BCryptDeriveKey(key, L"HASH", NULL, NULL, 0, &size, 0);
4818 ok(status == STATUS_INVALID_HANDLE, "got %#lx\n", status);
4819
4821 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
4822
4823 status = BCryptDeriveKey(secret, L"HASH", NULL, NULL, 0, &size, 0);
4824 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4825
4827 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
4828
4830 ok(status == STATUS_INVALID_HANDLE, "got %#lx\n", status);
4831
4833 ok(status == STATUS_INVALID_HANDLE, "got %#lx\n", status);
4834
4836 ok(status == STATUS_INVALID_HANDLE, "got %#lx\n", status);
4837
4839 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4840
4842 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4843
4845 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4847 }
4848
4849 /* DH */
4851 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4852
4853 key = NULL;
4854 status = BCryptGenerateKeyPair(alg, &key, 1024, 0);
4855 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4856 ok(key != NULL, "key not set\n");
4857
4860 {
4861 win_skip("broken DH detected\n");
4863 return;
4864 }
4865 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4866
4868 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4869
4871 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4872
4873 status = BCryptDeriveKey(secret, L"HASH", NULL, NULL, 0, &size, 0);
4874 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4875
4877 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
4878
4879 key = NULL;
4880 status = BCryptGenerateKeyPair(alg, &key, 256, 0);
4881 ok(status == STATUS_INVALID_PARAMETER, "got %08lx\n", status);
4882
4884 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4885 ok(key != NULL, "key not set\n");
4886
4887 memset(buffer, 0xcc, sizeof(buffer));
4889 ok(status == STATUS_INVALID_HANDLE, "got %08lx\n", status);
4890
4892 ok(status == STATUS_INVALID_HANDLE, "got %08lx\n", status);
4893
4895 if (status != STATUS_SUCCESS)
4896 {
4899 return;
4900 }
4901 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4902
4904 ok(status == STATUS_INVALID_HANDLE, "got %08lx\n", status);
4905
4906 size = 0xdeadbeef;
4908 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4909 ok(size == sizeof(BCRYPT_DH_PARAMETER_HEADER) + length / 8 * 2, "Got unexpected size %lu.\n", size);
4910
4911 size = 0xdeadbeef;
4913 ok(status == STATUS_BUFFER_TOO_SMALL, "got %08lx\n", status);
4914 ok(size == sizeof(BCRYPT_DH_PARAMETER_HEADER) + length / 8 * 2, "Got unexpected size %lu.\n", size);
4915
4916 size = 0xdeadbeef;
4918 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4919 ok(size == sizeof(BCRYPT_DH_PARAMETER_HEADER) + length / 8 * 2, "Got unexpected size %lu.\n", size);
4920
4921 dh_header = (BCRYPT_DH_PARAMETER_HEADER *)buffer;
4922 ok(dh_header->cbLength == sizeof(*dh_header) + length / 8 * 2, "Got unexpected length %lu.\n", dh_header->cbLength);
4923 ok(dh_header->cbKeyLength == length / 8, "Got unexpected length %lu.\n", dh_header->cbKeyLength);
4924 ok(dh_header->dwMagic == BCRYPT_DH_PARAMETERS_MAGIC, "Got unexpected magic %#lx.\n", dh_header->dwMagic);
4925
4927 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4928
4929 dh_key_blob = (BCRYPT_DH_KEY_BLOB *)buffer;
4930 dh_key_blob->dwMagic = BCRYPT_DH_PRIVATE_MAGIC;
4931 dh_key_blob->cbKey = length / 8;
4932 memcpy(dh_key_blob + 1, dh_private_key, sizeof(dh_private_key));
4933 size = sizeof(buffer);
4935 ok(status == STATUS_INVALID_PARAMETER, "got %08lx\n", status);
4936 size = sizeof(*dh_key_blob) + length / 8 * 4;
4938 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4939
4940 memset(buffer, 0xcc, sizeof(buffer));
4941 size = 0xdeadbeef;
4943 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4944 ok(size == sizeof(BCRYPT_DH_KEY_BLOB) + length / 8 * 3, "Got unexpected size %lu.\n", size);
4945
4946 size = 0xdeadbeef;
4948 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4949 ok(size == sizeof(BCRYPT_DH_KEY_BLOB) + length / 8 * 3, "Got unexpected size %lu.\n", size);
4950 dh_key_blob = (BCRYPT_DH_KEY_BLOB *)buffer;
4951 ok(dh_key_blob->dwMagic == BCRYPT_DH_PUBLIC_MAGIC, "Got unexpected magic %#lx.\n", dh_key_blob->dwMagic);
4952 ok(dh_key_blob->cbKey == length / 8, "Got unexpected length %lu.\n", dh_key_blob->cbKey);
4953 ok(!memcmp(dh_key_blob + 1, dh_private_key, length / 8 * 3), "Key data does not match.\n");
4954
4956 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4957 dh_header = (BCRYPT_DH_PARAMETER_HEADER *)buffer;
4959 dh_header->cbLength = sizeof(*dh_header) + length / 8 * 2;
4960 dh_header->cbKeyLength = length / 8;
4961 memcpy(dh_header + 1, dh_private_key, length / 8 * 2);
4963 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4965 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4966
4968 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4969 ok(size == sizeof(BCRYPT_DH_KEY_BLOB) + length / 8 * 3, "Got unexpected size %lu.\n", size);
4970 ok(dh_key_blob->dwMagic == BCRYPT_DH_PUBLIC_MAGIC, "Got unexpected dwMagic %#lx.\n", dh_key_blob->dwMagic);
4971 ok(dh_key_blob->cbKey == length / 8, "Got unexpected length %lu.\n", dh_key_blob->cbKey);
4972 ok(!memcmp(dh_key_blob + 1, dh_private_key, length / 8 * 2), "DH parameters do not match.\n");
4973 ok(memcmp((BYTE *)(dh_key_blob + 1) + length / 8 * 2, (BYTE *)dh_private_key + length / 8 * 2, length / 8),
4974 "Random public key data matches.\n");
4975
4976 memset(buffer, 0xcc, sizeof(buffer));
4978 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4979 dh_key_blob = (BCRYPT_DH_KEY_BLOB *)buffer;
4980 ok(size == sizeof(BCRYPT_DH_KEY_BLOB) + length / 8 * 4, "Got unexpected size %lu.\n", size);
4981 ok(dh_key_blob->dwMagic == BCRYPT_DH_PRIVATE_MAGIC, "Got unexpected dwMagic %#lx.\n", dh_key_blob->dwMagic);
4982 ok(dh_key_blob->cbKey == length / 8, "Got unexpected length %lu.\n", dh_key_blob->cbKey);
4983 ok(!memcmp(dh_key_blob + 1, dh_private_key, length / 8 * 4), "Private key data does not match.\n");
4984
4986 ok(status == STATUS_INVALID_HANDLE, "got %08lx\n", status);
4987
4989 ok(status == STATUS_INVALID_HANDLE, "got %08lx\n", status);
4990
4992 ok(status == STATUS_INVALID_PARAMETER, "got %08lx\n", status);
4993
4995 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
4996
4997 status = BCryptDeriveKey(NULL, L"HASH", NULL, NULL, 0, &size, 0);
4998 ok(status == STATUS_INVALID_HANDLE, "got %08lx\n", status);
4999
5000 status = BCryptDeriveKey(key, L"HASH", NULL, NULL, 0, &size, 0);
5001 ok(status == STATUS_INVALID_HANDLE, "got %08lx\n", status);
5002
5004 ok(status == STATUS_INVALID_PARAMETER, "got %08lx\n", status);
5005
5006 size = 0xdeadbeef;
5007 status = BCryptDeriveKey(secret, L"HASH", NULL, NULL, 0, &size, 0);
5008 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5009 ok(size == 20, "Got unexpected size %lu.\n", size);
5010
5011 size = 0xdeadbeef;
5013 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5014 ok(size == length / 8, "Got unexpected size %lu.\n", size);
5015
5017 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5018 ok(size == length / 8, "Got unexpected size %lu.\n", size);
5019 ok(!memcmp(buffer, dh_shared_secret_raw, size), "Raw shared secret data does not match.\n");
5020
5021 size = sizeof(buffer);
5022 memset(buffer, 0xcc, sizeof(buffer));
5024 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5025 ok(size == 20, "Got unexpected size %lu.\n", size);
5026 ok(!memcmp(buffer, dh_shared_secret_sha1, sizeof(dh_shared_secret_sha1)),
5027 "sha1 shared secret data does not match.\n");
5028
5029 size = sizeof(buffer);
5030 status = BCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, buffer, size, &size, 0);
5031 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5032 ok(size == 32, "Got unexpected size %lu.\n", size);
5033 ok(!memcmp(buffer, dh_shared_secret_sha256, sizeof(dh_shared_secret_sha256)),
5034 "sha256 shared secret data does not match.\n");
5035
5036 for (i = size; i < sizeof(buffer); ++i)
5037 if (buffer[i] != 0xcc) break;
5038 ok(i == sizeof(buffer), "Buffer modified at %lu, value %#x.\n", i, buffer[i]);
5039
5041 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5042
5044 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5046 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5047
5049 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5051 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5052 ok(!memcmp(buffer, buffer + size, size), "Shared secrets do not match.\n");
5053
5055 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5057 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5058
5060 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5062 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5063
5064 dh_key_blob = (BCRYPT_DH_KEY_BLOB *)buffer;
5065 dh_key_blob->dwMagic = BCRYPT_DH_PRIVATE_MAGIC;
5066 dh_key_blob->cbKey = length / 8;
5067 memcpy(dh_key_blob + 1, dh_private_key2, sizeof(dh_private_key2));
5068
5069 size = sizeof(*dh_key_blob) + length / 8 * 4;
5071 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5072
5073 dh_key_blob = (BCRYPT_DH_KEY_BLOB *)buffer;
5074 dh_key_blob->dwMagic = BCRYPT_DH_PUBLIC_MAGIC;
5075 dh_key_blob->cbKey = length / 8;
5076 memcpy(dh_key_blob + 1, dh_peer_key, sizeof(dh_peer_key));
5077
5078 size = sizeof(*dh_key_blob) + length / 8 * 3;
5080 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5081
5083 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5084
5086 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5087 ok(size == length / 8, "Got unexpected size %lu.\n", size);
5088 ok(!memcmp(buffer, dh_shared_secret_raw2, size), "Raw shared secret data does not match.\n");
5089
5091 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5093 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5095 ok(status == STATUS_SUCCESS, "got %08lx\n", status);
5096
5098 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5099}
5100
5101static void test_RC4(void)
5102{
5105 ULONG len, size;
5106
5108 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5109
5110 len = size = 0;
5112 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5113 ok(len, "expected non-zero len\n");
5114 ok(size == sizeof(len), "got %lu\n", size);
5115
5116 len = size = 0;
5118 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5119 ok(len == 1, "got %lu\n", len);
5120 ok(size == sizeof(len), "got %lu\n", size);
5121
5122 size = sizeof(BCRYPT_CHAIN_MODE_NA);
5124 ok(!status, "got %#lx\n", status);
5125
5127 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5128}
5129
5130static void test_PBKDF2(void)
5131{
5132 static char salt[] = "cCxuHMEHLibcglJOG88dIw==";
5133 static ULONGLONG iter_count = 25;
5134 static BCryptBuffer pbkdf2_param_buffers[] =
5135 {
5136 {
5137 sizeof(BCRYPT_SHA1_ALGORITHM),
5139 (void *)BCRYPT_SHA1_ALGORITHM,
5140 },
5141 {
5142 sizeof(salt) - 1,
5143 KDF_SALT,
5144 salt,
5145 },
5146 {
5147 sizeof(iter_count),
5149 (void *)&iter_count,
5150 }
5151 };
5152 static BCryptBufferDesc pbkdf2_params =
5153 {
5155 ARRAY_SIZE(pbkdf2_param_buffers),
5156 pbkdf2_param_buffers,
5157 };
5158 static UCHAR pbkdf2_hash[] =
5159 {
5160 0x18, 0xf2, 0x58, 0x0b, 0x92, 0x6e, 0x6d, 0xfe,
5161 0x55, 0xbb, 0x62, 0x87, 0x5b, 0x1f, 0x61, 0x83,
5162 0x4d, 0x16, 0xe4, 0x04, 0xcd, 0xab, 0x43, 0x77,
5163 0x25, 0x3e, 0x1d, 0xb4, 0x95, 0x5f, 0xf7, 0x01,
5164 };
5165 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
5169 ULONG val, size;
5170 static BYTE buf[32];
5171
5173 if (status == STATUS_NOT_FOUND)
5174 {
5175 win_skip("PBKDF2 not available\n");
5176 return;
5177 }
5178 ok(!status, "got %#lx\n", status);
5179
5180 val = size = 0;
5182 ok(!status, "got %#lx\n", status);
5183 ok(val, "got %lu\n", val);
5184 ok(size == sizeof(val), "got %lu\n", size);
5185
5186 val = size = 0;
5188 ok(status == STATUS_NOT_SUPPORTED, "got %#lx\n", status);
5189
5190 memset(&key_lengths, 0xfe, sizeof(key_lengths));
5191 size = 0;
5192 status = BCryptGetProperty(alg, BCRYPT_KEY_LENGTHS, (UCHAR *)&key_lengths, sizeof(key_lengths), &size, 0);
5193 ok(!status, "got %#lx\n", status);
5194 ok(size == sizeof(key_lengths), "got %lu\n", size);
5195 ok(key_lengths.dwMinLength == 0, "got %lu\n", key_lengths.dwMinLength);
5196 ok(key_lengths.dwMaxLength == 16384, "got %lu\n", key_lengths.dwMaxLength);
5197 ok(key_lengths.dwIncrement == 8, "got %lu\n", key_lengths.dwIncrement);
5198
5199 key = 0;
5200 status = BCryptGenerateSymmetricKey(alg, &key, NULL, 0, (UCHAR *)"test", 4, 0);
5201 ok(!status, "got %#lx\n", status);
5202 val = size = 0;
5204 ok(!status, "got %#lx\n", status);
5205 ok(val == strlen("test") * 8, "got %lu\n", val);
5206
5207 status = BCryptKeyDerivation(key, &pbkdf2_params, NULL, 0, &size, 0);
5208 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
5209
5210 buf[0] = buf[1] = 'x';
5211 status = BCryptKeyDerivation(key, &pbkdf2_params, buf, 1, &size, 0);
5212 ok(!status, "got %#lx\n", status);
5213 ok(size == 1, "size = %lu\n", size);
5214 ok(buf[0] == pbkdf2_hash[0], "buf[0] = %x\n", buf[0]);
5215 ok(buf[1] == 'x', "buf[1] = %x\n", buf[1]);
5216
5217 memset(buf, 'x', sizeof(buf));
5218 status = BCryptKeyDerivation(key, &pbkdf2_params, buf, sizeof(buf), &size, 0);
5219 ok(!status, "got %#lx\n", status);
5220 ok(size == sizeof(buf), "size = %lu\n", size);
5221 ok(!memcmp(buf, pbkdf2_hash, sizeof(pbkdf2_hash)),
5222 "wrong data (%s)\n", wine_dbgstr_an((char *)buf, size));
5223
5225 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5226
5228 ok(!status, "got %#lx\n", status);
5230 ok(!status, "got %#lx\n", status);
5232 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5233}
5234
5235static void test_TLS_PRF(void)
5236{
5237 static const UCHAR expect[32] =
5238 {
5239 0x28,0xd2,0xfd,0xb7,0x19,0x56,0x47,0x9d,0x88,0xd1,0x13,0x50,0x01,0x08,0x40,0x8e,
5240 0xfa,0xb3,0x92,0x80,0xe4,0xe2,0x6a,0x2a,0xd0,0xe6,0xac,0x39,0x80,0x18,0xeb,0x30
5241 };
5242 static const UCHAR expect2[32] =
5243 {
5244 0x33,0x63,0x83,0x14,0x8c,0x50,0x48,0x99,0x63,0x7b,0xc0,0x33,0x81,0xb1,0x0e,0x4f,
5245 0x5c,0x27,0xe3,0xe8,0x23,0xa8,0xb3,0xe8,0x52,0x96,0x47,0xa5,0xf8,0xca,0x17,0x24
5246 };
5247 static UCHAR label[32] = "label", seed[32] = "seed", buf[32];
5248 static BCryptBuffer param_buffers[] =
5249 {
5250 {
5254 },
5255 {
5256 sizeof(label),
5258 label,
5259 },
5260 {
5261 sizeof(seed),
5263 seed,
5264 }
5265 };
5266 static BCryptBufferDesc params =
5267 {
5269 ARRAY_SIZE(param_buffers),
5270 param_buffers,
5271 };
5275 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
5276 ULONG len, size;
5277
5279 if (status == STATUS_NOT_FOUND) /* win8 */
5280 {
5281 win_skip("BCRYPT_TLS1_1_KDF_ALGORITHM not available\n");
5282 return;
5283 }
5284 ok(!status, "got %#lx\n", status);
5285
5286 len = size = 0;
5288 ok(!status, "got %#lx\n", status);
5289 ok(len, "got %lu\n", len);
5290 ok(size == sizeof(len), "got %lu\n", size);
5291
5292 len = size = 0;
5294 ok(status == STATUS_NOT_SUPPORTED, "got %#lx\n", status);
5295
5296 memset(&key_lengths, 0xfe, sizeof(key_lengths));
5297 size = 0;
5298 status = BCryptGetProperty(alg, BCRYPT_KEY_LENGTHS, (UCHAR *)&key_lengths, sizeof(key_lengths), &size, 0);
5299 ok(!status, "got %#lx\n", status);
5300 ok(size == sizeof(key_lengths), "got %lu\n", size);
5301 ok(key_lengths.dwMinLength == 0, "got %lu\n", key_lengths.dwMinLength);
5302 ok(key_lengths.dwMaxLength == 16384, "got %lu\n", key_lengths.dwMaxLength);
5303 ok(key_lengths.dwIncrement == 8, "got %lu\n", key_lengths.dwIncrement);
5304
5305 status = BCryptGenerateSymmetricKey(alg, &key, NULL, 0, (UCHAR *)"test", 4, 0);
5306 ok(!status, "got %#lx\n", status);
5307
5308 len = size = 0;
5310 ok(!status, "got %#lx\n", status);
5311 ok(len == strlen("test") * 8, "got %lu\n", len);
5312
5314 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
5315
5316 buf[0] = buf[1] = 'x';
5318 ok(!status, "got %#lx\n", status);
5319 ok(size == 1, "size = %lu\n", size);
5320 ok(buf[0] == expect[0], "buf[0] = %x\n", buf[0]);
5321 ok(buf[1] == 'x', "buf[1] = %x\n", buf[1]);
5322
5323 memset(buf, 'x', sizeof(buf));
5324 status = BCryptKeyDerivation(key, &params, buf, sizeof(buf), &size, 0);
5325 ok(!status, "got %#lx\n", status);
5326 ok(size == sizeof(buf), "size = %lu\n", size);
5327 ok(!memcmp(buf, expect, sizeof(expect)), "wrong data (%s)\n", wine_dbgstr_an((char *)buf, size));
5328
5330 ok(!status, "got %#lx\n", status);
5331
5333 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5334
5336 ok(!status, "got %#lx\n", status);
5337
5338 status = BCryptGenerateSymmetricKey(alg, &key, NULL, 0, (UCHAR *)"test", 4, 0);
5339 ok(!status, "got %#lx\n", status);
5340
5342 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
5343
5344 buf[0] = buf[1] = 'x';
5346 ok(!status, "got %#lx\n", status);
5347 ok(size == 1, "size = %lu\n", size);
5348 ok(buf[0] == expect2[0], "buf[0] = %x\n", buf[0]);
5349 ok(buf[1] == 'x', "buf[1] = %x\n", buf[1]);
5350
5351 memset(buf, 'x', sizeof(buf));
5352 status = BCryptKeyDerivation(key, &params, buf, sizeof(buf), &size, 0);
5353 ok(!status, "got %#lx\n", status);
5354 ok(size == sizeof(buf), "size = %lu\n", size);
5355 ok(!memcmp(buf, expect2, sizeof(expect2)), "wrong data\n");
5356
5357 /* label is optional */
5358 param_buffers[1].cbBuffer = 0;
5359 param_buffers[1].pvBuffer = NULL;
5360 status = BCryptKeyDerivation(key, &params, buf, sizeof(buf), &size, 0);
5361 ok(!status, "got %#lx\n", status);
5362
5364 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5365
5367 ok(!status, "got %#lx\n", status);
5369 ok(!status, "got %#lx\n", status);
5371 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5372}
5373
5374static void test_HKDF(void)
5375{
5376 static const UCHAR expect[] =
5377 {
5378 0x9e,0xc7,0x96,0xeb,0x03,0xf9,0xbd,0xaa,0xfa,0x68,0x90,0x1c,0x7b,0x71,0x20,0xda,
5379 0x88,0xf1,0xc2,0x15,0x07,0xaf,0xc6,0xde,0x1a,0x86,0xb5,0x6e,0x96,0xe9,0x7d,0x7a
5380 };
5381 static const UCHAR expect2[] =
5382 {
5383 0x54,0xe0,0x42,0xd2,0x92,0xc8,0x02,0x02,0x14,0xae,0x57,0xe8,0x7e,0x67,0x32,0xd7,
5384 0x46,0x90,0xca,0x7b,0xef,0x5a,0x62,0x74,0x90,0x8f,0x1e,0x99,0x20,0x04,0x1e,0x27
5385 };
5386 static const UCHAR expect3[] =
5387 {
5388 0xb5,0x12,0x7d,0x38,0x03,0x6a,0x64,0xd0,0x76,0xde,0x48,0xe2,0xa0,0x7a,0x4f,0x3d,
5389 0x6f,0xc8,0x55,0xab,0xf5,0x14,0x66,0x5d,0xd6,0x02,0x1c,0x28,0x75,0xe7,0xdc,0x96
5390 };
5391 UCHAR buf[32], salt[] = "salt";
5392 static BCryptBuffer param_buffers[] =
5393 {
5394 {
5395 sizeof("info"),
5397 (void *)"info",
5398 },
5399 };
5400 static BCryptBufferDesc params =
5401 {
5403 ARRAY_SIZE(param_buffers),
5404 param_buffers,
5405 };
5409 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
5410 ULONG len, size;
5411
5413 if (status == STATUS_NOT_FOUND) /* win8 */
5414 {
5415 win_skip("BCRYPT_HKDF_ALGORITHM not available\n");
5416 return;
5417 }
5418 ok(!status, "got %#lx\n", status);
5419
5420 len = size = 0;
5422 ok(!status, "got %#lx\n", status);
5423 ok(len, "got %lu\n", len);
5424 ok(size == sizeof(len), "got %lu\n", size);
5425
5426 len = size = 0;
5428 ok(status == STATUS_NOT_SUPPORTED, "got %#lx\n", status);
5429
5430 memset(&key_lengths, 0xfe, sizeof(key_lengths));
5431 size = 0;
5432 status = BCryptGetProperty(alg, BCRYPT_KEY_LENGTHS, (UCHAR *)&key_lengths, sizeof(key_lengths), &size, 0);
5433 ok(!status, "got %#lx\n", status);
5434 ok(size == sizeof(key_lengths), "got %lu\n", size);
5435 ok(key_lengths.dwMinLength == 0, "got %lu\n", key_lengths.dwMinLength);
5436 ok(key_lengths.dwMaxLength == 16384, "got %lu\n", key_lengths.dwMaxLength);
5437 ok(key_lengths.dwIncrement == 8, "got %lu\n", key_lengths.dwIncrement);
5438
5439 /* salt, info */
5440 status = BCryptGenerateSymmetricKey(alg, &key, NULL, 0, (UCHAR *)"test", 4, 0);
5441 ok(!status, "got %#lx\n", status);
5442
5443 len = size = 0;
5445 ok(!status, "got %#lx\n", status);
5446 ok(len == strlen("test") * 8, "got %lu\n", len);
5447
5448 size = sizeof(BCRYPT_SHA256_ALGORITHM);
5450 ok(!status, "got %#lx\n", status);
5451
5453 ok(!status, "got %#lx\n", status);
5454
5456 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
5457
5458 buf[0] = buf[1] = 'x';
5460 ok(!status, "got %#lx\n", status);
5461 ok(size == 1, "size = %lu\n", size);
5462 ok(buf[0] == expect[0], "buf[0] = %x\n", buf[0]);
5463 ok(buf[1] == 'x', "buf[1] = %x\n", buf[1]);
5464
5465 memset(buf, 'x', sizeof(buf));
5466 status = BCryptKeyDerivation(key, &params, buf, sizeof(buf), &size, 0);
5467 ok(!status, "got %#lx\n", status);
5468 ok(size == sizeof(buf), "size = %lu\n", size);
5469 ok(!memcmp(buf, expect, sizeof(expect)), "wrong data (%s)\n", wine_dbgstr_an((char *)buf, size));
5470
5472 ok(!status, "got %#lx\n", status);
5473
5474 /* no salt, info */
5475 status = BCryptGenerateSymmetricKey(alg, &key, NULL, 0, (UCHAR *)"test", 4, 0);
5476 ok(!status, "got %#lx\n", status);
5477
5478 len = size = 0;
5480 ok(!status, "got %#lx\n", status);
5481 ok(len == strlen("test") * 8, "got %lu\n", len);
5482
5483 size = sizeof(BCRYPT_SHA256_ALGORITHM);
5485 ok(!status, "got %#lx\n", status);
5486
5488 ok(!status, "got %#lx\n", status);
5489
5491 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
5492
5493 buf[0] = buf[1] = 'x';
5495 ok(!status, "got %#lx\n", status);
5496 ok(size == 1, "size = %lu\n", size);
5497 ok(buf[0] == expect2[0], "buf[0] = %x\n", buf[0]);
5498 ok(buf[1] == 'x', "buf[1] = %x\n", buf[1]);
5499
5500 memset(buf, 'x', sizeof(buf));
5501 status = BCryptKeyDerivation(key, &params, buf, sizeof(buf), &size, 0);
5502 ok(!status, "got %#lx\n", status);
5503 ok(size == sizeof(buf), "size = %lu\n", size);
5504 ok(!memcmp(buf, expect2, sizeof(expect2)), "wrong data (%s)\n", wine_dbgstr_an((char *)buf, size));
5505
5507 ok(!status, "got %#lx\n", status);
5508
5509 /* salt, no info */
5510 status = BCryptGenerateSymmetricKey(alg, &key, NULL, 0, (UCHAR *)"test", 4, 0);
5511 ok(!status, "got %#lx\n", status);
5512
5513 len = size = 0;
5515 ok(!status, "got %#lx\n", status);
5516 ok(len == strlen("test") * 8, "got %lu\n", len);
5517
5518 size = sizeof(BCRYPT_SHA256_ALGORITHM);
5520 ok(!status, "got %#lx\n", status);
5521
5523 ok(!status, "got %#lx\n", status);
5524
5526 ok(status == STATUS_INVALID_PARAMETER, "got %#lx\n", status);
5527
5528 buf[0] = buf[1] = 'x';
5530 ok(!status, "got %#lx\n", status);
5531 ok(size == 1, "size = %lu\n", size);
5532 ok(buf[0] == expect3[0], "buf[0] = %x\n", buf[0]);
5533 ok(buf[1] == 'x', "buf[1] = %x\n", buf[1]);
5534
5535 memset(buf, 'x', sizeof(buf));
5536 status = BCryptKeyDerivation(key, NULL, buf, sizeof(buf), &size, 0);
5537 ok(!status, "got %#lx\n", status);
5538 ok(size == sizeof(buf), "size = %lu\n", size);
5539 ok(!memcmp(buf, expect3, sizeof(expect3)), "wrong data (%s)\n", wine_dbgstr_an((char *)buf, size));
5540
5542 ok(!status, "got %#lx\n", status);
5544 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5545}
5546
5547static void test_CHACHA20_POLY1305(void)
5548{
5551 ULONG len, size;
5552
5554 if (status == STATUS_NOT_FOUND)
5555 {
5556 win_skip("CHACHA20_POLY1305 not supported\n");
5557 return;
5558 }
5559 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5560
5561 len = size = 0;
5563 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5564 ok(len, "expected non-zero len\n");
5565 ok(size == sizeof(len), "got %lu\n", size);
5566
5567 len = size = 0;
5569 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5570 ok(len == 1, "got %lu\n", len);
5571 ok(size == sizeof(len), "got %lu\n", size);
5572
5573 size = sizeof(BCRYPT_CHAIN_MODE_NA);
5575 ok(!status, "got %#lx\n", status);
5576
5578 ok(status == STATUS_SUCCESS, "got %#lx\n", status);
5579}
5580
5582{
5584
5585 module = LoadLibraryA("bcrypt.dll");
5586 if (!module)
5587 {
5588 win_skip("bcrypt.dll not found\n");
5589 return;
5590 }
5591 pBCryptHash = (void *)GetProcAddress(module, "BCryptHash");
5592
5595 test_hashes();
5598 test_rng();
5599 test_3des();
5600 test_aes();
5605 test_ECDSA();
5606 test_RSA();
5607 test_RSA_SIGN();
5608 test_ECDH();
5609 test_DH();
5616 test_DSA();
5619 test_RC4();
5620 test_PBKDF2();
5621 test_TLS_PRF();
5622 test_HKDF();
5624
5626}
#define expect(EXPECTED, GOT)
Definition: SystemMenu.c:483
unsigned char BOOLEAN
Definition: actypes.h:127
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
#define InterlockedIncrement
Definition: armddk.h:53
#define ok(value,...)
Definition: atltest.h:57
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
#define ok_(x1, x2)
Definition: atltest.h:61
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAY_SIZE(A)
Definition: main.h:20
static void test_BCryptDecrypt(void)
Definition: bcrypt.c:1720
static void test_HKDF(void)
Definition: bcrypt.c:5374
static void test_key_import_export(void)
Definition: bcrypt.c:2127
static UCHAR long_password[]
Definition: bcrypt.c:496
static UCHAR rsaFullPrivateBlob[]
Definition: bcrypt.c:2609
static BYTE dh_hashed_secret_prepended[]
Definition: bcrypt.c:3868
static BYTE rsapublic[]
Definition: bcrypt.c:4104
static void test_DH(void)
Definition: bcrypt.c:3914
RSAPUBKEY rsapubkey
Definition: bcrypt.c:2636
static void test_aes_vector_property(void)
Definition: bcrypt.c:4352
static BYTE cert521Signature[]
Definition: bcrypt.c:2290
static BYTE ecc521Privkey[]
Definition: bcrypt.c:2246
static BYTE eccPrivkey[]
Definition: bcrypt.c:2234
static void test_ECDH(void)
Definition: bcrypt.c:3552
ULONG pwd_len
Definition: bcrypt.c:511
static void test_BCryptEnumAlgorithms(void)
Definition: bcrypt.c:4253
static LONG encrypt_race_start_barrier
Definition: bcrypt.c:994
static struct @1910 rsaLegacyPrivateBlob
static void test_BCryptGenRandom(void)
Definition: bcrypt.c:33
static UCHAR dk3[]
Definition: bcrypt.c:503
static void test_aes_vector(void)
Definition: bcrypt.c:4290
#define test_hash_block_length(a, b)
Definition: bcrypt.c:169
BCryptBuffer dh_hash_param_buffers_prepended[]
Definition: bcrypt.c:3882
static void test_ECDSA(void)
Definition: bcrypt.c:2303
static void test_BcryptHash(void)
Definition: bcrypt.c:431
BCryptBufferDesc dh_hash_params
Definition: bcrypt.c:3901
ULONGLONG iterations
Definition: bcrypt.c:513
static void test_DSA(void)
Definition: bcrypt.c:4567
const UCHAR * dk
Definition: bcrypt.c:517
static UCHAR dsaSignature[]
Definition: bcrypt.c:4523
PUBLICKEYSTRUC header
Definition: bcrypt.c:2635
UCHAR * pwd
Definition: bcrypt.c:515
static void test_BCryptGetFipsAlgorithmMode(void)
Definition: bcrypt.c:75
static void test_ECDH_alg(const struct ecdh_test *t)
Definition: bcrypt.c:3356
BYTE exp2[512/16]
Definition: bcrypt.c:2641
BYTE prime1[512/16]
Definition: bcrypt.c:2638
#define test_alg_name(a, b)
Definition: bcrypt.c:181
static UCHAR dssKey[]
Definition: bcrypt.c:4546
static BYTE certSignature[]
Definition: bcrypt.c:2281
static UCHAR ULONG
Definition: bcrypt.c:31
#define RACE_TEST_COUNT
Definition: bcrypt.c:993
static void test_BCryptSignHash(void)
Definition: bcrypt.c:4124
static UCHAR rsaPrivateBlob[]
Definition: bcrypt.c:2595
static void test_RSA(void)
Definition: bcrypt.c:2974
BCryptBufferDesc dh_hash_params_prepended
Definition: bcrypt.c:3907
static void test_CHACHA20_POLY1305(void)
Definition: bcrypt.c:5547
static BYTE dh_privkey[]
Definition: bcrypt.c:3828
BYTE prime2[512/16]
Definition: bcrypt.c:2639
static void test_BcryptDeriveKeyPBKDF2(void)
Definition: bcrypt.c:529
static BYTE certHash[]
Definition: bcrypt.c:2276
static void test_hash(const struct hash_test *test)
Definition: bcrypt.c:207
static void test_BCryptEnumContextFunctions(void)
Definition: bcrypt.c:4092
static UCHAR long_salt[]
Definition: bcrypt.c:497
static const UCHAR rsa_encrypted_no_padding[]
Definition: bcrypt.c:2701
static BYTE eccPubkey[]
Definition: bcrypt.c:2267
static void test_rsa_encrypt(void)
Definition: bcrypt.c:2709
static UCHAR rsaPublicBlobWithInvalidPublicExpSize[]
Definition: bcrypt.c:2684
static UCHAR salt_NUL[]
Definition: bcrypt.c:499
static const struct @1909 rfc6070[]
static UCHAR password_NUL[]
Definition: bcrypt.c:498
static UCHAR rsaPublicBlob[]
Definition: bcrypt.c:2547
static void _test_alg_name(unsigned line, void *handle, const WCHAR *exname)
Definition: bcrypt.c:182
#define test_hash_length(a, b)
Definition: bcrypt.c:157
ULONG dk_len
Definition: bcrypt.c:514
BCryptBuffer dh_hash_param_buffers[]
Definition: bcrypt.c:3874
static UCHAR dsaPublicBlob[]
Definition: bcrypt.c:4529
static UCHAR password[]
Definition: bcrypt.c:494
static void test_aes(void)
Definition: bcrypt.c:602
static void test_RSA_SIGN(void)
Definition: bcrypt.c:3221
static UCHAR dk5[]
Definition: bcrypt.c:505
static void format_hash(const UCHAR *bytes, ULONG size, char *buf)
Definition: bcrypt.c:110
static const UCHAR hash_prepend[][2]
Definition: bcrypt.c:3354
static BYTE dh_secret[]
Definition: bcrypt.c:3854
static void test_BcryptDeriveKeyCapi(void)
Definition: bcrypt.c:4437
static void _test_object_length(unsigned line, void *handle)
Definition: bcrypt.c:122
ULONG salt_len
Definition: bcrypt.c:512
static UCHAR rsaSignature[]
Definition: bcrypt.c:2575
static void _test_hash_block_length(unsigned line, void *handle, ULONG exlen)
Definition: bcrypt.c:170
#define test_object_length(a)
Definition: bcrypt.c:121
static UCHAR dk4[]
Definition: bcrypt.c:504
static void test_BCryptEncrypt(void)
Definition: bcrypt.c:1051
static UCHAR legacy_rsa_key[]
Definition: bcrypt.c:2950
static void test_rng(void)
Definition: bcrypt.c:571
static UCHAR salt[]
Definition: bcrypt.c:495
static BYTE dh_hashed_secret[]
Definition: bcrypt.c:3862
BYTE exp1[512/16]
Definition: bcrypt.c:2640
static void test_3des(void)
Definition: bcrypt.c:709
static void test_SecretAgreement(void)
Definition: bcrypt.c:4667
static UCHAR dk2[]
Definition: bcrypt.c:502
BYTE private_exp[512/8]
Definition: bcrypt.c:2643
static UCHAR dk6[]
Definition: bcrypt.c:506
static UCHAR dk1[]
Definition: bcrypt.c:501
static void test_RC4(void)
Definition: bcrypt.c:5101
static UCHAR dk7[]
Definition: bcrypt.c:507
static void test_BCryptGenerateSymmetricKey(void)
Definition: bcrypt.c:770
BYTE coefficient[512/16]
Definition: bcrypt.c:2642
static UCHAR rsaHash[]
Definition: bcrypt.c:2569
static void _test_hash_length(unsigned line, void *handle, ULONG exlen)
Definition: bcrypt.c:158
static BYTE dh_pubkey[]
Definition: bcrypt.c:3807
static UCHAR dsaHash[]
Definition: bcrypt.c:4518
static DWORD WINAPI encrypt_race_thread(void *parameter)
Definition: bcrypt.c:996
static void test_hashes(void)
Definition: bcrypt.c:370
static void test_TLS_PRF(void)
Definition: bcrypt.c:5235
static void test_PBKDF2(void)
Definition: bcrypt.c:5130
#define CRYPT_LOCAL
Definition: bcrypt.h:489
#define BCRYPT_KEY_LENGTHS
Definition: bcrypt.h:62
#define LEGACY_RSAPRIVATE_BLOB
Definition: bcrypt.h:90
#define BCRYPT_RSAPUBLIC_BLOB
Definition: bcrypt.h:76
#define BCRYPT_RNG_ALG_HANDLE
Definition: bcrypt.h:424
#define LEGACY_DSA_V2_PRIVATE_BLOB
Definition: bcrypt.h:88
#define BCRYPT_KDF_HASH
Definition: bcrypt.h:146
#define BCRYPT_HKDF_HASH_ALGORITHM
Definition: bcrypt.h:127
#define BCRYPT_ECDH_P384_ALGORITHM
Definition: bcrypt.h:104
#define BCRYPT_SECRET_AGREEMENT_OPERATION
Definition: bcrypt.h:180
#define BCRYPT_3DES_ALGORITHM
Definition: bcrypt.h:95
#define BCRYPT_CHAIN_MODE_GCM
Definition: bcrypt.h:136
#define BCRYPT_SIGNATURE_OPERATION
Definition: bcrypt.h:181
struct _BCRYPT_DSA_KEY_BLOB BCRYPT_DSA_KEY_BLOB
#define BCRYPT_DH_PUBLIC_MAGIC
Definition: bcrypt.h:318
#define BCRYPT_ECDH_PRIVATE_P256_MAGIC
Definition: bcrypt.h:165
#define BCRYPT_KEY_DATA_BLOB_MAGIC
Definition: bcrypt.h:406
#define BCRYPT_HMAC_SHA1_ALG_HANDLE
Definition: bcrypt.h:426
#define BCRYPT_ECDSA_PUBLIC_P256_MAGIC
Definition: bcrypt.h:157
#define BCRYPT_SIGNATURE_LENGTH
Definition: bcrypt.h:68
#define BCRYPT_ECCPUBLIC_BLOB
Definition: bcrypt.h:74
#define BCRYPT_RSA_ALGORITHM
Definition: bcrypt.h:117
#define BCRYPT_ECDH_PUBLIC_P384_MAGIC
Definition: bcrypt.h:166
#define BCRYPT_HKDF_ALGORITHM
Definition: bcrypt.h:125
#define BCRYPT_ECDH_P521_ALGORITHM
Definition: bcrypt.h:105
#define BCRYPT_HASH_BLOCK_LENGTH
Definition: bcrypt.h:57
#define BCRYPT_OBJECT_LENGTH
Definition: bcrypt.h:65
#define BCRYPT_RC4_ALGORITHM
Definition: bcrypt.h:115
#define KDF_SALT
Definition: bcrypt.h:386
#define BCRYPT_ECDSA_ALGORITHM
Definition: bcrypt.h:106
#define BCRYPT_KEY_LENGTH
Definition: bcrypt.h:61
#define BCRYPT_AUTH_TAG_LENGTH
Definition: bcrypt.h:52
#define BCRYPT_CHAINING_MODE
Definition: bcrypt.h:55
#define BCRYPT_CHAIN_MODE_CFB
Definition: bcrypt.h:134
#define BCRYPT_CHAIN_MODE_CBC
Definition: bcrypt.h:132
#define KDF_ITERATION_COUNT
Definition: bcrypt.h:387
#define BCRYPT_RSA_ALG_HANDLE
Definition: bcrypt.h:430
#define BCRYPT_KEY_DATA_BLOB
Definition: bcrypt.h:72
#define BCRYPT_ALGORITHM_NAME
Definition: bcrypt.h:51
#define BCRYPT_DH_PARAMETERS
Definition: bcrypt.h:153
#define BCRYPT_DSA_ALGORITHM
Definition: bcrypt.h:101
#define BCRYPT_KEY_STRENGTH
Definition: bcrypt.h:64
#define BCRYPT_ECC_CURVE_NAME
Definition: bcrypt.h:138
#define BCRYPT_ECC_CURVE_25519
Definition: bcrypt.h:139
#define BCRYPTBUFFER_VERSION
Definition: bcrypt.h:397
#define BCRYPT_RNG_USE_ENTROPY_IN_BUFFER
Definition: bcrypt.h:477
#define BCRYPT_DH_ALG_HANDLE
Definition: bcrypt.h:456
#define BCRYPT_AES_ALGORITHM
Definition: bcrypt.h:96
#define BCRYPT_PBKDF2_ALGORITHM
Definition: bcrypt.h:113
#define BCRYPT_ECC_CURVE_BRAINPOOLP256R1
Definition: bcrypt.h:140
PVOID BCRYPT_KEY_HANDLE
Definition: bcrypt.h:410
#define BCRYPT_PAD_PKCS1
Definition: bcrypt.h:274
struct _BCRYPT_KEY_DATA_BLOB_HEADER BCRYPT_KEY_DATA_BLOB_HEADER
#define BCRYPT_RSAFULLPRIVATE_MAGIC
Definition: bcrypt.h:243
#define BCRYPT_BLOCK_LENGTH
Definition: bcrypt.h:53
#define BCRYPT_PUBLIC_KEY_BLOB
Definition: bcrypt.h:81
#define BCRYPT_SHA256_ALGORITHM
Definition: bcrypt.h:120
#define BCRYPT_CHAIN_MODE_NA
Definition: bcrypt.h:131
#define BCRYPT_RSAPRIVATE_MAGIC
Definition: bcrypt.h:242
struct _BCRYPT_ECCKEY_BLOB BCRYPT_ECCKEY_BLOB
#define BCRYPT_PAD_PSS
Definition: bcrypt.h:276
#define BCRYPT_RSAPRIVATE_BLOB
Definition: bcrypt.h:77
#define KDF_SECRET_PREPEND
Definition: bcrypt.h:372
#define BCRYPT_DSA_PUBLIC_BLOB
Definition: bcrypt.h:79
#define BCRYPT_ECDH_PUBLIC_P256_MAGIC
Definition: bcrypt.h:164
#define BCRYPT_ALG_HANDLE_HMAC_FLAG
Definition: bcrypt.h:481
#define BCRYPT_ECCPRIVATE_BLOB
Definition: bcrypt.h:75
#define KDF_HASH_ALGORITHM
Definition: bcrypt.h:371
#define KDF_TLS_PRF_SEED
Definition: bcrypt.h:376
#define BCRYPT_ECDSA_PRIVATE_P521_MAGIC
Definition: bcrypt.h:162
#define BCRYPT_CIPHER_OPERATION
Definition: bcrypt.h:177
#define BCRYPT_ECDSA_P256_ALGORITHM
Definition: bcrypt.h:107
#define KDF_HKDF_INFO
Definition: bcrypt.h:388
#define BCRYPT_HKDF_PRK_AND_FINALIZE
Definition: bcrypt.h:129
#define BCRYPT_RNG_ALGORITHM
Definition: bcrypt.h:116
#define BCRYPT_AES_WRAP_KEY_BLOB
Definition: bcrypt.h:73
struct _BCRYPT_RSAKEY_BLOB BCRYPT_RSAKEY_BLOB
#define BCRYPT_HKDF_SALT_AND_FINALIZE
Definition: bcrypt.h:128
#define BCRYPT_ECDSA_P521_ALGORITHM
Definition: bcrypt.h:109
#define BCRYPT_DSA_PRIVATE_BLOB
Definition: bcrypt.h:80
#define BCRYPT_HASH_LENGTH
Definition: bcrypt.h:58
#define BCRYPT_ECDSA_PRIVATE_P256_MAGIC
Definition: bcrypt.h:158
#define BCRYPT_ECDH_ALGORITHM
Definition: bcrypt.h:102
#define BCRYPT_KDF_RAW_SECRET
Definition: bcrypt.h:150
#define BCRYPT_BLOCK_PADDING
Definition: bcrypt.h:484
#define BCRYPT_MD5_ALG_HANDLE
Definition: bcrypt.h:418
#define BCRYPT_ECDSA_PUBLIC_P521_MAGIC
Definition: bcrypt.h:161
#define BCRYPT_AES_GMAC_ALGORITHM
Definition: bcrypt.h:97
PVOID BCRYPT_ALG_HANDLE
Definition: bcrypt.h:409
#define BCRYPT_DH_PARAMETERS_MAGIC
Definition: bcrypt.h:327
#define BCRYPT_RSAPUBLIC_MAGIC
Definition: bcrypt.h:241
#define BCRYPT_ECDH_PRIVATE_P384_MAGIC
Definition: bcrypt.h:167
#define BCRYPT_TLS1_2_KDF_ALGORITHM
Definition: bcrypt.h:124
#define BCRYPT_HASH_REUSABLE_FLAG
Definition: bcrypt.h:487
#define BCRYPT_KEY_DATA_BLOB_VERSION1
Definition: bcrypt.h:407
#define BCRYPT_INITIALIZATION_VECTOR
Definition: bcrypt.h:60
#define BCRYPT_ECC_CURVE_SECP256R1
Definition: bcrypt.h:142
#define MS_PRIMITIVE_PROVIDER
Definition: bcrypt.h:92
#define BCRYPT_ECDH_PUBLIC_P521_MAGIC
Definition: bcrypt.h:168
#define KDF_TLS_PRF_LABEL
Definition: bcrypt.h:375
#define BCRYPT_DH_PRIVATE_BLOB
Definition: bcrypt.h:84
#define BCRYPT_ECDH_P256_ALGORITHM
Definition: bcrypt.h:103
#define BCRYPT_PAD_OAEP
Definition: bcrypt.h:275
#define BCRYPT_ASYMMETRIC_ENCRYPTION_OPERATION
Definition: bcrypt.h:179
#define BCRYPT_CHACHA20_POLY1305_ALGORITHM
Definition: bcrypt.h:98
#define BCRYPT_ECDH_PRIVATE_P521_MAGIC
Definition: bcrypt.h:169
#define BCRYPT_RSA_SIGN_ALGORITHM
Definition: bcrypt.h:118
#define BCRYPT_SHA384_ALGORITHM
Definition: bcrypt.h:121
#define BCRYPT_DSA_PUBLIC_MAGIC
Definition: bcrypt.h:279
#define BCRYPT_OPAQUE_KEY_BLOB
Definition: bcrypt.h:71
#define BCRYPT_DH_ALGORITHM
Definition: bcrypt.h:100
#define BCRYPT_TLS1_1_KDF_ALGORITHM
Definition: bcrypt.h:123
#define BCRYPT_CHAIN_MODE_ECB
Definition: bcrypt.h:133
#define BCRYPT_SHA1_ALGORITHM
Definition: bcrypt.h:119
#define BCRYPT_PAD_NONE
Definition: bcrypt.h:273
#define BCRYPT_RSAFULLPRIVATE_BLOB
Definition: bcrypt.h:78
#define BCRYPT_MESSAGE_BLOCK_LENGTH
Definition: bcrypt.h:155
#define BCRYPT_AES_CBC_ALG_HANDLE
Definition: bcrypt.h:442
#define BCRYPT_MD5_ALGORITHM
Definition: bcrypt.h:112
#define BCRYPT_ECDH_PRIVATE_GENERIC_MAGIC
Definition: bcrypt.h:172
#define BCRYPT_SHA1_ALG_HANDLE
Definition: bcrypt.h:419
#define BCRYPT_DH_PUBLIC_BLOB
Definition: bcrypt.h:83
#define BCRYPT_DH_PRIVATE_MAGIC
Definition: bcrypt.h:319
#define BCRYPT_USE_SYSTEM_PREFERRED_RNG
Definition: bcrypt.h:478
#define BCRYPT_ECDSA_P256_ALG_HANDLE
Definition: bcrypt.h:462
NTSTATUS WINAPI BCryptSecretAgreement(BCRYPT_KEY_HANDLE privkey_handle, BCRYPT_KEY_HANDLE pubkey_handle, BCRYPT_SECRET_HANDLE *ret_handle, ULONG flags)
Definition: bcrypt_main.c:4071
NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE handle, UCHAR *buffer, ULONG count, ULONG flags)
Definition: bcrypt_main.c:574
NTSTATUS WINAPI BCryptDuplicateKey(BCRYPT_KEY_HANDLE handle, BCRYPT_KEY_HANDLE *handle_copy, UCHAR *object, ULONG object_len, ULONG flags)
Definition: bcrypt_main.c:3717
NTSTATUS WINAPI BCryptHashData(BCRYPT_HASH_HANDLE handle, UCHAR *input, ULONG size, ULONG flags)
Definition: bcrypt_main.c:1503
NTSTATUS WINAPI BCryptGetProperty(BCRYPT_HANDLE handle, const WCHAR *prop, UCHAR *buffer, ULONG count, ULONG *res, ULONG flags)
Definition: bcrypt_main.c:1325
NTSTATUS WINAPI BCryptCreateHash(BCRYPT_ALG_HANDLE handle, BCRYPT_HASH_HANDLE *ret_handle, UCHAR *object, ULONG object_len, UCHAR *secret, ULONG secret_len, ULONG flags)
Definition: bcrypt_main.c:1416
NTSTATUS WINAPI BCryptDecrypt(BCRYPT_KEY_HANDLE handle, UCHAR *input, ULONG input_len, void *padding, UCHAR *iv, ULONG iv_len, UCHAR *output, ULONG output_len, ULONG *ret_len, ULONG flags)
Definition: bcrypt_main.c:1968
NTSTATUS WINAPI BCryptImportKeyPair(BCRYPT_ALG_HANDLE handle, BCRYPT_KEY_HANDLE decrypt_key_handle, const WCHAR *type, BCRYPT_KEY_HANDLE *ret_handle, UCHAR *input, ULONG input_len, ULONG flags)
Definition: bcrypt_main.c:3481
NTSTATUS WINAPI BCryptGenerateKeyPair(BCRYPT_ALG_HANDLE handle, BCRYPT_KEY_HANDLE *ret_handle, ULONG bitlen, ULONG flags)
Definition: bcrypt_main.c:3571
NTSTATUS WINAPI BCryptDeriveKeyPBKDF2(BCRYPT_ALG_HANDLE handle, UCHAR *pwd, ULONG pwd_len, UCHAR *salt, ULONG salt_len, ULONGLONG iterations, UCHAR *key, ULONG key_len, ULONG flags)
Definition: bcrypt_main.c:4153
NTSTATUS WINAPI BCryptDestroyHash(BCRYPT_HASH_HANDLE handle)
Definition: bcrypt_main.c:1483
NTSTATUS WINAPI BCryptGenerateSymmetricKey(BCRYPT_ALG_HANDLE handle, BCRYPT_KEY_HANDLE *ret_handle, UCHAR *object, ULONG object_len, UCHAR *secret, ULONG secret_len, ULONG flags)
Definition: bcrypt_main.c:1737
NTSTATUS WINAPI BCryptExportKey(BCRYPT_KEY_HANDLE export_key_handle, BCRYPT_KEY_HANDLE encrypt_key_handle, const WCHAR *type, UCHAR *output, ULONG output_len, ULONG *size, ULONG flags)
Definition: bcrypt_main.c:2749
NTSTATUS WINAPI BCryptEncrypt(BCRYPT_KEY_HANDLE handle, UCHAR *input, ULONG input_len, void *padding, UCHAR *iv, ULONG iv_len, UCHAR *output, ULONG output_len, ULONG *ret_len, ULONG flags)
Definition: bcrypt_main.c:2307
NTSTATUS WINAPI BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE *handle, const WCHAR *id, const WCHAR *implementation, DWORD flags)
Definition: bcrypt_main.c:629
NTSTATUS WINAPI BCryptEnumAlgorithms(ULONG type, ULONG *ret_count, BCRYPT_ALGORITHM_IDENTIFIER **ret_list, ULONG flags)
Definition: bcrypt_main.c:424
NTSTATUS WINAPI BCryptKeyDerivation(BCRYPT_KEY_HANDLE handle, BCryptBufferDesc *desc, UCHAR *output, ULONG output_len, ULONG *ret_len, ULONG flags)
Definition: bcrypt_main.c:4404
NTSTATUS WINAPI BCryptSetProperty(BCRYPT_HANDLE handle, const WCHAR *prop, UCHAR *value, ULONG size, ULONG flags)
Definition: bcrypt_main.c:1230
NTSTATUS WINAPI BCryptFinalizeKeyPair(BCRYPT_KEY_HANDLE handle, ULONG flags)
Definition: bcrypt_main.c:3658
NTSTATUS WINAPI BCryptDeriveKeyCapi(BCRYPT_HASH_HANDLE handle, BCRYPT_ALG_HANDLE halg, UCHAR *key, ULONG keylen, ULONG flags)
Definition: bcrypt_main.c:4021
NTSTATUS WINAPI BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE handle, DWORD flags)
Definition: bcrypt_main.c:684
NTSTATUS WINAPI BCryptDeriveKey(BCRYPT_SECRET_HANDLE handle, const WCHAR *kdf, BCryptBufferDesc *desc, UCHAR *output, ULONG output_len, ULONG *ret_len, ULONG flags)
Definition: bcrypt_main.c:4266
NTSTATUS WINAPI BCryptDestroySecret(BCRYPT_SECRET_HANDLE handle)
Definition: bcrypt_main.c:4127
NTSTATUS WINAPI BCryptVerifySignature(BCRYPT_KEY_HANDLE handle, void *padding, UCHAR *hash, ULONG hash_len, UCHAR *signature, ULONG signature_len, ULONG flags)
Definition: bcrypt_main.c:3975
NTSTATUS WINAPI BCryptImportKey(BCRYPT_ALG_HANDLE handle, BCRYPT_KEY_HANDLE decrypt_key_handle, const WCHAR *type, BCRYPT_KEY_HANDLE *ret_handle, UCHAR *object, ULONG object_len, UCHAR *input, ULONG input_len, ULONG flags)
Definition: bcrypt_main.c:2101
NTSTATUS WINAPI BCryptSignHash(BCRYPT_KEY_HANDLE handle, void *padding, UCHAR *hash, ULONG hash_len, UCHAR *signature, ULONG signature_len, ULONG *ret_len, ULONG flags)
Definition: bcrypt_main.c:3870
NTSTATUS WINAPI BCryptDestroyKey(BCRYPT_KEY_HANDLE handle)
Definition: bcrypt_main.c:4008
NTSTATUS WINAPI BCryptFinishHash(BCRYPT_HASH_HANDLE handle, UCHAR *output, ULONG size, ULONG flags)
Definition: bcrypt_main.c:1525
void WINAPI BCryptFreeBuffer(void *buffer)
Definition: bcrypt_main.c:332
NTSTATUS WINAPI BCryptGetFipsAlgorithmMode(BOOLEAN *enabled)
Definition: bcrypt_main.c:696
NTSTATUS WINAPI BCryptEnumContextFunctions(ULONG table, const WCHAR *ctx, ULONG iface, ULONG *buflen, CRYPT_CONTEXT_FUNCTIONS **buffer)
Definition: bcrypt_main.c:325
#define RegCloseKey(hKey)
Definition: registry.h:49
Definition: list.h:39
#define md5
Definition: compat-1.3.h:2034
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
UINT op
Definition: effect.c:235
#define NTSTATUS
Definition: precomp.h:19
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3268
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
const char * wine_dbgstr_an(const char *str, int n)
Definition: compat.c:313
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define lstrlenW
Definition: compat.h:750
static const WCHAR pubkey[]
Definition: asmname.c:68
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:139
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
return ret
Definition: mutex.c:147
#define L(x)
Definition: resources.c:13
#define INFINITE
Definition: serial.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble GLdouble t
Definition: gl.h:2047
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLenum mode
Definition: glext.h:6217
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
GLenum const GLfloat * params
Definition: glext.h:5645
GLenum GLenum GLenum input
Definition: glext.h:9031
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
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 * u
Definition: glfuncs.h:240
#define InterlockedCompareExchange
Definition: interlocked.h:119
#define debugstr_w
Definition: kernel32.h:32
#define wine_dbgstr_w
Definition: kernel32.h:34
#define win_skip
Definition: minitest.h:67
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl void winetest_pop_context(void)
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl winetest_push_context(const char *fmt,...) __WINE_PRINTF_ATTR(1
Definition: test.h:539
#define todo_wine
Definition: minitest.h:80
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static struct test_info tests[]
#define sprintf
Definition: sprintf.c:45
#define expect2(expected1, expected2, got1, got2)
Definition: listview.c:50
static const WCHAR label[]
Definition: itemdlg.c:1608
static char secret2[]
Definition: protectdata.c:31
BOOL expected
Definition: store.c:2000
#define NCRYPT_SCHANNEL_INTERFACE
Definition: ncrypt.h:83
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:559
#define STATUS_AUTH_TAG_MISMATCH
Definition: ntstatus.h:1399
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:772
#define STATUS_INVALID_SIGNATURE
Definition: ntstatus.h:1397
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
#define calloc
Definition: rosglue.h:14
#define list
Definition: rosglue.h:35
#define test
Definition: rosglue.h:37
const WCHAR * str
strcpy
Definition: string.h:131
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_NOT_FOUND
Definition: shellext.h:72
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
ULONG ulVersion
Definition: bcrypt.h:401
ULONG cbBuffer
Definition: bcrypt.h:392
void * pvBuffer
Definition: bcrypt.h:394
Definition: image.c:229
Definition: tftpd.h:138
BYTE * ecdh_secret
Definition: bcrypt.c:3346
DWORD public_magic
Definition: bcrypt.c:3350
BYTE * hashed_secret_prepended
Definition: bcrypt.c:3349
BYTE * ecdh_pubkey
Definition: bcrypt.c:3344
BYTE * hashed_secret
Definition: bcrypt.c:3348
ULONG eccprivkey_len
Definition: bcrypt.c:3343
ULONG bitlen
Definition: bcrypt.c:3341
DWORD private_magic
Definition: bcrypt.c:3351
ULONG ecdh_secret_len
Definition: bcrypt.c:3347
BYTE * eccprivkey
Definition: bcrypt.c:3342
const WCHAR * alg
Definition: bcrypt.c:3340
ULONG ecdh_pubkey_len
Definition: bcrypt.c:3345
const char * hmac_hash2
Definition: bcrypt.c:204
const char * hmac_hash
Definition: bcrypt.c:203
unsigned block_size
Definition: bcrypt.c:200
const WCHAR * alg
Definition: bcrypt.c:198
const char * hash2
Definition: bcrypt.c:202
unsigned hash_size
Definition: bcrypt.c:199
const char * hash
Definition: bcrypt.c:201
Definition: copy.c:22
Definition: parser.c:49
Definition: name.c:39
Definition: ps.c:97
Definition: ecma_167.h:138
UINT32 len2
SYMCRYPT_AES_EXPANDED_KEY key2
UINT32 nonce[3]
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
unsigned char UCHAR
Definition: typedefs.h:53
uint64_t ULONGLONG
Definition: typedefs.h:67
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
Definition: pdh_main.c:64
#define PRIVATEKEYBLOB
Definition: wincrypt.h:2445
#define CALG_RSA_KEYX
Definition: wincrypt.h:2080
#define CUR_BLOB_VERSION
Definition: wincrypt.h:2451
#define WINAPI
Definition: msvc.h:6
#define NTE_BAD_DATA
Definition: winerror.h:4252
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
unsigned char BYTE
Definition: xxhash.c:193