* Sync up to trunk head (r64377).
[reactos.git] / dll / win32 / bcrypt / bcrypt_main.c
1 /*
2 * Copyright 2009 Henri Verbeet for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 *
18 */
19
20 #include <wine/config.h>
21
22 #include <ntstatus.h>
23 #define WIN32_NO_STATUS
24
25 #include <wine/debug.h>
26
27 #include <winbase.h>
28 #include <ntsecapi.h>
29 #include <bcrypt.h>
30
31 WINE_DEFAULT_DEBUG_CHANNEL(bcrypt);
32
33 NTSTATUS WINAPI BCryptEnumAlgorithms(ULONG dwAlgOperations, ULONG *pAlgCount,
34 BCRYPT_ALGORITHM_IDENTIFIER **ppAlgList, ULONG dwFlags)
35 {
36 FIXME("%08x, %p, %p, %08x - stub\n", dwAlgOperations, pAlgCount, ppAlgList, dwFlags);
37
38 *ppAlgList=NULL;
39 *pAlgCount=0;
40
41 return STATUS_NOT_IMPLEMENTED;
42 }
43
44 NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE algorithm, UCHAR *buffer, ULONG count, ULONG flags)
45 {
46 const DWORD supported_flags = BCRYPT_USE_SYSTEM_PREFERRED_RNG;
47 TRACE("%p, %p, %u, %08x - semi-stub\n", algorithm, buffer, count, flags);
48
49 if (!algorithm)
50 {
51 /* It's valid to call without an algorithm if BCRYPT_USE_SYSTEM_PREFERRED_RNG
52 * is set. In this case the preferred system RNG is used.
53 */
54 if (!(flags & BCRYPT_USE_SYSTEM_PREFERRED_RNG))
55 return STATUS_INVALID_HANDLE;
56 }
57 if (!buffer)
58 return STATUS_INVALID_PARAMETER;
59
60 if (flags & ~supported_flags)
61 FIXME("unsupported flags %08x\n", flags & ~supported_flags);
62
63 if (algorithm)
64 FIXME("ignoring selected algorithm\n");
65
66 /* When zero bytes are requested the function returns success too. */
67 if (!count)
68 return STATUS_SUCCESS;
69
70 if (flags & BCRYPT_USE_SYSTEM_PREFERRED_RNG)
71 {
72 if (RtlGenRandom(buffer, count))
73 return STATUS_SUCCESS;
74 }
75
76 FIXME("called with unsupported parameters, returning error\n");
77 return STATUS_NOT_IMPLEMENTED;
78 }
79
80 NTSTATUS WINAPI BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE *algorithm, LPCWSTR algorithmId,
81 LPCWSTR implementation, DWORD flags)
82 {
83 FIXME("%p, %s, %s, %08x - stub\n", algorithm, wine_dbgstr_w(algorithmId), wine_dbgstr_w(implementation), flags);
84
85 if (!algorithm)
86 return STATUS_INVALID_PARAMETER;
87
88 *algorithm = NULL;
89
90 return STATUS_NOT_IMPLEMENTED;
91 }
92
93 NTSTATUS WINAPI BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE algorithm, DWORD flags)
94 {
95 FIXME("%p, %08x - stub\n", algorithm, flags);
96
97 return STATUS_NOT_IMPLEMENTED;
98 }
99
100 NTSTATUS WINAPI BCryptGetFipsAlgorithmMode(BOOLEAN *enabled)
101 {
102 FIXME("%p - semi-stub\n", enabled);
103
104 if (!enabled)
105 return STATUS_INVALID_PARAMETER;
106
107 *enabled = FALSE;
108 return STATUS_SUCCESS;
109 }