- Implement cases 2 & 4 of RtlSplayTree
[reactos.git] / reactos / lib / rtl / encode.c
1 /* COPYRIGHT: See COPYING in the top level directory
2 * PROJECT: ReactOS system libraries
3 * PURPOSE: Security descriptor functions
4 * FILE: lib/rtl/encode.c
5 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
6 * (code contributed by crazylord <crazyl0rd@minithins.net>)
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include <rtl.h>
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* FUNCTIONS ***************************************************************/
17
18 VOID NTAPI
19 RtlRunDecodeUnicodeString (IN UCHAR Hash,
20 IN OUT PUNICODE_STRING String)
21 {
22 PUCHAR ptr;
23 USHORT i;
24
25 ptr = (PUCHAR)String->Buffer;
26 if (String->Length > 1)
27 {
28 for (i = String->Length; i > 1; i--)
29 {
30 ptr[i - 1] ^= ptr[i - 2] ^ Hash;
31 }
32 }
33
34 if (String->Length >= 1)
35 {
36 ptr[0] ^= Hash | (UCHAR)0x43;
37 }
38 }
39
40
41 VOID NTAPI
42 RtlRunEncodeUnicodeString (IN OUT PUCHAR Hash,
43 IN OUT PUNICODE_STRING String)
44 {
45 LARGE_INTEGER CurrentTime;
46 PUCHAR ptr;
47 USHORT i;
48 NTSTATUS Status;
49
50 ptr = (PUCHAR) String->Buffer;
51 if (*Hash == 0)
52 {
53 Status = NtQuerySystemTime (&CurrentTime);
54 if (NT_SUCCESS(Status))
55 {
56 for (i = 1; i < sizeof(LARGE_INTEGER) && (*Hash == 0); i++)
57 *Hash |= *(PUCHAR)(((PUCHAR)&CurrentTime) + i);
58 }
59
60 if (*Hash == 0)
61 *Hash = 1;
62 }
63
64 if (String->Length >= 1)
65 {
66 ptr[0] ^= (*Hash) | (UCHAR)0x43;
67 if (String->Length > 1)
68 {
69 for (i = 1; i < String->Length; i++)
70 {
71 ptr[i] ^= ptr[i - 1] ^ (*Hash);
72 }
73 }
74 }
75 }
76
77 /* EOF */