ReactOS 0.4.16-dev-2354-g16de117
crypt.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wincrypt.h"
#include "winerror.h"
#include "winreg.h"
#include "wine/test.h"
Include dependency graph for crypt.c:

Go to the source code of this file.

Macros

#define NON_DEF_PROV_TYPE   999
 
#define key_length   16
 

Functions

static BOOL (WINAPI *pCryptEnumProviderTypesA)(DWORD
 
static BOOLEAN (WINAPI *pSystemFunction036)(PVOID
 
static void init_function_pointers (void)
 
static void init_environment (void)
 
static void clean_up_environment (void)
 
static void test_CryptReleaseContext (void)
 
static void test_acquire_context (void)
 
static void test_incorrect_api_usage (void)
 
static void test_verify_sig (void)
 
static BOOL FindProvRegVals (DWORD dwIndex, DWORD *pdwProvType, LPSTR *pszProvName, DWORD *pcbProvName, DWORD *pdwProvCount)
 
static void test_enum_providers (void)
 
static BOOL FindProvTypesRegVals (DWORD *pdwIndex, DWORD *pdwProvType, LPSTR *pszTypeName, DWORD *pcbTypeName, DWORD *pdwTypeCount)
 
static void test_enum_provider_types (void)
 
static BOOL FindDfltProvRegVals (DWORD dwProvType, DWORD dwFlags, LPSTR *pszProvName, DWORD *pcbProvName)
 
static void test_get_default_provider (void)
 
static void test_set_provider_ex (void)
 
static void test_machine_guid (void)
 
static void test_rc2_keylen (void)
 
static void test_SystemFunction036 (void)
 
static void test_container_sd (void)
 
 START_TEST (crypt)
 

Variables

static const char szRsaBaseProv [] = MS_DEF_PROV_A
 
static const char szNonExistentProv [] = "Wine Nonexistent Cryptographic Provider v11.2"
 
static const char szKeySet [] = "wine_test_keyset"
 
static const char szBadKeySet [] = "wine_test_bad_keyset"
 
static DWORD DWORD
 
static DWORD DWORD LPSTR
 
static BYTE *static DWORD HCRYPTHASH *static HCRYPTKEY
 
static LPCWSTR
 
static ULONG
 
static const BYTE privKey []
 
static const unsigned char key [key_length]
 

Macro Definition Documentation

◆ key_length

#define key_length   16

Definition at line 1100 of file crypt.c.

◆ NON_DEF_PROV_TYPE

#define NON_DEF_PROV_TYPE   999

Definition at line 35 of file crypt.c.

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pCryptEnumProviderTypesA)
static

◆ BOOLEAN()

static BOOLEAN ( WINAPI pSystemFunction036)
static

◆ clean_up_environment()

static void clean_up_environment ( void  )
static

Definition at line 95 of file crypt.c.

96{
98 BOOL ret;
99
100 /* Remove container "wine_test_keyset" */
102 {
104 ok(ret, "got %lu\n", GetLastError());
105
107 }
108
109 /* Remove container "wine_test_keyset" from default PROV_RSA_FULL type provider */
111 {
113 ok(ret, "got %lu\n", GetLastError());
114
116 }
117
118 /* Remove container "wine_test_bad_keyset" */
120 {
122 ok(ret, "got %lu\n", GetLastError());
123
125 }
126}
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags)
Definition: crypt.c:661
BOOL WINAPI CryptAcquireContextA(HCRYPTPROV *phProv, LPCSTR pszContainer, LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
Definition: crypt.c:569
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
static const char szBadKeySet[]
Definition: crypt.c:34
static const char szKeySet[]
Definition: crypt.c:33
static const char szRsaBaseProv[]
Definition: crypt.c:31
static HCRYPTPROV hProv
Definition: rsaenh.c:32
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define PROV_RSA_FULL
Definition: wincrypt.h:2243
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:55
#define CRYPT_DELETEKEYSET
Definition: wincrypt.h:2275

Referenced by START_TEST().

◆ FindDfltProvRegVals()

static BOOL FindDfltProvRegVals ( DWORD  dwProvType,
DWORD  dwFlags,
LPSTR pszProvName,
DWORD pcbProvName 
)
static

Definition at line 857 of file crypt.c.

858{
859 HKEY hKey;
860 PSTR keyname;
861 PSTR ptr;
863
864 LPCSTR machinestr = "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types\\Type XXX";
865 LPCSTR userstr = "Software\\Microsoft\\Cryptography\\Provider Type XXX";
866
867 keyname = LocalAlloc(LMEM_ZEROINIT, (user ? strlen(userstr) : strlen(machinestr)) + 1);
868 if (keyname)
869 {
870 user ? strcpy(keyname, userstr) : strcpy(keyname, machinestr);
871 ptr = keyname + strlen(keyname);
872 *(--ptr) = (dwProvType % 10) + '0';
873 *(--ptr) = ((dwProvType / 10) % 10) + '0';
874 *(--ptr) = (dwProvType / 100) + '0';
875 } else
876 return FALSE;
877
879 {
880 LocalFree(keyname);
881 return FALSE;
882 }
883 LocalFree(keyname);
884
885 if (RegQueryValueExA(hKey, "Name", NULL, NULL, (LPBYTE)*pszProvName, pcbProvName))
886 {
889 return FALSE;
890 }
891
892 if (!(*pszProvName = LocalAlloc(LMEM_ZEROINIT, *pcbProvName)))
893 return FALSE;
894
895 if (RegQueryValueExA(hKey, "Name", NULL, NULL, (LPBYTE)*pszProvName, pcbProvName))
896 {
899 return FALSE;
900 }
901
903
904 return TRUE;
905}
void user(int argc, const char *argv[])
Definition: cmds.c:1350
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3234
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4009
#define SetLastError(x)
Definition: compat.h:752
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define LMEM_ZEROINIT
Definition: minwinbase.h:85
static PVOID ptr
Definition: dispmode.c:27
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
strcpy
Definition: string.h:131
char * PSTR
Definition: typedefs.h:51
unsigned char * LPBYTE
Definition: typedefs.h:53
#define CRYPT_USER_DEFAULT
Definition: wincrypt.h:2281
#define NTE_PROV_TYPE_ENTRY_BAD
Definition: winerror.h:4271
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11
const char * LPCSTR
Definition: xmlstorage.h:183

Referenced by test_get_default_provider().

◆ FindProvRegVals()

static BOOL FindProvRegVals ( DWORD  dwIndex,
DWORD pdwProvType,
LPSTR pszProvName,
DWORD pcbProvName,
DWORD pdwProvCount 
)
static

Definition at line 582 of file crypt.c.

584{
585 HKEY hKey;
586 HKEY subkey;
587 DWORD size = sizeof(DWORD);
588
589 if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\Defaults\\Provider", &hKey))
590 return FALSE;
591
592 RegQueryInfoKeyA(hKey, NULL, NULL, NULL, pdwProvCount, pcbProvName,
593 NULL, NULL, NULL, NULL, NULL, NULL);
594 (*pcbProvName)++;
595
596 if (!(*pszProvName = LocalAlloc(LMEM_ZEROINIT, *pcbProvName)))
597 return FALSE;
598
599 RegEnumKeyExA(hKey, dwIndex, *pszProvName, pcbProvName, NULL, NULL, NULL, NULL);
600 (*pcbProvName)++;
601
602 RegOpenKeyA(hKey, *pszProvName, &subkey);
603 RegQueryValueExA(subkey, "Type", NULL, NULL, (LPBYTE)pdwProvType, &size);
604
605 RegCloseKey(subkey);
607
608 return TRUE;
609}
LONG WINAPI RegQueryInfoKeyA(HKEY hKey, LPSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3583
LONG WINAPI RegEnumKeyExA(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2419
GLsizeiptr size
Definition: glext.h:5919
#define DWORD
Definition: nt_native.h:44

Referenced by test_enum_providers().

◆ FindProvTypesRegVals()

static BOOL FindProvTypesRegVals ( DWORD pdwIndex,
DWORD pdwProvType,
LPSTR pszTypeName,
DWORD pcbTypeName,
DWORD pdwTypeCount 
)
static

Definition at line 704 of file crypt.c.

706{
707 HKEY hKey;
708 HKEY hSubKey;
709 PSTR ch;
711 DWORD cbName;
712 BOOL ret = FALSE;
713
714 if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types", &hKey))
715 return FALSE;
716
717 if (RegQueryInfoKeyA(hKey, NULL, NULL, NULL, pdwTypeCount, &cbName, NULL,
718 NULL, NULL, NULL, NULL, NULL))
719 goto cleanup;
720 cbName++;
721
722 if (!(szName = LocalAlloc(LMEM_ZEROINIT, cbName)))
723 goto cleanup;
724
725 while (!RegEnumKeyExA(hKey, *pdwIndex, szName, &cbName, NULL, NULL, NULL, NULL))
726 {
727 cbName++;
728 ch = szName + strlen(szName);
729 /* Convert "Type 000" to 0, etc/ */
730 *pdwProvType = *(--ch) - '0';
731 *pdwProvType += (*(--ch) - '0') * 10;
732 *pdwProvType += (*(--ch) - '0') * 100;
733
734 if (RegOpenKeyA(hKey, szName, &hSubKey))
735 break;
736
737 if (!RegQueryValueExA(hSubKey, "TypeName", NULL, NULL, NULL, pcbTypeName))
738 {
739 if (!(*pszTypeName = LocalAlloc(LMEM_ZEROINIT, *pcbTypeName)))
740 break;
741
742 if (!RegQueryValueExA(hSubKey, "TypeName", NULL, NULL, (LPBYTE)*pszTypeName, pcbTypeName))
743 {
744 ret = TRUE;
745 break;
746 }
747
748 LocalFree(*pszTypeName);
749 }
750
751 RegCloseKey(hSubKey);
752
753 (*pdwIndex)++;
754 }
755 RegCloseKey(hSubKey);
757
758cleanup:
760
761 return ret;
762}
static void cleanup(void)
Definition: main.c:1335
unsigned char ch[4][2]
Definition: console.c:118
static const WCHAR szName[]
Definition: powrprof.c:45
char * LPSTR
Definition: xmlstorage.h:182

Referenced by test_enum_provider_types().

◆ init_environment()

static void init_environment ( void  )
static

Definition at line 64 of file crypt.c.

65{
67 BOOL ret;
68
69 /* Ensure that container "wine_test_keyset" does exist */
71 {
73 }
75 ok(ret, "got %lu\n", GetLastError());
76
77 /* Ensure that container "wine_test_keyset" does exist in default PROV_RSA_FULL type provider */
79 {
81 }
83 ok(ret, "got %lu\n", GetLastError());
84
85 /* Ensure that container "wine_test_bad_keyset" does not exist. */
87 {
89 ok(ret, "got %lu\n", GetLastError());
90
92 }
93}
#define CRYPT_NEWKEYSET
Definition: wincrypt.h:2274

Referenced by START_TEST().

◆ init_function_pointers()

static void init_function_pointers ( void  )
static

Definition at line 48 of file crypt.c.

49{
50 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
51
52 pCryptEnumProviderTypesA = (void*)GetProcAddress(hadvapi32, "CryptEnumProviderTypesA");
53 pCryptEnumProvidersA = (void*)GetProcAddress(hadvapi32, "CryptEnumProvidersA");
54 pCryptGetDefaultProviderA = (void*)GetProcAddress(hadvapi32, "CryptGetDefaultProviderA");
55 pCryptSetProviderExA = (void*)GetProcAddress(hadvapi32, "CryptSetProviderExA");
56 pCryptGenRandom = (void*)GetProcAddress(hadvapi32, "CryptGenRandom");
57 pCryptDuplicateHash = (void*)GetProcAddress(hadvapi32, "CryptDuplicateHash");
58 pCryptHashSessionKey = (void*)GetProcAddress(hadvapi32, "CryptHashSessionKey");
59 pCryptSignHashW = (void*)GetProcAddress(hadvapi32, "CryptSignHashW");
60 pCryptVerifySignatureW = (void*)GetProcAddress(hadvapi32, "CryptVerifySignatureW");
61 pSystemFunction036 = (void*)GetProcAddress(hadvapi32, "SystemFunction036");
62}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( crypt  )

Definition at line 1292 of file crypt.c.

1293{
1295
1297
1306
1312}
static void test_verify_sig(void)
Definition: crypt.c:513
static void test_rc2_keylen(void)
Definition: crypt.c:1106
static void test_SystemFunction036(void)
Definition: crypt.c:1229
static void test_set_provider_ex(void)
Definition: crypt.c:989
static void init_function_pointers(void)
Definition: crypt.c:48
static void test_machine_guid(void)
Definition: crypt.c:1052
static void test_incorrect_api_usage(void)
Definition: crypt.c:253
static void init_environment(void)
Definition: crypt.c:64
static void test_get_default_provider(void)
Definition: crypt.c:907
static void test_enum_provider_types(void)
Definition: crypt.c:764
static void clean_up_environment(void)
Definition: crypt.c:95
static void test_container_sd(void)
Definition: crypt.c:1258
static void test_CryptReleaseContext(void)
Definition: crypt.c:128
static void test_acquire_context(void)
Definition: crypt.c:183
static void test_enum_providers(void)
Definition: crypt.c:611

◆ test_acquire_context()

static void test_acquire_context ( void  )
static

Definition at line 183 of file crypt.c.

184{
185 BOOL result;
187 DWORD GLE;
188
189 /* Provoke all kinds of error conditions (which are easy to provoke).
190 * The order of the error tests seems to match Windows XP's rsaenh.dll CSP,
191 * but since this is likely to change between CSP versions, we don't check
192 * this. Please don't change the order of tests. */
195
198
201
204
207
208
209if (0)
210{
211 /* This test fails under Win2k SP4:
212 result = TRUE, GetLastError() == ERROR_INVALID_PARAMETER */
213 SetLastError(0xdeadbeef);
216}
217
218 /* Last not least, try to really acquire a context. */
219 hProv = 0;
220 SetLastError(0xdeadbeef);
222 GLE = GetLastError();
224 GLE == ERROR_SUCCESS ||
226 GLE == NTE_FAIL ||
227 GLE == ERROR_NOT_LOGGED_ON), "%d/%ld\n", result, GLE);
228
229 if (hProv)
230 {
232 ok(result, "got %lu\n", GetLastError());
233 }
234
235 /* Try again, witch an empty ("\0") szProvider parameter */
236 hProv = 0;
237 SetLastError(0xdeadbeef);
239 GLE = GetLastError();
241 GLE == ERROR_SUCCESS ||
243 GLE == NTE_FAIL ||
244 GLE == ERROR_NOT_LOGGED_ON), "%d/%ld\n", result, GetLastError());
245
246 if (hProv)
247 {
249 ok(result, "got %lu\n", GetLastError());
250 }
251}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
GLuint64EXT * result
Definition: glext.h:11304
#define NON_DEF_PROV_TYPE
Definition: crypt.c:35
static const char szNonExistentProv[]
Definition: crypt.c:32
static DWORD GLE
Definition: registry.c:54
#define ERROR_NOT_LOGGED_ON
Definition: winerror.h:1077
#define NTE_BAD_PROV_TYPE
Definition: winerror.h:4267
#define ERROR_RING2_STACK_IN_USE
Definition: winerror.h:386
#define NTE_KEYSET_NOT_DEF
Definition: winerror.h:4272
#define NTE_FAIL
Definition: winerror.h:4279
#define NTE_PROV_TYPE_NO_MATCH
Definition: winerror.h:4274
#define ERROR_ENVVAR_NOT_FOUND
Definition: winerror.h:383
#define NTE_PROV_TYPE_NOT_DEF
Definition: winerror.h:4270

