From: Elizabeth Figura zfigura@codeweavers.com
--- dlls/advapi32/advapi32.spec | 6 +- dlls/advapi32/crypt.c | 129 ----------------------------- dlls/cryptbase/Makefile.in | 1 + dlls/cryptbase/cryptbase.spec | 6 +- dlls/cryptbase/cryptbase_main.c | 140 ++++++++++++++++++++++++++++++++ tools/make_specfiles | 4 + 6 files changed, 151 insertions(+), 135 deletions(-) create mode 100644 dlls/cryptbase/cryptbase_main.c
diff --git a/dlls/advapi32/advapi32.spec b/dlls/advapi32/advapi32.spec index f45e4cb023f..79b64df8abb 100644 --- a/dlls/advapi32/advapi32.spec +++ b/dlls/advapi32/advapi32.spec @@ -812,9 +812,9 @@ @ stub SystemFunction033 @ stub SystemFunction034 @ stdcall SystemFunction035(str) cryptsp.SystemFunction035 -@ stdcall SystemFunction036(ptr long) # RtlGenRandom -@ stdcall SystemFunction040(ptr long long) # RtlEncryptMemory -@ stdcall SystemFunction041(ptr long long) # RtlDecryptMemory +@ stdcall SystemFunction036(ptr long) cryptbase.SystemFunction036 +@ stdcall SystemFunction040(ptr long long) cryptbase.SystemFunction040 +@ stdcall SystemFunction041(ptr long long) cryptbase.SystemFunction041 @ stdcall TraceEvent(int64 ptr) ntdll.EtwLogTraceEvent @ stub TraceEventInstance @ varargs TraceMessage(int64 long ptr long) ntdll.EtwTraceMessage diff --git a/dlls/advapi32/crypt.c b/dlls/advapi32/crypt.c index 03591e041e1..50dc7869422 100644 --- a/dlls/advapi32/crypt.c +++ b/dlls/advapi32/crypt.c @@ -2284,135 +2284,6 @@ DWORD WINAPI ReadEncryptedFileRaw(PFE_EXPORT_FUNC export, PVOID callback, PVOID return ERROR_CALL_NOT_IMPLEMENTED; }
-static CRITICAL_SECTION random_cs; -static CRITICAL_SECTION_DEBUG random_debug = -{ - 0, 0, &random_cs, - { &random_debug.ProcessLocksList, &random_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": random_cs") } -}; -static CRITICAL_SECTION random_cs = { &random_debug, -1, 0, 0, 0, 0 }; - -#define MAX_CPUS 256 -static char random_buf[sizeof(SYSTEM_INTERRUPT_INFORMATION) * MAX_CPUS]; -static ULONG random_len; -static ULONG random_pos; - -/* FIXME: assumes interrupt information provides sufficient randomness */ -static BOOL fill_random_buffer(void) -{ - ULONG len = sizeof(SYSTEM_INTERRUPT_INFORMATION) * min( NtCurrentTeb()->Peb->NumberOfProcessors, MAX_CPUS ); - NTSTATUS status; - - if ((status = NtQuerySystemInformation( SystemInterruptInformation, random_buf, len, NULL ))) - { - WARN( "failed to get random bytes %08lx\n", status ); - return FALSE; - } - random_len = len; - random_pos = 0; - return TRUE; -} - -/****************************************************************************** - * SystemFunction036 (ADVAPI32.@) - * - * MSDN documents this function as RtlGenRandom and declares it in ntsecapi.h - * - * PARAMS - * pbBuffer [O] Pointer to memory to receive random bytes. - * dwLen [I] Number of random bytes to fetch. - * - * RETURNS - * Success: TRUE - * Failure: FALSE - */ - -BOOLEAN WINAPI SystemFunction036( void *buffer, ULONG len ) -{ - char *ptr = buffer; - - EnterCriticalSection( &random_cs ); - while (len) - { - ULONG size; - if (random_pos >= random_len && !fill_random_buffer()) - { - SetLastError( NTE_FAIL ); - LeaveCriticalSection( &random_cs ); - return FALSE; - } - size = min( len, random_len - random_pos ); - memcpy( ptr, random_buf + random_pos, size ); - random_pos += size; - ptr += size; - len -= size; - } - LeaveCriticalSection( &random_cs ); - return TRUE; -} - -/* - These functions have nearly identical prototypes to CryptProtectMemory and CryptUnprotectMemory, - in crypt32.dll. - */ - -/****************************************************************************** - * SystemFunction040 (ADVAPI32.@) - * - * MSDN documents this function as RtlEncryptMemory and declares it in ntsecapi.h. - * - * PARAMS - * memory [I/O] Pointer to memory to encrypt. - * length [I] Length of region to encrypt in bytes. - * flags [I] Control whether other processes are able to decrypt the memory. - * RTL_ENCRYPT_OPTION_SAME_PROCESS - * RTL_ENCRYPT_OPTION_CROSS_PROCESS - * RTL_ENCRYPT_OPTION_SAME_LOGON - * - * RETURNS - * Success: STATUS_SUCCESS - * Failure: NTSTATUS error code - * - * NOTES - * length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE. - * If flags are specified when encrypting, the same flag value must be given - * when decrypting the memory. - */ -NTSTATUS WINAPI SystemFunction040(PVOID memory, ULONG length, ULONG flags) -{ - FIXME("(%p, %lx, %lx): stub [RtlEncryptMemory]\n", memory, length, flags); - return STATUS_SUCCESS; -} - -/****************************************************************************** - * SystemFunction041 (ADVAPI32.@) - * - * MSDN documents this function as RtlDecryptMemory and declares it in ntsecapi.h. - * - * PARAMS - * memory [I/O] Pointer to memory to decrypt. - * length [I] Length of region to decrypt in bytes. - * flags [I] Control whether other processes are able to decrypt the memory. - * RTL_ENCRYPT_OPTION_SAME_PROCESS - * RTL_ENCRYPT_OPTION_CROSS_PROCESS - * RTL_ENCRYPT_OPTION_SAME_LOGON - * - * RETURNS - * Success: STATUS_SUCCESS - * Failure: NTSTATUS error code - * - * NOTES - * length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE. - * If flags are specified when encrypting, the same flag value must be given - * when decrypting the memory. - */ -NTSTATUS WINAPI SystemFunction041(PVOID memory, ULONG length, ULONG flags) -{ - FIXME("(%p, %lx, %lx): stub [RtlDecryptMemory]\n", memory, length, flags); - return STATUS_SUCCESS; -} - /****************************************************************************** * WriteEncryptedFileRaw (ADVAPI32.@) * diff --git a/dlls/cryptbase/Makefile.in b/dlls/cryptbase/Makefile.in index eb651765c8a..32742f897d4 100644 --- a/dlls/cryptbase/Makefile.in +++ b/dlls/cryptbase/Makefile.in @@ -1,4 +1,5 @@ MODULE = cryptbase.dll
SOURCES = \ + cryptbase_main.c \ des.c diff --git a/dlls/cryptbase/cryptbase.spec b/dlls/cryptbase/cryptbase.spec index 3fa0102fc33..ebd836df365 100644 --- a/dlls/cryptbase/cryptbase.spec +++ b/dlls/cryptbase/cryptbase.spec @@ -6,6 +6,6 @@ @ stub SystemFunction028 @ stub SystemFunction029 @ stub SystemFunction034 -@ stub SystemFunction036 -@ stub SystemFunction040 -@ stub SystemFunction041 +@ stdcall SystemFunction036(ptr long) +@ stdcall SystemFunction040(ptr long long) +@ stdcall SystemFunction041(ptr long long) diff --git a/dlls/cryptbase/cryptbase_main.c b/dlls/cryptbase/cryptbase_main.c new file mode 100644 index 00000000000..daa3e8ff21d --- /dev/null +++ b/dlls/cryptbase/cryptbase_main.c @@ -0,0 +1,140 @@ +/* + * Copyright 1999 Ian Schmidt + * Copyright 2001 Travis Michielsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdarg.h> +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "windef.h" +#include "winternl.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(crypt); + +static CRITICAL_SECTION random_cs; +static CRITICAL_SECTION_DEBUG random_debug = +{ + 0, 0, &random_cs, + { &random_debug.ProcessLocksList, &random_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": random_cs") } +}; +static CRITICAL_SECTION random_cs = { &random_debug, -1, 0, 0, 0, 0 }; + +#define MAX_CPUS 256 +static char random_buf[sizeof(SYSTEM_INTERRUPT_INFORMATION) * MAX_CPUS]; +static ULONG random_len; +static ULONG random_pos; + +/* FIXME: assumes interrupt information provides sufficient randomness */ +static BOOL fill_random_buffer(void) +{ + ULONG len = sizeof(SYSTEM_INTERRUPT_INFORMATION) * min( NtCurrentTeb()->Peb->NumberOfProcessors, MAX_CPUS ); + NTSTATUS status; + + if ((status = NtQuerySystemInformation( SystemInterruptInformation, random_buf, len, NULL ))) + { + WARN( "failed to get random bytes, status %#lx\n", status ); + return FALSE; + } + random_len = len; + random_pos = 0; + return TRUE; +} + +/****************************************************************************** + * SystemFunction036 (cryptbase.@) + */ +BOOLEAN WINAPI SystemFunction036( void *buffer, ULONG len ) +{ + char *ptr = buffer; + + EnterCriticalSection( &random_cs ); + while (len) + { + ULONG size; + if (random_pos >= random_len && !fill_random_buffer()) + { + SetLastError( NTE_FAIL ); + LeaveCriticalSection( &random_cs ); + return FALSE; + } + size = min( len, random_len - random_pos ); + memcpy( ptr, random_buf + random_pos, size ); + random_pos += size; + ptr += size; + len -= size; + } + LeaveCriticalSection( &random_cs ); + return TRUE; +} + +/****************************************************************************** + * SystemFunction040 (cryptbase.@) + * + * MSDN documents this function as RtlEncryptMemory and declares it in ntsecapi.h. + * + * PARAMS + * memory [I/O] Pointer to memory to encrypt. + * length [I] Length of region to encrypt in bytes. + * flags [I] Control whether other processes are able to decrypt the memory. + * RTL_ENCRYPT_OPTION_SAME_PROCESS + * RTL_ENCRYPT_OPTION_CROSS_PROCESS + * RTL_ENCRYPT_OPTION_SAME_LOGON + * + * RETURNS + * Success: STATUS_SUCCESS + * Failure: NTSTATUS error code + * + * NOTES + * length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE. + * If flags are specified when encrypting, the same flag value must be given + * when decrypting the memory. + */ +NTSTATUS WINAPI SystemFunction040( void *memory, ULONG length, ULONG flags ) +{ + FIXME("(%p, %lu, %#lx): stub [RtlEncryptMemory]\n", memory, length, flags); + return STATUS_SUCCESS; +} + +/****************************************************************************** + * SystemFunction041 (cryptbase.@) + * + * MSDN documents this function as RtlDecryptMemory and declares it in ntsecapi.h. + * + * PARAMS + * memory [I/O] Pointer to memory to decrypt. + * length [I] Length of region to decrypt in bytes. + * flags [I] Control whether other processes are able to decrypt the memory. + * RTL_ENCRYPT_OPTION_SAME_PROCESS + * RTL_ENCRYPT_OPTION_CROSS_PROCESS + * RTL_ENCRYPT_OPTION_SAME_LOGON + * + * RETURNS + * Success: STATUS_SUCCESS + * Failure: NTSTATUS error code + * + * NOTES + * length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE. + * If flags are specified when encrypting, the same flag value must be given + * when decrypting the memory. + */ +NTSTATUS WINAPI SystemFunction041( void *memory, ULONG length, ULONG flags ) +{ + FIXME( "(%p, %lu, %#lx): stub [RtlDecryptMemory]\n", memory, length, flags ); + return STATUS_SUCCESS; +} diff --git a/tools/make_specfiles b/tools/make_specfiles index 0509d41d5c1..48518213201 100755 --- a/tools/make_specfiles +++ b/tools/make_specfiles @@ -97,6 +97,10 @@ my @dll_groups = "advapi32", "sechost", ], + [ + "cryptbase", + "advapi32", + ], [ "netapi32", "srvcli",