Allow the implementation of the VxDCall entry points to be moved to
[wine] / dlls / rsabase / main.c
1 /*
2  * RSABASE - RSA encryption for Wine
3  *
4  * Copyright 2004 Mike McCormack for Codeweavers
5  * Copyright 2002 Transgaming Technologies
6  *
7  * David Hammerton
8  *
9  * (based upon code from dlls/wininet/netconnection.c)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public 
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
25  */
26
27
28 #include "config.h"
29 #include "wine/port.h"
30
31 #include <stdarg.h>
32
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wincrypt.h"
36
37 #ifdef HAVE_OPENSSL_SSL_H
38 #define DSA __ssl_DSA  /* avoid conflict with commctrl.h */
39 #undef FAR
40 # include <openssl/rand.h>
41 #undef FAR
42 #define FAR do_not_use_this_in_wine
43 #undef DSA
44 #endif
45
46 #include "wine/library.h"
47 #include "wine/debug.h"
48
49 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
50
51 #define RSABASE_MAGIC 0x52534100
52
53 #ifdef HAVE_OPENSSL_SSL_H
54
55 #ifndef SONAME_LIBCRYPTO
56 #define SONAME_LIBCRYPTO "libcrypto.so"
57 #endif
58
59 static void *libcrypto;
60
61 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
62
63 /* OpenSSL funtions that we use */
64 MAKE_FUNCPTR(RAND_bytes);
65
66 static BOOL load_libcrypto( void )
67 {
68     libcrypto = wine_dlopen(SONAME_LIBCRYPTO, RTLD_NOW, NULL, 0);
69     if (!libcrypto)
70     {
71         MESSAGE("Couldn't load %s, RSA encryption not available.\n", SONAME_LIBCRYPTO);
72         MESSAGE("Install the openssl package if you're have problems.\n");
73         return FALSE;
74     }
75
76     #define GETFUNC(x) \
77     p##x = wine_dlsym(libcrypto, #x, NULL, 0); \
78     if (!p##x) \
79     { \
80         ERR("failed to load symbol %s\n", #x); \
81         return FALSE; \
82     }
83
84     GETFUNC(RAND_bytes);
85
86     return TRUE;
87 }
88
89 #endif
90
91 typedef struct _RSA_CryptProv
92 {
93     DWORD dwMagic;
94 } RSA_CryptProv;
95
96 BOOL WINAPI RSA_CPAcquireContext(HCRYPTPROV *phProv, LPSTR pszContainer,
97                    DWORD dwFlags, PVTableProvStruc pVTable)
98 {
99     BOOL ret = FALSE;
100     RSA_CryptProv *cp;
101
102     TRACE("%p %s %08lx %p\n", phProv, debugstr_a(pszContainer),
103            dwFlags, pVTable);
104
105 #ifdef HAVE_OPENSSL_SSL_H
106
107     if( !load_libcrypto() )
108         return FALSE;
109
110     cp = HeapAlloc( GetProcessHeap(), 0, sizeof (RSA_CryptProv) );
111     if( !cp )
112     {
113         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
114         return FALSE;
115     }
116
117     cp->dwMagic = RSABASE_MAGIC;
118
119     *phProv = (HCRYPTPROV) cp;
120     ret = TRUE;
121
122 #endif
123
124     return ret;
125 }
126
127 BOOL WINAPI RSA_CPCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
128 {
129     FIXME("%08lx %d %08lx %08lx %p\n", hProv, Algid, hKey, dwFlags, phHash);
130     return FALSE;
131 }
132
133 BOOL WINAPI RSA_CPDecrypt(HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
134 {
135     FIXME("(stub)\n");
136     return FALSE;
137 }
138
139 BOOL WINAPI RSA_CPDeriveKey(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTHASH hBaseData, DWORD dwFlags, HCRYPTKEY *phKey)
140 {
141     FIXME("(stub)\n");
142     return FALSE;
143 }
144
145 BOOL WINAPI RSA_CPDestroyHash(HCRYPTPROV hProv, HCRYPTHASH hHash)
146 {
147     FIXME("(stub)\n");
148     return FALSE;
149 }
150
151 BOOL WINAPI RSA_CPDestroyKey(HCRYPTPROV hProv, HCRYPTKEY hKey)
152 {
153     FIXME("(stub)\n");
154     return FALSE;
155 }
156
157 BOOL WINAPI RSA_CPDuplicateHash(HCRYPTPROV hUID, HCRYPTHASH hHash, DWORD *pdwReserved, DWORD dwFlags, HCRYPTHASH *phHash)
158 {
159     FIXME("(stub)\n");
160     return FALSE;
161 }
162
163 BOOL WINAPI RSA_CPDuplicateKey(HCRYPTPROV hUID, HCRYPTKEY hKey, DWORD *pdwReserved, DWORD dwFlags, HCRYPTKEY *phKey)
164 {
165     FIXME("(stub)\n");
166     return FALSE;
167 }
168
169 BOOL WINAPI RSA_CPEncrypt(HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen)
170 {
171     FIXME("(stub)\n");
172     return FALSE;
173 }
174
175 BOOL WINAPI RSA_CPExportKey(HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTKEY hPubKey, DWORD dwBlobType, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
176 {
177     FIXME("(stub)\n");
178     return FALSE;
179 }
180
181 BOOL WINAPI RSA_CPGenKey(HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY *phKey)
182 {
183     FIXME("(stub)\n");
184     return FALSE;
185 }
186
187 BOOL WINAPI RSA_CPGenRandom(HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer)
188 {
189     BOOL ret = FALSE;
190     RSA_CryptProv *cp = (RSA_CryptProv*) hProv;
191
192     TRACE("%08lx %ld %p\n", hProv, dwLen, pbBuffer);
193
194     if( cp && ( cp->dwMagic != RSABASE_MAGIC ) )
195         return FALSE;
196
197 #ifdef HAVE_OPENSSL_SSL_H
198
199     if( !pRAND_bytes)
200         return FALSE;
201     ret = pRAND_bytes( pbBuffer, dwLen );
202
203 #endif
204
205     return ret;
206 }
207
208 BOOL WINAPI RSA_CPGetHashParam(HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
209 {
210     FIXME("(stub)\n");
211     return FALSE;
212 }
213
214 BOOL WINAPI RSA_CPGetKeyParam(HCRYPTPROV hProv, HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
215 {
216     FIXME("(stub)\n");
217     return FALSE;
218 }
219
220 BOOL WINAPI RSA_CPGetProvParam(HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
221 {
222     FIXME("(stub)\n");
223     return FALSE;
224 }
225
226 BOOL WINAPI RSA_CPGetUserKey(HCRYPTPROV hProv, DWORD dwKeySpec, HCRYPTKEY *phUserKey)
227 {
228     FIXME("(stub)\n");
229     return FALSE;
230 }
231
232 BOOL WINAPI RSA_CPHashData(HCRYPTPROV hProv, HCRYPTHASH hHash, CONST BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
233 {
234     FIXME("(stub)\n");
235     return FALSE;
236 }
237
238 BOOL WINAPI RSA_CPHashSessionKey(HCRYPTPROV hProv, HCRYPTHASH hHash, HCRYPTKEY hKey, DWORD dwFlags)
239 {
240     FIXME("(stub)\n");
241     return FALSE;
242 }
243
244 BOOL WINAPI RSA_CPImportKey(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
245 {
246     FIXME("(stub)\n");
247     return FALSE;
248 }
249
250 BOOL WINAPI RSA_CPReleaseContext(HCRYPTPROV hProv, DWORD dwFlags)
251 {
252     RSA_CryptProv *cp = (RSA_CryptProv*) hProv;
253
254     TRACE("%08lx %08lx\n", hProv, dwFlags);
255
256     if( cp && ( cp->dwMagic != RSABASE_MAGIC ) )
257         return FALSE;
258
259     HeapFree( GetProcessHeap(), 0, cp );
260
261     return TRUE;
262 }
263
264 BOOL WINAPI RSA_CPSetHashParam(HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD dwFlags)
265 {
266     FIXME("(stub)\n");
267     return FALSE;
268 }
269
270 BOOL WINAPI RSA_CPSetKeyParam(HCRYPTPROV hProv, HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData, DWORD dwFlags)
271 {
272     FIXME("(stub)\n");
273     return FALSE;
274 }
275
276 BOOL WINAPI RSA_CPSetProvParam(HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData, DWORD dwFlags)
277 {
278     FIXME("(stub)\n");
279     return FALSE;
280 }
281
282 BOOL WINAPI RSA_CPSignHash(HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwKeySpec, LPCWSTR sDescription, DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
283 {
284     FIXME("(stub)\n");
285     return FALSE;
286 }
287
288 BOOL WINAPI RSA_CPVerifySignature(HCRYPTPROV hProv, HCRYPTHASH hHash, CONST BYTE *pbSignature, DWORD dwSigLen, HCRYPTKEY hPubKey, LPCWSTR sDescription, DWORD dwFlags)
289 {
290     FIXME("(stub)\n");
291     return FALSE;
292 }
293
294 /***********************************************************************
295  *              DllRegisterServer (RSABASE.@)
296  */
297 HRESULT WINAPI RSABASE_DllRegisterServer()
298 {
299     FIXME("\n");
300     return S_OK;
301 }
302
303 /***********************************************************************
304  *              DllUnregisterServer (RSABASE.@)
305  */
306 HRESULT WINAPI RSABASE_DllUnregisterServer()
307 {
308     FIXME("\n");
309     return S_OK;
310 }