diff --git a/reactos/include/ndk/umtypes.h b/reactos/include/ndk/umtypes.h index 10ea029a24f..0efd600ace9 100644 --- a/reactos/include/ndk/umtypes.h +++ b/reactos/include/ndk/umtypes.h @@ -184,6 +184,11 @@ #define VER_CONDITION_MASK 7 #define VER_NUM_BITS_PER_CONDITION_MASK 3 +/* RTL String Hash Algorithms */ +#define HASH_STRING_ALGORITHM_DEFAULT 0 +#define HASH_STRING_ALGORITHM_X65599 1 +#define HASH_STRING_ALGORITHM_INVALID 0xffffffff + /* List Macros */ static __inline VOID diff --git a/reactos/lib/ntdll/def/ntdll.def b/reactos/lib/ntdll/def/ntdll.def index 30cf30f4379..ba8329751de 100644 --- a/reactos/lib/ntdll/def/ntdll.def +++ b/reactos/lib/ntdll/def/ntdll.def @@ -475,6 +475,7 @@ RtlGetSaclSecurityDescriptor@16 RtlGetSecurityDescriptorRMControl@8 ;RtlGetUserInfoHeap RtlGetVersion@4 +RtlHashUnicodeString@16 RtlIdentifierAuthoritySid@4 RtlImageDirectoryEntryToData@16 RtlImageNtHeader@4 diff --git a/reactos/lib/rtl/unicode.c b/reactos/lib/rtl/unicode.c index c0769a0302a..e26aa6e0c0b 100644 --- a/reactos/lib/rtl/unicode.c +++ b/reactos/lib/rtl/unicode.c @@ -1603,19 +1603,55 @@ RtlEraseUnicodeString( } /* -* @unimplemented +* @implemented */ NTSTATUS STDCALL RtlHashUnicodeString( - IN const UNICODE_STRING *String, - IN BOOLEAN CaseInSensitive, - IN ULONG HashAlgorithm, - OUT PULONG HashValue - ) + IN CONST UNICODE_STRING *String, + IN BOOLEAN CaseInSensitive, + IN ULONG HashAlgorithm, + OUT PULONG HashValue) { - UNIMPLEMENTED; - return STATUS_NOT_IMPLEMENTED; + if (String != NULL && HashValue != NULL) + { + switch (HashAlgorithm) + { + case HASH_STRING_ALGORITHM_DEFAULT: + case HASH_STRING_ALGORITHM_X65599: + { + WCHAR *c, *end; + + *HashValue = 0; + end = String->Buffer + (String->Length / sizeof(WCHAR)); + + if (CaseInSensitive) + { + for (c = String->Buffer; + c != end; + c++) + { + /* only uppercase characters if they are 'a' ... 'z'! */ + *HashValue = ((65599 * (*HashValue)) + + (ULONG)(((*c) >= L'a' && (*c) <= L'z') ? + (*c) - L'a' + L'A' : (*c))); + } + } + else + { + for (c = String->Buffer; + c != end; + c++) + { + *HashValue = ((65599 * (*HashValue)) + (ULONG)(*c)); + } + } + return STATUS_SUCCESS; + } + } + } + + return STATUS_INVALID_PARAMETER; } /*