2 * Unit test for bcrypt functions
4 * Copyright 2014 Bruno Jesus
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.
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.
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
23 #define WIN32_NO_STATUS
27 #include "wine/test.h"
29 static NTSTATUS (WINAPI
*pBCryptOpenAlgorithmProvider
)(BCRYPT_ALG_HANDLE
*, LPCWSTR
, LPCWSTR
, ULONG
);
30 static NTSTATUS (WINAPI
*pBCryptCloseAlgorithmProvider
)(BCRYPT_ALG_HANDLE
, ULONG
);
31 static NTSTATUS (WINAPI
*pBCryptGetFipsAlgorithmMode
)(BOOLEAN
*);
32 static NTSTATUS (WINAPI
*pBCryptCreateHash
)(BCRYPT_ALG_HANDLE
, BCRYPT_HASH_HANDLE
*, PUCHAR
, ULONG
, PUCHAR
,
34 static NTSTATUS (WINAPI
*pBCryptHash
)(BCRYPT_ALG_HANDLE
, UCHAR
*, ULONG
, UCHAR
*, ULONG
, UCHAR
*, ULONG
);
35 static NTSTATUS (WINAPI
*pBCryptHashData
)(BCRYPT_HASH_HANDLE
, PUCHAR
, ULONG
, ULONG
);
36 static NTSTATUS (WINAPI
*pBCryptDuplicateHash
)(BCRYPT_HASH_HANDLE
, BCRYPT_HASH_HANDLE
*, UCHAR
*, ULONG
, ULONG
);
37 static NTSTATUS (WINAPI
*pBCryptFinishHash
)(BCRYPT_HASH_HANDLE
, PUCHAR
, ULONG
, ULONG
);
38 static NTSTATUS (WINAPI
*pBCryptDestroyHash
)(BCRYPT_HASH_HANDLE
);
39 static NTSTATUS (WINAPI
*pBCryptGenRandom
)(BCRYPT_ALG_HANDLE
, PUCHAR
, ULONG
, ULONG
);
40 static NTSTATUS (WINAPI
*pBCryptGetProperty
)(BCRYPT_HANDLE
, LPCWSTR
, PUCHAR
, ULONG
, ULONG
*, ULONG
);
41 static NTSTATUS (WINAPI
*pBCryptSetProperty
)(BCRYPT_HANDLE
, LPCWSTR
, PUCHAR
, ULONG
, ULONG
);
42 static NTSTATUS (WINAPI
*pBCryptGenerateSymmetricKey
)(BCRYPT_ALG_HANDLE
, BCRYPT_KEY_HANDLE
*, PUCHAR
, ULONG
,
43 PUCHAR
, ULONG
, ULONG
);
44 static NTSTATUS (WINAPI
*pBCryptEncrypt
)(BCRYPT_KEY_HANDLE
, PUCHAR
, ULONG
, VOID
*, PUCHAR
, ULONG
, PUCHAR
, ULONG
,
46 static NTSTATUS (WINAPI
*pBCryptDecrypt
)(BCRYPT_KEY_HANDLE
, PUCHAR
, ULONG
, VOID
*, PUCHAR
, ULONG
, PUCHAR
, ULONG
,
48 static NTSTATUS (WINAPI
*pBCryptDestroyKey
)(BCRYPT_KEY_HANDLE
);
50 static void test_BCryptGenRandom(void)
55 ret
= pBCryptGenRandom(NULL
, NULL
, 0, 0);
56 ok(ret
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got 0x%x\n", ret
);
57 ret
= pBCryptGenRandom(NULL
, buffer
, 0, 0);
58 ok(ret
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got 0x%x\n", ret
);
59 ret
= pBCryptGenRandom(NULL
, buffer
, sizeof(buffer
), 0);
60 ok(ret
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got 0x%x\n", ret
);
61 ret
= pBCryptGenRandom(NULL
, buffer
, sizeof(buffer
), BCRYPT_USE_SYSTEM_PREFERRED_RNG
);
62 ok(ret
== STATUS_SUCCESS
, "Expected success, got 0x%x\n", ret
);
63 ret
= pBCryptGenRandom(NULL
, buffer
, sizeof(buffer
),
64 BCRYPT_USE_SYSTEM_PREFERRED_RNG
|BCRYPT_RNG_USE_ENTROPY_IN_BUFFER
);
65 ok(ret
== STATUS_SUCCESS
, "Expected success, got 0x%x\n", ret
);
66 ret
= pBCryptGenRandom(NULL
, NULL
, sizeof(buffer
), BCRYPT_USE_SYSTEM_PREFERRED_RNG
);
67 ok(ret
== STATUS_INVALID_PARAMETER
, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret
);
69 /* Zero sized buffer should work too */
70 ret
= pBCryptGenRandom(NULL
, buffer
, 0, BCRYPT_USE_SYSTEM_PREFERRED_RNG
);
71 ok(ret
== STATUS_SUCCESS
, "Expected success, got 0x%x\n", ret
);
73 /* Test random number generation - It's impossible for a sane RNG to return 8 zeros */
74 memset(buffer
, 0, 16);
75 ret
= pBCryptGenRandom(NULL
, buffer
, 8, BCRYPT_USE_SYSTEM_PREFERRED_RNG
);
76 ok(ret
== STATUS_SUCCESS
, "Expected success, got 0x%x\n", ret
);
77 ok(memcmp(buffer
, buffer
+ 8, 8), "Expected a random number, got 0\n");
80 static void test_BCryptGetFipsAlgorithmMode(void)
82 static const WCHAR policyKeyVistaW
[] = {
83 'S','y','s','t','e','m','\\',
84 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
85 'C','o','n','t','r','o','l','\\',
87 'F','I','P','S','A','l','g','o','r','i','t','h','m','P','o','l','i','c','y',0};
88 static const WCHAR policyValueVistaW
[] = {'E','n','a','b','l','e','d',0};
89 static const WCHAR policyKeyXPW
[] = {
90 'S','y','s','t','e','m','\\',
91 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
92 'C','o','n','t','r','o','l','\\',
94 static const WCHAR policyValueXPW
[] = {
95 'F','I','P','S','A','l','g','o','r','i','t','h','m','P','o','l','i','c','y',0};
99 DWORD value
, count
[2] = {sizeof(value
), sizeof(value
)};
102 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, policyKeyVistaW
, &hkey
) == ERROR_SUCCESS
&&
103 RegQueryValueExW(hkey
, policyValueVistaW
, NULL
, NULL
, (void *)&value
, &count
[0]) == ERROR_SUCCESS
)
107 else if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, policyKeyXPW
, &hkey
) == ERROR_SUCCESS
&&
108 RegQueryValueExW(hkey
, policyValueXPW
, NULL
, NULL
, (void *)&value
, &count
[0]) == ERROR_SUCCESS
)
116 ok(0, "Neither XP or Vista key is present\n");
120 ret
= pBCryptGetFipsAlgorithmMode(&enabled
);
121 ok(ret
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got 0x%x\n", ret
);
122 ok(enabled
== expected
, "expected result %d, got %d\n", expected
, enabled
);
124 ret
= pBCryptGetFipsAlgorithmMode(NULL
);
125 ok(ret
== STATUS_INVALID_PARAMETER
, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret
);
128 static void format_hash(const UCHAR
*bytes
, ULONG size
, char *buf
)
132 for (i
= 0; i
< size
; i
++)
134 sprintf(buf
+ i
* 2, "%02x", bytes
[i
]);
139 static int strcmp_wa(const WCHAR
*strw
, const char *stra
)
142 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(buf
[0]));
143 return lstrcmpW(strw
, buf
);
146 #define test_object_length(a) _test_object_length(__LINE__,a)
147 static void _test_object_length(unsigned line
, void *handle
)
152 len
= size
= 0xdeadbeef;
153 status
= pBCryptGetProperty(NULL
, BCRYPT_OBJECT_LENGTH
, (UCHAR
*)&len
, sizeof(len
), &size
, 0);
154 ok_(__FILE__
,line
)(status
== STATUS_INVALID_HANDLE
, "BCryptGetProperty failed: %08x\n", status
);
156 len
= size
= 0xdeadbeef;
157 status
= pBCryptGetProperty(handle
, NULL
, (UCHAR
*)&len
, sizeof(len
), &size
, 0);
158 ok_(__FILE__
,line
)(status
== STATUS_INVALID_PARAMETER
, "BCryptGetProperty failed: %08x\n", status
);
160 len
= size
= 0xdeadbeef;
161 status
= pBCryptGetProperty(handle
, BCRYPT_OBJECT_LENGTH
, (UCHAR
*)&len
, sizeof(len
), NULL
, 0);
162 ok_(__FILE__
,line
)(status
== STATUS_INVALID_PARAMETER
, "BCryptGetProperty failed: %08x\n", status
);
164 len
= size
= 0xdeadbeef;
165 status
= pBCryptGetProperty(handle
, BCRYPT_OBJECT_LENGTH
, NULL
, sizeof(len
), &size
, 0);
166 ok_(__FILE__
,line
)(status
== STATUS_SUCCESS
, "BCryptGetProperty failed: %08x\n", status
);
167 ok_(__FILE__
,line
)(size
== sizeof(len
), "got %u\n", size
);
169 len
= size
= 0xdeadbeef;
170 status
= pBCryptGetProperty(handle
, BCRYPT_OBJECT_LENGTH
, (UCHAR
*)&len
, 0, &size
, 0);
171 ok_(__FILE__
,line
)(status
== STATUS_BUFFER_TOO_SMALL
, "BCryptGetProperty failed: %08x\n", status
);
172 ok_(__FILE__
,line
)(len
== 0xdeadbeef, "got %u\n", len
);
173 ok_(__FILE__
,line
)(size
== sizeof(len
), "got %u\n", size
);
175 len
= size
= 0xdeadbeef;
176 status
= pBCryptGetProperty(handle
, BCRYPT_OBJECT_LENGTH
, (UCHAR
*)&len
, sizeof(len
), &size
, 0);
177 ok_(__FILE__
,line
)(status
== STATUS_SUCCESS
, "BCryptGetProperty failed: %08x\n", status
);
178 ok_(__FILE__
,line
)(len
!= 0xdeadbeef, "len not set\n");
179 ok_(__FILE__
,line
)(size
== sizeof(len
), "got %u\n", size
);
182 #define test_hash_length(a,b) _test_hash_length(__LINE__,a,b)
183 static void _test_hash_length(unsigned line
, void *handle
, ULONG exlen
)
185 ULONG len
= 0xdeadbeef, size
= 0xdeadbeef;
188 status
= pBCryptGetProperty(handle
, BCRYPT_HASH_LENGTH
, (UCHAR
*)&len
, sizeof(len
), &size
, 0);
189 ok_(__FILE__
,line
)(status
== STATUS_SUCCESS
, "BCryptGetProperty failed: %08x\n", status
);
190 ok_(__FILE__
,line
)(size
== sizeof(len
), "got %u\n", size
);
191 ok_(__FILE__
,line
)(len
== exlen
, "len = %u, expected %u\n", len
, exlen
);
194 #define test_alg_name(a,b) _test_alg_name(__LINE__,a,b)
195 static void _test_alg_name(unsigned line
, void *handle
, const char *exname
)
197 ULONG size
= 0xdeadbeef;
199 const WCHAR
*name
= (const WCHAR
*)buf
;
202 status
= pBCryptGetProperty(handle
, BCRYPT_ALGORITHM_NAME
, buf
, sizeof(buf
), &size
, 0);
203 ok_(__FILE__
,line
)(status
== STATUS_SUCCESS
, "BCryptGetProperty failed: %08x\n", status
);
204 ok_(__FILE__
,line
)(size
== (strlen(exname
)+1)*sizeof(WCHAR
), "got %u\n", size
);
205 ok_(__FILE__
,line
)(!strcmp_wa(name
, exname
), "alg name = %s, expected %s\n", wine_dbgstr_w(name
), exname
);
213 const char *hmac_hash
;
216 static void test_hash(const struct hash_test
*test
)
218 BCRYPT_ALG_HANDLE alg
;
219 BCRYPT_HASH_HANDLE hash
;
220 UCHAR buf
[512], buf_hmac
[1024], hash_buf
[128], hmac_hash
[128];
226 MultiByteToWideChar(CP_ACP
, 0, test
->alg
, -1, alg_name
, sizeof(alg_name
)/sizeof(WCHAR
));
229 ret
= pBCryptOpenAlgorithmProvider(&alg
, alg_name
, MS_PRIMITIVE_PROVIDER
, 0);
230 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
231 ok(alg
!= NULL
, "alg not set\n");
233 test_object_length(alg
);
234 test_hash_length(alg
, test
->hash_size
);
235 test_alg_name(alg
, test
->alg
);
239 ret
= pBCryptCreateHash(alg
, &hash
, buf
, len
, NULL
, 0, 0);
240 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
241 ok(hash
!= NULL
, "hash not set\n");
243 ret
= pBCryptHashData(hash
, NULL
, 0, 0);
244 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
246 ret
= pBCryptHashData(hash
, (UCHAR
*)"test", sizeof("test"), 0);
247 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
249 test_hash_length(hash
, test
->hash_size
);
250 test_alg_name(hash
, test
->alg
);
252 memset(hash_buf
, 0, sizeof(hash_buf
));
253 ret
= pBCryptFinishHash(hash
, hash_buf
, test
->hash_size
, 0);
254 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
255 format_hash( hash_buf
, test
->hash_size
, str
);
256 ok(!strcmp(str
, test
->hash
), "got %s\n", str
);
258 ret
= pBCryptDestroyHash(hash
);
259 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
261 ret
= pBCryptCloseAlgorithmProvider(alg
, 0);
262 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
265 ret
= pBCryptOpenAlgorithmProvider(&alg
, alg_name
, MS_PRIMITIVE_PROVIDER
, BCRYPT_ALG_HANDLE_HMAC_FLAG
);
266 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
267 ok(alg
!= NULL
, "alg not set\n");
270 len
= sizeof(buf_hmac
);
271 ret
= pBCryptCreateHash(alg
, &hash
, buf_hmac
, len
, (UCHAR
*)"key", sizeof("key"), 0);
272 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
273 ok(hash
!= NULL
, "hash not set\n");
275 ret
= pBCryptHashData(hash
, (UCHAR
*)"test", sizeof("test"), 0);
276 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
278 test_hash_length(hash
, test
->hash_size
);
279 test_alg_name(hash
, test
->alg
);
281 memset(hmac_hash
, 0, sizeof(hmac_hash
));
282 ret
= pBCryptFinishHash(hash
, hmac_hash
, test
->hash_size
, 0);
283 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
284 format_hash( hmac_hash
, test
->hash_size
, str
);
285 ok(!strcmp(str
, test
->hmac_hash
), "got %s\n", str
);
287 ret
= pBCryptDestroyHash(hash
);
288 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
290 ret
= pBCryptCloseAlgorithmProvider(alg
, 0);
291 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
294 static void test_hashes(void)
296 static const struct hash_test tests
[] = {
300 "961fa64958818f767707072755d7018dcd278e94",
301 "2472cf65d0e090618d769d3e46f0d9446cf212da"
306 "ceb73749c899693706ede1e30c9929b3fd5dd926163831c2fb8bd41e6efb1126",
307 "34c1aa473a4468a91d06e7cdbc75bc4f93b830ccfc2a47ffd74e8e6ed29e4c72"
312 "62b21e90c9022b101671ba1f808f8631a8149f0f12904055839a35c1ca78ae53"
313 "63eed1e743a692d70e0504b0cfd12ef9",
314 "4b3e6d6ff2da121790ab7e7b9247583e3a7eed2db5bd4dabc680303b1608f37d"
315 "fdc836d96a704c03283bc05b4f6c5eb8"
320 "d55ced17163bf5386f2cd9ff21d6fd7fe576a915065c24744d09cfae4ec84ee1"
321 "ef6ef11bfbc5acce3639bab725b50a1fe2c204f8c820d6d7db0df0ecbc49c5ca",
322 "415fb6b10018ca03b38a1b1399c42ac0be5e8aceddb9a73103f5e543bf2d888f"
323 "2eecf91373941f9315dd730a77937fa92444450fbece86f409d9cb5ec48c6513"
328 "1bb33606ba908912a84221109d29cd7e",
329 "7f05b0638d77f4a27f3a9c4d353cd648"
334 "74b5db93c0b41e36ca7074338fc0b637",
335 "bc2e8ac4d8248ed21b8d26227a30ea3a"
340 "e2a3e68d23ce348b8f68b3079de3d4c9",
341 "7bda029b93fa8d817fcc9e13d6bdf092"
346 for(i
= 0; i
< sizeof(tests
)/sizeof(*tests
); i
++)
350 static void test_BcryptHash(void)
352 static const char expected
[] =
353 "e2a3e68d23ce348b8f68b3079de3d4c9";
354 static const char expected_hmac
[] =
355 "7bda029b93fa8d817fcc9e13d6bdf092";
356 BCRYPT_ALG_HANDLE alg
;
357 UCHAR md5
[16], md5_hmac
[16];
362 ret
= pBCryptOpenAlgorithmProvider(&alg
, BCRYPT_MD5_ALGORITHM
, MS_PRIMITIVE_PROVIDER
, 0);
363 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
364 ok(alg
!= NULL
, "alg not set\n");
366 test_hash_length(alg
, 16);
367 test_alg_name(alg
, "MD5");
369 memset(md5
, 0, sizeof(md5
));
370 ret
= pBCryptHash(alg
, NULL
, 0, (UCHAR
*)"test", sizeof("test"), md5
, sizeof(md5
));
371 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
372 format_hash( md5
, sizeof(md5
), str
);
373 ok(!strcmp(str
, expected
), "got %s\n", str
);
375 ret
= pBCryptCloseAlgorithmProvider(alg
, 0);
376 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
379 memset(md5_hmac
, 0, sizeof(md5_hmac
));
380 ret
= pBCryptOpenAlgorithmProvider(&alg
, BCRYPT_MD5_ALGORITHM
, MS_PRIMITIVE_PROVIDER
, BCRYPT_ALG_HANDLE_HMAC_FLAG
);
381 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
382 ok(alg
!= NULL
, "alg not set\n");
384 ret
= pBCryptHash(alg
, (UCHAR
*)"key", sizeof("key"), (UCHAR
*)"test", sizeof("test"), md5_hmac
, sizeof(md5_hmac
));
385 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
386 format_hash( md5_hmac
, sizeof(md5_hmac
), str
);
387 ok(!strcmp(str
, expected_hmac
), "got %s\n", str
);
389 ret
= pBCryptCloseAlgorithmProvider(alg
, 0);
390 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
393 static void test_rng(void)
395 BCRYPT_ALG_HANDLE alg
;
401 ret
= pBCryptOpenAlgorithmProvider(&alg
, BCRYPT_RNG_ALGORITHM
, MS_PRIMITIVE_PROVIDER
, 0);
402 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
403 ok(alg
!= NULL
, "alg not set\n");
405 len
= size
= 0xdeadbeef;
406 ret
= pBCryptGetProperty(alg
, BCRYPT_OBJECT_LENGTH
, (UCHAR
*)&len
, sizeof(len
), &size
, 0);
407 ok(ret
== STATUS_NOT_SUPPORTED
, "got %08x\n", ret
);
409 len
= size
= 0xdeadbeef;
410 ret
= pBCryptGetProperty(alg
, BCRYPT_HASH_LENGTH
, (UCHAR
*)&len
, sizeof(len
), &size
, 0);
411 ok(ret
== STATUS_NOT_SUPPORTED
, "got %08x\n", ret
);
413 test_alg_name(alg
, "RNG");
416 ret
= pBCryptGenRandom(alg
, buf
, 8, 0);
417 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
418 ok(memcmp(buf
, buf
+ 8, 8), "got zeroes\n");
420 ret
= pBCryptCloseAlgorithmProvider(alg
, 0);
421 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
424 static void test_aes(void)
426 BCRYPT_KEY_LENGTHS_STRUCT key_lengths
;
427 BCRYPT_ALG_HANDLE alg
;
433 ret
= pBCryptOpenAlgorithmProvider(&alg
, BCRYPT_AES_ALGORITHM
, MS_PRIMITIVE_PROVIDER
, 0);
434 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
435 ok(alg
!= NULL
, "alg not set\n");
438 ret
= pBCryptGetProperty(alg
, BCRYPT_OBJECT_LENGTH
, (UCHAR
*)&len
, sizeof(len
), &size
, 0);
439 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
440 ok(len
, "expected non-zero len\n");
441 ok(size
== sizeof(len
), "got %u\n", size
);
444 ret
= pBCryptGetProperty(alg
, BCRYPT_BLOCK_LENGTH
, (UCHAR
*)&len
, sizeof(len
), &size
, 0);
445 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
446 ok(len
== 16, "got %u\n", len
);
447 ok(size
== sizeof(len
), "got %u\n", size
);
450 ret
= pBCryptGetProperty(alg
, BCRYPT_CHAINING_MODE
, mode
, 0, &size
, 0);
451 ok(ret
== STATUS_BUFFER_TOO_SMALL
, "got %08x\n", ret
);
452 ok(size
== 64, "got %u\n", size
);
455 ret
= pBCryptGetProperty(alg
, BCRYPT_CHAINING_MODE
, mode
, sizeof(mode
), &size
, 0);
456 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
457 ok(!lstrcmpW((const WCHAR
*)mode
, BCRYPT_CHAIN_MODE_CBC
), "got %s\n", mode
);
458 ok(size
== 64, "got %u\n", size
);
461 memset(&key_lengths
, 0, sizeof(key_lengths
));
462 ret
= BCryptGetProperty(alg
, BCRYPT_KEY_LENGTHS
, (UCHAR
*)&key_lengths
, sizeof(key_lengths
), &size
, 0);
463 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
464 ok(size
== sizeof(key_lengths
), "got %u\n", size
);
465 ok(key_lengths
.dwMinLength
== 128, "Expected 128, got %d\n", key_lengths
.dwMinLength
);
466 ok(key_lengths
.dwMaxLength
== 256, "Expected 256, got %d\n", key_lengths
.dwMaxLength
);
467 ok(key_lengths
.dwIncrement
== 64, "Expected 64, got %d\n", key_lengths
.dwIncrement
);
469 test_alg_name(alg
, "AES");
471 ret
= pBCryptCloseAlgorithmProvider(alg
, 0);
472 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
475 static void test_BCryptGenerateSymmetricKey(void)
477 static UCHAR secret
[] =
478 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
480 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
481 static UCHAR data
[] =
482 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
483 static UCHAR expected
[] =
484 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79};
485 BCRYPT_ALG_HANDLE aes
;
486 BCRYPT_KEY_HANDLE key
;
487 UCHAR
*buf
, ciphertext
[16], plaintext
[16], ivbuf
[16];
491 ret
= pBCryptOpenAlgorithmProvider(&aes
, BCRYPT_AES_ALGORITHM
, NULL
, 0);
492 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
494 len
= size
= 0xdeadbeef;
495 ret
= pBCryptGetProperty(aes
, BCRYPT_OBJECT_LENGTH
, (UCHAR
*)&len
, sizeof(len
), &size
, 0);
496 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
499 buf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
500 ret
= pBCryptGenerateSymmetricKey(aes
, &key
, buf
, len
, secret
, sizeof(secret
), 0);
501 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
502 ok(key
!= NULL
, "key not set\n");
504 ret
= pBCryptSetProperty(aes
, BCRYPT_CHAINING_MODE
, (UCHAR
*)BCRYPT_CHAIN_MODE_CBC
,
505 sizeof(BCRYPT_CHAIN_MODE_CBC
), 0);
506 todo_wine
ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
509 ret
= pBCryptEncrypt(key
, NULL
, 0, NULL
, NULL
, 0, NULL
, 0, &size
, 0);
510 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
511 ok(!size
, "got %u\n", size
);
514 memcpy(ivbuf
, iv
, sizeof(iv
));
515 ret
= pBCryptEncrypt(key
, data
, 16, NULL
, ivbuf
, 16, NULL
, 0, &size
, 0);
516 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
517 ok(size
== 16, "got %u\n", size
);
520 memcpy(ivbuf
, iv
, sizeof(iv
));
521 memset(ciphertext
, 0, sizeof(ciphertext
));
522 ret
= pBCryptEncrypt(key
, data
, 16, NULL
, ivbuf
, 16, ciphertext
, 16, &size
, 0);
523 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
524 ok(size
== 16, "got %u\n", size
);
525 ok(!memcmp(ciphertext
, expected
, sizeof(expected
)), "wrong data\n");
526 for (i
= 0; i
< 16; i
++)
527 ok(ciphertext
[i
] == expected
[i
], "%u: %02x != %02x\n", i
, ciphertext
[i
], expected
[i
]);
530 ret
= pBCryptDecrypt(key
, NULL
, 0, NULL
, NULL
, 0, NULL
, 0, &size
, 0);
531 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
532 ok(!size
, "got %u\n", size
);
535 memcpy(ivbuf
, iv
, sizeof(iv
));
536 ret
= pBCryptDecrypt(key
, ciphertext
, 16, NULL
, ivbuf
, 16, NULL
, 0, &size
, 0);
537 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
538 ok(size
== 16, "got %u\n", size
);
541 memcpy(ivbuf
, iv
, sizeof(iv
));
542 memset(plaintext
, 0, sizeof(plaintext
));
543 ret
= pBCryptDecrypt(key
, ciphertext
, 16, NULL
, ivbuf
, 16, plaintext
, 16, &size
, 0);
544 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
545 ok(size
== 16, "got %u\n", size
);
546 ok(!memcmp(plaintext
, data
, sizeof(data
)), "wrong data\n");
548 ret
= pBCryptDestroyKey(key
);
549 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
550 HeapFree(GetProcessHeap(), 0, buf
);
552 ret
= pBCryptCloseAlgorithmProvider(aes
, 0);
553 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
556 static void test_BCryptEncrypt(void)
558 static UCHAR secret
[] =
559 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
561 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
562 static UCHAR data
[] =
563 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10};
564 static UCHAR data2
[] =
565 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
566 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
567 static UCHAR expected
[] =
568 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79};
569 static UCHAR expected2
[] =
570 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
571 0x28,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9};
572 static UCHAR expected3
[] =
573 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
574 0xb1,0xa2,0x92,0x73,0xbe,0x2c,0x42,0x07,0xa5,0xac,0xe3,0x93,0x39,0x8c,0xb6,0xfb,
575 0x87,0x5d,0xea,0xa3,0x7e,0x0f,0xde,0xfa,0xd9,0xec,0x6c,0x4e,0x3c,0x76,0x86,0xe4};
576 BCRYPT_ALG_HANDLE aes
;
577 BCRYPT_KEY_HANDLE key
;
578 UCHAR
*buf
, ciphertext
[48], ivbuf
[16];
582 ret
= pBCryptOpenAlgorithmProvider(&aes
, BCRYPT_AES_ALGORITHM
, NULL
, 0);
583 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
587 ret
= pBCryptGetProperty(aes
, BCRYPT_OBJECT_LENGTH
, (UCHAR
*)&len
, sizeof(len
), &size
, 0);
588 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
590 buf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
591 ret
= pBCryptGenerateSymmetricKey(aes
, &key
, buf
, len
, secret
, sizeof(secret
), 0);
592 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
594 /* input size is a multiple of block size */
596 memcpy(ivbuf
, iv
, sizeof(iv
));
597 ret
= pBCryptEncrypt(key
, data
, 16, NULL
, ivbuf
, 16, NULL
, 0, &size
, 0);
598 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
599 ok(size
== 16, "got %u\n", size
);
602 memcpy(ivbuf
, iv
, sizeof(iv
));
603 memset(ciphertext
, 0, sizeof(ciphertext
));
604 ret
= pBCryptEncrypt(key
, data
, 16, NULL
, ivbuf
, 16, ciphertext
, 16, &size
, 0);
605 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
606 ok(size
== 16, "got %u\n", size
);
607 ok(!memcmp(ciphertext
, expected
, sizeof(expected
)), "wrong data\n");
608 for (i
= 0; i
< 16; i
++)
609 ok(ciphertext
[i
] == expected
[i
], "%u: %02x != %02x\n", i
, ciphertext
[i
], expected
[i
]);
611 /* input size is not a multiple of block size */
613 memcpy(ivbuf
, iv
, sizeof(iv
));
614 ret
= pBCryptEncrypt(key
, data
, 17, NULL
, ivbuf
, 16, NULL
, 0, &size
, 0);
615 ok(ret
== STATUS_INVALID_BUFFER_SIZE
, "got %08x\n", ret
);
616 ok(size
== 17, "got %u\n", size
);
618 /* input size is not a multiple of block size, block padding set */
620 memcpy(ivbuf
, iv
, sizeof(iv
));
621 ret
= pBCryptEncrypt(key
, data
, 17, NULL
, ivbuf
, 16, NULL
, 0, &size
, BCRYPT_BLOCK_PADDING
);
622 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
623 ok(size
== 32, "got %u\n", size
);
626 memcpy(ivbuf
, iv
, sizeof(iv
));
627 memset(ciphertext
, 0, sizeof(ciphertext
));
628 ret
= pBCryptEncrypt(key
, data
, 17, NULL
, ivbuf
, 16, ciphertext
, 32, &size
, BCRYPT_BLOCK_PADDING
);
629 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
630 ok(size
== 32, "got %u\n", size
);
631 ok(!memcmp(ciphertext
, expected2
, sizeof(expected2
)), "wrong data\n");
632 for (i
= 0; i
< 32; i
++)
633 ok(ciphertext
[i
] == expected2
[i
], "%u: %02x != %02x\n", i
, ciphertext
[i
], expected2
[i
]);
635 /* input size is a multiple of block size, block padding set */
637 memcpy(ivbuf
, iv
, sizeof(iv
));
638 ret
= pBCryptEncrypt(key
, data2
, 32, NULL
, ivbuf
, 16, NULL
, 0, &size
, BCRYPT_BLOCK_PADDING
);
639 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
640 ok(size
== 48, "got %u\n", size
);
643 memcpy(ivbuf
, iv
, sizeof(iv
));
644 memset(ciphertext
, 0, sizeof(ciphertext
));
645 ret
= pBCryptEncrypt(key
, data2
, 32, NULL
, ivbuf
, 16, ciphertext
, 48, &size
, BCRYPT_BLOCK_PADDING
);
646 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
647 ok(size
== 48, "got %u\n", size
);
648 ok(!memcmp(ciphertext
, expected3
, sizeof(expected3
)), "wrong data\n");
649 for (i
= 0; i
< 48; i
++)
650 ok(ciphertext
[i
] == expected3
[i
], "%u: %02x != %02x\n", i
, ciphertext
[i
], expected3
[i
]);
652 /* output size too small */
654 memcpy(ivbuf
, iv
, sizeof(iv
));
655 memset(ciphertext
, 0, sizeof(ciphertext
));
656 ret
= pBCryptEncrypt(key
, data
, 17, NULL
, ivbuf
, 16, ciphertext
, 31, &size
, BCRYPT_BLOCK_PADDING
);
657 ok(ret
== STATUS_BUFFER_TOO_SMALL
, "got %08x\n", ret
);
658 ok(size
== 32, "got %u\n", size
);
661 memcpy(ivbuf
, iv
, sizeof(iv
));
662 memset(ciphertext
, 0, sizeof(ciphertext
));
663 ret
= pBCryptEncrypt(key
, data2
, 32, NULL
, ivbuf
, 16, ciphertext
, 32, &size
, BCRYPT_BLOCK_PADDING
);
664 ok(ret
== STATUS_BUFFER_TOO_SMALL
, "got %08x\n", ret
);
665 ok(size
== 48, "got %u\n", size
);
667 ret
= pBCryptDestroyKey(key
);
668 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
669 HeapFree(GetProcessHeap(), 0, buf
);
671 ret
= pBCryptCloseAlgorithmProvider(aes
, 0);
672 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
675 static void test_BCryptDecrypt(void)
677 static UCHAR secret
[] =
678 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
680 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
681 static UCHAR expected
[] =
682 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
683 static UCHAR expected2
[] =
684 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10};
685 static UCHAR expected3
[] =
686 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
687 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
688 static UCHAR ciphertext
[32] =
689 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
690 0x28,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9};
691 static UCHAR ciphertext2
[] =
692 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
693 0x28,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9};
694 static UCHAR ciphertext3
[] =
695 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
696 0xb1,0xa2,0x92,0x73,0xbe,0x2c,0x42,0x07,0xa5,0xac,0xe3,0x93,0x39,0x8c,0xb6,0xfb,
697 0x87,0x5d,0xea,0xa3,0x7e,0x0f,0xde,0xfa,0xd9,0xec,0x6c,0x4e,0x3c,0x76,0x86,0xe4};
698 BCRYPT_KEY_LENGTHS_STRUCT key_lengths
;
699 BCRYPT_ALG_HANDLE aes
;
700 BCRYPT_KEY_HANDLE key
;
701 UCHAR
*buf
, plaintext
[48], ivbuf
[16];
705 ret
= pBCryptOpenAlgorithmProvider(&aes
, BCRYPT_AES_ALGORITHM
, NULL
, 0);
706 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
709 memset(&key_lengths
, 0, sizeof(key_lengths
));
710 ret
= BCryptGetProperty(aes
, BCRYPT_KEY_LENGTHS
, (UCHAR
*)&key_lengths
, sizeof(key_lengths
), &size
, 0);
711 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
712 ok(size
== sizeof(key_lengths
), "got %u\n", size
);
713 ok(key_lengths
.dwMinLength
== 128, "Expected 128, got %d\n", key_lengths
.dwMinLength
);
714 ok(key_lengths
.dwMaxLength
== 256, "Expected 256, got %d\n", key_lengths
.dwMaxLength
);
715 ok(key_lengths
.dwIncrement
== 64, "Expected 64, got %d\n", key_lengths
.dwIncrement
);
719 ret
= pBCryptGetProperty(aes
, BCRYPT_OBJECT_LENGTH
, (UCHAR
*)&len
, sizeof(len
), &size
, 0);
720 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
722 buf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
723 ret
= pBCryptGenerateSymmetricKey(aes
, &key
, buf
, len
, secret
, sizeof(secret
), 0);
724 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
726 /* input size is a multiple of block size */
728 memcpy(ivbuf
, iv
, sizeof(iv
));
729 ret
= pBCryptDecrypt(key
, ciphertext
, 32, NULL
, ivbuf
, 16, NULL
, 0, &size
, 0);
730 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
731 ok(size
== 32, "got %u\n", size
);
734 memcpy(ivbuf
, iv
, sizeof(iv
));
735 memset(plaintext
, 0, sizeof(plaintext
));
736 ret
= pBCryptDecrypt(key
, ciphertext
, 32, NULL
, ivbuf
, 16, plaintext
, 32, &size
, 0);
737 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
738 ok(size
== 32, "got %u\n", size
);
739 ok(!memcmp(plaintext
, expected
, sizeof(expected
)), "wrong data\n");
741 /* test with padding smaller than block size */
743 memcpy(ivbuf
, iv
, sizeof(iv
));
744 ret
= pBCryptDecrypt(key
, ciphertext2
, 32, NULL
, ivbuf
, 16, NULL
, 0, &size
, 0);
745 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
746 ok(size
== 32, "got %u\n", size
);
749 memcpy(ivbuf
, iv
, sizeof(iv
));
750 memset(plaintext
, 0, sizeof(plaintext
));
751 ret
= pBCryptDecrypt(key
, ciphertext2
, 32, NULL
, ivbuf
, 16, plaintext
, 17, &size
, BCRYPT_BLOCK_PADDING
);
752 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
753 ok(size
== 17, "got %u\n", size
);
754 ok(!memcmp(plaintext
, expected2
, sizeof(expected2
)), "wrong data\n");
756 /* test with padding of block size */
758 memcpy(ivbuf
, iv
, sizeof(iv
));
759 ret
= pBCryptDecrypt(key
, ciphertext3
, 48, NULL
, ivbuf
, 16, NULL
, 0, &size
, 0);
760 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
761 ok(size
== 48, "got %u\n", size
);
764 memcpy(ivbuf
, iv
, sizeof(iv
));
765 memset(plaintext
, 0, sizeof(plaintext
));
766 ret
= pBCryptDecrypt(key
, ciphertext3
, 48, NULL
, ivbuf
, 16, plaintext
, 32, &size
, BCRYPT_BLOCK_PADDING
);
767 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
768 ok(size
== 32, "got %u\n", size
);
769 ok(!memcmp(plaintext
, expected3
, sizeof(expected3
)), "wrong data\n");
771 /* output size too small */
773 memcpy(ivbuf
, iv
, sizeof(iv
));
774 ret
= pBCryptDecrypt(key
, ciphertext
, 32, NULL
, ivbuf
, 16, plaintext
, 31, &size
, 0);
775 ok(ret
== STATUS_BUFFER_TOO_SMALL
, "got %08x\n", ret
);
776 ok(size
== 32, "got %u\n", size
);
779 memcpy(ivbuf
, iv
, sizeof(iv
));
780 ret
= pBCryptDecrypt(key
, ciphertext2
, 32, NULL
, ivbuf
, 16, plaintext
, 15, &size
, BCRYPT_BLOCK_PADDING
);
781 ok(ret
== STATUS_BUFFER_TOO_SMALL
, "got %08x\n", ret
);
782 ok(size
== 32, "got %u\n", size
);
785 memcpy(ivbuf
, iv
, sizeof(iv
));
786 ret
= pBCryptDecrypt(key
, ciphertext2
, 32, NULL
, ivbuf
, 16, plaintext
, 16, &size
, BCRYPT_BLOCK_PADDING
);
787 ok(ret
== STATUS_BUFFER_TOO_SMALL
, "got %08x\n", ret
);
788 ok(size
== 17, "got %u\n", size
);
791 memcpy(ivbuf
, iv
, sizeof(iv
));
792 ret
= pBCryptDecrypt(key
, ciphertext3
, 48, NULL
, ivbuf
, 16, plaintext
, 31, &size
, BCRYPT_BLOCK_PADDING
);
793 ok(ret
== STATUS_BUFFER_TOO_SMALL
, "got %08x\n", ret
);
794 ok(size
== 48, "got %u\n", size
);
796 /* input size is not a multiple of block size */
798 memcpy(ivbuf
, iv
, sizeof(iv
));
799 ret
= pBCryptDecrypt(key
, ciphertext
, 17, NULL
, ivbuf
, 16, NULL
, 0, &size
, 0);
800 ok(ret
== STATUS_INVALID_BUFFER_SIZE
, "got %08x\n", ret
);
801 ok(size
== 17 || broken(size
== 0 /* Win < 7 */), "got %u\n", size
);
803 /* input size is not a multiple of block size, block padding set */
805 memcpy(ivbuf
, iv
, sizeof(iv
));
806 ret
= pBCryptDecrypt(key
, ciphertext
, 17, NULL
, ivbuf
, 16, NULL
, 0, &size
, BCRYPT_BLOCK_PADDING
);
807 ok(ret
== STATUS_INVALID_BUFFER_SIZE
, "got %08x\n", ret
);
808 ok(size
== 17 || broken(size
== 0 /* Win < 7 */), "got %u\n", size
);
810 ret
= pBCryptDestroyKey(key
);
811 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
812 HeapFree(GetProcessHeap(), 0, buf
);
814 ret
= pBCryptCloseAlgorithmProvider(aes
, 0);
815 ok(ret
== STATUS_SUCCESS
, "got %08x\n", ret
);
822 module
= LoadLibraryA("bcrypt.dll");
825 win_skip("bcrypt.dll not found\n");
829 pBCryptOpenAlgorithmProvider
= (void *)GetProcAddress(module
, "BCryptOpenAlgorithmProvider");
830 pBCryptCloseAlgorithmProvider
= (void *)GetProcAddress(module
, "BCryptCloseAlgorithmProvider");
831 pBCryptGetFipsAlgorithmMode
= (void *)GetProcAddress(module
, "BCryptGetFipsAlgorithmMode");
832 pBCryptCreateHash
= (void *)GetProcAddress(module
, "BCryptCreateHash");
833 pBCryptHash
= (void *)GetProcAddress(module
, "BCryptHash");
834 pBCryptHashData
= (void *)GetProcAddress(module
, "BCryptHashData");
835 pBCryptDuplicateHash
= (void *)GetProcAddress(module
, "BCryptDuplicateHash");
836 pBCryptFinishHash
= (void *)GetProcAddress(module
, "BCryptFinishHash");
837 pBCryptDestroyHash
= (void *)GetProcAddress(module
, "BCryptDestroyHash");
838 pBCryptGenRandom
= (void *)GetProcAddress(module
, "BCryptGenRandom");
839 pBCryptGetProperty
= (void *)GetProcAddress(module
, "BCryptGetProperty");
840 pBCryptSetProperty
= (void *)GetProcAddress(module
, "BCryptSetProperty");
841 pBCryptGenerateSymmetricKey
= (void *)GetProcAddress(module
, "BCryptGenerateSymmetricKey");
842 pBCryptEncrypt
= (void *)GetProcAddress(module
, "BCryptEncrypt");
843 pBCryptDecrypt
= (void *)GetProcAddress(module
, "BCryptDecrypt");
844 pBCryptDestroyKey
= (void *)GetProcAddress(module
, "BCryptDestroyKey");
846 test_BCryptGenRandom();
847 test_BCryptGetFipsAlgorithmMode();
851 test_BCryptGenerateSymmetricKey();
852 test_BCryptEncrypt();
853 test_BCryptDecrypt();
855 if (pBCryptHash
) /* >= Win 10 */
858 win_skip("BCryptHash is not available\n");