Referenced by START_TEST().

◆ test_container_sd()

static void test_container_sd ( void  )
static

Definition at line 1258 of file crypt.c.

1259{
1260 HCRYPTPROV prov;
1262 DWORD len, err;
1263 BOOL ret;
1264
1265 ret = CryptAcquireContextA(&prov, "winetest", "Microsoft Enhanced Cryptographic Provider v1.0",
1267 ok(ret, "got %lu\n", GetLastError());
1268
1269 len = 0;
1270 SetLastError(0xdeadbeef);
1272 err = GetLastError();
1273 ok(ret, "got %lu\n", err);
1275 ok(len, "expected len > 0\n");
1276
1277 sd = malloc(len);
1279 ok(ret, "got %lu\n", GetLastError());
1280 free(sd);
1281
1282 ret = CryptReleaseContext(prov, 0);
1283 ok(ret, "got %lu\n", GetLastError());
1284
1285 prov = 0xdeadbeef;
1286 ret = CryptAcquireContextA(&prov, "winetest", "Microsoft Enhanced Cryptographic Provider v1.0",
1288 ok(ret, "got %lu\n", GetLastError());
1289 ok(prov == 0, "got %Id\n", prov);
1290}
#define broken(x)
Definition: atltest.h:178
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
BOOL WINAPI CryptGetProvParam(HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: crypt.c:1753
GLenum GLsizei len
Definition: glext.h:6722
static const WCHAR sd[]
Definition: suminfo.c:286
#define err(...)
#define PP_KEYSET_SEC_DESCR
Definition: wincrypt.h:2293
#define CRYPT_MACHINE_KEYSET
Definition: wincrypt.h:2276
#define OWNER_SECURITY_INFORMATION
Definition: setypes.h:123
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

◆ test_CryptReleaseContext()

static void test_CryptReleaseContext ( void  )
static

Definition at line 128 of file crypt.c.

129{
130 BOOL ret;
131 HCRYPTPROV prov;
132
133 /* TODO: Add cases for ERROR_BUSY, ERROR_INVALID_HANDLE and NTE_BAD_UID */
134
135 /* NULL provider */
136
137 SetLastError(0xdeadbeef);
138 ret = CryptReleaseContext(0, 0);
139 ok(!ret, "CryptReleaseContext succeeded unexpectedly\n");
141
142 SetLastError(0xdeadbeef);
143 ret = CryptReleaseContext(0, ~0);
144 ok(!ret, "CryptReleaseContext succeeded unexpectedly\n");
146
147 /* Additional refcount */
148
150 ok(ret, "got %lu\n", GetLastError());
151
152 ret = CryptContextAddRef(prov, NULL, 0);
153 ok(ret, "got %lu\n", GetLastError());
154
155 ret = CryptContextAddRef(0, NULL, 0);
156 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %lu\n", GetLastError());
157 ret = CryptContextAddRef(0xdeadbeef, NULL, 0);
158 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %lu\n", GetLastError());
159
160 ret = CryptReleaseContext(prov, 0);
161 ok(ret, "got %lu\n", GetLastError());
162
163 /* Nonzero flags, which allow release nonetheless */
164
165 SetLastError(0xdeadbeef);
166 ret = CryptReleaseContext(prov, ~0);
167 ok(!ret, "CryptReleaseContext succeeded unexpectedly\n");
168 ok(GetLastError() == NTE_BAD_FLAGS, "got %lu\n", GetLastError());
169
170 /* Obsolete provider */
171
172 SetLastError(0xdeadbeef);
173 ret = CryptReleaseContext(prov, 0);
174 ok(!ret, "CryptReleaseContext succeeded unexpectedly\n");
176
177 SetLastError(0xdeadbeef);
178 ret = CryptReleaseContext(prov, ~0);
179 ok(!ret, "CryptReleaseContext succeeded unexpectedly\n");
181}
BOOL WINAPI CryptContextAddRef(HCRYPTPROV hProv, DWORD *pdwReserved, DWORD dwFlags)
Definition: crypt.c:613
#define NTE_BAD_FLAGS
Definition: winerror.h:4256

Referenced by START_TEST().

◆ test_enum_provider_types()

static void test_enum_provider_types ( void  )
static

Definition at line 764 of file crypt.c.

765{
766 /* expected values */
767 DWORD dwProvType = 0;
768 LPSTR pszTypeName = NULL;
769 DWORD cbTypeName;
770 DWORD dwTypeCount;
771
772 /* actual values */
773 DWORD index = 0;
774 DWORD provType;
775 LPSTR typeName = NULL;
776 DWORD typeNameSize;
777 DWORD typeCount;
779 DWORD notNull = 5;
780 DWORD notZeroFlags = 5;
781
782 if(!pCryptEnumProviderTypesA)
783 {
784 win_skip("CryptEnumProviderTypesA is not available\n");
785 return;
786 }
787
788 if (!FindProvTypesRegVals(&index, &dwProvType, &pszTypeName, &cbTypeName, &dwTypeCount))
789 {
790 skip("Could not find provider types in registry\n");
791 return;
792 }
793
794 /* check pdwReserved for NULL */
795 result = pCryptEnumProviderTypesA(index, &notNull, 0, &provType, typeName, &typeNameSize);
796 ok(!result && GetLastError()==ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n",
797 GetLastError());
798
799 /* check dwFlags == zero */
800 result = pCryptEnumProviderTypesA(index, NULL, notZeroFlags, &provType, typeName, &typeNameSize);
801 ok(!result && GetLastError()==NTE_BAD_FLAGS, "expected ERROR_INVALID_PARAMETER, got %ld\n",
802 GetLastError());
803
804 /* This test fails under Win2k SP4:
805 * result = TRUE, GetLastError() == 0xdeadbeef */
806 if (0)
807 {
808 /* alloc provider type to half the size required
809 * cbTypeName holds the size required */
810 typeNameSize = cbTypeName / 2;
811 if (!(typeName = LocalAlloc(LMEM_ZEROINIT, typeNameSize)))
812 goto cleanup;
813
814 SetLastError(0xdeadbeef);
815 result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, typeName, &typeNameSize);
816 ok(!result && GetLastError()==ERROR_MORE_DATA, "expected 0/ERROR_MORE_DATA, got %ld/%ld\n",
818
819 LocalFree(typeName);
820 }
821
822 /* loop through the provider types to get the number of provider types
823 * after loop ends, count should be dwTypeCount + 1 so subtract 1
824 * to get actual number of provider types */
825 typeCount = 0;
826 while(pCryptEnumProviderTypesA(typeCount++, NULL, 0, &provType, NULL, &typeNameSize))
827 ;
828 typeCount--;
829 ok(typeCount==dwTypeCount, "expected %ld, got %ld\n", dwTypeCount, typeCount);
830
831 /* loop past the actual number of provider types to get the error
832 * ERROR_NO_MORE_ITEMS */
833 for (typeCount = 0; typeCount < dwTypeCount + 1; typeCount++)
834 result = pCryptEnumProviderTypesA(typeCount, NULL, 0, &provType, NULL, &typeNameSize);
835 ok(!result && GetLastError()==ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %ld\n",
836 GetLastError());
837
838 /* check expected versus actual values returned */
839 result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, NULL, &typeNameSize);
840 ok(result && typeNameSize==cbTypeName, "expected %ld, got %ld\n", cbTypeName, typeNameSize);
841 if (!(typeName = LocalAlloc(LMEM_ZEROINIT, typeNameSize)))
842 goto cleanup;
843
844 typeNameSize = 0xdeadbeef;
845 result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, typeName, &typeNameSize);
846 ok(result, "expected TRUE, got %ld\n", result);
847 ok(provType==dwProvType, "expected %ld, got %ld\n", dwProvType, provType);
848 if (pszTypeName)
849 ok(!strcmp(pszTypeName, typeName), "expected %s, got %s\n", pszTypeName, typeName);
850 ok(typeNameSize==cbTypeName, "expected %ld, got %ld\n", cbTypeName, typeNameSize);
851
852 LocalFree(typeName);
853cleanup:
854 LocalFree(pszTypeName);
855}
#define skip(...)
Definition: atltest.h:64
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
GLuint index
Definition: glext.h:6031
#define win_skip
Definition: minitest.h:67
static BOOL FindProvTypesRegVals(DWORD *pdwIndex, DWORD *pdwProvType, LPSTR *pszTypeName, DWORD *pcbTypeName, DWORD *pdwTypeCount)
Definition: crypt.c:704

Referenced by START_TEST().

◆ test_enum_providers()

static void test_enum_providers ( void  )
static

Definition at line 611 of file crypt.c.

612{
613 /* expected results */
614 CHAR *pszProvName = NULL;
615 DWORD cbName;
616 DWORD dwType;
617 DWORD provCount;
618 DWORD dwIndex = 0;
619
620 /* actual results */
621 CHAR *provider = NULL;
622 DWORD providerLen;
623 DWORD type;
624 DWORD count;
626 DWORD notNull = 5;
627 DWORD notZeroFlags = 5;
628
629 if(!pCryptEnumProvidersA)
630 {
631 win_skip("CryptEnumProvidersA is not available\n");
632 return;
633 }
634
635 if (!FindProvRegVals(dwIndex, &dwType, &pszProvName, &cbName, &provCount))
636 {
637 win_skip("Could not find providers in registry\n");
638 return;
639 }
640
641 /* check pdwReserved flag for NULL */
642 result = pCryptEnumProvidersA(dwIndex, &notNull, 0, &type, NULL, &providerLen);
644
645 /* check dwFlags == 0 */
646 result = pCryptEnumProvidersA(dwIndex, NULL, notZeroFlags, &type, NULL, &providerLen);
647 ok(!result && GetLastError()==NTE_BAD_FLAGS, "%ld\n", GetLastError());
648
649 /* alloc provider to half the size required
650 * cbName holds the size required */
651 providerLen = cbName / 2;
652 if (!(provider = LocalAlloc(LMEM_ZEROINIT, providerLen)))
653 return;
654
655 result = pCryptEnumProvidersA(dwIndex, NULL, 0, &type, provider, &providerLen);
656 ok(!result && GetLastError()==ERROR_MORE_DATA, "expected %i, got %ld\n",
658
659 LocalFree(provider);
660
661 /* loop through the providers to get the number of providers
662 * after loop ends, count should be provCount + 1 so subtract 1
663 * to get actual number of providers */
664 count = 0;
665 while(pCryptEnumProvidersA(count++, NULL, 0, &type, NULL, &providerLen))
666 ;
667 count--;
668 ok(count==provCount, "expected %i, got %i\n", (int)provCount, (int)count);
669
670 /* loop past the actual number of providers to get the error
671 * ERROR_NO_MORE_ITEMS */
672 for (count = 0; count < provCount + 1; count++)
673 result = pCryptEnumProvidersA(count, NULL, 0, &type, NULL, &providerLen);
674 ok(!result && GetLastError()==ERROR_NO_MORE_ITEMS, "expected %i, got %ld\n",
676
677 /* check expected versus actual values returned */
678 result = pCryptEnumProvidersA(dwIndex, NULL, 0, &type, NULL, &providerLen);
679 ok(result && providerLen==cbName, "expected %i, got %i\n", (int)cbName, (int)providerLen);
680 if (!(provider = LocalAlloc(LMEM_ZEROINIT, providerLen)))
681 return;
682
683 providerLen = -1;
684 result = pCryptEnumProvidersA(dwIndex, NULL, 0, &type, provider, &providerLen);
685 ok(result, "expected TRUE, got %ld\n", result);
686 ok(type==dwType, "expected %ld, got %ld\n", dwType, type);
687 if (pszProvName)
688 ok(!strcmp(pszProvName, provider), "expected %s, got %s\n", pszProvName, provider);
689 ok(cbName==providerLen, "expected %ld, got %ld\n", cbName, providerLen);
690
691 providerLen = -1000;
692 provider[0] = 0;
693 result = pCryptEnumProvidersA(dwIndex, NULL, 0, &type, provider, &providerLen);
694 ok(result, "expected TRUE, got %ld\n", result);
695 ok(type==dwType, "expected %ld, got %ld\n", dwType, type);
696 if (pszProvName)
697 ok(!strcmp(pszProvName, provider), "expected %s, got %s\n", pszProvName, provider);
698 ok(cbName==providerLen, "expected %ld, got %ld\n", cbName, providerLen);
699
700 LocalFree(pszProvName);
701 LocalFree(provider);
702}
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
static BOOL FindProvRegVals(DWORD dwIndex, DWORD *pdwProvType, LPSTR *pszProvName, DWORD *pcbProvName, DWORD *pdwProvCount)
Definition: crypt.c:582
char CHAR
Definition: xmlstorage.h:175

Referenced by START_TEST().

◆ test_get_default_provider()

static void test_get_default_provider ( void  )
static

Definition at line 907 of file crypt.c.

908{
909 /* expected results */
910 DWORD dwProvType = PROV_RSA_FULL;
912 LPSTR pszProvName = NULL;
913 DWORD cbProvName;
914
915 /* actual results */
916 DWORD provType = PROV_RSA_FULL;
918 LPSTR provName = NULL;
919 DWORD provNameSize;
921 DWORD notNull = 5;
922
923 if(!pCryptGetDefaultProviderA)
924 {
925 win_skip("CryptGetDefaultProviderA is not available\n");
926 return;
927 }
928
929 if(!FindDfltProvRegVals(dwProvType, dwFlags, &pszProvName, &cbProvName))
930 {
931 skip("Could not find default provider in registry\n");
932 return;
933 }
934
935 /* check pdwReserved for NULL */
936 result = pCryptGetDefaultProviderA(provType, &notNull, flags, provName, &provNameSize);
937 ok(!result && GetLastError()==ERROR_INVALID_PARAMETER, "expected %i, got %ld\n",
939
940 /* check for invalid flag */
941 flags = 0xdeadbeef;
942 result = pCryptGetDefaultProviderA(provType, NULL, flags, provName, &provNameSize);
943 ok(!result && GetLastError()==NTE_BAD_FLAGS, "expected %ld, got %ld\n",
946
947 /* check for invalid prov type */
948 provType = 0xdeadbeef;
949 result = pCryptGetDefaultProviderA(provType, NULL, flags, provName, &provNameSize);
952 "expected NTE_BAD_PROV_TYPE or ERROR_INVALID_PARAMETER, got %ld/%ld\n",
954 provType = PROV_RSA_FULL;
955
956 SetLastError(0);
957
958 /* alloc provName to half the size required
959 * cbProvName holds the size required */
960 provNameSize = cbProvName / 2;
961 if (!(provName = LocalAlloc(LMEM_ZEROINIT, provNameSize)))
962 return;
963
964 result = pCryptGetDefaultProviderA(provType, NULL, flags, provName, &provNameSize);
965 ok(!result && GetLastError()==ERROR_MORE_DATA, "expected %i, got %ld\n",
967
968 LocalFree(provName);
969
970 /* check expected versus actual values returned */
971 result = pCryptGetDefaultProviderA(provType, NULL, flags, NULL, &provNameSize);
972 ok(result && provNameSize==cbProvName, "expected %ld, got %ld\n", cbProvName, provNameSize);
973 provNameSize = cbProvName;
974
975 if (!(provName = LocalAlloc(LMEM_ZEROINIT, provNameSize)))
976 return;
977
978 provNameSize = 0xdeadbeef;
979 result = pCryptGetDefaultProviderA(provType, NULL, flags, provName, &provNameSize);
980 ok(result, "expected TRUE, got %ld\n", result);
981 if(pszProvName)
982 ok(!strcmp(pszProvName, provName), "expected %s, got %s\n", pszProvName, provName);
983 ok(provNameSize==cbProvName, "expected %ld, got %ld\n", cbProvName, provNameSize);
984
985 LocalFree(pszProvName);
986 LocalFree(provName);
987}
GLbitfield flags
Definition: glext.h:7161
static BOOL FindDfltProvRegVals(DWORD dwProvType, DWORD dwFlags, LPSTR *pszProvName, DWORD *pcbProvName)
Definition: crypt.c:857
#define CRYPT_MACHINE_DEFAULT
Definition: wincrypt.h:2280

Referenced by START_TEST().

◆ test_incorrect_api_usage()

static void test_incorrect_api_usage ( void  )
static

Definition at line 253 of file crypt.c.

254{
255 BOOL result;
256 HCRYPTPROV hProv, hProv2;
257 HCRYPTHASH hHash, hHash2;
258 HCRYPTKEY hKey, hKey2;
259 BYTE temp;
260 DWORD dwLen, dwTemp;
261
262 /* This is to document incorrect api usage in the
263 * "Uru - Ages beyond Myst Demo" installer as reported by Paul Vriens.
264 *
265 * The installer destroys a hash object after having released the context
266 * with which the hash was created. This is not allowed according to MSDN,
267 * since CryptReleaseContext destroys all hash and key objects belonging to
268 * the respective context. However, while wine used to crash, Windows is more
269 * robust here and returns an ERROR_INVALID_PARAMETER code.
270 */
271
274 ok (result, "%08lx\n", GetLastError());
275 if (!result) return;
276
277 /* Looks like native handles are just pointers. */
278 ok(!!*(void **)hProv, "Got zero *(void **)hProv.\n");
279
280 result = CryptCreateHash(hProv, CALG_SHA, 0, 0, &hHash);
281 ok (result, "%ld\n", GetLastError());
282 if (!result) return;
283
284 result = CryptDeriveKey(0, CALG_RC4, hHash, 0, &hKey2);
286
287 result = CryptDeriveKey(hProv, CALG_RC4, 0, 0, &hKey2);
289
290 result = CryptHashData(0, &temp, 1, 0);
292
294 ok (result, "%ld\n", GetLastError());
295 if (!result) return;
296
297 result = pCryptHashSessionKey(hHash, 0, 0);
299
300 result = pCryptHashSessionKey(0, hKey, 0);
302
303 result = CryptDestroyHash(hHash);
304 ok (result, "%08lx\n", GetLastError());
305
308
309 result = CryptCreateHash(0xdeadbeef, CALG_SHA, 0, 0, &hHash);
311
312 result = CryptCreateHash(0, CALG_SHA, 0, 0, &hHash);
314
315 result = CryptGenKey(0, CALG_RC4, 0, &hKey);
317
318 dwLen = 0;
319 SetLastError(0xdeadbeef);
320 result = CryptDecrypt(hKey, 0, FALSE, 0, &temp, &dwLen);
321 ok (result, "%lx\n", GetLastError());
322 dwLen = 0;
323 SetLastError(0xdeadbeef);
324 result = CryptDecrypt(hKey, 0, TRUE, 0, &temp, &dwLen);
325 ok (!result && GetLastError() == NTE_BAD_LEN, "%lx\n", GetLastError());
326 dwLen = 1;
327 result = CryptDecrypt(hKey, 0, TRUE, 0, &temp, &dwLen);
328 ok (result, "%ld\n", GetLastError());
329 result = CryptDecrypt(hKey, 0xdeadbeef, TRUE, 0, &temp, &dwLen);
331 result = CryptDecrypt(0, 0, TRUE, 0, &temp, &dwLen);
333 result = CryptDecrypt(0xdeadbeef, 0, TRUE, 0, &temp, &dwLen);
335
336 result = CryptEncrypt(hKey, 0, TRUE, 0, &temp, &dwLen, sizeof(temp));
337 ok (result, "%ld\n", GetLastError());
338 result = CryptEncrypt(hKey, 0xdeadbeef, TRUE, 0, &temp, &dwLen, sizeof(temp));
340 result = CryptEncrypt(0, 0, TRUE, 0, &temp, &dwLen, sizeof(temp));
342 result = CryptEncrypt(0xdeadbeef, 0, TRUE, 0, &temp, &dwLen, sizeof(temp));
344
345 dwLen = 1;
346 result = CryptExportKey(hKey, 0xdeadbeef, 0, 0, &temp, &dwLen);
348
350 ok (result, "%ld\n", GetLastError());
351
352 result = CryptGenKey(hProv, CALG_RC4, 0, &hKey2);
353 ok (result, "%ld\n", GetLastError());
354 if (!result) return;
355
356 result = CryptDestroyKey(hKey2);
357 ok (result, "%ld\n", GetLastError());
358
361
362 dwTemp = CRYPT_MODE_ECB;
363 result = CryptSetKeyParam(hKey2, KP_MODE, (BYTE*)&dwTemp, sizeof(DWORD));
365
366 hProv2 = 0xdeadbeef;
369 ok (result, "%ld\n", GetLastError());
370 ok (hProv2 == 0, "%Id\n", hProv2);
371 if (!result) return;
372
374 ok(result, "got %lu\n", GetLastError());
375 if (!result) return;
376
377 result = pCryptGenRandom(0, 1, &temp);
379
380 result = pCryptGenRandom(hProv, 1, &temp);
382
385
386 result = CryptCreateHash(hProv, CALG_SHA, 0, 0, &hHash2);
388
389 dwLen = 1;
390 result = CryptDecrypt(hKey, 0, TRUE, 0, &temp, &dwLen);
392
393 dwLen = 1;
394 result = CryptEncrypt(hKey, 0, TRUE, 0, &temp, &dwLen, 1);
396
397 result = CryptDeriveKey(hProv, CALG_RC4, hHash, 0, &hKey2);
399
400#if defined(__REACTOS__) && defined(_M_AMD64)
401 if (is_reactos()) {
402 ok(FALSE, "FIXME: The following tests normally completes on ReactOS x64, but not after being fuzzed from other tests in our test suite.\n");
403 return;
404 }
405#endif
406 result = pCryptDuplicateHash(hHash, NULL, 0, &hHash2);
408
409 result = CryptDuplicateKey(hKey, NULL, 0, &hKey2);
411
412 dwLen = 1;
413 result = CryptExportKey(hKey, 0, 0, 0, &temp, &dwLen);
415
416 result = CryptGenKey(hProv, CALG_RC4, 0, &hKey2);
418
419 dwLen = 1;
420 result = CryptGetHashParam(hHash, 0, &temp, &dwLen, 0);
422
423 dwLen = 1;
424 result = CryptGetKeyParam(hKey, 0, &temp, &dwLen, 0);
426
427 dwLen = 1;
428 result = CryptGetProvParam(hProv, 0, &temp, &dwLen, 0);
430
431 result = CryptGetUserKey(0, 0, &hKey2);
433
434 result = CryptGetUserKey(hProv, 0, &hKey2);
436
437 result = CryptHashData(hHash, &temp, 1, 0);
439
440 result = pCryptHashSessionKey(hHash, hKey, 0);
442
443 result = CryptImportKey(hProv, &temp, 1, 0, 0, &hKey2);
445
446 if (pCryptSignHashW)
447 {
448 dwLen = 1;
449 result = pCryptSignHashW(hHash, 0, NULL, 0, &temp, &dwLen);
452 result = pCryptSignHashW(hHash, 0, NULL, 0, &temp, &dwLen);
455 }
456 else
457 win_skip("CryptSignHashW is not available\n");
458
459 result = CryptSetKeyParam(hKey, 0, &temp, 1);
461
462 result = CryptSetHashParam(hHash, 0, &temp, 1);
464
465 result = CryptSetProvParam(0, 0, &temp, 1);
467
470
471 if (pCryptVerifySignatureW)
472 {
473 result = pCryptVerifySignatureW(hHash, &temp, 1, hKey, NULL, 0);
476 }
477 else
478 win_skip("CryptVerifySignatureW is not available\n");
479
480 result = CryptDestroyHash(hHash);
482
485}
BOOL WINAPI CryptExportKey(HCRYPTKEY hKey, HCRYPTKEY hExpKey, DWORD dwBlobType, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
Definition: crypt.c:1468
BOOL WINAPI CryptCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
Definition: crypt.c:753
BOOL WINAPI CryptSetProvParam(HCRYPTPROV hProv, DWORD dwParam, const BYTE *pbData, DWORD dwFlags)
Definition: crypt.c:2244
BOOL WINAPI CryptGetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: crypt.c:1675
BOOL WINAPI CryptDestroyKey(HCRYPTKEY hKey)
Definition: crypt.c:969
BOOL WINAPI CryptDestroyHash(HCRYPTHASH hHash)
Definition: crypt.c:929
BOOL WINAPI CryptDuplicateKey(HCRYPTKEY hKey, DWORD *pdwReserved, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: crypt.c:1068
BOOL WINAPI CryptHashData(HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
Definition: crypt.c:1836
BOOL WINAPI CryptDeriveKey(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTHASH hBaseData, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: crypt.c:877
BOOL WINAPI CryptGenKey(HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: crypt.c:1516
BOOL WINAPI CryptDecrypt(HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
Definition: crypt.c:826
BOOL WINAPI CryptGetUserKey(HCRYPTPROV hProv, DWORD dwKeySpec, HCRYPTKEY *phUserKey)
Definition: crypt.c:1783
BOOL WINAPI CryptGetKeyParam(HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: crypt.c:1714
BOOL WINAPI CryptSetKeyParam(HCRYPTKEY hKey, DWORD dwParam, const BYTE *pbData, DWORD dwFlags)
Definition: crypt.c:2069
BOOL WINAPI CryptSetHashParam(HCRYPTHASH hHash, DWORD dwParam, const BYTE *pbData, DWORD dwFlags)
Definition: crypt.c:2035
BOOL WINAPI CryptEncrypt(HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen)
Definition: crypt.c:1132
BOOL WINAPI CryptImportKey(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: crypt.c:1915
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
static calc_node_t temp
Definition: rpn_ieee.c:38
#define is_reactos()
Definition: test.h:1041
#define KP_MODE
Definition: wincrypt.h:2335
#define CALG_RC4
Definition: wincrypt.h:2091
#define CRYPT_MODE_ECB
Definition: wincrypt.h:2395
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:58
ULONG_PTR HCRYPTHASH
Definition: wincrypt.h:59
#define CALG_SHA
Definition: wincrypt.h:2059
#define NTE_BAD_LEN
Definition: winerror.h:4251

Referenced by START_TEST().

◆ test_machine_guid()

static void test_machine_guid ( void  )
static

Definition at line 1052 of file crypt.c.

1053{
1054 char originalGuid[40];
1055 LONG r;
1056 HKEY key;
1057 DWORD size;
1058 HCRYPTPROV hCryptProv;
1059 BOOL restoreGuid = FALSE, ret;
1060
1061 r = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography",
1062 0, KEY_ALL_ACCESS, &key);
1063 if (r != ERROR_SUCCESS)
1064 {
1065 skip("couldn't open HKLM\\Software\\Microsoft\\Cryptography\n");
1066 return;
1067 }
1068 /* Cache existing MachineGuid, and delete it */
1069 size = sizeof(originalGuid);
1070 r = RegQueryValueExA(key, "MachineGuid", NULL, NULL, (BYTE *)originalGuid,
1071 &size);
1072 if (r == ERROR_SUCCESS)
1073 {
1074 restoreGuid = TRUE;
1075 r = RegDeleteValueA(key, "MachineGuid");
1076 ok(!r || broken(r == ERROR_ACCESS_DENIED) /*win8*/, "RegDeleteValueA failed: %ld\n", r);
1077 if (r == ERROR_ACCESS_DENIED)
1078 {
1079 skip("broken virtualization on HKLM\\Software\\Microsoft\\Cryptography\n");
1081 return;
1082 }
1083 }
1084 else
1085 ok(r == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %ld\n",
1086 r);
1087 /* Create and release a provider */
1088 ret = CryptAcquireContextA(&hCryptProv, szKeySet, NULL, PROV_RSA_FULL, 0);
1089 ok(ret || broken(!ret && GetLastError() == NTE_KEYSET_ENTRY_BAD /* NT4 */),
1090 "CryptAcquireContextA failed: %08lx\n", GetLastError());
1091 ret = CryptReleaseContext(hCryptProv, 0);
1092 ok(ret, "got %lu\n", GetLastError());
1093
1094 if (restoreGuid)
1095 RegSetValueExA(key, "MachineGuid", 0, REG_SZ, (const BYTE *)originalGuid,
1096 strlen(originalGuid)+1);
1098}
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4799
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
LONG WINAPI RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
Definition: reg.c:2287
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define REG_SZ
Definition: layer.c:22
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
long LONG
Definition: pedump.c:60
Definition: copy.c:22
#define NTE_KEYSET_ENTRY_BAD
Definition: winerror.h:4273

Referenced by START_TEST().

◆ test_rc2_keylen()

static void test_rc2_keylen ( void  )
static

Definition at line 1106 of file crypt.c.

1107{
1108 struct KeyBlob
1109 {
1111 DWORD key_size;
1112 BYTE key_data[2048];
1113 } key_blob;
1114
1115 HCRYPTPROV provider;
1116 HCRYPTKEY hkey = 0;
1117 BOOL ret;
1118
1119 SetLastError(0xdeadbeef);
1120 ret = CryptAcquireContextA(&provider, NULL, NULL,
1122 ok(ret, "CryptAcquireContext error %lu\n", GetLastError());
1123 if (ret)
1124 {
1125 key_blob.header.bType = PLAINTEXTKEYBLOB;
1126 key_blob.header.bVersion = CUR_BLOB_VERSION;
1127 key_blob.header.reserved = 0;
1128 key_blob.header.aiKeyAlg = CALG_RC2;
1129 key_blob.key_size = sizeof(key);
1130 memcpy(key_blob.key_data, key, key_length);
1131
1132 /* Importing a 16-byte key works with the default provider. */
1133 SetLastError(0xdeadbeef);
1134 ret = CryptImportKey(provider, (BYTE *)&key_blob, sizeof(BLOBHEADER) + sizeof(DWORD) + key_blob.key_size,
1135 0, CRYPT_IPSEC_HMAC_KEY, &hkey);
1136 /* CRYPT_IPSEC_HMAC_KEY is not supported on W2K and lower */
1137 ok(ret ||
1139 "CryptImportKey error %08lx\n", GetLastError());
1140 if (ret)
1141 CryptDestroyKey(hkey);
1142
1143 ret = CryptReleaseContext(provider, 0);
1144 ok(ret, "got %lu\n", GetLastError());
1145 }
1146
1147 SetLastError(0xdeadbeef);
1150 ok(ret, "CryptAcquireContext error %08lx\n", GetLastError());
1151
1152 if (ret)
1153 {
1154 /* Importing a 16-byte key doesn't work with the base provider.. */
1155 SetLastError(0xdeadbeef);
1156 ret = CryptImportKey(provider, (BYTE *)&key_blob, sizeof(BLOBHEADER) + sizeof(DWORD) + key_blob.key_size,
1157 0, 0, &hkey);
1158 ok(!ret && (GetLastError() == NTE_BAD_DATA ||
1159 GetLastError() == NTE_BAD_LEN || /* Win7 */
1160 GetLastError() == NTE_BAD_TYPE || /* W2K */
1161 GetLastError() == NTE_PERM), /* Win9x, WinMe and NT4 */
1162 "unexpected error %08lx\n", GetLastError());
1163 /* but importing an 56-bit (7-byte) key does.. */
1164 key_blob.key_size = 7;
1165 SetLastError(0xdeadbeef);
1166 ret = CryptImportKey(provider, (BYTE *)&key_blob, sizeof(BLOBHEADER) + sizeof(DWORD) + key_blob.key_size,
1167 0, 0, &hkey);
1168 ok(ret ||
1169 broken(!ret && GetLastError() == NTE_BAD_TYPE) || /* W2K */
1170 broken(!ret && GetLastError() == NTE_PERM), /* Win9x, WinMe and NT4 */
1171 "CryptAcquireContext error %08lx\n", GetLastError());
1172 if (ret)
1173 CryptDestroyKey(hkey);
1174 /* as does importing a 16-byte key with the base provider when
1175 * CRYPT_IPSEC_HMAC_KEY is specified.
1176 */
1177 key_blob.key_size = sizeof(key);
1178 SetLastError(0xdeadbeef);
1179 ret = CryptImportKey(provider, (BYTE *)&key_blob, sizeof(BLOBHEADER) + sizeof(DWORD) + key_blob.key_size,
1180 0, CRYPT_IPSEC_HMAC_KEY, &hkey);
1181 /* CRYPT_IPSEC_HMAC_KEY is not supported on W2K and lower */
1182 ok(ret ||
1184 "CryptImportKey error %08lx\n", GetLastError());
1185 if (ret)
1186 CryptDestroyKey(hkey);
1187
1188 ret = CryptReleaseContext(provider, 0);
1189 ok(ret, "got %lu\n", GetLastError());
1190 }
1191
1192 key_blob.key_size = sizeof(key);
1193 SetLastError(0xdeadbeef);
1195 ok(ret, "CryptAcquireContext error %08lx\n", GetLastError());
1196
1197 if (ret)
1198 {
1199 /* Importing a 16-byte key also works with the default provider when
1200 * CRYPT_IPSEC_HMAC_KEY is specified.
1201 */
1202 SetLastError(0xdeadbeef);
1203 ret = CryptImportKey(provider, (BYTE *)&key_blob, sizeof(BLOBHEADER) + sizeof(DWORD) + key_blob.key_size,
1204 0, CRYPT_IPSEC_HMAC_KEY, &hkey);
1205 ok(ret ||
1207 "CryptImportKey error %08lx\n", GetLastError());
1208 if (ret)
1209 CryptDestroyKey(hkey);
1210
1211 /* There is no apparent limit to the size of the input key when
1212 * CRYPT_IPSEC_HMAC_KEY is specified.
1213 */
1214 key_blob.key_size = sizeof(key_blob.key_data);
1215 SetLastError(0xdeadbeef);
1216 ret = CryptImportKey(provider, (BYTE *)&key_blob, sizeof(BLOBHEADER) + sizeof(DWORD) + key_blob.key_size,
1217 0, CRYPT_IPSEC_HMAC_KEY, &hkey);
1218 ok(ret ||
1220 "CryptImportKey error %08lx\n", GetLastError());
1221 if (ret)
1222 CryptDestroyKey(hkey);
1223
1224 ret = CryptReleaseContext(provider, 0);
1225 ok(ret, "got %lu\n", GetLastError());
1226 }
1227}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define key_length
Definition: crypt.c:1100
#define PLAINTEXTKEYBLOB
Definition: wincrypt.h:2446
#define MS_DEF_PROV_A
Definition: wincrypt.h:2115
#define CALG_RC2
Definition: wincrypt.h:2083
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2273
#define CRYPT_IPSEC_HMAC_KEY
Definition: wincrypt.h:100
#define CUR_BLOB_VERSION
Definition: wincrypt.h:2451
#define NTE_BAD_DATA
Definition: winerror.h:4252
#define NTE_PERM
Definition: winerror.h:4263
#define NTE_BAD_TYPE
Definition: winerror.h:4257

Referenced by START_TEST().

◆ test_set_provider_ex()

static void test_set_provider_ex ( void  )
static

Definition at line 989 of file crypt.c.

990{
992 DWORD notNull = 5;
993 LPSTR curProvName = NULL;
994 DWORD curlen;
995
996 /* results */
997 LPSTR pszProvName = NULL;
998 DWORD cbProvName;
999
1000 if(!pCryptGetDefaultProviderA || !pCryptSetProviderExA)
1001 {
1002 win_skip("CryptGetDefaultProviderA and/or CryptSetProviderExA are not available\n");
1003 return;
1004 }
1005
1006 /* store the current one */
1007 pCryptGetDefaultProviderA(PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT, NULL, &curlen);
1008 if (!(curProvName = LocalAlloc(LMEM_ZEROINIT, curlen)))
1009 return;
1010 result = pCryptGetDefaultProviderA(PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT, curProvName, &curlen);
1011 ok(result, "%ld\n", GetLastError());
1012
1013 /* check pdwReserved for NULL */
1014 result = pCryptSetProviderExA(MS_DEF_PROV_A, PROV_RSA_FULL, &notNull, CRYPT_MACHINE_DEFAULT);
1015 ok(!result && GetLastError()==ERROR_INVALID_PARAMETER, "expected %i, got %ld\n",
1017
1018 /* remove the default provider and then set it to MS_DEF_PROV/PROV_RSA_FULL */
1019 SetLastError(0xdeadbeef);
1021 if (!result)
1022 {
1024 "wrong error %lu\n", GetLastError() );
1025 skip("Not enough rights to remove the default provider\n");
1026 LocalFree(curProvName);
1027 return;
1028 }
1029
1030 result = pCryptSetProviderExA(MS_DEF_PROV_A, PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT);
1031 ok(result, "%ld\n", GetLastError());
1032
1033 /* call CryptGetDefaultProvider to see if they match */
1034 result = pCryptGetDefaultProviderA(PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT, NULL, &cbProvName);
1035 ok(result, "%ld\n", GetLastError());
1036 if (!(pszProvName = LocalAlloc(LMEM_ZEROINIT, cbProvName)))
1037 goto reset;
1038
1039 result = pCryptGetDefaultProviderA(PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT, pszProvName, &cbProvName);
1040 ok(result && !strcmp(MS_DEF_PROV_A, pszProvName), "expected %s, got %s\n", MS_DEF_PROV_A, pszProvName);
1041 ok(result && cbProvName==(strlen(MS_DEF_PROV_A) + 1), "expected %i, got %ld\n", (lstrlenA(MS_DEF_PROV_A) + 1), cbProvName);
1042
1043 LocalFree(pszProvName);
1044
1045reset:
1046 /* Set the provider back to its original */
1047 result = pCryptSetProviderExA(curProvName, PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT);
1048 ok(result, "%ld\n", GetLastError());
1049 LocalFree(curProvName);
1050}
GLboolean reset
Definition: glext.h:5666
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define CRYPT_DELETE_DEFAULT
Definition: wincrypt.h:2282

Referenced by START_TEST().

◆ test_SystemFunction036()

static void test_SystemFunction036 ( void  )
static

Definition at line 1229 of file crypt.c.

1230{
1231 BOOL ret;
1232 int test;
1233
1234 if (!pSystemFunction036)
1235 {
1236 win_skip("SystemFunction036 is not available\n");
1237 return;
1238 }
1239
1240 ret = pSystemFunction036(NULL, 0);
1241 ok(ret == TRUE, "Expected SystemFunction036 to return TRUE, got %d\n", ret);
1242
1243 /* Test crashes on Windows. */
1244 if (0)
1245 {
1246 SetLastError(0xdeadbeef);
1247 ret = pSystemFunction036(NULL, 5);
1248 trace("ret = %d, GetLastError() = %ld\n", ret, GetLastError());
1249 }
1250
1251 ret = pSystemFunction036(&test, 0);
1252 ok(ret == TRUE, "Expected SystemFunction036 to return TRUE, got %d\n", ret);
1253
1254 ret = pSystemFunction036(&test, sizeof(int));
1255 ok(ret == TRUE, "Expected SystemFunction036 to return TRUE, got %d\n", ret);
1256}
#define trace
Definition: atltest.h:70
#define test
Definition: rosglue.h:37

Referenced by START_TEST().

◆ test_verify_sig()

static void test_verify_sig ( void  )
static

Definition at line 513 of file crypt.c.

514{
515 BOOL ret;
516 HCRYPTPROV prov;
519 BYTE bogus[] = { 0 };
520
521 if (!pCryptVerifySignatureW)
522 {
523 win_skip("CryptVerifySignatureW is not available\n");
524 return;
525 }
526
527 SetLastError(0xdeadbeef);
528 ret = pCryptVerifySignatureW(0, NULL, 0, 0, NULL, 0);
530 {
531 win_skip("CryptVerifySignatureW is not implemented\n");
532 return;
533 }
535 "Expected ERROR_INVALID_PARAMETER, got %08lx\n", GetLastError());
538 if (!ret && GetLastError() == NTE_EXISTS)
540 ok(ret, "CryptAcquireContextA failed: %08lx\n", GetLastError());
541 ret = CryptImportKey(prov, (LPBYTE)privKey, sizeof(privKey), 0, 0, &key);
542 ok(ret, "CryptImportKey failed: %08lx\n", GetLastError());
543 ret = CryptCreateHash(prov, CALG_MD5, 0, 0, &hash);
544 ok(ret, "CryptCreateHash failed: %08lx\n", GetLastError());
545 SetLastError(0xdeadbeef);
546 ret = pCryptVerifySignatureW(hash, NULL, 0, 0, NULL, 0);
548 "Expected ERROR_INVALID_PARAMETER, got %08lx\n", GetLastError());
549 SetLastError(0xdeadbeef);
550 ret = pCryptVerifySignatureW(0, NULL, 0, key, NULL, 0);
552 "Expected ERROR_INVALID_PARAMETER, got %08lx\n", GetLastError());
553 SetLastError(0xdeadbeef);
554 ret = pCryptVerifySignatureW(hash, NULL, 0, key, NULL, 0);
557 "Expected NTE_BAD_SIGNATURE or ERROR_INVALID_PARAMETER, got %08lx\n",
558 GetLastError());
559 SetLastError(0xdeadbeef);
560 ret = pCryptVerifySignatureW(hash, NULL, sizeof(bogus), key, NULL, 0);
563 "Expected NTE_BAD_SIGNATURE or ERROR_INVALID_PARAMETER, got %08lx\n",
564 GetLastError());
565 SetLastError(0xdeadbeef);
566 ret = pCryptVerifySignatureW(hash, bogus, 0, key, NULL, 0);
568 "Expected NTE_BAD_SIGNATURE, got %08lx\n", GetLastError());
569 SetLastError(0xdeadbeef);
570 ret = pCryptVerifySignatureW(hash, bogus, sizeof(bogus), key, NULL, 0);
571 ok(!ret &&
573 broken(GetLastError() == NTE_BAD_HASH_STATE /* older NT4 */)),
574 "Expected NTE_BAD_SIGNATURE, got %08lx\n", GetLastError());
577
578 ret = CryptReleaseContext(prov, 0);
579 ok(ret, "got %lu\n", GetLastError());
580}
static const BYTE privKey[]
Definition: crypt.c:487
Definition: _hash_fun.h:40
#define CALG_MD5
Definition: wincrypt.h:2058
#define NTE_BAD_HASH_STATE
Definition: winerror.h:4259
#define NTE_BAD_SIGNATURE
Definition: winerror.h:4253
#define NTE_EXISTS
Definition: winerror.h:4262

Referenced by START_TEST().

Variable Documentation

◆ DWORD

BYTE DWORD *static BYTE DWORD

Definition at line 37 of file crypt.c.

◆ HCRYPTKEY

Definition at line 43 of file crypt.c.

◆ key

Initial value:
=
{ 0xbf, 0xf6, 0x83, 0x4b, 0x3e, 0xa3, 0x23, 0xdd,
0x96, 0x78, 0x70, 0x8e, 0xa1, 0x9d, 0x3b, 0x40 }

Definition at line 1102 of file crypt.c.

◆ LPCWSTR

Definition at line 44 of file crypt.c.

◆ LPSTR

Definition at line 37 of file crypt.c.

◆ privKey

const BYTE privKey[]
static
Initial value:
= {
0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00,
0x02, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x79, 0x10, 0x1c, 0xd0, 0x6b, 0x10,
0x18, 0x30, 0x94, 0x61, 0xdc, 0x0e, 0xcb, 0x96, 0x4e, 0x21, 0x3f, 0x79, 0xcd,
0xa9, 0x17, 0x62, 0xbc, 0xbb, 0x61, 0x4c, 0xe0, 0x75, 0x38, 0x6c, 0xf3, 0xde,
0x60, 0x86, 0x03, 0x97, 0x65, 0xeb, 0x1e, 0x6b, 0xdb, 0x53, 0x85, 0xad, 0x68,
0x21, 0xf1, 0x5d, 0xe7, 0x1f, 0xe6, 0x53, 0xb4, 0xbb, 0x59, 0x3e, 0x14, 0x27,
0xb1, 0x83, 0xa7, 0x3a, 0x54, 0xe2, 0x8f, 0x65, 0x8e, 0x6a, 0x4a, 0xcf, 0x3b,
0x1f, 0x65, 0xff, 0xfe, 0xf1, 0x31, 0x3a, 0x37, 0x7a, 0x8b, 0xcb, 0xc6, 0xd4,
0x98, 0x50, 0x36, 0x67, 0xe4, 0xa1, 0xe8, 0x7e, 0x8a, 0xc5, 0x23, 0xf2, 0x77,
0xf5, 0x37, 0x61, 0x49, 0x72, 0x59, 0xe8, 0x3d, 0xf7, 0x60, 0xb2, 0x77, 0xca,
0x78, 0x54, 0x6d, 0x65, 0x9e, 0x03, 0x97, 0x1b, 0x61, 0xbd, 0x0c, 0xd8, 0x06,
0x63, 0xe2, 0xc5, 0x48, 0xef, 0xb3, 0xe2, 0x6e, 0x98, 0x7d, 0xbd, 0x4e, 0x72,
0x91, 0xdb, 0x31, 0x57, 0xe3, 0x65, 0x3a, 0x49, 0xca, 0xec, 0xd2, 0x02, 0x4e,
0x22, 0x7e, 0x72, 0x8e, 0xf9, 0x79, 0x84, 0x82, 0xdf, 0x7b, 0x92, 0x2d, 0xaf,
0xc9, 0xe4, 0x33, 0xef, 0x89, 0x5c, 0x66, 0x99, 0xd8, 0x80, 0x81, 0x47, 0x2b,
0xb1, 0x66, 0x02, 0x84, 0x59, 0x7b, 0xc3, 0xbe, 0x98, 0x45, 0x4a, 0x3d, 0xdd,
0xea, 0x2b, 0xdf, 0x4e, 0xb4, 0x24, 0x6b, 0xec, 0xe7, 0xd9, 0x0c, 0x45, 0xb8,
0xbe, 0xca, 0x69, 0x37, 0x92, 0x4c, 0x38, 0x6b, 0x96, 0x6d, 0xcd, 0x86, 0x67,
0x5c, 0xea, 0x54, 0x94, 0xa4, 0xca, 0xa4, 0x02, 0xa5, 0x21, 0x4d, 0xae, 0x40,
0x8f, 0x9d, 0x51, 0x83, 0xf2, 0x3f, 0x33, 0xc1, 0x72, 0xb4, 0x1d, 0x94, 0x6e,
0x7d, 0xe4, 0x27, 0x3f, 0xea, 0xff, 0xe5, 0x9b, 0xa7, 0x5e, 0x55, 0x8e, 0x0d,
0x69, 0x1c, 0x7a, 0xff, 0x81, 0x9d, 0x53, 0x52, 0x97, 0x9a, 0x76, 0x79, 0xda,
0x93, 0x32, 0x16, 0xec, 0x69, 0x51, 0x1a, 0x4e, 0xc3, 0xf1, 0x72, 0x80, 0x78,
0x5e, 0x66, 0x4a, 0x8d, 0x85, 0x2f, 0x3f, 0xb2, 0xa7 }

Definition at line 487 of file crypt.c.

Referenced by test_verify_sig().

◆ szBadKeySet

const char szBadKeySet[] = "wine_test_bad_keyset"
static

Definition at line 34 of file crypt.c.

Referenced by clean_up_environment(), init_environment(), and test_incorrect_api_usage().

◆ szKeySet

const char szKeySet[] = "wine_test_keyset"
static

◆ szNonExistentProv

const char szNonExistentProv[] = "Wine Nonexistent Cryptographic Provider v11.2"
static

Definition at line 32 of file crypt.c.

Referenced by test_acquire_context().

◆ szRsaBaseProv

◆ ULONG

Definition at line 46 of file crypt.c.