1
0
mirror of https://github.com/wine-mirror/wine synced 2024-07-05 17:28:47 +00:00

bcrypt/tests: Use CRT allocation functions.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2022-08-31 08:31:46 +03:00 committed by Alexandre Julliard
parent c0ad6d745e
commit c6a75d01b5

View File

@ -696,7 +696,7 @@ static void test_BCryptGenerateSymmetricKey(void)
ok(key == (void *)0xdeadbeef, "got %p\n", key);
key = NULL;
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
buf = calloc(1, len);
key = (BCRYPT_KEY_HANDLE)0xdeadbeef;
ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, 1, 0);
@ -840,7 +840,7 @@ static void test_BCryptGenerateSymmetricKey(void)
ret = BCryptDestroyKey(key);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
ret = BCryptCloseAlgorithmProvider(aes, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
@ -999,7 +999,7 @@ static void test_BCryptEncrypt(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
key = NULL;
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
buf = calloc(1, len);
ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(key != NULL, "key not set\n");
@ -1098,10 +1098,10 @@ static void test_BCryptEncrypt(void)
ret = BCryptDestroyKey(key);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
/* 256 bit key */
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
buf = calloc(1, len);
ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret256, sizeof(secret256), 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
@ -1131,7 +1131,7 @@ static void test_BCryptEncrypt(void)
ret = BCryptDestroyKey(key);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
/******************
* AES - GCM mode *
@ -1164,7 +1164,7 @@ static void test_BCryptEncrypt(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
key = NULL;
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
buf = calloc(1, len);
ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(key != NULL, "key not set\n");
@ -1311,7 +1311,7 @@ static void test_BCryptEncrypt(void)
ret = BCryptDestroyKey(key);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
/******************
* AES - ECB mode *
@ -1325,7 +1325,7 @@ static void test_BCryptEncrypt(void)
ret = BCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
buf = calloc(1, len);
ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
@ -1402,7 +1402,7 @@ static void test_BCryptEncrypt(void)
ret = BCryptDestroyKey(key);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
/******************
* AES - CFB mode *
@ -1412,7 +1412,7 @@ static void test_BCryptEncrypt(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
key = NULL;
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
buf = calloc(1, len);
ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(key != NULL, "key not set\n");
@ -1511,10 +1511,10 @@ static void test_BCryptEncrypt(void)
ret = BCryptDestroyKey(key);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
/* 256 bit key */
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
buf = calloc(1, len);
ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret256, sizeof(secret256), 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
@ -1618,7 +1618,7 @@ static void test_BCryptDecrypt(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
key = NULL;
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
buf = calloc(1, len);
ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(key != NULL, "key not set\n");
@ -1709,7 +1709,7 @@ static void test_BCryptDecrypt(void)
ret = BCryptDestroyKey(key);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
/******************
* AES - GCM mode *
@ -1719,7 +1719,7 @@ static void test_BCryptDecrypt(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
key = NULL;
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
buf = calloc(1, len);
ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(key != NULL, "key not set\n");
@ -1767,7 +1767,7 @@ static void test_BCryptDecrypt(void)
ret = BCryptDestroyKey(key);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
/******************
* AES - ECB mode *
@ -1781,7 +1781,7 @@ static void test_BCryptDecrypt(void)
ret = BCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
buf = calloc(1, len);
ret = BCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
@ -1869,7 +1869,7 @@ static void test_BCryptDecrypt(void)
ret = BCryptDestroyKey(key);
ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
ret = BCryptDestroyKey(NULL);
ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
@ -1930,7 +1930,7 @@ static void test_key_import_export(void)
ok(ret == STATUS_BUFFER_TOO_SMALL, "got %#lx\n", ret);
ok(size > 0, "got zero\n");
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
ret = BCryptExportKey(key, NULL, BCRYPT_OPAQUE_KEY_BLOB, buf, size, &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
@ -1941,7 +1941,7 @@ static void test_key_import_export(void)
ret = BCryptImportKey(aes, NULL, BCRYPT_OPAQUE_KEY_BLOB, &key, NULL, 0, buf, size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(key != NULL, "key not set\n");
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
ret = BCryptDestroyKey(key);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
@ -2380,7 +2380,7 @@ static void test_RSA(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(size, "size not set\n");
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
ret = BCryptExportKey(key, NULL, BCRYPT_RSAPRIVATE_BLOB, buf, size, &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
@ -2392,14 +2392,14 @@ static void test_RSA(void)
ok(rsablob->cbPrime2 == 32, "got %lu\n", rsablob->cbPrime2);
size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus + rsablob->cbPrime1 + rsablob->cbPrime2;
ok(size == size2, "got %lu expected %lu\n", size2, size);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
size = 0;
ret = BCryptExportKey(key, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, NULL, 0, &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(size, "size not set\n");
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
ret = BCryptExportKey(key, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, buf, size, &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
@ -2411,7 +2411,7 @@ static void test_RSA(void)
ok(rsablob->cbPrime2 == 32, "got %lu\n", rsablob->cbPrime2);
size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus * 2 + rsablob->cbPrime1 * 3 + rsablob->cbPrime2 * 2;
ok(size == size2, "got %lu expected %lu\n", size2, size);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
/* import/export public key */
size = 0;
@ -2419,7 +2419,7 @@ static void test_RSA(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(size, "size not set\n");
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
ret = BCryptExportKey(key, NULL, BCRYPT_RSAPUBLIC_BLOB, buf, size, &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
@ -2439,7 +2439,7 @@ static void test_RSA(void)
ret = BCryptImportKeyPair(alg, NULL, BCRYPT_RSAPUBLIC_BLOB, &key, buf, size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
ret = BCryptVerifySignature(key, &pad, hash, sizeof(hash), sig, len, BCRYPT_PAD_PKCS1);
ok(!ret, "got %#lx\n", ret);
@ -2454,12 +2454,12 @@ static void test_RSA(void)
ok(ret == STATUS_INVALID_HANDLE, "got %#lx\n", ret);
size = 0;
buf = HeapAlloc(GetProcessHeap(), 0, sizeof(rsaPrivateBlob));
buf = malloc(sizeof(rsaPrivateBlob));
ret = BCryptExportKey(key, NULL, BCRYPT_RSAPRIVATE_BLOB, buf, sizeof(rsaPrivateBlob), &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(size == sizeof(rsaPrivateBlob), "got %lu\n", size);
ok(!memcmp(buf, rsaPrivateBlob, size), "wrong data\n");
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
BCryptDestroyKey(key);
/* import/export full private key */
@ -2467,12 +2467,12 @@ static void test_RSA(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
size = 0;
buf = HeapAlloc(GetProcessHeap(), 0, sizeof(rsaFullPrivateBlob));
buf = malloc(sizeof(rsaFullPrivateBlob));
ret = BCryptExportKey(key, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, buf, sizeof(rsaFullPrivateBlob), &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(size == sizeof(rsaFullPrivateBlob), "got %lu\n", size);
ok(!memcmp(buf, rsaFullPrivateBlob, size), "wrong data\n");
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
BCryptDestroyKey(key);
ret = BCryptCloseAlgorithmProvider(alg, 0);
@ -2555,7 +2555,7 @@ static void test_RSA_SIGN(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(size, "size not set\n");
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
ret = BCryptExportKey(key, NULL, BCRYPT_RSAPRIVATE_BLOB, buf, size, &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
@ -2567,14 +2567,14 @@ static void test_RSA_SIGN(void)
ok(rsablob->cbPrime2 == 32, "got %lu\n", rsablob->cbPrime2);
size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus + rsablob->cbPrime1 + rsablob->cbPrime2;
ok(size == size2, "got %lu expected %lu\n", size2, size);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
size = 0;
ret = BCryptExportKey(key, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, NULL, 0, &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(size, "size not set\n");
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
ret = BCryptExportKey(key, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, buf, size, &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
@ -2586,7 +2586,7 @@ static void test_RSA_SIGN(void)
ok(rsablob->cbPrime2 == 32, "got %lu\n", rsablob->cbPrime2);
size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus * 2 + rsablob->cbPrime1 * 3 + rsablob->cbPrime2 * 2;
ok(size == size2, "got %lu expected %lu\n", size2, size);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
BCryptDestroyKey(key);
ret = BCryptCloseAlgorithmProvider(alg, 0);
@ -2672,7 +2672,7 @@ static void test_ECDH(void)
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
ok(size, "size not set\n");
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
status = BCryptExportKey(key, NULL, BCRYPT_ECCPUBLIC_BLOB, buf, size, &size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
ecckey = (BCRYPT_ECCKEY_BLOB *)buf;
@ -2686,14 +2686,14 @@ static void test_ECDH(void)
status = BCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &pubkey, buf, size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
size = 0;
status = BCryptExportKey(key, NULL, BCRYPT_ECCPRIVATE_BLOB, NULL, 0, &size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
ok(size, "size not set\n");
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
status = BCryptExportKey(key, NULL, BCRYPT_ECCPRIVATE_BLOB, buf, size, &size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
ecckey = (BCRYPT_ECCKEY_BLOB *)buf;
@ -2703,7 +2703,7 @@ static void test_ECDH(void)
status = BCryptImportKeyPair(alg, NULL, BCRYPT_ECCPRIVATE_BLOB, &privkey, buf, size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
BCryptDestroyKey(pubkey);
BCryptDestroyKey(privkey);
BCryptDestroyKey(key);
@ -2716,12 +2716,12 @@ static void test_ECDH(void)
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
ok(size, "size not set\n");
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
status = BCryptExportKey(privkey, NULL, BCRYPT_ECCPRIVATE_BLOB, buf, size, &size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
ok(size == sizeof(eccprivkey), "got %lu\n", size);
ok(!memcmp(buf, eccprivkey, size), "wrong data\n");
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
status = BCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &pubkey, ecdh_pubkey, sizeof(ecdh_pubkey), 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
@ -2743,11 +2743,11 @@ static void test_ECDH(void)
if (status != STATUS_SUCCESS) goto raw_secret_end;
ok(size == 32, "size of secret key incorrect, got %lu, expected 32\n", size);
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
status = BCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, NULL, buf, size, &size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
ok(!(memcmp(ecdh_secret, buf, size)), "wrong data\n");
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
raw_secret_end:
status = BCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, NULL, 0, &size, 0);
@ -2755,11 +2755,11 @@ raw_secret_end:
if (status != STATUS_SUCCESS) goto derive_end;
ok (size == 20, "got %lu\n", size);
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
status = BCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, buf, size, &size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
ok(!(memcmp(hashed_secret, buf, size)), "wrong data\n");
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
/* ulVersion is not verified */
hash_params.ulVersion = 0xdeadbeef;
@ -2800,7 +2800,7 @@ derive_end:
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
ok(size, "size not set\n");
buf = HeapAlloc(GetProcessHeap(), 0, size);
buf = malloc(size);
status = BCryptExportKey(key, NULL, BCRYPT_ECCPUBLIC_BLOB, buf, size, &size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
ecckey = (BCRYPT_ECCKEY_BLOB *)buf;
@ -2814,7 +2814,7 @@ derive_end:
status = BCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &pubkey, buf, size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
BCryptDestroyKey(pubkey);
BCryptCloseAlgorithmProvider(alg, 0);
}
@ -3260,7 +3260,7 @@ static void test_DSA(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(size, "size not set\n");
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
buf = calloc(1, size);
ret = BCryptExportKey(key, NULL, BCRYPT_DSA_PUBLIC_BLOB, buf, size, &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
dsablob = (BCRYPT_DSA_KEY_BLOB *)buf;
@ -3273,7 +3273,7 @@ static void test_DSA(void)
ret = BCryptImportKeyPair(alg, NULL, BCRYPT_DSA_PUBLIC_BLOB, &key, buf, size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
ret = BCryptVerifySignature(key, NULL, dsaHash, sizeof(dsaHash), sig, len, 0);
ok(!ret, "got %#lx\n", ret);
@ -3288,12 +3288,12 @@ static void test_DSA(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(size, "size not set\n");
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
buf = calloc(1, size);
ret = BCryptExportKey(key, NULL, LEGACY_DSA_V2_PRIVATE_BLOB, buf, size, &size, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(size == sizeof(dssKey), "got %lu expected %Iu\n", size, sizeof(dssKey));
ok(!memcmp(dssKey, buf, size), "wrong data\n");
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
ret = BCryptDestroyKey(key);
ok(!ret, "got %#lx\n", ret);